@@ -1064,43 +1064,49 @@ a sequence that also correctly destroys the current value.
10641064This instruction is only valid in Raw SIL and is rewritten as
10651065appropriate by the definitive initialization pass.
10661066
1067- ### assign_by_wrapper
1068-
1069- ```
1070- sil-instruction ::= 'assign_by_wrapper' sil-operand 'to' mode? sil-operand ',' 'init' sil-operand ',' 'set' sil-operand
1071-
1072- mode ::= '[init]' | '[assign]' | '[assign_wrapped_value]'
1073-
1074- assign_by_wrapper %0 : $S to %1 : $*T, init %2 : $F, set %3 : $G
1075- // $S can be a value or address type
1076- // $T must be the type of a property wrapper.
1077- // $F must be a function type, taking $S as a single argument (or multiple arguments in case of a tuple) and returning $T
1078- // $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
1079- ```
1080-
1081- Similar to the [ assign] ( #assign ) instruction, but the assignment is done
1082- via a delegate.
1083-
1084- Initially the instruction is created with no mode. Once the mode is
1085- decided (by the definitive initialization pass), the instruction is
1086- lowered as follows:
1087-
1088- If the mode is ` initialization ` , the function ` %2 ` is called with ` %0 `
1089- as argument. The result is stored to ` %1 ` . In case of an address type,
1090- ` %1 ` is simply passed as a first out-argument to ` %2 ` .
1091-
1092- The ` assign ` mode works similar to ` initialization ` , except that the
1093- destination is "assigned" rather than "initialized". This means that
1094- the existing value in the destination is destroyed before the new value
1095- is stored.
1096-
1097- If the mode is ` assign_wrapped_value ` , the function ` %3 ` is called with
1098- ` %0 ` as argument. As ` %3 ` is a setter (e.g. for the property in the
1099- containing nominal type), the destination address ` %1 ` is not used in
1100- this case.
1101-
1102- This instruction is only valid in Raw SIL and is rewritten as
1103- appropriate by the definitive initialization pass.
1067+ ### assign_or_init
1068+
1069+ ```
1070+ sil-instruction ::= 'assign_or_init' mode? attached-property ',' self-or-local ',' sil-operand ',' 'value' ',' sil-operand ',' 'init' sil-operand ',' 'set' sil-operand
1071+
1072+ mode ::= '[init]' | '[assign]'
1073+ attached-property ::= '#' sil-decl-ref
1074+ self-or-local ::= 'self' | 'local'
1075+
1076+ // Nominal Context:
1077+ assign_or_init #MyStruct.x, self %A, value %V, init %I, set %S
1078+ // Local Context (only emitted with compiler synthesized thunks currently):
1079+ assign_or_init #x, local %L, value %V, init %I, set %S
1080+ ```
1081+
1082+ Assigns or initializes a computed property with an attached init accessor.
1083+ This instruction is emitted during SILGen without an explicit mode.
1084+ The definitive initialization (DI) pass resolves the mode and rewrites
1085+ the instruction accordingly:
1086+
1087+ - ` [init] ` : In this mode, the init accessor ` %I ` is called with ` %V `
1088+ as an argument.
1089+ - ` [assign] ` : In this mode, the setter function ` %S ` is called with ` %V `
1090+ as an argument.
1091+
1092+ This instruction is only valid in Raw SIL and is rewritten as appropriate by
1093+ the DI pass.
1094+
1095+ Operand Roles:
1096+ - ` attached-property ` : The property being written to. For nominal contexts, this
1097+ refers to a property with an attached init accessor (e.g. ` #MyStruct.x ` ). For local
1098+ contexts, it refers to a local variable name (e.g. ` #x ` ).
1099+ - ` self-or-local ` :
1100+ - ` self %A ` : Refers to the instance of the type that owns the property with the
1101+ attached init accessor.
1102+ - ` local %L ` : Indicates the assignment is to a local variable (` %L ` ) rather than
1103+ a property of a nominal type. While init accessors are not currently available to be
1104+ used in local contexts in user-authored code, the compiler can synthesize an ` assign_or_init `
1105+ in local contexts using an init accessor thunk in special cases.
1106+ - ` value %V ` : The input value passed to either the ` init ` or ` set ` function, depending on
1107+ the selected DI mode.
1108+ - ` init %I ` : A partially applied function implementing the property's init accessor.
1109+ - ` set %S ` : A partially applied function implementing the property's setter.
11041110
11051111### mark_uninitialized
11061112
0 commit comments