Skip to content

Commit 0bcc956

Browse files
authored
Merge pull request #83886 from janbaig/temp-branch
[SILGen] Remove and replace ad-hoc `assign_by_wrapper` instruction
2 parents a4da07e + 48cedb5 commit 0bcc956

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+839
-741
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/AddressUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ extension AddressUseVisitor {
125125
case is SwitchEnumAddrInst, is CheckedCastAddrBranchInst,
126126
is SelectEnumAddrInst, is InjectEnumAddrInst,
127127
is StoreInst, is StoreUnownedInst, is StoreWeakInst,
128-
is AssignInst, is AssignByWrapperInst, is AssignOrInitInst,
128+
is AssignInst, is AssignOrInitInst,
129129
is TupleAddrConstructorInst, is InitBlockStorageHeaderInst,
130130
is RetainValueAddrInst, is ReleaseValueAddrInst,
131131
is DestroyAddrInst, is DeallocStackInst,

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,6 @@ final public class AssignInst : Instruction, StoringInstruction {
347347
}
348348
}
349349

350-
final public class AssignByWrapperInst : Instruction, StoringInstruction {}
351-
352350
final public class AssignOrInitInst : Instruction, StoringInstruction {}
353351

354352
/// Instruction that copy or move from a source to destination address.

SwiftCompilerSources/Sources/SIL/Registration.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ private func registerSILClasses() {
4343
register(StoreUnownedInst.self)
4444
register(StoreBorrowInst.self)
4545
register(AssignInst.self)
46-
register(AssignByWrapperInst.self)
4746
register(AssignOrInitInst.self)
4847
register(CopyAddrInst.self)
4948
register(ExplicitCopyAddrInst.self)

docs/ABI/Mangling.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ Entities
368368
entity-spec ::= entity 'fa' // runtime discoverable attribute generator
369369
entity-spec ::= 'fi' // non-local variable initializer
370370
entity-spec ::= 'fP' // property wrapper backing initializer
371+
entity-spec ::= 'fF' // property wrapped field init accessor
371372
entity-spec ::= 'fW' // property wrapper init from projected value
372373
entity-spec ::= 'fD' // deallocating destructor; untyped
373374
entity-spec ::= 'fZ' // isolated deallocating destructor; untyped

docs/SIL/Instructions.md

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,43 +1064,49 @@ a sequence that also correctly destroys the current value.
10641064
This instruction is only valid in Raw SIL and is rewritten as
10651065
appropriate 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

include/swift/AST/ASTMangler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ class ASTMangler : public Mangler {
246246
std::string mangleInitializerEntity(const VarDecl *var, SymbolKind SKind);
247247
std::string mangleBackingInitializerEntity(const VarDecl *var,
248248
SymbolKind SKind = SymbolKind::Default);
249+
std::string manglePropertyWrappedFieldInitAccessorEntity(
250+
const VarDecl *var, SymbolKind SKind = SymbolKind::Default);
249251
std::string mangleInitFromProjectedValueEntity(const VarDecl *var,
250252
SymbolKind SKind = SymbolKind::Default);
251253

@@ -722,6 +724,7 @@ class ASTMangler : public Mangler {
722724

723725
void appendInitializerEntity(const VarDecl *var);
724726
void appendBackingInitializerEntity(const VarDecl *var);
727+
void appendPropertyWrappedFieldInitAccessorEntity(const VarDecl *var);
725728
void appendInitFromProjectedValueEntity(const VarDecl *var);
726729

727730
CanType getDeclTypeForMangling(const ValueDecl *decl,

include/swift/Demangling/DemangleNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ NODE(PrefixOperator)
213213
NODE(PrivateDeclName)
214214
NODE(PropertyDescriptor)
215215
CONTEXT_NODE(PropertyWrapperBackingInitializer)
216+
CONTEXT_NODE(PropertyWrappedFieldInitAccessor)
216217
CONTEXT_NODE(PropertyWrapperInitFromProjectedValue)
217218
CONTEXT_NODE(Protocol)
218219
CONTEXT_NODE(ProtocolSymbolicReference)

include/swift/SIL/AddressWalker.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,7 @@ TransitiveAddressWalker<Impl>::walk(SILValue projectedAddress) {
214214
isa<AssignInst>(user) || isa<LoadUnownedInst>(user) ||
215215
isa<StoreUnownedInst>(user) || isa<EndApplyInst>(user) ||
216216
isa<LoadWeakInst>(user) || isa<StoreWeakInst>(user) ||
217-
isa<AssignByWrapperInst>(user) || isa<AssignOrInitInst>(user) ||
218-
isa<BeginUnpairedAccessInst>(user) ||
217+
isa<AssignOrInitInst>(user) || isa<BeginUnpairedAccessInst>(user) ||
219218
isa<EndUnpairedAccessInst>(user) || isa<WitnessMethodInst>(user) ||
220219
isa<SelectEnumAddrInst>(user) || isa<InjectEnumAddrInst>(user) ||
221220
isa<IsUniqueInst>(user) || isa<ValueMetatypeInst>(user) ||
@@ -229,7 +228,8 @@ TransitiveAddressWalker<Impl>::walk(SILValue projectedAddress) {
229228
isa<PackElementSetInst>(user) || isa<PackElementGetInst>(user) ||
230229
isa<DeinitExistentialAddrInst>(user) || isa<LoadBorrowInst>(user) ||
231230
isa<TupleAddrConstructorInst>(user) || isa<DeallocPackInst>(user) ||
232-
isa<MergeIsolationRegionInst>(user) || isa<EndCOWMutationAddrInst>(user)) {
231+
isa<MergeIsolationRegionInst>(user) ||
232+
isa<EndCOWMutationAddrInst>(user)) {
233233
callVisitUse(op);
234234
continue;
235235
}

include/swift/SIL/InstructionUtils.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,6 @@ bool isInstrumentation(SILInstruction *Instruction);
158158
/// argument of the partial apply if it is.
159159
SILValue isPartialApplyOfReabstractionThunk(PartialApplyInst *PAI);
160160

161-
/// Returns true if \p PAI is only used by an assign_by_wrapper instruction as
162-
/// init or set function.
163-
bool onlyUsedByAssignByWrapper(PartialApplyInst *PAI);
164-
165161
/// Returns true if \p PAI is only used by an \c assign_or_init
166162
/// instruction as init or set function.
167163
bool onlyUsedByAssignOrInit(PartialApplyInst *PAI);

include/swift/SIL/SILBuilder.h

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -972,25 +972,13 @@ class SILBuilder {
972972
Qualifier));
973973
}
974974

975-
AssignByWrapperInst *createAssignByWrapper(SILLocation Loc, SILValue Src,
976-
SILValue Dest,
977-
SILValue Initializer,
978-
SILValue Setter,
979-
AssignByWrapperInst::Mode mode) {
980-
return insert(new (getModule()) AssignByWrapperInst(
981-
getSILDebugLocation(Loc), Src, Dest, Initializer, Setter, mode));
982-
}
983-
984-
AssignOrInitInst *createAssignOrInit(SILLocation Loc,
985-
VarDecl *Property,
986-
SILValue Self,
987-
SILValue Src,
988-
SILValue Initializer,
989-
SILValue Setter,
975+
AssignOrInitInst *createAssignOrInit(SILLocation Loc, VarDecl *Property,
976+
SILValue SelfOrLocal, SILValue Src,
977+
SILValue Initializer, SILValue Setter,
990978
AssignOrInitInst::Mode Mode) {
991-
return insert(new (getModule())
992-
AssignOrInitInst(getSILDebugLocation(Loc), Property, Self,
993-
Src, Initializer, Setter, Mode));
979+
return insert(new (getModule()) AssignOrInitInst(
980+
getSILDebugLocation(Loc), Property, SelfOrLocal, Src, Initializer,
981+
Setter, Mode));
994982
}
995983

996984
StoreBorrowInst *createStoreBorrow(SILLocation Loc, SILValue Src,

0 commit comments

Comments
 (0)