Skip to content

Commit 0b9c973

Browse files
authored
Merge pull request #15077 from atrick/noescape-doc
2 parents 4cef8ae + 2aebd75 commit 0b9c973

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

docs/SIL.rst

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -425,19 +425,33 @@ number of ways:
425425
generic function with ``function_ref`` will give a value of
426426
generic function type.
427427

428+
- A SIL function type may be declared ``@noescape``. This is required for any
429+
function type passed to a parameter not declared with ``@escaping``
430+
declaration modifier. ``@noescape`` function types may be either
431+
``@convention(thin)`` or ``@callee_guaranteed``. They have an
432+
unowned context--the context's lifetime must be independently guaranteed.
433+
428434
- A SIL function type declares its conventional treatment of its
429435
context value:
430436

431437
- If it is ``@convention(thin)``, the function requires no context value.
438+
Such types may also be declared ``@noescape``, which trivially has no effect
439+
passing the context value.
432440

433-
- If it is ``@callee_owned``, the context value is treated as an
434-
owned direct parameter.
441+
- If it is ``@callee_guaranteed``, the context value is treated as a direct
442+
parameter. This implies ``@convention(thick)``. If the function type is also
443+
``@noescape``, then the context value is unowned, otherwise it is
444+
guaranteed.
435445

436-
- If it is ``@callee_guaranteed``, the context value is treated as
437-
a guaranteed direct parameter.
446+
- If it is ``@callee_owned``, the context value is treated as an owned direct
447+
parameter. This implies ``@convention(thick)`` and is mutually exclusive
448+
with ``@noescape``.
438449

439-
- Otherwise, the context value is treated as an unowned direct
440-
parameter.
450+
- If it is ``@convention(block)``, the context value is treated as an unowned
451+
direct parameter.
452+
453+
- Other function type conventions are described in ``Properties of Types`` and
454+
``Calling Convention``.
441455

442456
- A SIL function type declares the conventions for its parameters.
443457
The parameters are written as an unlabeled tuple; the elements of that
@@ -549,14 +563,6 @@ the caller. A non-autoreleased ``apply`` of a function that is defined
549563
with an autoreleased result has the effect of performing an
550564
autorelease in the callee.
551565

552-
- The ``@noescape`` declaration attribute on Swift parameters (which is valid only
553-
on parameters of function type, and is implied by the ``@autoclosure`` attribute)
554-
is turned into a ``@noescape`` type attribute on SIL arguments. ``@noescape``
555-
indicates that the lifetime of the closure parameter will not be extended by
556-
the callee (e.g. the pointer will not be stored in a global variable). It
557-
corresponds to the LLVM "nocapture" attribute in terms of semantics (but is
558-
limited to only work with parameters of function type in Swift).
559-
560566
- SIL function types may provide an optional error result, written by
561567
placing ``@error`` on a result. An error result is always
562568
implicitly ``@owned``. Only functions with a native calling
@@ -704,6 +710,7 @@ types. Function types are transformed in order to encode additional attributes:
704710
- ``@convention(thick)`` indicates a "thick" function reference, which
705711
uses the Swift calling convention and carries a reference-counted context
706712
object used to represent captures or other state required by the function.
713+
This attribute is implied by ``@callee_owned`` or ``@callee_guaranteed``.
707714
- ``@convention(block)`` indicates an Objective-C compatible block reference.
708715
The function value is represented as a reference to the block object,
709716
which is an ``id``-compatible Objective-C object that embeds its invocation

0 commit comments

Comments
 (0)