Skip to content

Commit 1134036

Browse files
committed
[Compile Time Constant Extraction] Map types with archetypes out of context, before mangling them for printing.
Matching logic in the ASTPrinter. Otherwise we attempt to mangle types with archetypes in them, which cannot be done, and causes the compiler to crash. Resolves rdar://113039215
1 parent 149e8e4 commit 1134036

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

lib/ConstExtract/ConstExtract.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ std::string toFullyQualifiedProtocolNameString(const swift::ProtocolDecl &Protoc
8585
}
8686

8787
std::string toMangledTypeNameString(const swift::Type &Type) {
88-
return Mangle::ASTMangler().mangleTypeWithoutPrefix(Type->getCanonicalType());
88+
auto PrintingType = Type;
89+
if (Type->hasArchetype())
90+
PrintingType = Type->mapTypeOutOfContext();
91+
return Mangle::ASTMangler().mangleTypeWithoutPrefix(PrintingType->getCanonicalType());
8992
}
9093

9194
} // namespace
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: echo "[MyProto]" > %t/protocols.json
3+
4+
// RUN: %target-swift-frontend -typecheck -emit-const-values-path %t/ExtractEnums.swiftconstvalues -const-gather-protocols-file %t/protocols.json -primary-file %s
5+
// RUN: cat %t/ExtractEnums.swiftconstvalues 2>&1 | %FileCheck %s
6+
7+
protocol MyProto {}
8+
9+
public struct Foo {
10+
init(bar: Any) {
11+
}
12+
}
13+
14+
public struct ArchetypalConformance<T>: MyProto {
15+
let baz: Foo = Foo(bar: T.self)
16+
public init() {}
17+
}
18+
19+
// CHECK: [
20+
// CHECK-NEXT: {
21+
// CHECK-NEXT: "typeName": "ExtractArchetype.ArchetypalConformance<T>"
22+
// CHECK: "valueKind": "InitCall",
23+
// CHECK-NEXT: "value": {
24+
// CHECK-NEXT: "type": "ExtractArchetype.Foo",
25+
// CHECK-NEXT: "arguments": [
26+
// CHECK-NEXT: {
27+
// CHECK-NEXT: "label": "bar",
28+
// CHECK-NEXT: "type": "Any",
29+
// CHECK-NEXT: "valueKind": "Type",
30+
// CHECK-NEXT: "value": {
31+
// CHECK-NEXT: "type": "T",
32+
// CHECK-NEXT: "mangledName": "x"
33+
// CHECK-NEXT: }
34+
// CHECK-NEXT: }
35+
// CHECK-NEXT: ]
36+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)