Skip to content

Commit 6ec6cbf

Browse files
committed
---
yaml --- r: 345547 b: refs/heads/master c: 370f93f h: refs/heads/master i: 345545: 6ec1f0b 345543: 75931a7
1 parent 2fdad9a commit 6ec6cbf

File tree

4 files changed

+60
-9
lines changed

4 files changed

+60
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 1ff59f7d73487a1cb1ae2c3638a9f1023ad85fa5
2+
refs/heads/master: 370f93ff39241bb5b60ffb1f071cbf9b91c8f010
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/lib/IRGen/IRGenMangler.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,29 @@ IRGenMangler::mangleTypeForReflection(IRGenModule &IGM,
8787
llvm::SaveAndRestore<std::function<bool (const DeclContext *)>>
8888
SymbolicReferencesForLocalTypes(CanSymbolicReference);
8989

90-
if (IGM.CurSourceFile
91-
&& !isa<ClangModuleUnit>(IGM.CurSourceFile)
90+
if ((!IGM.CurSourceFile || !isa<ClangModuleUnit>(IGM.CurSourceFile))
9291
&& !IGM.getOptions().IntegratedREPL) {
9392
CanSymbolicReference = [&](const DeclContext *dc) -> bool {
93+
// Can only symbolically reference nominal type declarations.
94+
auto nominal = dyn_cast<NominalTypeDecl>(dc);
95+
if (!nominal || isa<ProtocolDecl>(dc))
96+
return false;
97+
9498
// Symbolically reference types that are defined in the same file unit
9599
// as we're referencing from.
96-
//
97-
// We could eventually improve this to reference any type that ends
100+
if (IGM.CurSourceFile &&
101+
dc->getModuleScopeContext() == IGM.CurSourceFile)
102+
return true;
103+
104+
// fileprivate and private entities are always in the same file unit
105+
// that they're referenced from.
106+
if (nominal->getEffectiveAccess() < AccessLevel::Internal)
107+
return true;
108+
109+
// FIXME: We could eventually improve this to reference any type that ends
98110
// up with its nominal type descriptor in the same linked binary as us,
99111
// but IRGen doesn't know that with much certainty currently.
100-
return dc->getModuleScopeContext() == IGM.CurSourceFile
101-
&& isa<NominalTypeDecl>(dc)
102-
&& !isa<ProtocolDecl>(dc);
112+
return false;
103113
};
104114
}
105115

trunk/test/IRGen/associated_type_witness.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ protocol Assocked {
1212

1313
struct Universal : P, Q {}
1414

15+
16+
// CHECK-LABEL: @"symbolic \01____ 23associated_type_witness12OuterPrivate{{.*}}V" = linkonce_odr hidden constant
17+
// CHECK-SAME: @"$s23associated_type_witness12OuterPrivate{{.*}}5InnerE0V9InnermostVMn"
18+
private struct OuterPrivate {
19+
struct InnerPrivate: HasSimpleAssoc {
20+
struct Innermost { }
21+
typealias Assoc = Innermost
22+
}
23+
}
24+
1525
// CHECK: [[ASSOC_TYPE_NAMES:@.*]] = private constant [29 x i8] c"OneAssoc TwoAssoc ThreeAssoc\00"
1626
// CHECK: @"$s23associated_type_witness18HasThreeAssocTypesMp" =
1727
// CHECK-SAME: [[ASSOC_TYPE_NAMES]] to i64
@@ -121,7 +131,6 @@ protocol HasSimpleAssoc {
121131
}
122132
protocol DerivedFromSimpleAssoc : HasSimpleAssoc {}
123133

124-
125134
// Generic witness table pattern for GenericComputed : DerivedFromSimpleAssoc.
126135
// GLOBAL-LABEL: @"$s23associated_type_witness15GenericComputedVyxGAA22DerivedFromSimpleAssocAAWp" = internal constant [2 x i8*]
127136
// 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)