Skip to content

[Serialization] Use decl mangling for local decls, not type mangling. #10022

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
merged 1 commit into from
Jun 1, 2017
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
3 changes: 1 addition & 2 deletions lib/Serialization/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4468,8 +4468,7 @@ void Serializer::writeAST(ModuleOrSourceFile DC,
for (auto TD : localTypeDecls) {
hasLocalTypes = true;
Mangle::ASTMangler Mangler;
std::string MangledName = Mangler.mangleTypeAsUSR(
TD->getDeclaredInterfaceType());
std::string MangledName = Mangler.mangleDeclAsUSR(TD, /*USRPrefix*/"");
assert(!MangledName.empty() && "Mangled type came back empty!");
localTypeGenerator.insert(MangledName, {
addDeclRef(TD), TD->getLocalDiscriminator()
Expand Down
25 changes: 24 additions & 1 deletion test/IDE/local_types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

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

public func singleFunc() {
// CHECK-DAG: 10LocalTypes10singleFuncyyF06SingleD6StructL_V
Expand All @@ -20,6 +22,27 @@ public func singleFunc() {
enum SingleFuncEnum {
case SFEI(Int)
}

// CHECK-DAG: 10LocalTypes10singleFuncyyF13GenericStructL_V
struct GenericStruct<T> {
let sfgsi: Int
}

// CHECK-DAG: 10LocalTypes10singleFuncyyF12GenericClassL_C
class GenericClass<T> {
let sfgci: Int = 0
}

// CHECK-DAG: 10LocalTypes10singleFuncyyF11GenericEnumL_O
enum GenericEnum<T> {
case sfgei(Int)
}

// We'll need to handle this if we start saving alias types.
// NEGATIVE-NOT: AliasAAA
typealias SingleFuncAliasAAA = Int
// NEGATIVE-NOT: AliasGGG
typealias GenericAliasGGG<T> = (T, T)
}

public func singleFuncWithDuplicates(_ fake: Bool) {
Expand Down
28 changes: 20 additions & 8 deletions tools/swift-ide-test/swift-ide-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1572,15 +1572,27 @@ static int doPrintLocalTypes(const CompilerInvocation &InitInvok,
node = node->getFirstChild();

switch (node->getKind()) {
case NodeKind::Structure:
case NodeKind::Class:
case NodeKind::Enum:
break;
case NodeKind::Structure:
case NodeKind::Class:
case NodeKind::Enum:
break;

default:
llvm::errs() << "Expected a nominal type node in " <<
MangledName << "\n";
return EXIT_FAILURE;
case NodeKind::BoundGenericStructure:
case NodeKind::BoundGenericClass:
case NodeKind::BoundGenericEnum:
// Base type
typeNode = node->getFirstChild();
// Nominal type
node = typeNode->getFirstChild();
assert(node->getKind() == NodeKind::Structure ||
node->getKind() == NodeKind::Class ||
node->getKind() == NodeKind::Enum);
break;

default:
llvm::errs() << "Expected a nominal type node in " <<
MangledName << "\n";
return EXIT_FAILURE;
}

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