Skip to content

Commit 383b927

Browse files
authored
Merge pull request #20011 from DougGregor/private-symbolic-reference-mangling
[IRGen] Use symbolic references to (file)private entities in mangled names
2 parents d34ce17 + 54615ff commit 383b927

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

lib/IRGen/IRGenMangler.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ IRGenMangler::withSymbolicReferences(IRGenModule &IGM,
101101
// TODO: We ought to be able to use indirect symbolic references even
102102
// when the referent may be in another file, once the on-disk
103103
// ObjectMemoryReader can handle them.
104-
if (!IGM.CurSourceFile || IGM.CurSourceFile != type->getParentSourceFile())
104+
// Private entities are known to be accessible.
105+
if (type->getEffectiveAccess() >= AccessLevel::Internal &&
106+
(!IGM.CurSourceFile ||
107+
IGM.CurSourceFile != type->getParentSourceFile()))
105108
return false;
106109

107110
// @objc protocols don't have descriptors.
@@ -114,6 +117,7 @@ IRGenMangler::withSymbolicReferences(IRGenModule &IGM,
114117
llvm_unreachable("symbolic referent not handled");
115118
}
116119
};
120+
117121
SymbolicReferences.clear();
118122

119123
body();

test/IRGen/associated_type_witness.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -primary-file %s -emit-ir > %t.ll
22
// RUN: %FileCheck %s -check-prefix=GLOBAL < %t.ll
33
// RUN: %FileCheck %s < %t.ll
4+
5+
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -primary-file %s -emit-ir -wmo -num-threads 1 > %t.ll.wmo
6+
// RUN: %FileCheck %s -check-prefix=GLOBAL < %t.ll.wmo
7+
// RUN: %FileCheck %s < %t.ll.wmo
48
// REQUIRES: CPU=x86_64
59

610
protocol P {}
@@ -12,6 +16,16 @@ protocol Assocked {
1216

1317
struct Universal : P, Q {}
1418

19+
20+
// CHECK-LABEL: @"symbolic _____ 23associated_type_witness12OuterPrivate{{.*}}V" = linkonce_odr hidden constant
21+
// CHECK-SAME: @"$s23associated_type_witness12OuterPrivate{{.*}}5InnerE0V9InnermostVMn"
22+
private struct OuterPrivate {
23+
struct InnerPrivate: HasSimpleAssoc {
24+
struct Innermost { }
25+
typealias Assoc = Innermost
26+
}
27+
}
28+
1529
// CHECK: [[ASSOC_TYPE_NAMES:@.*]] = private constant [29 x i8] c"OneAssoc TwoAssoc ThreeAssoc\00"
1630
// CHECK: @"$s23associated_type_witness18HasThreeAssocTypesMp" =
1731
// CHECK-SAME: [[ASSOC_TYPE_NAMES]] to i64
@@ -116,7 +130,6 @@ protocol HasSimpleAssoc {
116130
}
117131
protocol DerivedFromSimpleAssoc : HasSimpleAssoc {}
118132

119-
120133
// Generic witness table pattern for GenericComputed : DerivedFromSimpleAssoc.
121134
// GLOBAL-LABEL: @"$s23associated_type_witness15GenericComputedVyxGAA22DerivedFromSimpleAssocAAWp" = internal constant [2 x i8*]
122135
// GLOBAL-SAME: @"$s23associated_type_witness15GenericComputedVyxGAA22DerivedFromSimpleAssocAAMc"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift -parse-stdlib %s -module-name main -o %t/a.out
3+
// RUN: %target-codesign %t/a.out
4+
// RUN: %target-run %t/a.out
5+
// REQUIRES: executable_test
6+
7+
import Swift
8+
import StdlibUnittest
9+
10+
protocol P {
11+
associatedtype A
12+
}
13+
14+
fileprivate struct Foo {
15+
fileprivate struct Inner: P {
16+
fileprivate struct Innermost { }
17+
typealias A = Innermost
18+
}
19+
}
20+
21+
func getP_A<T: P>(_: T.Type) -> Any.Type {
22+
return T.A.self
23+
}
24+
25+
let AssociatedTypeDemangleTests = TestSuite("AssociatedTypeDemangle")
26+
27+
28+
AssociatedTypeDemangleTests.test("private types") {
29+
expectEqual(Foo.Inner.Innermost.self, getP_A(Foo.Inner.self))
30+
}
31+
32+
runAllTests()

0 commit comments

Comments
 (0)