Skip to content

Commit 5d1412d

Browse files
authored
[Serialization] Use decl mangling for local decls, not type mangling. (#10022)
Otherwise we get an error with local generic types. We don't need the complexity of type mangling anyway. https://bugs.swift.org/browse/SR-5038
1 parent 89fed4f commit 5d1412d

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4468,8 +4468,7 @@ void Serializer::writeAST(ModuleOrSourceFile DC,
44684468
for (auto TD : localTypeDecls) {
44694469
hasLocalTypes = true;
44704470
Mangle::ASTMangler Mangler;
4471-
std::string MangledName = Mangler.mangleTypeAsUSR(
4472-
TD->getDeclaredInterfaceType());
4471+
std::string MangledName = Mangler.mangleDeclAsUSR(TD, /*USRPrefix*/"");
44734472
assert(!MangledName.empty() && "Mangled type came back empty!");
44744473
localTypeGenerator.insert(MangledName, {
44754474
addDeclRef(TD), TD->getLocalDiscriminator()

test/IDE/local_types.swift

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
// RUN: rm -rf %t && mkdir -p %t
44
// RUN: %target-swiftc_driver -swift-version 3 -v -emit-module -module-name LocalTypes -o %t/LocalTypes.swiftmodule %s
5-
// RUN: %target-swift-ide-test -swift-version 3 -print-local-types -I %t -module-to-print LocalTypes -source-filename %s | %FileCheck %s
5+
// RUN: %target-swift-ide-test -swift-version 3 -print-local-types -I %t -module-to-print LocalTypes -source-filename %s > %t.dump
6+
// RUN: %FileCheck %s < %t.dump
7+
// RUN: %FileCheck -check-prefix=NEGATIVE %s < %t.dump
68

79
public func singleFunc() {
810
// CHECK-DAG: 10LocalTypes10singleFuncyyF06SingleD6StructL_V
@@ -20,6 +22,27 @@ public func singleFunc() {
2022
enum SingleFuncEnum {
2123
case SFEI(Int)
2224
}
25+
26+
// CHECK-DAG: 10LocalTypes10singleFuncyyF13GenericStructL_V
27+
struct GenericStruct<T> {
28+
let sfgsi: Int
29+
}
30+
31+
// CHECK-DAG: 10LocalTypes10singleFuncyyF12GenericClassL_C
32+
class GenericClass<T> {
33+
let sfgci: Int = 0
34+
}
35+
36+
// CHECK-DAG: 10LocalTypes10singleFuncyyF11GenericEnumL_O
37+
enum GenericEnum<T> {
38+
case sfgei(Int)
39+
}
40+
41+
// We'll need to handle this if we start saving alias types.
42+
// NEGATIVE-NOT: AliasAAA
43+
typealias SingleFuncAliasAAA = Int
44+
// NEGATIVE-NOT: AliasGGG
45+
typealias GenericAliasGGG<T> = (T, T)
2346
}
2447

2548
public func singleFuncWithDuplicates(_ fake: Bool) {

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,15 +1572,27 @@ static int doPrintLocalTypes(const CompilerInvocation &InitInvok,
15721572
node = node->getFirstChild();
15731573

15741574
switch (node->getKind()) {
1575-
case NodeKind::Structure:
1576-
case NodeKind::Class:
1577-
case NodeKind::Enum:
1578-
break;
1575+
case NodeKind::Structure:
1576+
case NodeKind::Class:
1577+
case NodeKind::Enum:
1578+
break;
15791579

1580-
default:
1581-
llvm::errs() << "Expected a nominal type node in " <<
1582-
MangledName << "\n";
1583-
return EXIT_FAILURE;
1580+
case NodeKind::BoundGenericStructure:
1581+
case NodeKind::BoundGenericClass:
1582+
case NodeKind::BoundGenericEnum:
1583+
// Base type
1584+
typeNode = node->getFirstChild();
1585+
// Nominal type
1586+
node = typeNode->getFirstChild();
1587+
assert(node->getKind() == NodeKind::Structure ||
1588+
node->getKind() == NodeKind::Class ||
1589+
node->getKind() == NodeKind::Enum);
1590+
break;
1591+
1592+
default:
1593+
llvm::errs() << "Expected a nominal type node in " <<
1594+
MangledName << "\n";
1595+
return EXIT_FAILURE;
15841596
}
15851597

15861598
while (node->getKind() != NodeKind::LocalDeclName)

0 commit comments

Comments
 (0)