Skip to content

Document the @noescape SIL function type attribute. #15077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions docs/SIL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -425,19 +425,33 @@ number of ways:
generic function with ``function_ref`` will give a value of
generic function type.

- A SIL function type may be declared ``@noescape``. This is required for any
function type passed to a parameter not declared with ``@escaping``
declaration modifier. ``@noescape`` function types may be either
``@convention(thin)`` or ``@callee_guaranteed``. They have an
unowned context--the context's lifetime must be independently guaranteed.

- A SIL function type declares its conventional treatment of its
context value:

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

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

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

- Otherwise, the context value is treated as an unowned direct
parameter.
- If it is ``@convention(block)``, the context value is treated as an unowned
direct parameter.

- Other function type conventions are described in ``Properties of Types`` and
``Calling Convention``.

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

- The ``@noescape`` declaration attribute on Swift parameters (which is valid only
on parameters of function type, and is implied by the ``@autoclosure`` attribute)
is turned into a ``@noescape`` type attribute on SIL arguments. ``@noescape``
indicates that the lifetime of the closure parameter will not be extended by
the callee (e.g. the pointer will not be stored in a global variable). It
corresponds to the LLVM "nocapture" attribute in terms of semantics (but is
limited to only work with parameters of function type in Swift).

- SIL function types may provide an optional error result, written by
placing ``@error`` on a result. An error result is always
implicitly ``@owned``. Only functions with a native calling
Expand Down Expand Up @@ -704,6 +710,7 @@ types. Function types are transformed in order to encode additional attributes:
- ``@convention(thick)`` indicates a "thick" function reference, which
uses the Swift calling convention and carries a reference-counted context
object used to represent captures or other state required by the function.
This attribute is implied by ``@callee_owned`` or ``@callee_guaranteed``.
- ``@convention(block)`` indicates an Objective-C compatible block reference.
The function value is represented as a reference to the block object,
which is an ``id``-compatible Objective-C object that embeds its invocation
Expand Down