Skip to content

Commit c510ae2

Browse files
authored
Merge pull request #31556 from gribozavr/improve-sil-rst
Improved the description of loadable and address-only types
2 parents 9574be1 + b384bf9 commit c510ae2

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/SIL.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,16 @@ generic constraints:
686686
* Class protocol types
687687
* Archetypes constrained by a class protocol
688688

689+
Values of loadable types are loaded and stored by loading and storing
690+
individual components of their representation. As a consequence:
691+
692+
* values of loadable types can be loaded into SIL SSA values and stored
693+
from SSA values into memory without running any user-written code,
694+
although compiler-generated reference counting operations can happen.
695+
696+
* values of loadable types can be take-initialized (moved between
697+
memory locations) with a bitwise copy.
698+
689699
A *loadable aggregate type* is a tuple or struct type that is loadable.
690700

691701
A *trivial type* is a loadable type with trivial value semantics.
@@ -706,6 +716,25 @@ generic constraints:
706716
* Runtime-sized types
707717
* Non-class protocol types
708718
* @weak types
719+
* Types that can't satisfy the requirements for being loadable because they
720+
care about the exact location of their value in memory and need to run some
721+
user-written code when they are copied or moved. Most commonly, types "care"
722+
about the addresses of values because addresses of values are registered in
723+
some global data structure, or because values may contain pointers into
724+
themselves. For example:
725+
726+
* Addresses of values of Swift ``@weak`` types are registered in a global
727+
table. That table needs to be adjusted when a ``@weak`` value is copied
728+
or moved to a new address.
729+
730+
* A non-COW collection type with a heap allocation (like ``std::vector`` in
731+
C++) needs to allocate memory and copy the collection elements when the
732+
collection is copied.
733+
734+
* A non-COW string type that implements a small string optimization (like
735+
many implementations of ``std::string`` in C++) can contain a pointer
736+
into the value itself. That pointer needs to be recomputed when the
737+
string is copied or moved.
709738

710739
Values of address-only type ("address-only values") must reside in
711740
memory and can only be referenced in SIL by address. Addresses of

0 commit comments

Comments
 (0)