Skip to content

Commit 677552f

Browse files
committed
Mangle private discriminators into typealias names.
...by mangling them the same as any other value decl. This is important for debug info to preserve and recover a private typealias. rdar://problem/24921067
1 parent 5726370 commit 677552f

File tree

6 files changed

+37
-21
lines changed

6 files changed

+37
-21
lines changed

lib/AST/Mangle.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -966,18 +966,17 @@ void Mangler::mangleType(Type type, unsigned uncurryLevel) {
966966
assert(DWARFMangling && "sugared types are only legal for the debugger");
967967
auto NameAliasTy = cast<NameAliasType>(tybase);
968968
TypeAliasDecl *decl = NameAliasTy->getDecl();
969-
if (decl->getModuleContext() == decl->getASTContext().TheBuiltinModule)
969+
if (decl->getModuleContext() == decl->getASTContext().TheBuiltinModule) {
970970
// It's not possible to mangle the context of the builtin module.
971971
return mangleType(decl->getUnderlyingType(), uncurryLevel);
972+
}
972973

973974
Buffer << "a";
974975
// For the DWARF output we want to mangle the type alias + context,
975976
// unless the type alias references a builtin type.
976977
ContextStack context(*this);
977-
while (DeclCtx && !DeclCtx->isInnermostContextGeneric())
978-
DeclCtx = DeclCtx->getParent();
979978
mangleContextOf(decl, BindGenerics::None);
980-
mangleIdentifier(decl->getName());
979+
mangleDeclName(decl);
981980
return;
982981
}
983982

test/DebugInfo/typealias.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@ func markUsed<T>(t: T) {}
44

55
class DWARF {
66
// CHECK-DAG: ![[DIEOFFSET:.*]] = !DIDerivedType(tag: DW_TAG_typedef, name: "_TtaC9typealias5DWARF9DIEOffset",{{.*}} line: [[@LINE+1]], baseType: !"_TtVs6UInt32")
7-
typealias DIEOffset = UInt32
7+
typealias DIEOffset = UInt32
8+
// CHECK-DAG: ![[PRIVATETYPE:.*]] = !DIDerivedType(tag: DW_TAG_typedef, name: "_TtaC9typealias5DWARFP{{.+}}11PrivateType",{{.*}} line: [[@LINE+1]], baseType: !"_TtT_")
9+
private typealias PrivateType = ()
10+
private static func usePrivateType() -> PrivateType { return () }
811
}
912

1013
func main () {
1114
// CHECK-DAG: !DILocalVariable(name: "a",{{.*}} type: ![[DIEOFFSET]]
12-
var a : DWARF.DIEOffset = 123
13-
markUsed("a is \(a)")
15+
var a : DWARF.DIEOffset = 123
16+
markUsed(a)
1417
// CHECK-DAG: !DILocalVariable(name: "b",{{.*}} type: ![[DIEOFFSET]]
15-
var b = DWARF.DIEOffset(456) as DWARF.DIEOffset
16-
markUsed("b is \(b)")
18+
var b = DWARF.DIEOffset(456) as DWARF.DIEOffset
19+
markUsed(b)
20+
21+
// CHECK-DAG: !DILocalVariable(name: "c",{{.*}} type: ![[PRIVATETYPE]]
22+
let c = DWARF.usePrivateType()
1723
}
1824

1925
main();

test/Demangle/Inputs/manglings.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ _TF8manglingoi2qqFTSiSi_T_ ---> mangling.?? infix (Swift.Int, Swift.Int) -> ()
181181
_TFE11ext_structAV11def_structA1A4testfT_T_ ---> (extension in ext_structA):def_structA.A.test () -> ()
182182
_TF13devirt_accessP5_DISC15getPrivateClassFT_CS_P5_DISC12PrivateClass ---> devirt_access.(getPrivateClass in _DISC) () -> devirt_access.(PrivateClass in _DISC)
183183
_TF4mainP5_mainX3wxaFT_T_ ---> main.(λ in _main) () -> ()
184+
_TF4mainP5_main3abcFT_aS_P5_DISC3xyz ---> main.(abc in _main) () -> main.(xyz in _DISC)
184185
_TtPMP_ ---> protocol<>.Type
185186
_TFCs13_NSSwiftArray29canStoreElementsOfDynamicTypefPMP_Sb ---> Swift._NSSwiftArray.canStoreElementsOfDynamicType (protocol<>.Type) -> Swift.Bool
186187
_TFCs13_NSSwiftArrayg17staticElementTypePMP_ ---> Swift._NSSwiftArray.staticElementType.getter : protocol<>.Type

test/Demangle/Inputs/simplified-manglings.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ _TF8manglingoi2qqFTSiSi_T_ ---> ?? infix(Int, Int) -> ()
167167
_TFE11ext_structAV11def_structA1A4testfT_T_ ---> A.test() -> ()
168168
_TF13devirt_accessP5_DISC15getPrivateClassFT_CS_P5_DISC12PrivateClass ---> (getPrivateClass in _DISC)() -> (PrivateClass in _DISC)
169169
_TF4mainP5_mainX3wxaFT_T_ ---> (λ in _main)() -> ()
170+
_TF4mainP5_main3abcFT_aS_P5_DISC3xyz ---> (abc in _main)() -> (xyz in _DISC)
170171
_TtPMP_ ---> protocol<>.Type
171172
_TFCs13_NSSwiftArray29canStoreElementsOfDynamicTypefPMP_Sb ---> _NSSwiftArray.canStoreElementsOfDynamicType(protocol<>.Type) -> Bool
172173
_TFCs13_NSSwiftArrayg17staticElementTypePMP_ ---> _NSSwiftArray.staticElementType.getter

test/Demangle/lookup.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
// RUN: not %target-swift-ide-test -source-filename=%s -print-ast-typechecked -find-mangled=_TtCC14swift_ide_test5OuterP1_12PrivateInner
1616
// RUN: %target-swift-ide-test -source-filename=%s -print-ast-typechecked -find-mangled=_TtCC14swift_ide_test5OuterP33_5CB4BCC03C4B9CB2AEEDDFF10FE7BD1E12PrivateInner
1717
// RUN: %target-swift-ide-test -source-filename=%s -print-ast-typechecked -find-mangled=_TtCC14swift_ide_testP33_5CB4BCC03C4B9CB2AEEDDFF10FE7BD1E12PrivateOuter5Inner
18+
// RUN: %target-swift-ide-test -source-filename=%s -print-ast-typechecked -find-mangled=_Tta14swift_ide_testP33_5CB4BCC03C4B9CB2AEEDDFF10FE7BD1E16PrivateTypealias
19+
// RUN: %target-swift-ide-test -source-filename=%s -print-ast-typechecked -find-mangled=_TtaC14swift_ide_test5OuterP33_5CB4BCC03C4B9CB2AEEDDFF10FE7BD1E16PrivateTypealias
1820

1921
// RUN: %target-swiftc_driver -emit-module -o %t %s %S/Inputs/lookup_other.swift -module-name Lookup
2022
// RUN: echo 'import Lookup' > %t/test.swift
@@ -31,9 +33,12 @@ private struct PrivateStruct {
3133
let fromMainFile: Int
3234
}
3335

36+
private typealias PrivateTypealias = Int
37+
3438
class Outer {
3539
class Inner {}
3640
private class PrivateInner {}
41+
private typealias PrivateTypealias = Int
3742
}
3843

3944
private class PrivateOuter {

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,27 +1397,17 @@ static int doPrintAST(const CompilerInvocation &InitInvok,
13971397
case NodeKind::Enum:
13981398
case NodeKind::Protocol:
13991399
case NodeKind::Structure:
1400+
case NodeKind::TypeAlias:
14001401
break;
14011402
default:
1402-
llvm::errs() << "Name does not refer to a nominal type.\n";
1403+
llvm::errs() << "Name does not refer to a nominal type or typealias.\n";
14031404
return EXIT_FAILURE;
14041405
}
14051406

14061407
ASTContext &ctx = CI.getASTContext();
14071408

14081409
SmallVector<std::pair<DeclName, Identifier>, 4> identifiers;
14091410
do {
1410-
switch (node->getKind()) {
1411-
case NodeKind::Class:
1412-
case NodeKind::Enum:
1413-
case NodeKind::Protocol:
1414-
case NodeKind::Structure:
1415-
break;
1416-
default:
1417-
llvm::errs() << "Name does not refer to a nominal type.\n";
1418-
return EXIT_FAILURE;
1419-
}
1420-
14211411
auto nameNode = node->getChild(1);
14221412
switch (nameNode->getKind()) {
14231413
case NodeKind::Identifier:
@@ -1436,6 +1426,20 @@ static int doPrintAST(const CompilerInvocation &InitInvok,
14361426
}
14371427

14381428
node = node->getChild(0);
1429+
1430+
switch (node->getKind()) {
1431+
case NodeKind::Module:
1432+
// Will break out of loop below.
1433+
break;
1434+
case NodeKind::Class:
1435+
case NodeKind::Enum:
1436+
case NodeKind::Protocol:
1437+
case NodeKind::Structure:
1438+
break;
1439+
default:
1440+
llvm::errs() << "Name does not refer to a nominal type.\n";
1441+
return EXIT_FAILURE;
1442+
}
14391443
} while (node->getKind() != NodeKind::Module);
14401444

14411445
Module *M = getModuleByFullName(ctx, node->getText());

0 commit comments

Comments
 (0)