Skip to content

Commit 6972e38

Browse files
committed
Improved the description of loadable and address-only types
Added a missing requirement that loadable types must be loaded and stored in terms of their parts. Added some examples of loadable and address-only types that are not expressible in Swift today but help illustrate the concepts.
1 parent 7e6d62d commit 6972e38

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

docs/SIL.rst

Lines changed: 24 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,20 @@ 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. For example:
722+
723+
* Addresses of values of Swift ``@weak`` types are registered in a global
724+
table. That table needs to be adjusted when a ``@weak`` value is copied
725+
or moved to a new address.
726+
727+
* A non-COW collection type with a heap allocation needs to allocate memory
728+
and copy the collection elements when the collection is copied.
729+
730+
* A non-COW string type with an SSO buffer (like ``std::string`` in C++)
731+
can contain a pointer into the value itself. That pointer needs to be
732+
recomputed when the string is copied or moved.
709733

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

0 commit comments

Comments
 (0)