Skip to content

Commit 8621a52

Browse files
committed
[Property wrappers] Fix property wrapper backing initializer linkage.
Have property wrapper backing initializers determine their linkage in the same way as stored property initializers, which need to match the linkage of the enclosing type in cases where one can write an initializer outside of the source file where that type is declared. Fixes rdar://problem/59607192.
1 parent 62f6686 commit 8621a52

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

lib/SIL/SILDeclRef.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,8 @@ SILLinkage SILDeclRef::getLinkage(ForDefinition_t forDefinition) const {
293293
limit = Limit::NeverPublic;
294294
}
295295

296-
// The property wrapper backing initializer is never public for resilient
297-
// properties.
298-
if (kind == SILDeclRef::Kind::PropertyWrapperBackingInitializer) {
299-
if (cast<VarDecl>(d)->isResilient())
300-
limit = Limit::NeverPublic;
301-
}
302-
303296
// Stored property initializers get the linkage of their containing type.
304-
if (isStoredPropertyInitializer()) {
297+
if (isStoredPropertyInitializer() || isPropertyWrapperBackingInitializer()) {
305298
// Three cases:
306299
//
307300
// 1) Type is formally @_fixed_layout/@frozen. Root initializers can be
@@ -483,7 +476,7 @@ IsSerialized_t SILDeclRef::isSerialized() const {
483476

484477
// Stored property initializers are inlinable if the type is explicitly
485478
// marked as @frozen.
486-
if (isStoredPropertyInitializer()) {
479+
if (isStoredPropertyInitializer() || isPropertyWrapperBackingInitializer()) {
487480
auto *nominal = cast<NominalTypeDecl>(d->getDeclContext());
488481
auto scope =
489482
nominal->getFormalAccessScope(/*useDC=*/nullptr,
@@ -1130,8 +1123,7 @@ bool SILDeclRef::canBeDynamicReplacement() const {
11301123
bool SILDeclRef::isDynamicallyReplaceable() const {
11311124
if (kind == SILDeclRef::Kind::DefaultArgGenerator)
11321125
return false;
1133-
if (isStoredPropertyInitializer() ||
1134-
kind == SILDeclRef::Kind::PropertyWrapperBackingInitializer)
1126+
if (isStoredPropertyInitializer() || isPropertyWrapperBackingInitializer())
11351127
return false;
11361128

11371129
// Class allocators are not dynamic replaceable.

test/SILGen/dynamically_replaceable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ struct WrapperWithInitialValue<T> {
414414
}
415415
}
416416

417-
// CHECK-LABEL: sil hidden [ossa] @$s23dynamically_replaceable10SomeStructV1tSbvpfP
417+
// CHECK-NOT: sil hidden [ossa] @$s23dynamically_replaceable10SomeStructV1tSbvpfP
418418
public struct SomeStruct {
419419
@WrapperWithInitialValue var t = false
420420
}

test/SILGen/property_wrappers.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,8 @@ public protocol TestProtocol {}
510510
public class TestClass<T> {
511511
@WrapperWithInitialValue var value: T
512512

513+
// CHECK-LABEL: sil [ossa] @$s17property_wrappers9TestClassC5valuexvpfP : $@convention(thin) <T> (@in T) -> @out WrapperWithInitialValue<T>
514+
513515
// CHECK-LABEL: sil hidden [ossa] @$s17property_wrappers9TestClassC5value8protocolACyxGx_qd__tcAA0C8ProtocolRd__lufc
514516
// CHECK: [[BACKING_INIT:%.*]] = function_ref @$s17property_wrappers9TestClassC5valuexvpfP : $@convention(thin) <τ_0_0> (@in τ_0_0) -> @out WrapperWithInitialValue<τ_0_0>
515517
// CHECK-NEXT: partial_apply [callee_guaranteed] [[BACKING_INIT]]<T>()

0 commit comments

Comments
 (0)