Skip to content

Commit 6cbbce3

Browse files
committed
[Mangling] Don't mangle generic typealiases.
Mangling of generic typealiases for debug info is causing a long tail of bugs. Disable it on the Swift 4.2 branch; we'll fall back to the underlying type. Fixes rdar://problem/41444286.
1 parent 5a398c3 commit 6cbbce3

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,13 +739,16 @@ void ASTMangler::appendType(Type type) {
739739
auto aliasTy = cast<NameAliasType>(tybase);
740740

741741
// It's not possible to mangle the context of the builtin module.
742-
// FIXME: We also cannot yet mangle references to typealiases that
743-
// involve generics.
744742
TypeAliasDecl *decl = aliasTy->getDecl();
745743
if (decl->getModuleContext() == decl->getASTContext().TheBuiltinModule) {
746744
return appendType(aliasTy->getSinglyDesugaredType());
747745
}
748746

747+
// FIXME: We also cannot yet mangle references to typealiases that
748+
// involve generics.
749+
if (decl->getGenericSignature())
750+
return appendSugaredType<NameAliasType>(type);
751+
749752
// For the DWARF output we want to mangle the type alias + context,
750753
// unless the type alias references a builtin type.
751754
return appendAnyGenericType(decl);

test/ClangImporter/objc_ir.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,5 @@ func testBlocksWithGenerics(hba: HasBlockArray) -> Any {
363363
// CHECK: ![[SWIFT_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$SSo14SwiftNameAliasaD", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, baseType: !{{[0-9]+}})
364364

365365
// CHECK: ![[SWIFT_GENERIC_NAME_ALIAS_VAR]] = !DILocalVariable(name: "generic_obj", arg: 1, scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[SWIFT_GENERIC_NAME_ALIAS_TYPE:[0-9]+]])
366-
// CHECK: ![[SWIFT_GENERIC_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$SSo21SwiftGenericNameAliasaySo8NSNumberCGD", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, baseType: !{{[0-9]+}})
367366

368367
// CHECK: ![[SWIFT_CONSTR_GENERIC_NAME_ALIAS_VAR]] = !DILocalVariable(name: "constr_generic_obj", arg: 1, scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: ![[SWIFT_CONSTR_GENERIC_NAME_ALIAS_TYPE:[0-9]+]])
369-
// CHECK: ![[SWIFT_CONSTR_GENERIC_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$SSo27SwiftConstrGenericNameAliasaySo8NSNumberCGD", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, baseType: !{{[0-9]+}})

test/DebugInfo/DumpDeclFromMangledName.swift

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,56 @@ func patatino() -> Int {
3939
}
4040

4141
patatino()
42+
43+
class Foo<T> {
44+
var x : T
45+
init(_ x : T) {
46+
self.x = x
47+
}
48+
}
49+
50+
typealias Patatino<T> = Foo<T>
51+
52+
public struct Outer<T> {
53+
public struct Inner { }
54+
public struct GenericInner<U> { }
55+
56+
public typealias Foo<U> = Outer<U>.Inner
57+
58+
public func blah() {
59+
let foo: Foo<Int> = Outer<Int>.Inner()
60+
}
61+
}
62+
63+
extension Outer.GenericInner {
64+
public typealias Bar = Int
65+
66+
public func useBar() {
67+
let bar: Bar = 7
68+
}
69+
}
70+
71+
protocol P {
72+
associatedtype A
73+
}
74+
75+
protocol Q {
76+
associatedtype B: P
77+
typealias ProtocolTypeAliasThing = B.A
78+
}
79+
80+
struct ConformsToP: P {
81+
typealias A = Int
82+
}
83+
84+
struct ConformsToQ: Q {
85+
typealias B = ConformsToP
86+
}
87+
88+
struct Blah {
89+
typealias SomeQ = ConformsToQ
90+
91+
func foo() {
92+
let bar: SomeQ.ProtocolTypeAliasThing? = nil
93+
}
94+
}

0 commit comments

Comments
 (0)