Skip to content

Commit d4b52c8

Browse files
committed
[SILGen] Emit property wrapper generator functions in the same place
as default argument generator functions.
1 parent ebba478 commit d4b52c8

File tree

5 files changed

+51
-48
lines changed

5 files changed

+51
-48
lines changed

lib/SILGen/SILGen.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,8 +1299,8 @@ emitMarkFunctionEscapeForTopLevelCodeGlobals(SILLocation loc,
12991299
}
13001300

13011301
void SILGenModule::emitAbstractFuncDecl(AbstractFunctionDecl *AFD) {
1302-
// Emit any default argument generators.
1303-
emitDefaultArgGenerators(AFD, AFD->getParameters());
1302+
// Emit default arguments and property wrapper initializers.
1303+
emitArgumentGenerators(AFD, AFD->getParameters());
13041304

13051305
// If this is a function at global scope, it may close over a global variable.
13061306
// If we're emitting top-level code, then emit a "mark_function_escape" that
@@ -1389,6 +1389,9 @@ SILFunction *SILGenModule::emitClosure(AbstractClosureExpr *ce) {
13891389
if (!f->isExternalDeclaration())
13901390
return f;
13911391

1392+
// Emit property wrapper argument generators.
1393+
emitArgumentGenerators(ce, ce->getParameters());
1394+
13921395
emitFunctionDefinition(constant, f);
13931396
return f;
13941397
}
@@ -1575,13 +1578,17 @@ void SILGenModule::emitGlobalAccessor(VarDecl *global,
15751578
emitOrDelayFunction(*this, accessor);
15761579
}
15771580

1578-
void SILGenModule::emitDefaultArgGenerators(SILDeclRef::Loc decl,
1579-
ParameterList *paramList) {
1581+
void SILGenModule::emitArgumentGenerators(SILDeclRef::Loc decl,
1582+
ParameterList *paramList) {
15801583
unsigned index = 0;
15811584
for (auto param : *paramList) {
15821585
if (param->isDefaultArgument())
15831586
emitDefaultArgGenerator(SILDeclRef::getDefaultArgGenerator(decl, index),
15841587
param);
1588+
1589+
if (param->hasExternalPropertyWrapper())
1590+
emitPropertyWrapperBackingInitializer(param);
1591+
15851592
++index;
15861593
}
15871594
}

lib/SILGen/SILGen.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,9 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
321321
/// Emits the backing initializer for a property with an attached wrapper.
322322
void emitPropertyWrapperBackingInitializer(VarDecl *var);
323323

324-
/// Emits default argument generators for the given parameter list.
325-
void emitDefaultArgGenerators(SILDeclRef::Loc decl,
326-
ParameterList *paramList);
324+
/// Emits argument generators, including default argument generators and
325+
/// property wrapper argument generators, for the given parameter list.
326+
void emitArgumentGenerators(SILDeclRef::Loc decl, ParameterList *paramList);
327327

328328
/// Emits a thunk from a foreign function to the native Swift convention.
329329
void emitForeignToNativeThunk(SILDeclRef thunk);

lib/SILGen/SILGenProlog.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,6 @@ struct ArgumentInitHelper {
245245

246246
void emitParam(ParamDecl *PD) {
247247
if (PD->hasExternalPropertyWrapper()) {
248-
auto initInfo = PD->getPropertyWrapperInitializerInfo();
249-
if (initInfo.hasSynthesizedInitializers()) {
250-
SGF.SGM.emitPropertyWrapperBackingInitializer(PD);
251-
}
252-
253248
PD = cast<ParamDecl>(PD->getPropertyWrapperBackingProperty());
254249
}
255250

lib/SILGen/SILGenType.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ class SILGenType : public TypeMemberVisitor<SILGenType> {
11061106
return;
11071107

11081108
// Emit any default argument generators.
1109-
SGM.emitDefaultArgGenerators(EED, EED->getParameterList());
1109+
SGM.emitArgumentGenerators(EED, EED->getParameterList());
11101110
}
11111111

11121112
void visitPatternBindingDecl(PatternBindingDecl *pd) {
@@ -1141,7 +1141,7 @@ class SILGenType : public TypeMemberVisitor<SILGenType> {
11411141
}
11421142

11431143
void visitSubscriptDecl(SubscriptDecl *sd) {
1144-
SGM.emitDefaultArgGenerators(sd, sd->getIndices());
1144+
SGM.emitArgumentGenerators(sd, sd->getIndices());
11451145
visitAbstractStorageDecl(sd);
11461146
}
11471147

@@ -1268,7 +1268,7 @@ class SILGenExtension : public TypeMemberVisitor<SILGenExtension> {
12681268
}
12691269

12701270
void visitSubscriptDecl(SubscriptDecl *sd) {
1271-
SGM.emitDefaultArgGenerators(sd, sd->getIndices());
1271+
SGM.emitArgumentGenerators(sd, sd->getIndices());
12721272
visitAbstractStorageDecl(sd);
12731273
}
12741274

test/SILGen/property_wrapper_parameter.swift

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ public struct Wrapper<T> {
2626
}
2727
}
2828

29+
// property wrapper backing initializer of value #1 in testSimpleWrapperParameter(value:)
30+
// CHECK: sil non_abi [serialized] [ossa] @$s26property_wrapper_parameter26testSimpleWrapperParameter5valueyAA0F0VySiG_tFACL_SivpfP : $@convention(thin) (Int) -> Wrapper<Int>
31+
32+
// property wrapper init from projected value of value #1 in testSimpleWrapperParameter(value:)
33+
// CHECK: sil non_abi [serialized] [ossa] @$s26property_wrapper_parameter26testSimpleWrapperParameter5valueyAA0F0VySiG_tFACL_SivpfW : $@convention(thin) (Projection<Int>) -> Wrapper<Int>
34+
2935
// CHECK-LABEL: sil [ossa] @$s26property_wrapper_parameter26testSimpleWrapperParameter5valueyAA0F0VySiG_tF : $@convention(thin) (Wrapper<Int>) -> ()
3036
public func testSimpleWrapperParameter(@Wrapper value: Int) {
3137
_ = value
3238
_ = _value
3339
_ = $value
3440

35-
// property wrapper backing initializer of value #1 in testSimpleWrapperParameter(value:)
36-
// CHECK: sil non_abi [serialized] [ossa] @$s26property_wrapper_parameter26testSimpleWrapperParameter5valueyAA0F0VySiG_tFACL_SivpfP : $@convention(thin) (Int) -> Wrapper<Int>
37-
38-
// property wrapper init from projected value of value #1 in testSimpleWrapperParameter(value:)
39-
// CHECK: sil non_abi [serialized] [ossa] @$s26property_wrapper_parameter26testSimpleWrapperParameter5valueyAA0F0VySiG_tFACL_SivpfW : $@convention(thin) (Projection<Int>) -> Wrapper<Int>
40-
4141
// getter of $value #1 in testSimpleWrapperParameter(value:)
4242
// CHECK: sil private [ossa] @$s26property_wrapper_parameter26testSimpleWrapperParameter5valueyAA0F0VySiG_tF6$valueL_AA10ProjectionVySiGvg : $@convention(thin) (Wrapper<Int>) -> Projection<Int>
4343

@@ -58,14 +58,14 @@ func simpleWrapperParameterCaller(projection: Projection<Int>) {
5858
// CHECK: function_ref @$s26property_wrapper_parameter26testSimpleWrapperParameter5valueyAA0F0VySiG_tFACL_SivpfP : $@convention(thin) (Int) -> Wrapper<Int>
5959
}
6060

61-
// CHECK-LABEL: sil [ossa] @$s26property_wrapper_parameter18testGenericWrapper5valueyAA0F0VyxG_tlF : $@convention(thin) <T> (@in_guaranteed Wrapper<T>) -> ()
62-
public func testGenericWrapper<T>(@Wrapper value: T) {
61+
// property wrapper backing initializer of value #1 in testGenericWrapper<A>(value:)
62+
// CHECK: sil non_abi [serialized] [ossa] @$s26property_wrapper_parameter18testGenericWrapper5valueyAA0F0VyxG_tlFACL_xvpfP : $@convention(thin) <T> (@in T) -> @out Wrapper<T>
6363

64-
// property wrapper backing initializer of value #1 in testGenericWrapper<A>(value:)
65-
// CHECK: sil non_abi [serialized] [ossa] @$s26property_wrapper_parameter18testGenericWrapper5valueyAA0F0VyxG_tlFACL_xvpfP : $@convention(thin) <T> (@in T) -> @out Wrapper<T>
64+
// property wrapper init from projected value of value #1 in testGenericWrapper<A>(value:)
65+
// CHECK: sil non_abi [serialized] [ossa] @$s26property_wrapper_parameter18testGenericWrapper5valueyAA0F0VyxG_tlFACL_xvpfW : $@convention(thin) <T> (@in Projection<T>) -> @out Wrapper<T>
6666

67-
// property wrapper init from projected value of value #1 in testGenericWrapper<A>(value:)
68-
// CHECK: sil non_abi [serialized] [ossa] @$s26property_wrapper_parameter18testGenericWrapper5valueyAA0F0VyxG_tlFACL_xvpfW : $@convention(thin) <T> (@in Projection<T>) -> @out Wrapper<T>
67+
// CHECK-LABEL: sil [ossa] @$s26property_wrapper_parameter18testGenericWrapper5valueyAA0F0VyxG_tlF : $@convention(thin) <T> (@in_guaranteed Wrapper<T>) -> ()
68+
public func testGenericWrapper<T>(@Wrapper value: T) {
6969
}
7070

7171
// CHECK-LABEL: sil hidden [ossa] @$s26property_wrapper_parameter20genericWrapperCaller10projectionyAA10ProjectionVySiG_tF : $@convention(thin) (Projection<Int>) -> ()
@@ -99,11 +99,12 @@ public struct AutoClosureWrapper<T> {
9999
}
100100
}
101101

102+
// property wrapper backing initializer of value #1 in testAutoClosureWrapper<A>(value:)
103+
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter22testAutoClosureWrapper5valueyAA0efG0VyxG_tlFACL_xvpfP : $@convention(thin) <T> (@noescape @callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for <T>) -> @out AutoClosureWrapper<T>
104+
// CHECK: function_ref @$s26property_wrapper_parameter18AutoClosureWrapperV12wrappedValueACyxGxyXK_tcfC : $@convention(method) <τ_0_0> (@noescape @callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for <τ_0_0>, @thin AutoClosureWrapper<τ_0_0>.Type) -> @out AutoClosureWrapper<τ_0_0>
105+
102106
// CHECK-LABEL: sil hidden [ossa] @$s26property_wrapper_parameter22testAutoClosureWrapper5valueyAA0efG0VyxG_tlF : $@convention(thin) <T> (@in_guaranteed AutoClosureWrapper<T>) -> ()
103107
func testAutoClosureWrapper<T>(@AutoClosureWrapper value: T) {
104-
// property wrapper backing initializer of value #1 in testAutoClosureWrapper<A>(value:)
105-
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter22testAutoClosureWrapper5valueyAA0efG0VyxG_tlFACL_xvpfP : $@convention(thin) <T> (@noescape @callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for <T>) -> @out AutoClosureWrapper<T>
106-
// CHECK: function_ref @$s26property_wrapper_parameter18AutoClosureWrapperV12wrappedValueACyxGxyXK_tcfC : $@convention(method) <τ_0_0> (@noescape @callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for <τ_0_0>, @thin AutoClosureWrapper<τ_0_0>.Type) -> @out AutoClosureWrapper<τ_0_0>
107108
}
108109

109110
// CHECK-LABEL: sil hidden [ossa] @$s26property_wrapper_parameter24autoClosureWrapperCalleryyF : $@convention(thin) () -> ()
@@ -275,25 +276,25 @@ func genericContext<T>(_: T) where T: P {
275276
// property wrapper init from projected value of $value #1 in closure #2 in implicit closure #2 in genericContext<A>(_:)
276277
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter14genericContextyyxAA1PRzlFxAA17ProjectionWrapperVySiGcfu0_xAFcfU0_6$valueL_AFvpfW : $@convention(thin) <T where T : P> (ProjectionWrapper<Int>) -> ProjectionWrapper<Int>
277278

278-
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter14genericContextyyxAA1PRzlF5innerL_1ayAA7WrapperVySiG_tAaCRzlF : $@convention(thin) (Wrapper<Int>) -> ()
279-
func inner(@Wrapper a: Int) {}
280-
281279
// property wrapper backing initializer of a #1 in inner #1 <A>(a:) in genericContext<A>(_:)
282280
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter14genericContextyyxAA1PRzlF5innerL_1ayAA7WrapperVySiG_tAaCRzlFAEL_SivpfP : $@convention(thin) (Int) -> Wrapper<Int>
283281

282+
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter14genericContextyyxAA1PRzlF5innerL_1ayAA7WrapperVySiG_tAaCRzlF : $@convention(thin) (Wrapper<Int>) -> ()
283+
func inner(@Wrapper a: Int) {}
284+
284285
inner(a: 1)
285286

286287
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter14genericContextyyxAA1PRzlF5innerL0_yyAaCRzlF : $@convention(thin) <T where T : P> () -> ()
287288
func inner() { _ = T.self }
288289

290+
// property wrapper backing initializer of b #1 in inner #3 <A>(b:) in genericContext<A>(_:)
291+
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter14genericContextyyxAA1PRzlF5innerL1_1byAA7WrapperVySiG_tAaCRzlFAEL_SivpfP : $@convention(thin) <T where T : P> (Int) -> Wrapper<Int>
292+
289293
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter14genericContextyyxAA1PRzlF5innerL1_1byAA7WrapperVySiG_tAaCRzlF : $@convention(thin) <T where T : P> (Wrapper<Int>) -> ()
290294
func inner(@Wrapper b: Int) {
291295
inner()
292296
}
293297

294-
// property wrapper backing initializer of b #1 in inner #3 <A>(b:) in genericContext<A>(_:)
295-
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter14genericContextyyxAA1PRzlF5innerL1_1byAA7WrapperVySiG_tAaCRzlFAEL_SivpfP : $@convention(thin) <T where T : P> (Int) -> Wrapper<Int>
296-
297298
inner(b: 1)
298299
}
299300

@@ -314,24 +315,24 @@ public struct PublicWrapper<T> {
314315
}
315316
}
316317

318+
// property wrapper backing initializer of value #1 in publicFunc(value:)
319+
// CHECK: sil non_abi [serialized] [ossa] @$s26property_wrapper_parameter10publicFunc5valueyAA13PublicWrapperVySSG_tFACL_SSvpfP : $@convention(thin) (@owned String) -> @owned PublicWrapper<String>
320+
321+
// property wrapper init from projected value of value #1 in publicFunc(value:)
322+
// CHECK: sil non_abi [serialized] [ossa] @$s26property_wrapper_parameter10publicFunc5valueyAA13PublicWrapperVySSG_tFACL_SSvpfW : $@convention(thin) (@owned PublicWrapper<String>) -> @owned PublicWrapper<String>
323+
317324
// CHECK-LABEL: sil [ossa] @$s26property_wrapper_parameter10publicFunc5valueyAA13PublicWrapperVySSG_tF : $@convention(thin) (@guaranteed PublicWrapper<String>) -> ()
318325
public func publicFunc(@PublicWrapper value: String) {
319-
// property wrapper backing initializer of value #1 in publicFunc(value:)
320-
// CHECK: sil non_abi [serialized] [ossa] @$s26property_wrapper_parameter10publicFunc5valueyAA13PublicWrapperVySSG_tFACL_SSvpfP : $@convention(thin) (@owned String) -> @owned PublicWrapper<String>
321-
322-
// property wrapper init from projected value of value #1 in publicFunc(value:)
323-
// CHECK: sil non_abi [serialized] [ossa] @$s26property_wrapper_parameter10publicFunc5valueyAA13PublicWrapperVySSG_tFACL_SSvpfW : $@convention(thin) (@owned PublicWrapper<String>) -> @owned PublicWrapper<String>
324326
}
325327

326-
// CHECK-LABEL: sil [serialized] [ossa] @$s26property_wrapper_parameter13inlinableFunc5valueyAA13PublicWrapperVySSG_tF : $@convention(thin) (@guaranteed PublicWrapper<String>) -> ()
327-
@inlinable func inlinableFunc(@PublicWrapper value: String) {
328-
// property wrapper backing initializer of value #1 in inlinableFunc(value:)
329-
// CHECK: sil non_abi [serialized] [ossa] @$s26property_wrapper_parameter13inlinableFunc5valueyAA13PublicWrapperVySSG_tFACL_SSvpfP : $@convention(thin) (@owned String) -> @owned PublicWrapper<String>
330-
331-
// property wrapper init from projected value of value #1 in inlinableFunc(value:)
332-
// CHECK: sil non_abi [serialized] [ossa] @$s26property_wrapper_parameter13inlinableFunc5valueyAA13PublicWrapperVySSG_tFACL_SSvpfW : $@convention(thin) (@owned PublicWrapper<String>) -> @owned PublicWrapper<String>
328+
// property wrapper backing initializer of value #1 in inlinableFunc(value:)
329+
// CHECK: sil non_abi [serialized] [ossa] @$s26property_wrapper_parameter13inlinableFunc5valueyAA13PublicWrapperVySSG_tFACL_SSvpfP : $@convention(thin) (@owned String) -> @owned PublicWrapper<String>
333330

331+
// property wrapper init from projected value of value #1 in inlinableFunc(value:)
332+
// CHECK: sil non_abi [serialized] [ossa] @$s26property_wrapper_parameter13inlinableFunc5valueyAA13PublicWrapperVySSG_tFACL_SSvpfW : $@convention(thin) (@owned PublicWrapper<String>) -> @owned PublicWrapper<String>
334333

334+
// CHECK-LABEL: sil [serialized] [ossa] @$s26property_wrapper_parameter13inlinableFunc5valueyAA13PublicWrapperVySSG_tF : $@convention(thin) (@guaranteed PublicWrapper<String>) -> ()
335+
@inlinable func inlinableFunc(@PublicWrapper value: String) {
335336
_ = publicFunc(value:)
336337

337338
// implicit closure #1 in inlinableFunc(value:)

0 commit comments

Comments
 (0)