Skip to content

Commit 988cf07

Browse files
authored
Merge pull request #21455 from DougGregor/generic-anonymous-context-descriptors
[IRGen/Runtime] Anonymous context descriptors can (should be) generic.
2 parents 625cd94 + 4cdfa7e commit 988cf07

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

lib/IRGen/GenMeta.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ namespace {
510510

511511
void layout() {
512512
super::layout();
513+
asImpl().addGenericSignature();
513514
}
514515

515516
ConstantReference getParent() {
@@ -522,7 +523,7 @@ namespace {
522523
}
523524

524525
GenericSignature *getGenericSignature() {
525-
return nullptr;
526+
return DC->getGenericSignatureOfContext();
526527
}
527528

528529
bool isUniqueDescriptor() {

stdlib/public/runtime/Demangle.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ swift::_buildDemanglingForContext(const ContextDescriptor *context,
4646
[&](const ContextDescriptor *context) -> NodePointer {
4747
if (demangledGenerics.empty())
4848
return nullptr;
49+
50+
if (context->getKind() == ContextDescriptorKind::Anonymous)
51+
return nullptr;
4952

5053
auto generics = context->getGenericContext();
5154
if (!generics)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s
2+
3+
import Builtin
4+
import Swift
5+
6+
protocol P { }
7+
8+
class Blah<T: P> {
9+
private struct Inner<U: P> { }
10+
}
11+
12+
// Anonymous descriptor
13+
// CHECK: @"$s29anonymous_context_descriptors4BlahC5Inner33{{.*}}MXX" =
14+
15+
// Flags: anonymous (2) + generic (0x80) + unique (0x40)
16+
// CHECK-SAME: i32 194
17+
18+
// Parent
19+
// CHECK-SAME: $s29anonymous_context_descriptors4BlahCMn
20+
21+
// # generic header
22+
// CHECK-SAME: i16 2, i16 2
23+
// CHECK-SAME: i16 4, i16 0

test/Runtime/associated_type_demangle_private.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ private protocol P2 {
4343
associatedtype A
4444
}
4545

46+
private func getP2_A<T: P2>(_: T.Type) -> Any.Type {
47+
return T.A.self
48+
}
49+
4650
struct Bar: P2 {
4751
typealias A = Int
4852
}
@@ -55,4 +59,19 @@ AssociatedTypeDemangleTests.test("private protocols") {
5559
expectEqual("C2<Bar>", String(describing: C2<Bar>.self))
5660
}
5761

62+
// rdar://problem/46853806
63+
class C3<T: P>: P2 {
64+
fileprivate struct Inner<U: P> { }
65+
fileprivate typealias A = Inner<T>
66+
}
67+
68+
extension Int: P {
69+
typealias A = Int
70+
}
71+
72+
AssociatedTypeDemangleTests.test("generic anonymous contexts") {
73+
expectEqual("Inner<Int>", String(describing: getP2_A(C3<Int>.self)))
74+
}
75+
76+
5877
runAllTests()

0 commit comments

Comments
 (0)