Skip to content

Commit fb0121e

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

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
@@ -1277,8 +1277,8 @@ emitMarkFunctionEscapeForTopLevelCodeGlobals(SILLocation loc,
12771277
}
12781278

12791279
void SILGenModule::emitAbstractFuncDecl(AbstractFunctionDecl *AFD) {
1280-
// Emit any default argument generators.
1281-
emitDefaultArgGenerators(AFD, AFD->getParameters());
1280+
// Emit default arguments and property wrapper initializers.
1281+
emitArgumentGenerators(AFD, AFD->getParameters());
12821282

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

1376+
// Emit property wrapper argument generators.
1377+
emitArgumentGenerators(ce, ce->getParameters());
1378+
13761379
emitFunctionDefinition(constant, f);
13771380
return f;
13781381
}
@@ -1559,13 +1562,17 @@ void SILGenModule::emitGlobalAccessor(VarDecl *global,
15591562
emitOrDelayFunction(*this, accessor);
15601563
}
15611564

1562-
void SILGenModule::emitDefaultArgGenerators(SILDeclRef::Loc decl,
1563-
ParameterList *paramList) {
1565+
void SILGenModule::emitArgumentGenerators(SILDeclRef::Loc decl,
1566+
ParameterList *paramList) {
15641567
unsigned index = 0;
15651568
for (auto param : *paramList) {
15661569
if (param->isDefaultArgument())
15671570
emitDefaultArgGenerator(SILDeclRef::getDefaultArgGenerator(decl, index),
15681571
param);
1572+
1573+
if (param->hasExternalPropertyWrapper())
1574+
emitPropertyWrapperBackingInitializer(param);
1575+
15691576
++index;
15701577
}
15711578
}

lib/SILGen/SILGen.h

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

321-
/// Emits default argument generators for the given parameter list.
322-
void emitDefaultArgGenerators(SILDeclRef::Loc decl,
323-
ParameterList *paramList);
321+
/// Emits argument generators, including default argument generators and
322+
/// property wrapper argument generators, for the given parameter list.
323+
void emitArgumentGenerators(SILDeclRef::Loc decl, ParameterList *paramList);
324324

325325
/// Emits a thunk from a foreign function to the native Swift convention.
326326
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
@@ -1100,7 +1100,7 @@ class SILGenType : public TypeMemberVisitor<SILGenType> {
11001100
return;
11011101

11021102
// Emit any default argument generators.
1103-
SGM.emitDefaultArgGenerators(EED, EED->getParameterList());
1103+
SGM.emitArgumentGenerators(EED, EED->getParameterList());
11041104
}
11051105

11061106
void visitPatternBindingDecl(PatternBindingDecl *pd) {
@@ -1135,7 +1135,7 @@ class SILGenType : public TypeMemberVisitor<SILGenType> {
11351135
}
11361136

11371137
void visitSubscriptDecl(SubscriptDecl *sd) {
1138-
SGM.emitDefaultArgGenerators(sd, sd->getIndices());
1138+
SGM.emitArgumentGenerators(sd, sd->getIndices());
11391139
visitAbstractStorageDecl(sd);
11401140
}
11411141

@@ -1261,7 +1261,7 @@ class SILGenExtension : public TypeMemberVisitor<SILGenExtension> {
12611261
}
12621262

12631263
void visitSubscriptDecl(SubscriptDecl *sd) {
1264-
SGM.emitDefaultArgGenerators(sd, sd->getIndices());
1264+
SGM.emitArgumentGenerators(sd, sd->getIndices());
12651265
visitAbstractStorageDecl(sd);
12661266
}
12671267

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)