Skip to content

Commit c1a9f6f

Browse files
authored
Merge pull request #36078 from gottesmm/silrst-improvements
[sil.rst] Just added some docs for begin_borrow, updated end_borrow syntax, adding more inline links.
2 parents ad8e624 + a78458c commit c1a9f6f

File tree

1 file changed

+34
-20
lines changed

1 file changed

+34
-20
lines changed

docs/SIL.rst

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3540,43 +3540,57 @@ load_borrow
35403540
%1 = load_borrow %0 : $*T
35413541
// $T must be a loadable type
35423542

3543-
Loads the value ``%1`` from the memory location ``%0``. The ``load_borrow``
3543+
Loads the value ``%1`` from the memory location ``%0``. The `load_borrow`_
35443544
instruction creates a borrowed scope in which a read-only borrow value ``%1``
35453545
can be used to read the value stored in ``%0``. The end of scope is delimited
3546-
by an ``end_borrow`` instruction. All ``load_borrow`` instructions must be
3547-
paired with exactly one ``end_borrow`` instruction along any path through the
3548-
program. Until ``end_borrow``, it is illegal to invalidate or store to ``%0``.
3546+
by an `end_borrow`_ instruction. All `load_borrow`_ instructions must be
3547+
paired with exactly one `end_borrow`_ instruction along any path through the
3548+
program. Until `end_borrow`_, it is illegal to invalidate or store to ``%0``.
35493549

35503550
begin_borrow
35513551
````````````
35523552

3553-
TODO
3553+
::
3554+
3555+
sil-instruction ::= 'begin_borrow' sil-operand
3556+
3557+
%1 = begin_borrow %0 : $T
3558+
3559+
Given a value ``%0`` with `Owned`_ or `Guaranteed`_ ownership, produces a new
3560+
same typed value with `Guaranteed`_ ownership: ``%1``. ``%1`` is guaranteed to
3561+
have a lifetime ending use (e.x.: `end_borrow`_) along all paths that do not end
3562+
in `Dead End Blocks`_. This `begin_borrow`_ and the lifetime ending uses of
3563+
``%1`` are considered to be liveness requiring uses of ``%0`` and as such in the
3564+
region in between this borrow and its lifetime ending use, ``%0`` must be
3565+
live. This makes sense semantically since ``%1`` is modeling a new value with a
3566+
dependent lifetime on ``%0``.
3567+
3568+
This instruction is only valid in functions in Ownership SSA form.
35543569

35553570
end_borrow
35563571
``````````
35573572

35583573
::
35593574

3560-
sil-instruction ::= 'end_borrow' sil-value 'from' sil-value : sil-type, sil-type
3575+
sil-instruction ::= 'end_borrow' sil-operand
35613576

3562-
end_borrow %1 from %0 : $T, $T
3563-
end_borrow %1 from %0 : $T, $*T
3564-
end_borrow %1 from %0 : $*T, $T
3565-
end_borrow %1 from %0 : $*T, $*T
3566-
// We allow for end_borrow to be specified in between values and addresses
3567-
// all of the same type T.
3577+
// somewhere earlier
3578+
// %1 = begin_borrow %0
3579+
end_borrow %1 : $T
35683580

3569-
Ends the scope for which the SILValue ``%1`` is borrowed from the SILValue
3570-
``%0``. Must be paired with at most 1 borrowing instruction (like
3571-
``load_borrow``) along any path through the program. In the region in between
3572-
the borrow instruction and the ``end_borrow``, the original SILValue can not be
3573-
modified. This means that:
3581+
Ends the scope for which the `Guaranteed`_ ownership possessing SILValue ``%1``
3582+
is borrowed from the SILValue ``%0``. Must be paired with at most 1 borrowing
3583+
instruction (like `load_borrow`_, `begin_borrow`_) along any path through the
3584+
program. In the region in between the borrow instruction and the `end_borrow`_,
3585+
the original SILValue can not be modified. This means that:
35743586

35753587
1. If ``%0`` is an address, ``%0`` can not be written to.
35763588
2. If ``%0`` is a non-trivial value, ``%0`` can not be destroyed.
35773589

35783590
We require that ``%1`` and ``%0`` have the same type ignoring SILValueCategory.
35793591

3592+
This instruction is only valid in functions in Ownership SSA form.
3593+
35803594
assign
35813595
``````
35823596
::
@@ -3592,12 +3606,12 @@ The type of %1 is ``*T`` and the type of ``%0`` is ``T``, which must be a
35923606
loadable type. This will overwrite the memory at ``%1`` and destroy the value
35933607
currently held there.
35943608

3595-
The purpose of the ``assign`` instruction is to simplify the
3609+
The purpose of the `assign`_ instruction is to simplify the
35963610
definitive initialization analysis on loadable variables by removing
35973611
what would otherwise appear to be a load and use of the current value.
35983612
It is produced by SILGen, which cannot know which assignments are
35993613
meant to be initializations. If it is deemed to be an initialization,
3600-
it can be replaced with a ``store``; otherwise, it must be replaced
3614+
it can be replaced with a `store`_; otherwise, it must be replaced
36013615
with a sequence that also correctly destroys the current value.
36023616

36033617
This instruction is only valid in Raw SIL and is rewritten as appropriate
@@ -3615,7 +3629,7 @@ assign_by_wrapper
36153629
// $F must be a function type, taking $S as a single argument (or multiple arguments in case of a tuple) and returning $T
36163630
// $G must be a function type, taking $S as a single argument (or multiple arguments in case of a tuple) and without a return value
36173631

3618-
Similar to the ``assign`` instruction, but the assignment is done via a
3632+
Similar to the `assign`_ instruction, but the assignment is done via a
36193633
delegate.
36203634

36213635
In case of an initialization, the function ``%2`` is called with ``%0`` as

0 commit comments

Comments
 (0)