Skip to content

Commit 28aec55

Browse files
committed
[SIL] Fix linkage of external property wrapper backing initializers
This should be based on the access level of the function they're attached to. rdar://100240367
1 parent b51d82d commit 28aec55

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

lib/SIL/IR/SILDeclRef.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,10 +459,14 @@ SILLinkage SILDeclRef::getDefinitionLinkage() const {
459459
if (isPropertyWrapperBackingInitializer()) {
460460
auto *dc = decl->getDeclContext();
461461

462-
// Property wrapper generators of public functions have PublicNonABI
463-
// linkage.
464-
if (isa<ParamDecl>(decl) && isSerialized())
465-
return SILLinkage::PublicNonABI;
462+
// External property wrapper backing initializers have linkage based
463+
// on the access level of their function.
464+
if (isa<ParamDecl>(decl)) {
465+
if (isa<AbstractClosureExpr>(dc))
466+
return privateLinkage();
467+
468+
decl = cast<ValueDecl>(dc->getAsDecl());
469+
}
466470

467471
// Property wrappers in types have linkage based on the access level of
468472
// their nominal.

test/SILGen/property_wrapper_parameter.swift

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ struct ImplementationDetail<T> {
9494

9595
struct TestStructInit {
9696
// property wrapper backing initializer of number #1 in TestStructInit.init(number:message:)
97-
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter14TestStructInitV6number7messageAcA7WrapperVySiG_SStcfcADL_SivpfP : $@convention(thin) (Int) -> Wrapper<Int>
97+
// CHECK-LABEL: sil hidden [ossa] @$s26property_wrapper_parameter14TestStructInitV6number7messageAcA7WrapperVySiG_SStcfcADL_SivpfP : $@convention(thin) (Int) -> Wrapper<Int>
9898

9999
// property wrapper init from projected value of number #1 in TestStructInit.init(number:message:)
100-
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter14TestStructInitV6number7messageAcA7WrapperVySiG_SStcfcADL_SivpfW : $@convention(thin) (Projection<Int>) -> Wrapper<Int>
100+
// CHECK-LABEL: sil hidden [ossa] @$s26property_wrapper_parameter14TestStructInitV6number7messageAcA7WrapperVySiG_SStcfcADL_SivpfW : $@convention(thin) (Projection<Int>) -> Wrapper<Int>
101101

102102
// CHECK-LABEL: sil hidden [ossa] @$s26property_wrapper_parameter14TestStructInitV6number7messageAcA7WrapperVySiG_SStcfC : $@convention(method) (Wrapper<Int>, @owned String, @thin TestStructInit.Type) -> TestStructInit
103103
init(@Wrapper number: Int, @ImplementationDetail message: String) {
@@ -123,10 +123,10 @@ struct TestStructInit {
123123

124124
class TestClassInit {
125125
// property wrapper backing initializer of number #1 in TestClassInit.init(number:message:)
126-
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter13TestClassInitC6number7messageAcA7WrapperVySiG_SStcfcADL_SivpfP : $@convention(thin) (Int) -> Wrapper<Int>
126+
// CHECK-LABEL: sil hidden [ossa] @$s26property_wrapper_parameter13TestClassInitC6number7messageAcA7WrapperVySiG_SStcfcADL_SivpfP : $@convention(thin) (Int) -> Wrapper<Int>
127127

128128
// property wrapper init from projected value of number #1 in TestClassInit.init(number:message:)
129-
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter13TestClassInitC6number7messageAcA7WrapperVySiG_SStcfcADL_SivpfW : $@convention(thin) (Projection<Int>) -> Wrapper<Int>
129+
// CHECK-LABEL: sil hidden [ossa] @$s26property_wrapper_parameter13TestClassInitC6number7messageAcA7WrapperVySiG_SStcfcADL_SivpfW : $@convention(thin) (Projection<Int>) -> Wrapper<Int>
130130

131131
// TestClassInit.__allocating_init(number:message:)
132132
// CHECK-LABEL: sil hidden [exact_self_class] [ossa] @$s26property_wrapper_parameter13TestClassInitC6number7messageAcA7WrapperVySiG_SStcfC : $@convention(method) (Wrapper<Int>, @owned String, @thick TestClassInit.Type) -> @owned TestClassInit
@@ -172,7 +172,7 @@ public struct AutoClosureWrapper<T> {
172172
}
173173

174174
// property wrapper backing initializer of value #1 in testAutoClosureWrapper<A>(value:)
175-
// 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>
175+
// CHECK-LABEL: sil hidden [ossa] @$s26property_wrapper_parameter22testAutoClosureWrapper5valueyAA0efG0VyxG_tlFACL_xvpfP : $@convention(thin) <T> (@noescape @callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for <T>) -> @out AutoClosureWrapper<T>
176176
// 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>
177177

178178
// CHECK-LABEL: sil hidden [ossa] @$s26property_wrapper_parameter22testAutoClosureWrapper5valueyAA0efG0VyxG_tlF : $@convention(thin) <T> (@in_guaranteed AutoClosureWrapper<T>) -> ()
@@ -370,6 +370,26 @@ func genericContext<T>(_: T) where T: P {
370370
inner(b: 1)
371371
}
372372

373+
struct HasPrivate {
374+
// property wrapper backing initializer of x #1 in HasPrivate.testPrivateWrapper(x:)
375+
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter10HasPrivateV04testE7Wrapper{{.*}}LL1xyAA0G0VySiG_tFAFL_SivpfP : $@convention(thin) (Int) -> Wrapper<Int>
376+
377+
// property wrapper init from projected value of x #1 in HasPrivate.testPrivateWrapper(x:)
378+
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter10HasPrivateV04testE7Wrapper{{.*}}LL1xyAA0G0VySiG_tFAFL_SivpfW : $@convention(thin) (Projection<Int>) -> Wrapper<Int>
379+
380+
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter10HasPrivateV04testE7Wrapper{{.*}}LL1xyAA0G0VySiG_tF : $@convention(method) (Wrapper<Int>, HasPrivate) -> ()
381+
private func testPrivateWrapper(@Wrapper x: Int) {}
382+
383+
// property wrapper backing initializer of x #1 in HasPrivate.testFilePrivateWrapper(x:)
384+
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter10HasPrivateV08testFileE7Wrapper{{.*}}LL1xyAA0H0VySiG_tFAFL_SivpfP : $@convention(thin) (Int) -> Wrapper<Int>
385+
386+
// property wrapper init from projected value of x #1 in HasPrivate.testFilePrivateWrapper(x:)
387+
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter10HasPrivateV08testFileE7Wrapper{{.*}}LL1xyAA0H0VySiG_tFAFL_SivpfW : $@convention(thin) (Projection<Int>) -> Wrapper<Int>
388+
389+
// CHECK-LABEL: sil private [ossa] @$s26property_wrapper_parameter10HasPrivateV08testFileE7Wrapper{{.*}}LL1xyAA0H0VySiG_tF : $@convention(method) (Wrapper<Int>, HasPrivate) -> ()
390+
fileprivate func testFilePrivateWrapper(@Wrapper x: Int) {}
391+
}
392+
373393
@propertyWrapper
374394
public struct PublicWrapper<T> {
375395
public var wrappedValue: T
@@ -411,6 +431,10 @@ public func publicFunc(@PublicWrapper value: String) {
411431
// CHECK: sil shared [serialized] [ossa] @$s26property_wrapper_parameter13inlinableFunc5valueyAA13PublicWrapperVySSG_tFySScfu_ : $@convention(thin) (@guaranteed String) -> ()
412432
// CHECK: function_ref @$s26property_wrapper_parameter10publicFunc5valueyAA13PublicWrapperVySSG_tFACL_SSvpfP : $@convention(thin) (@owned String) -> @owned PublicWrapper<String>
413433
// CHECK: function_ref @$s26property_wrapper_parameter10publicFunc5valueyAA13PublicWrapperVySSG_tF : $@convention(thin) (@guaranteed PublicWrapper<String>) -> ()
434+
435+
// property wrapper init from projected value of $x #1 in closure #1 in implicit closure #1 in inlinableFunc(value:)
436+
// CHECK: sil shared [serialized] [ossa] @$s26property_wrapper_parameter13inlinableFunc5valueyAA13PublicWrapperVySSG_tFyAEySiGcfu0_yAGcfU_2$xL_AGvpfW : $@convention(thin) (PublicWrapper<Int>) -> PublicWrapper<Int>
437+
let _: (PublicWrapper<Int>) -> Void = { $x in }
414438
}
415439

416440
@propertyWrapper

0 commit comments

Comments
 (0)