Skip to content

Commit bd4a60f

Browse files
committed
[sil] Add some small docs for copy_value, destroy_value, end_borrow, load_borrow.
rdar://28851920
1 parent c2279d2 commit bd4a60f

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

docs/SIL.rst

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,6 +2166,48 @@ requires ``release`` or other cleanup, that value must be loaded before being
21662166
stored over and cleaned up. It is undefined behavior to store to an address
21672167
that points to deallocated storage.
21682168

2169+
load_borrow
2170+
```````````
2171+
2172+
::
2173+
2174+
sil-instruction ::= 'load_borrow' sil-value
2175+
2176+
%1 = load_borrow %0 : $*T
2177+
// $T must be a loadable type
2178+
2179+
Loads the value ``%1`` from the memory location ``%0``. The ``load_borrow``
2180+
instruction creates a borrowed scope in which a read-only borrow value ``%1``
2181+
can be used to read the value stored in ``%0``. The end of scope is deliminated
2182+
by an ``end_borrow`` instruction. All ``load_borrow`` instructions must be
2183+
paired with exactly one ``end_borrow`` instruction along any path through the
2184+
program. Until ``end_borrow``, it is illegal to invalidate or store to ``%0``.
2185+
2186+
end_borrow
2187+
``````````
2188+
2189+
::
2190+
2191+
sil-instruction ::= 'end_borrow' sil-value 'from' sil-value : sil-type, sil-type
2192+
2193+
end_borrow %1 from %0 : $T, $T
2194+
end_borrow %1 from %0 : $T, $*T
2195+
end_borrow %1 from %0 : $*T, $T
2196+
end_borrow %1 from %0 : $*T, $*T
2197+
// We allow for end_borrow to be specified in between values and addresses
2198+
// all of the same type T.
2199+
2200+
Ends the scope for which the SILValue ``%1`` is borrowed from the SILValue
2201+
``%0``. Must be paired with at most 1 borrowing instruction (like
2202+
``load_borrow``) along any path through the program. In the region in between
2203+
the borrow instruction and the ``end_borrow``, the original SILValue can not be
2204+
modified. This means that:
2205+
2206+
1. If ``%0`` is an address, ``%0`` can not be written to.
2207+
2. If ``%0`` is a non-trivial value, ``%0`` can not be destroyed.
2208+
2209+
We require that ``%1`` and ``%0`` have the same type ignoring SILValueCategory.
2210+
21692211
assign
21702212
``````
21712213
::
@@ -3191,6 +3233,32 @@ For aggregate types, especially enums, it is typically both easier
31913233
and more efficient to reason about aggregate copies than it is to
31923234
reason about copies of the subobjects.
31933235

3236+
copy_value
3237+
``````````
3238+
3239+
::
3240+
3241+
sil-instruction ::= 'copy_value' sil-operand
3242+
3243+
%1 = copy_value %0 : $A
3244+
3245+
Performs a copy of a loadable value as if by the value's type lowering and
3246+
returns the copy. The returned copy semantically is a value that is completely
3247+
independent of the operand. In terms of specific types:
3248+
3249+
1. For trivial types, this is equivalent to just propagating through the trivial
3250+
value.
3251+
2. For reference types, this is equivalent to performing a ``strong_retain``
3252+
operation and returning the reference.
3253+
3. For ``@unowned`` types, this is equivalent to performing an
3254+
``unowned_retain`` and returning the operand.
3255+
4. For aggregate types, this is equivalent to recursively performing a
3256+
``copy_value`` on its components, forming a new aggregate from the copied
3257+
components, and then returning the new aggregate.
3258+
3259+
In ownership qualified functions, a ``copy_value`` produces a +1 value that must
3260+
be consumed at most once along any path through the program.
3261+
31943262
release_value
31953263
`````````````
31963264

@@ -3214,6 +3282,29 @@ For aggregate types, especially enums, it is typically both easier
32143282
and more efficient to reason about aggregate destroys than it is to
32153283
reason about destroys of the subobjects.
32163284

3285+
destroy_value
3286+
`````````````
3287+
3288+
::
3289+
3290+
sil-instruction ::= 'destroy_value' sil-operand
3291+
3292+
destroy_value %0 : $A
3293+
3294+
Destroys a loadable value, by releasing any retainable pointers within it.
3295+
3296+
This is defined to be equivalent to storing the operand into a stack
3297+
allocation and using 'destroy_addr' to destroy the object there.
3298+
3299+
For trivial types, this is a no-op. For reference types, this is
3300+
equivalent to a ``strong_release``. For ``@unowned`` types, this is
3301+
equivalent to an ``unowned_release``. In each of these cases, those
3302+
are the preferred forms.
3303+
3304+
For aggregate types, especially enums, it is typically both easier
3305+
and more efficient to reason about aggregate destroys than it is to
3306+
reason about destroys of the subobjects.
3307+
32173308
autorelease_value
32183309
`````````````````
32193310

0 commit comments

Comments
 (0)