@@ -789,13 +789,16 @@ coroutine, where a normal function return would need to transfer ownership of
789789its return value, since a normal function's context ceases to exist and be able
790790to maintain ownership of the value after it returns.
791791
792- To support these concepts, SIL supports two kinds of coroutine:
793- ``@yield_many `` and ``@yield_once ``. Either of these attributes may be
792+ To support these concepts, SIL supports two flavors: single-yield and
793+ multi-yield. These two flavors correspond to three kinds. A multi-yield
794+ coroutine is of kind ``@yield_many ``. A single-yield coroutine is of kind
795+ either ``@yield_once `` or ``@yield_once_2 ``. Any of these attributes may be
794796written before a function type to indicate that it is a coroutine type.
795- ``@yield_many `` and ``@yield_once `` coroutines are allowed to also be
796- ``@async ``. (Note that ``@async `` functions are not themselves modeled
797- explicitly as coroutines in SIL, although the implementation may use a coroutine
798- lowering strategy.)
797+
798+ Both single-yield and multi-yield coroutines are allowed to also be ``@async ``.
799+ (Note that ``@async `` functions are not themselves modeled explicitly as
800+ coroutines in SIL, although the implementation may use a coroutine lowering
801+ strategy.)
799802
800803A coroutine type may declare any number of *yielded values *, which is to
801804say, values which are provided to the caller at a yield point. Yielded
@@ -816,9 +819,10 @@ calling a yield-many coroutine of any kind.
816819Coroutines may contain the special ``yield `` and ``unwind ``
817820instructions.
818821
819- A ``@yield_many `` coroutine may yield as many times as it desires.
820- A ``@yield_once `` coroutine may yield exactly once before returning,
821- although it may also ``throw `` before reaching that point.
822+ A multi-yield (``@yield_many ``) coroutine may yield as many times as it desires.
823+ A single-yield (``@yield_once `` or ``@yield_once_2 ``) coroutine may yield
824+ exactly once before returning, although it may also ``throw `` before reaching
825+ that point.
822826
823827Variadic Generics
824828`````````````````
@@ -6128,23 +6132,36 @@ begin_apply
61286132 // %float : $Float
61296133 // %token is a token
61306134
6135+ (%anyAddr, %float, %token, %allocation) = begin_apply %0() : $@yield_once_2 () -> (@yields @inout %Any, @yields Float)
6136+ // %anyAddr : $*Any
6137+ // %float : $Float
6138+ // %token is a token
6139+ // %allocation is a pointer to a token
6140+
61316141Transfers control to coroutine ``%0 ``, passing it the given arguments.
61326142The rules for the application generally follow the rules for ``apply ``,
61336143except:
61346144
6135- - the callee value must have a ``yield_once `` coroutine type,
6145+ - the callee value must have be of single-yield coroutine type (``yield_once ``
6146+ or ``yield_once_2 ``)
61366147
61376148- control returns to this function not when the coroutine performs a
61386149 ``return ``, but when it performs a ``yield ``, and
61396150
61406151- the instruction results are derived from the yields of the coroutine
61416152 instead of its normal results.
61426153
6143- The final result of a ``begin_apply `` is a "token", a special value which
6144- can only be used as the operand of an ``end_apply `` or ``abort_apply ``
6145- instruction. Before this second instruction is executed, the coroutine
6146- is said to be "suspended", and the token represents a reference to its
6147- suspended activation record.
6154+ The final (in the case of ``@yield_once ``) or penultimate (in the case of
6155+ ``@yield_once_2 ``) result of a ``begin_apply `` is a "token", a special value
6156+ which can only be used as the operand of an ``end_apply `` or ``abort_apply ``
6157+ instruction. Before this second instruction is executed, the coroutine is said
6158+ to be "suspended", and the token represents a reference to its suspended
6159+ activation record.
6160+
6161+ If the coroutine's kind ``yield_once_2 ``, its final result is an address of a
6162+ "token", representing the allocation done by the callee coroutine. It can only
6163+ be used as the operand of a ``dealloc_stack `` which must appear after the
6164+ coroutine is resumed.
61486165
61496166The other results of the instruction correspond to the yields in the
61506167coroutine type. In general, the rules of a yield are similar to the rules
@@ -8376,9 +8393,10 @@ the current function was invoked with a ``try_apply`` instruction, control
83768393resumes at the normal destination, and the value of the basic block argument
83778394will be the operand of this ``return `` instruction.
83788395
8379- If the current function is a ``yield_once `` coroutine, there must not be
8380- a path from the entry block to a ``return `` which does not pass through
8381- a ``yield `` instruction. This rule does not apply in the ``raw `` SIL stage.
8396+ If the current function is a single-yield coroutine (``yield_once `` or
8397+ ``yield_once_2 ``), there must not be a path from the entry block to a
8398+ ``return `` which does not pass through a ``yield `` instruction. This rule does
8399+ not apply in the ``raw `` SIL stage.
83828400
83838401``return `` does not retain or release its operand or any other values.
83848402
@@ -8446,9 +8464,10 @@ The ``resume`` and ``unwind`` destination blocks must be uniquely
84468464referenced by the ``yield `` instruction. This prevents them from becoming
84478465critical edges.
84488466
8449- In a ``yield_once `` coroutine, there must not be a control flow path leading
8450- from the ``resume `` edge to another ``yield `` instruction in this function.
8451- This rule does not apply in the ``raw `` SIL stage.
8467+ In a single-yield coroutine (``yield_once `` or ``yield_once_2 ``), there must
8468+ not be a control flow path leading from the ``resume `` edge to another
8469+ ``yield `` instruction in this function. This rule does not apply in the ``raw ``
8470+ SIL stage.
84528471
84538472There must not be a control flow path leading from the ``unwind `` edge to
84548473a ``return `` instruction, to a ``throw `` instruction, or to any block
0 commit comments