Skip to content

Commit 6786ceb

Browse files
committed
AST: Fix mangling of nominal types with a type alias parent type
The mangling AST cannot represent this, and we were incorrectly pulling generic arguments from the type alias type. Instead let's just desugar the parent type when mangling a nominal type. Fixes <rdar://problem/45900947>.
1 parent f49e0ba commit 6786ceb

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -679,20 +679,10 @@ static bool shouldMangleAsGeneric(Type type) {
679679
if (!type)
680680
return false;
681681

682-
TypeBase *typePtr = type.getPointer();
683-
if (auto typeAlias = dyn_cast<NameAliasType>(typePtr))
682+
if (auto typeAlias = dyn_cast<NameAliasType>(type.getPointer()))
684683
return !typeAlias->getSubstitutionMap().empty();
685684

686-
if (auto bound = dyn_cast<BoundGenericType>(typePtr))
687-
return true;
688-
689-
if (auto nominal = dyn_cast<NominalType>(typePtr))
690-
return shouldMangleAsGeneric(nominal->getParent());
691-
692-
if (auto unbound = dyn_cast<UnboundGenericType>(typePtr))
693-
return shouldMangleAsGeneric(unbound->getParent());
694-
695-
return false;
685+
return type->isSpecialized();
696686
}
697687

698688
/// Mangle a type into the buffer.
@@ -1110,15 +1100,15 @@ void ASTMangler::appendBoundGenericArgs(Type type, bool &isFirstArgList) {
11101100

11111101
if (auto *unboundType = dyn_cast<UnboundGenericType>(typePtr)) {
11121102
if (Type parent = unboundType->getParent())
1113-
appendBoundGenericArgs(parent, isFirstArgList);
1103+
appendBoundGenericArgs(parent->getDesugaredType(), isFirstArgList);
11141104
} else if (auto *nominalType = dyn_cast<NominalType>(typePtr)) {
11151105
if (Type parent = nominalType->getParent())
1116-
appendBoundGenericArgs(parent, isFirstArgList);
1106+
appendBoundGenericArgs(parent->getDesugaredType(), isFirstArgList);
11171107
} else {
11181108
auto boundType = cast<BoundGenericType>(typePtr);
11191109
genericArgs = boundType->getGenericArgs();
11201110
if (Type parent = boundType->getParent())
1121-
appendBoundGenericArgs(parent, isFirstArgList);
1111+
appendBoundGenericArgs(parent->getDesugaredType(), isFirstArgList);
11221112
}
11231113
if (isFirstArgList) {
11241114
appendOperator("y");

test/DebugInfo/typealias.swift

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ struct Generic<T> {
1919
}
2020

2121
typealias Specific = Generic<Int>
22+
typealias NotSpecific<T> = Generic<T>.Inner
23+
24+
struct Outer : P {
25+
enum Inner {
26+
case x
27+
}
28+
}
29+
30+
protocol P {
31+
typealias T = Outer
32+
}
33+
34+
// CHECK-DAG: [[INNER_TYPE:![0-9]+]] = !DICompositeType(tag: DW_TAG_structure_type{{.*}} identifier: "$s9typealias5OuterV5InnerOD"
2235

2336
func main () {
2437
// CHECK-DAG: !DILocalVariable(name: "a",{{.*}} type: ![[DIEOFFSET]]
@@ -33,9 +46,23 @@ func main () {
3346
markUsed(c);
3447

3548
// CHECK-DAG: !DILocalVariable(name: "d", {{.*}} type: [[NONGENERIC_TYPE:![0-9]+]])
36-
// CHECK: [[NONGENERIC_TYPE]] = !DICompositeType(tag: DW_TAG_structure_type{{.*}} identifier: "$s9typealias7GenericV5InnerOD"
49+
// CHECK: [[NONGENERIC_TYPE]] = !DICompositeType(tag: DW_TAG_structure_type{{.*}} identifier: "$s9typealias7GenericV5InnerOySi_GD"
3750
let d: Specific.Inner = .value
3851
markUsed(d)
52+
53+
// CHECK-DAG: !DILocalVariable(name: "e", {{.*}} type: [[INNER_TYPE]])
54+
let e: Outer.T.Inner = .x
55+
markUsed(e)
56+
57+
// CHECK-DAG: !DILocalVariable(name: "f", {{.*}} type: [[OUTER_T_TYPE:![0-9]+]])
58+
// CHECK: [[OUTER_T_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$s9typealias1PP1TayAA5OuterV_GD"
59+
let f: Outer.T = Outer()
60+
markUsed(f)
61+
62+
// CHECK-DAG: !DILocalVariable(name: "g", {{.*}} type: [[GENERIC_TYPE:![0-9]+]])
63+
// CHECK: [[GENERIC_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$s9typealias11NotSpecificaySiGD"
64+
let g: NotSpecific<Int> = .value
65+
markUsed(g)
3966
}
4067

41-
main();
68+
main()

0 commit comments

Comments
 (0)