Skip to content

Commit 9f8f2a1

Browse files
authored
Merge pull request #17576 from DougGregor/disable-generic-typealias-mangling-4.2
[4.2] Don't mangle generic type aliases at all
2 parents 73535cc + 6cbbce3 commit 9f8f2a1

File tree

9 files changed

+61
-43
lines changed

9 files changed

+61
-43
lines changed

include/swift/Demangling/DemangleNodes.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ NODE(BoundGenericClass)
3636
NODE(BoundGenericEnum)
3737
NODE(BoundGenericStructure)
3838
NODE(BoundGenericOtherNominalType)
39-
NODE(BoundGenericTypeAlias)
4039
NODE(BuiltinTypeName)
4140
NODE(CFunctionPointer)
4241
CONTEXT_NODE(Class)

lib/AST/ASTMangler.cpp

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -739,31 +739,18 @@ 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-
// For the DWARF output we want to mangle the type alias + context,
743-
// unless the type alias references a builtin type.
744742
TypeAliasDecl *decl = aliasTy->getDecl();
745743
if (decl->getModuleContext() == decl->getASTContext().TheBuiltinModule) {
746744
return appendType(aliasTy->getSinglyDesugaredType());
747745
}
748746

749-
if (type->isSpecialized()) {
750-
// Try to mangle the entire name as a substitution.
751-
if (tryMangleSubstitution(tybase))
752-
return;
753-
754-
appendAnyGenericType(decl);
755-
bool isFirstArgList = true;
756-
if (auto *nominalType = type->getAs<NominalType>()) {
757-
if (nominalType->getParent())
758-
type = nominalType->getParent();
759-
}
760-
appendBoundGenericArgs(type, isFirstArgList);
761-
appendRetroactiveConformances(type);
762-
appendOperator("G");
763-
addSubstitution(type.getPointer());
764-
return;
765-
}
747+
// FIXME: We also cannot yet mangle references to typealiases that
748+
// involve generics.
749+
if (decl->getGenericSignature())
750+
return appendSugaredType<NameAliasType>(type);
766751

752+
// For the DWARF output we want to mangle the type alias + context,
753+
// unless the type alias references a builtin type.
767754
return appendAnyGenericType(decl);
768755
}
769756

lib/Demangling/Demangler.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,9 +1335,6 @@ NodePointer Demangler::demangleBoundGenericArgs(NodePointer Nominal,
13351335
case Node::Kind::OtherNominalType:
13361336
kind = Node::Kind::BoundGenericOtherNominalType;
13371337
break;
1338-
case Node::Kind::TypeAlias:
1339-
kind = Node::Kind::BoundGenericTypeAlias;
1340-
break;
13411338
default:
13421339
return nullptr;
13431340
}

lib/Demangling/NodePrinter.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ class NodePrinter {
267267
case Node::Kind::BoundGenericEnum:
268268
case Node::Kind::BoundGenericStructure:
269269
case Node::Kind::BoundGenericOtherNominalType:
270-
case Node::Kind::BoundGenericTypeAlias:
271270
case Node::Kind::BuiltinTypeName:
272271
case Node::Kind::Class:
273272
case Node::Kind::DependentGenericType:
@@ -1541,7 +1540,6 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) {
15411540
case Node::Kind::BoundGenericStructure:
15421541
case Node::Kind::BoundGenericEnum:
15431542
case Node::Kind::BoundGenericOtherNominalType:
1544-
case Node::Kind::BoundGenericTypeAlias:
15451543
printBoundGeneric(Node);
15461544
return nullptr;
15471545
case Node::Kind::DynamicSelf:

lib/Demangling/OldRemangler.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,11 +1875,6 @@ void Remangler::mangleBoundGenericOtherNominalType(Node *node) {
18751875
mangleAnyNominalType(node, ctx);
18761876
}
18771877

1878-
void Remangler::mangleBoundGenericTypeAlias(Node *node) {
1879-
EntityContext ctx;
1880-
mangleAnyNominalType(node, ctx);
1881-
}
1882-
18831878
void Remangler::mangleTypeList(Node *node) {
18841879
mangleChildNodes(node); // all types
18851880
Out << '_';

lib/Demangling/Remangler.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,6 @@ void Remangler::mangleAnyNominalType(Node *node) {
463463
case Node::Kind::Enum: return mangleAnyGenericType(node, "O");
464464
case Node::Kind::Class: return mangleAnyGenericType(node, "C");
465465
case Node::Kind::OtherNominalType: return mangleAnyGenericType(node, "XY");
466-
case Node::Kind::TypeAlias: return mangleAnyGenericType(node, "a");
467466
default:
468467
unreachable("bad nominal type kind");
469468
}
@@ -482,8 +481,7 @@ void Remangler::mangleGenericArgs(Node *node, char &Separator) {
482481
case Node::Kind::BoundGenericOtherNominalType:
483482
case Node::Kind::BoundGenericStructure:
484483
case Node::Kind::BoundGenericEnum:
485-
case Node::Kind::BoundGenericClass:
486-
case Node::Kind::BoundGenericTypeAlias: {
484+
case Node::Kind::BoundGenericClass: {
487485
NodePointer unboundType = node->getChild(0);
488486
assert(unboundType->getKind() == Node::Kind::Type);
489487
NodePointer nominalType = unboundType->getChild(0);
@@ -595,10 +593,6 @@ void Remangler::mangleBoundGenericOtherNominalType(Node *node) {
595593
mangleAnyNominalType(node);
596594
}
597595

598-
void Remangler::mangleBoundGenericTypeAlias(Node *node) {
599-
mangleAnyNominalType(node);
600-
}
601-
602596
void Remangler::mangleBuiltinTypeName(Node *node) {
603597
Buffer << 'B';
604598
StringRef text = node->getText();
@@ -2037,7 +2031,6 @@ bool Demangle::isSpecialized(Node *node) {
20372031
case Node::Kind::BoundGenericEnum:
20382032
case Node::Kind::BoundGenericClass:
20392033
case Node::Kind::BoundGenericOtherNominalType:
2040-
case Node::Kind::BoundGenericTypeAlias:
20412034
return true;
20422035

20432036
case Node::Kind::Structure:
@@ -2073,8 +2066,7 @@ NodePointer Demangle::getUnspecialized(Node *node, NodeFactory &Factory) {
20732066
case Node::Kind::BoundGenericStructure:
20742067
case Node::Kind::BoundGenericEnum:
20752068
case Node::Kind::BoundGenericClass:
2076-
case Node::Kind::BoundGenericOtherNominalType:
2077-
case Node::Kind::BoundGenericTypeAlias: {
2069+
case Node::Kind::BoundGenericOtherNominalType: {
20782070
NodePointer unboundType = node->getChild(0);
20792071
assert(unboundType->getKind() == Node::Kind::Type);
20802072
NodePointer nominalType = unboundType->getChild(0);

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+
}

test/Demangle/Inputs/manglings.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,5 +310,4 @@ _$S3BBBBf0602365061_ ---> _$S3BBBBf0602365061_
310310
_$S3BBBBi0602365061_ ---> _$S3BBBBi0602365061_
311311
_$S3BBBBv0602365061_ ---> _$S3BBBBv0602365061_
312312
_T0lxxxmmmTk ---> _T0lxxxmmmTk
313-
$S4blah8PatatinoaySiGD -> blah.Patatino<Swift.Int>
314313

0 commit comments

Comments
 (0)