Skip to content

Commit e5eede5

Browse files
authored
Merge pull request #67574 from jckarter/raw-layout-doc-clarify
Clarify a statement in the @_rawLayout docs
2 parents a22bd27 + 523d7aa commit e5eede5

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

docs/ReferenceGuides/UnderscoredAttributes.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -851,20 +851,22 @@ the memory of the annotated type:
851851

852852
- A value has a **stable address** until it is either consumed or moved.
853853
No value of any type in Swift can ever be moved while it is being borrowed or
854-
mutated, so the address of `self` within a `borrowing` or `mutating` method,
855-
or more generally the address of a `borrowing` or `inout` parameter to any
856-
function, cannot change within the function body. Values that appear in a
857-
global variable or class stored property can never be moved, and can only be
858-
consumed by the deallocation of the containing object instance, so
859-
effectively has a stable address for their entire lifetime.
854+
mutated, so for a `@_rawLayout` type, the address of `self` within a
855+
`borrowing` or `mutating` method cannot change within the function body, and
856+
the same is true more generally for the address of any `@_rawLayout` typed
857+
parameter that is `borrowing` or `mutating` in any function or method.
858+
Values that appear in a global variable or class stored property can never be
859+
moved, and can only be consumed by the deallocation of the containing object
860+
instance, so effectively has a stable address for their entire lifetime.
860861
- A value's memory **may be read and mutated at any time** independent of
861862
formal accesses. In particular, pointers into the storage may be "escaped"
862-
outside of scopes where the address is statically guaranteed to be stable, and
863-
those pointers may be used freely for as long as the storage dynamically
863+
outside of scopes where the address is statically guaranteed to be stable,
864+
and those pointers may be used freely for as long as the storage dynamically
864865
isn't consumed or moved. It becomes the programmer's responsibility in this
865866
case to ensure that reads and writes to the storage do not race across
866867
threads, writes don't overlap with reads or writes coming from the same
867-
thread, and that the pointer is not used after the value is moved or consumed.
868+
thread, and that the pointer is not used after the value is moved or
869+
consumed.
868870
- When the value is moved, a bitwise copy of its memory is performed to the new
869871
address of the value in its new owner. As currently implemented, raw storage
870872
types are not suitable for storing values which are not bitwise-movable, such

0 commit comments

Comments
 (0)