Skip to content

[4.2] Don't mangle generic type aliases at all #17576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion include/swift/Demangling/DemangleNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ NODE(BoundGenericClass)
NODE(BoundGenericEnum)
NODE(BoundGenericStructure)
NODE(BoundGenericOtherNominalType)
NODE(BoundGenericTypeAlias)
NODE(BuiltinTypeName)
NODE(CFunctionPointer)
CONTEXT_NODE(Class)
Expand Down
25 changes: 6 additions & 19 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -739,31 +739,18 @@ void ASTMangler::appendType(Type type) {
auto aliasTy = cast<NameAliasType>(tybase);

// It's not possible to mangle the context of the builtin module.
// For the DWARF output we want to mangle the type alias + context,
// unless the type alias references a builtin type.
TypeAliasDecl *decl = aliasTy->getDecl();
if (decl->getModuleContext() == decl->getASTContext().TheBuiltinModule) {
return appendType(aliasTy->getSinglyDesugaredType());
}

if (type->isSpecialized()) {
// Try to mangle the entire name as a substitution.
if (tryMangleSubstitution(tybase))
return;

appendAnyGenericType(decl);
bool isFirstArgList = true;
if (auto *nominalType = type->getAs<NominalType>()) {
if (nominalType->getParent())
type = nominalType->getParent();
}
appendBoundGenericArgs(type, isFirstArgList);
appendRetroactiveConformances(type);
appendOperator("G");
addSubstitution(type.getPointer());
return;
}
// FIXME: We also cannot yet mangle references to typealiases that
// involve generics.
if (decl->getGenericSignature())
return appendSugaredType<NameAliasType>(type);

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

Expand Down
3 changes: 0 additions & 3 deletions lib/Demangling/Demangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1335,9 +1335,6 @@ NodePointer Demangler::demangleBoundGenericArgs(NodePointer Nominal,
case Node::Kind::OtherNominalType:
kind = Node::Kind::BoundGenericOtherNominalType;
break;
case Node::Kind::TypeAlias:
kind = Node::Kind::BoundGenericTypeAlias;
break;
default:
return nullptr;
}
Expand Down
2 changes: 0 additions & 2 deletions lib/Demangling/NodePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ class NodePrinter {
case Node::Kind::BoundGenericEnum:
case Node::Kind::BoundGenericStructure:
case Node::Kind::BoundGenericOtherNominalType:
case Node::Kind::BoundGenericTypeAlias:
case Node::Kind::BuiltinTypeName:
case Node::Kind::Class:
case Node::Kind::DependentGenericType:
Expand Down Expand Up @@ -1541,7 +1540,6 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) {
case Node::Kind::BoundGenericStructure:
case Node::Kind::BoundGenericEnum:
case Node::Kind::BoundGenericOtherNominalType:
case Node::Kind::BoundGenericTypeAlias:
printBoundGeneric(Node);
return nullptr;
case Node::Kind::DynamicSelf:
Expand Down
5 changes: 0 additions & 5 deletions lib/Demangling/OldRemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1875,11 +1875,6 @@ void Remangler::mangleBoundGenericOtherNominalType(Node *node) {
mangleAnyNominalType(node, ctx);
}

void Remangler::mangleBoundGenericTypeAlias(Node *node) {
EntityContext ctx;
mangleAnyNominalType(node, ctx);
}

void Remangler::mangleTypeList(Node *node) {
mangleChildNodes(node); // all types
Out << '_';
Expand Down
12 changes: 2 additions & 10 deletions lib/Demangling/Remangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ void Remangler::mangleAnyNominalType(Node *node) {
case Node::Kind::Enum: return mangleAnyGenericType(node, "O");
case Node::Kind::Class: return mangleAnyGenericType(node, "C");
case Node::Kind::OtherNominalType: return mangleAnyGenericType(node, "XY");
case Node::Kind::TypeAlias: return mangleAnyGenericType(node, "a");
default:
unreachable("bad nominal type kind");
}
Expand All @@ -482,8 +481,7 @@ void Remangler::mangleGenericArgs(Node *node, char &Separator) {
case Node::Kind::BoundGenericOtherNominalType:
case Node::Kind::BoundGenericStructure:
case Node::Kind::BoundGenericEnum:
case Node::Kind::BoundGenericClass:
case Node::Kind::BoundGenericTypeAlias: {
case Node::Kind::BoundGenericClass: {
NodePointer unboundType = node->getChild(0);
assert(unboundType->getKind() == Node::Kind::Type);
NodePointer nominalType = unboundType->getChild(0);
Expand Down Expand Up @@ -595,10 +593,6 @@ void Remangler::mangleBoundGenericOtherNominalType(Node *node) {
mangleAnyNominalType(node);
}

void Remangler::mangleBoundGenericTypeAlias(Node *node) {
mangleAnyNominalType(node);
}

void Remangler::mangleBuiltinTypeName(Node *node) {
Buffer << 'B';
StringRef text = node->getText();
Expand Down Expand Up @@ -2037,7 +2031,6 @@ bool Demangle::isSpecialized(Node *node) {
case Node::Kind::BoundGenericEnum:
case Node::Kind::BoundGenericClass:
case Node::Kind::BoundGenericOtherNominalType:
case Node::Kind::BoundGenericTypeAlias:
return true;

case Node::Kind::Structure:
Expand Down Expand Up @@ -2073,8 +2066,7 @@ NodePointer Demangle::getUnspecialized(Node *node, NodeFactory &Factory) {
case Node::Kind::BoundGenericStructure:
case Node::Kind::BoundGenericEnum:
case Node::Kind::BoundGenericClass:
case Node::Kind::BoundGenericOtherNominalType:
case Node::Kind::BoundGenericTypeAlias: {
case Node::Kind::BoundGenericOtherNominalType: {
NodePointer unboundType = node->getChild(0);
assert(unboundType->getKind() == Node::Kind::Type);
NodePointer nominalType = unboundType->getChild(0);
Expand Down
2 changes: 0 additions & 2 deletions test/ClangImporter/objc_ir.swift
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,5 @@ func testBlocksWithGenerics(hba: HasBlockArray) -> Any {
// CHECK: ![[SWIFT_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$SSo14SwiftNameAliasaD", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, baseType: !{{[0-9]+}})

// 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]+]])
// CHECK: ![[SWIFT_GENERIC_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$SSo21SwiftGenericNameAliasaySo8NSNumberCGD", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, baseType: !{{[0-9]+}})

// 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]+]])
// CHECK: ![[SWIFT_CONSTR_GENERIC_NAME_ALIAS_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$SSo27SwiftConstrGenericNameAliasaySo8NSNumberCGD", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, baseType: !{{[0-9]+}})
53 changes: 53 additions & 0 deletions test/DebugInfo/DumpDeclFromMangledName.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,56 @@ func patatino() -> Int {
}

patatino()

class Foo<T> {
var x : T
init(_ x : T) {
self.x = x
}
}

typealias Patatino<T> = Foo<T>

public struct Outer<T> {
public struct Inner { }
public struct GenericInner<U> { }

public typealias Foo<U> = Outer<U>.Inner

public func blah() {
let foo: Foo<Int> = Outer<Int>.Inner()
}
}

extension Outer.GenericInner {
public typealias Bar = Int

public func useBar() {
let bar: Bar = 7
}
}

protocol P {
associatedtype A
}

protocol Q {
associatedtype B: P
typealias ProtocolTypeAliasThing = B.A
}

struct ConformsToP: P {
typealias A = Int
}

struct ConformsToQ: Q {
typealias B = ConformsToP
}

struct Blah {
typealias SomeQ = ConformsToQ

func foo() {
let bar: SomeQ.ProtocolTypeAliasThing? = nil
}
}
1 change: 0 additions & 1 deletion test/Demangle/Inputs/manglings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -310,5 +310,4 @@ _$S3BBBBf0602365061_ ---> _$S3BBBBf0602365061_
_$S3BBBBi0602365061_ ---> _$S3BBBBi0602365061_
_$S3BBBBv0602365061_ ---> _$S3BBBBv0602365061_
_T0lxxxmmmTk ---> _T0lxxxmmmTk
$S4blah8PatatinoaySiGD -> blah.Patatino<Swift.Int>