Skip to content

Commit 2ebd24b

Browse files
Merge pull request #23429 from aschwaighofer/fix_enable_private_import_get_effective_access_level_symbolic_references_property_desc
Property descriptor and symbolic type references need to ignore enable-private-import
2 parents 8fcd4e6 + d2631c2 commit 2ebd24b

File tree

6 files changed

+67
-8
lines changed

6 files changed

+67
-8
lines changed

lib/IRGen/IRGenMangler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ IRGenMangler::withSymbolicReferences(IRGenModule &IGM,
103103
// when the referent may be in another file, once the on-disk
104104
// ObjectMemoryReader can handle them.
105105
// Private entities are known to be accessible.
106-
if (type->getEffectiveAccess() >= AccessLevel::Internal &&
106+
auto formalAccessScope = type->getFormalAccessScope(nullptr, true);
107+
if ((formalAccessScope.isPublic() || formalAccessScope.isInternal()) &&
107108
(!IGM.CurSourceFile ||
108109
IGM.CurSourceFile != type->getParentSourceFile()))
109110
return false;

lib/SILGen/SILGen.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,14 +1380,10 @@ static bool canStorageUseTrivialDescriptor(SILGenModule &SGM,
13801380
auto setter = decl->getSetter();
13811381
if (setter == nullptr)
13821382
return true;
1383-
1384-
auto setterLinkage = SILDeclRef(setter, SILDeclRef::Kind::Func)
1385-
.getLinkage(NotForDefinition);
1386-
1387-
if (setterLinkage == SILLinkage::PublicExternal
1388-
|| setterLinkage == SILLinkage::Public)
1383+
1384+
if (setter->getFormalAccessScope(nullptr, true).isPublic())
13891385
return true;
1390-
1386+
13911387
return false;
13921388
}
13931389
case ResilienceStrategy::Resilient: {

test/IRGen/symbolic_references.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s
2+
// RUN: %target-swift-frontend -emit-ir -enable-private-imports %s | %FileCheck %s --check-prefix=PRIVATE
3+
4+
protocol P {
5+
associatedtype A
6+
}
7+
// CHECK: @"symbolic _____ 19symbolic_references3Foo016_{{.*}}V5InnerV9InnermostV" = linkonce_odr hidden constant <{ i8, i32, i8 }> <{ i8 1,
8+
// CHECK: @"symbolic _____ 19symbolic_references3Foo016_{{.*}}V5InnerV" = linkonce_odr hidden constant <{ i8, i32, i8 }> <{ i8 1
9+
// CHECK: @"symbolic _____ 19symbolic_references3Foo016_{{.*}}V" = linkonce_odr hidden constant <{ i8, i32, i8 }> <{ i8 1
10+
11+
// PRIVATE: @"symbolic _____ 19symbolic_references3Foo016_{{.*}}V5InnerV9InnermostV" = linkonce_odr hidden constant <{ i8, i32, i8 }> <{ i8 2
12+
// PRIVATE: @"symbolic _____ 19symbolic_references3Foo016_{{.*}}V5InnerV" = linkonce_odr hidden constant <{ i8, i32, i8 }> <{ i8 1
13+
// PRIVATE: @"symbolic _____ 19symbolic_references3Foo016_{{.*}}V" = linkonce_odr hidden constant <{ i8, i32, i8 }> <{ i8 1
14+
fileprivate struct Foo {
15+
fileprivate struct Inner: P {
16+
fileprivate struct Innermost { }
17+
typealias A = Innermost
18+
}
19+
}

test/SILGen/keypath_property_descriptors.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %target-swift-emit-silgen %s | %FileCheck --check-prefix=CHECK --check-prefix=NONRESILIENT %s
22
// RUN: %target-swift-emit-silgen -enable-library-evolution %s | %FileCheck --check-prefix=CHECK --check-prefix=RESILIENT %s
3+
// RUN: %target-swift-emit-silgen -enable-private-imports %s | %FileCheck --check-prefix=PRIVATEIMPORTS %s
34

45
// TODO: globals should get descriptors
56
public var a: Int = 0
@@ -12,30 +13,38 @@ internal var c: Int = 0
1213

1314
// no descriptor
1415
// CHECK-NOT: sil_property #d
16+
// PRIVATEIMPORTS-NOT: sil_property #d
1517
internal var d: Int = 0
1618
// CHECK-NOT: sil_property #e
19+
// PRIVATEIMPORTS-NOT: sil_property #e
1720
private var e: Int = 0
1821

1922
public struct A {
2023
// NONRESILIENT-LABEL: sil_property #A.a ()
2124
// RESILIENT-LABEL: sil_property #A.a (stored_property
25+
// PRIVATEIMPORTS-LABEL: sil_property #A.a ()
2226
public var a: Int = 0
2327

2428
// CHECK-LABEL: sil_property #A.b ()
29+
// PRIVATEIMPORTS-LABEL: sil_property #A.b ()
2530
@inlinable
2631
public var b: Int { return 0 }
2732

2833
// NONRESILIENT-LABEL: sil_property #A.c ()
2934
// RESILIENT-LABEL: sil_property #A.c (stored_property
35+
// PRIVATEIMPORTS-LABEL: sil_property #A.c ()
3036
@usableFromInline
3137
internal var c: Int = 0
3238

3339
// no descriptor
3440
// CHECK-NOT: sil_property #A.d
41+
// PRIVATEIMPORTS-LABEL: sil_property #A.d ()
3542
internal var d: Int = 0
3643
// CHECK-NOT: sil_property #A.e
44+
// PRIVATEIMPORTS-LABEL: sil_property #A.e ()
3745
fileprivate var e: Int = 0
3846
// CHECK-NOT: sil_property #A.f
47+
// PRIVATEIMPORTS-LABEL: sil_property #A.f ()
3948
private var f: Int = 0
4049

4150
// TODO: static vars should get descriptors
@@ -99,19 +108,33 @@ public struct A {
99108
private var _count: Int = 0
100109

101110
// NONRESILIENT-LABEL: sil_property #A.getSet ()
111+
// PRIVATEIMPORTS-LABEL: sil_property #A.getSet ()
102112
// RESILIENT-LABEL: sil_property #A.getSet (settable_property
103113
public var getSet: Int {
104114
get { return 0 }
105115
set { }
106116
}
107117

108118
// CHECK-LABEL: sil_property #A.hiddenSetter (settable_property
119+
// PRIVATEIMPORTS-LABEL: sil_property #A.hiddenSetter (settable_property
109120
public internal(set) var hiddenSetter: Int {
110121
get { return 0 }
111122
set { }
112123
}
113124

125+
// PRIVATEIMPORTS-LABEL: sil_property #A.privateSetter (settable_property
126+
public private(set) var privateSetter: Int {
127+
get { return 0 }
128+
set { }
129+
}
130+
// PRIVATEIMPORTS-LABEL: sil_property #A.fileprivateSetter (settable_property
131+
public fileprivate(set) var fileprivateSetter: Int {
132+
get { return 0 }
133+
set { }
134+
}
135+
114136
// NONRESILIENT-LABEL: sil_property #A.usableFromInlineSetter ()
137+
// PRIVATEIMPORTS-LABEL: sil_property #A.usableFromInlineSetter ()
115138
// RESILIENT-LABEL: sil_property #A.usableFromInlineSetter (settable_property
116139
public internal(set) var usableFromInlineSetter: Int {
117140
get { return 0 }

test/stdlib/Inputs/KeyPathMultiModule_b.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ public struct A {
3636
set { }
3737
}
3838

39+
public internal(set) var w: Int {
40+
get { return 0 }
41+
set { }
42+
}
43+
public fileprivate(set) var v: Int {
44+
get { return 0 }
45+
set { }
46+
}
47+
48+
3949
public let immutable: Int = 1738
4050
}
4151

@@ -90,6 +100,14 @@ public func A_z_keypath() -> KeyPath<A, Int> {
90100
return \A.z
91101
}
92102

103+
public func A_w_keypath() -> KeyPath<A, Int> {
104+
return \A.w
105+
}
106+
107+
public func A_v_keypath() -> KeyPath<A, Int> {
108+
return \A.v
109+
}
110+
93111
public func A_immutable_keypath() -> KeyPath<A, Int> {
94112
return \A.immutable
95113
}

test/stdlib/KeyPathMultiModule.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ keyPathMultiModule.test("identity across multiple modules") {
5454
expectEqualWithHashes(A_x_keypath(), \A.x)
5555
expectEqualWithHashes(A_y_keypath(), \A.y)
5656
expectEqualWithHashes(A_z_keypath(), \A.z)
57+
expectEqualWithHashes(A_w_keypath(), \A.w)
58+
expectEqualWithHashes(A_v_keypath(), \A.v)
5759
expectEqualWithHashes(A_immutable_keypath(), \A.immutable)
5860
expectEqualWithHashes(A_subscript_withGeneric_keypath(index: 0), \A.[withGeneric: 0])
5961
expectEqualWithHashes(A_subscript_withGeneric_keypath(index: "butt"),

0 commit comments

Comments
 (0)