Skip to content

Respect the module ABI name when mangling for the debugger #73090

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
Apr 18, 2024
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: 3 additions & 0 deletions include/swift/Strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ constexpr static const StringLiteral SWIFT_ONONE_SUPPORT = "SwiftOnoneSupport";
constexpr static const StringLiteral SWIFT_CONCURRENCY_NAME = "_Concurrency";
/// The name of the Concurrency Shims Clang module
constexpr static const StringLiteral SWIFT_CONCURRENCY_SHIMS_NAME = "_SwiftConcurrencyShims";
/// The unique ABI prefix that swift-syntax uses when it's built as part of the
/// compiler.
constexpr static const StringLiteral SWIFT_MODULE_ABI_NAME_PREFIX = "Compiler";
/// The name of the Distributed module, which supports that extension.
constexpr static const StringLiteral SWIFT_DISTRIBUTED_NAME = "Distributed";
/// The name of the StringProcessing module, which supports that extension.
Expand Down
15 changes: 12 additions & 3 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2514,10 +2514,19 @@ void ASTMangler::appendModule(const ModuleDecl *module,
// For example, if a module Foo has 'import Bar', and '-module-alias Bar=Baz'
// was passed, the name 'Baz' will be used for mangling besides loading.
StringRef ModName = module->getRealName().str();
if (RespectOriginallyDefinedIn &&
module->getABIName() != module->getName()) { // check if the ABI name is set

// If RespectOriginallyDefinedIn is not set, ignore the ABI name only for
// _Concurrency and swift-syntax (which adds "Compiler" as a prefix when
// building swift-syntax as part of the compiler).
// TODO: Mangling for the debugger should respect originally defined in, but
// as of right now there is not enough information in the mangled name to
// reconstruct AST types from mangled names when using that attribute.
if ((RespectOriginallyDefinedIn ||
(module->getName().str() != SWIFT_CONCURRENCY_NAME &&
!module->getABIName().str().starts_with(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why starts_with?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a CMake variable:

# Add unique ABI prefix to swift-syntax libraries so that compiler libraries (e.g. sourcekitdInProc)
# can be used from tools that has its own swift-syntax libraries as SwiftPM dependencies.
set(SWIFT_MODULE_ABI_NAME_PREFIX "Compiler")

This is prefixed to swift-syntax. It could potentially be prefixed to some other special compiler library in the future, so I'm checking for that. Option 2 would be to specifically check for "CompilerSwiftSyntax"

SWIFT_MODULE_ABI_NAME_PREFIX))) &&
module->getABIName() != module->getName())
ModName = module->getABIName().str();
}

// Try the special 'swift' substitution.
if (ModName == STDLIB_NAME) {
Expand Down
13 changes: 13 additions & 0 deletions test/DebugInfo/module_abi_name.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: %target-swift-frontend -primary-file %s -emit-ir -g -module-name=Hello -module-abi-name Goodbye -emit-ir -o - | %FileCheck %s

class SomeClass {}
// CHECK: DICompositeType(tag: DW_TAG_structure_type, name: "SomeClass",{{.*}}runtimeLang: DW_LANG_Swift, identifier: "$s7Goodbye9SomeClassCD"

@available(macOS 10.13, *)
@_originallyDefinedIn(module: "ThirdModule", OSX 10.12)
class DefinedElsewhere {}
// CHECK: DICompositeType(tag: DW_TAG_structure_type, name: "DefinedElsewhere",{{.*}}runtimeLang: DW_LANG_Swift, identifier: "$s7Goodbye16DefinedElsewhereCD")

let v1 = SomeClass()
let v2 = DefinedElsewhere()