Skip to content

Commit b102270

Browse files
committed
[lldb] Remove functionality to rename module names before reconstruction
Remove functionality to rename a type's module name from ABI name to real name before type reconstruction. With changes in the compiler side, this functionality is not needed anymore. Besides, this functionality was incomplete as it could not deal with multiple modules sharing the same ABI name.
1 parent fe0f467 commit b102270

File tree

9 files changed

+95
-105
lines changed

9 files changed

+95
-105
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3977,29 +3977,6 @@ void SwiftASTContext::CacheModule(swift::ModuleDecl *module) {
39773977
m_swift_module_cache.insert({ID, module});
39783978
}
39793979

3980-
void SwiftASTContext::RegisterModuleABINameToRealName(
3981-
swift::ModuleDecl *module) {
3982-
if (module->getABIName() == module->getName())
3983-
return;
3984-
3985-
// Ignore _Concurrency, which is hardcoded in the compiler and should be
3986-
// looked up using its ABI name "Swift"
3987-
if (module->getName().str() == swift::SWIFT_CONCURRENCY_NAME)
3988-
return;
3989-
3990-
// Also ignore modules with the special "Compiler" prefix.
3991-
if (module->getABIName().str().starts_with(
3992-
swift::SWIFT_MODULE_ABI_NAME_PREFIX))
3993-
return;
3994-
3995-
LOG_PRINTF(GetLog(LLDBLog::Types),
3996-
"Mapping module ABI name \"%s\" to its regular name \"%s\"",
3997-
module->getABIName().str().str().c_str(),
3998-
module->getName().str().str().c_str());
3999-
m_module_abi_to_regular_name.insert({module->getABIName().str(),
4000-
module->getName().str()});
4001-
}
4002-
40033980
swift::ModuleDecl *SwiftASTContext::GetModule(const SourceModule &module,
40043981
Status &error, bool *cached) {
40053982
if (cached)
@@ -4109,7 +4086,6 @@ swift::ModuleDecl *SwiftASTContext::GetModule(const SourceModule &module,
41094086
module.path.front().GetCString(),
41104087
module_decl->getName().str().str().c_str());
41114088

4112-
RegisterModuleABINameToRealName(module_decl);
41134089
m_swift_module_cache[module.path.front().GetStringRef()] = module_decl;
41144090
return module_decl;
41154091
}
@@ -4164,7 +4140,6 @@ swift::ModuleDecl *SwiftASTContext::GetModule(const FileSpec &module_spec,
41644140
module_spec.GetPath().c_str(),
41654141
module->getName().str().str().c_str());
41664142

4167-
RegisterModuleABINameToRealName(module);
41684143
m_swift_module_cache[module_basename.GetCString()] = module;
41694144
return module;
41704145
} else {
@@ -4833,7 +4808,7 @@ SwiftASTContext::ReconstructTypeOrWarn(ConstString mangled_typename) {
48334808
}
48344809

48354810
llvm::Expected<swift::TypeBase *>
4836-
SwiftASTContext::ReconstructTypeImpl(ConstString mangled_typename) {
4811+
SwiftASTContext::ReconstructType(ConstString mangled_typename) {
48374812
VALID_OR_RETURN(nullptr);
48384813

48394814
const char *mangled_cstr = mangled_typename.AsCString();
@@ -4939,43 +4914,6 @@ SwiftASTContext::ReconstructTypeImpl(ConstString mangled_typename) {
49394914
"\" was not found");
49404915
}
49414916

4942-
llvm::Expected<swift::TypeBase *>
4943-
SwiftASTContext::ReconstructType(ConstString mangled_typename) {
4944-
VALID_OR_RETURN(nullptr);
4945-
4946-
// Mangled names are encoded with the ABI module name in debug info, but with
4947-
// the regular module name in the swift module. When reconstructing these
4948-
// types, SwiftASTContext must first substitute the ABI module name with the
4949-
// regular one on the type's mangled name before attempting to reconstruct
4950-
// them.
4951-
auto mangling = TypeSystemSwiftTypeRef::TransformModuleName(
4952-
mangled_typename, m_module_abi_to_regular_name);
4953-
ConstString module_adjusted_mangled_typename;
4954-
if (mangling.isSuccess())
4955-
module_adjusted_mangled_typename = ConstString(mangling.result());
4956-
4957-
if (mangled_typename == module_adjusted_mangled_typename)
4958-
return ReconstructTypeImpl(mangled_typename);
4959-
4960-
// If the mangles names don't match, try the one with the module's regular
4961-
// name first.
4962-
auto result = ReconstructTypeImpl(module_adjusted_mangled_typename);
4963-
4964-
if (result)
4965-
return result;
4966-
4967-
auto error = llvm::toString(result.takeError());
4968-
LOG_PRINTF(
4969-
GetLog(LLDBLog::Types),
4970-
"Reconstruct type failed for adjusted type: \"%s\" with error: \"%s\"",
4971-
module_adjusted_mangled_typename.GetCString(), error.c_str());
4972-
4973-
// If the mangled name with the regular name fails, try the one with the ABI
4974-
// name. This could happen if a module's ABI name is the same as another
4975-
// module's regular name.
4976-
return ReconstructTypeImpl(mangled_typename);
4977-
}
4978-
49794917
CompilerType SwiftASTContext::GetAnyObjectType() {
49804918
VALID_OR_RETURN(CompilerType());
49814919
ThreadSafeASTContext ast = GetASTContext();

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,6 @@ class SwiftASTContext : public TypeSystemSwift {
433433
/// Import compiler_type into this context and return the swift::CanType.
434434
swift::CanType GetCanonicalSwiftType(CompilerType compiler_type);
435435
private:
436-
/// Reconstruct a Swift AST type from a mangled name by looking its
437-
/// components up in Swift modules.
438-
llvm::Expected<swift::TypeBase *>
439-
ReconstructTypeImpl(ConstString mangled_typename);
440436

441437
protected:
442438
swift::Type GetSwiftType(lldb::opaque_compiler_type_t opaque_type);
@@ -907,10 +903,6 @@ class SwiftASTContext : public TypeSystemSwift {
907903

908904
CompilerType GetAsClangType(ConstString mangled_name);
909905

910-
/// Inserts the mapping from the module's ABI name to it's regular name into
911-
/// m_module_abi_to_regular_name if they're different.
912-
void RegisterModuleABINameToRealName(swift::ModuleDecl *module);
913-
914906
/// Data members.
915907
/// @{
916908
// Always non-null outside of unit tests.
@@ -974,9 +966,6 @@ class SwiftASTContext : public TypeSystemSwift {
974966
mutable bool m_reported_fatal_error = false;
975967
mutable bool m_logged_fatal_error = false;
976968

977-
/// Holds the source module name (value) for all modules with a custom ABI
978-
/// name (key).
979-
llvm::StringMap<llvm::StringRef> m_module_abi_to_regular_name;
980969
/// Whether this is a scratch or a module AST context.
981970
bool m_is_scratch_context = false;
982971

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -147,31 +147,6 @@ TypeSystemSwiftTypeRef::CanonicalizeSugar(swift::Demangle::Demangler &dem,
147147
});
148148
}
149149

150-
swift::Demangle::ManglingErrorOr<std::string>
151-
TypeSystemSwiftTypeRef::TransformModuleName(
152-
llvm::StringRef mangled_name,
153-
const llvm::StringMap<llvm::StringRef> &module_name_map) {
154-
swift::Demangle::Demangler dem;
155-
auto *node = dem.demangleSymbol(mangled_name);
156-
auto *adjusted_node = TypeSystemSwiftTypeRef::Transform(
157-
dem, node, [&](swift::Demangle::NodePointer node) {
158-
if (node->getKind() == Node::Kind::Module) {
159-
auto module_name = node->getText();
160-
if (module_name_map.contains(module_name)) {
161-
auto real_name = module_name_map.lookup(module_name);
162-
auto *adjusted_module_node =
163-
dem.createNodeWithAllocatedText(Node::Kind::Module, real_name);
164-
return adjusted_module_node;
165-
}
166-
}
167-
168-
return node;
169-
});
170-
171-
auto mangling = mangleNode(adjusted_node);
172-
return mangling;
173-
}
174-
175150
llvm::StringRef
176151
TypeSystemSwiftTypeRef::GetBaseName(swift::Demangle::NodePointer node) {
177152
if (!node)

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,6 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift {
364364
CanonicalizeSugar(swift::Demangle::Demangler &dem,
365365
swift::Demangle::NodePointer node);
366366

367-
/// Transforms the module name in the mangled type name using module_name_map
368-
/// as the mapping source.
369-
static swift::Demangle::ManglingErrorOr<std::string>
370-
TransformModuleName(llvm::StringRef mangled_name,
371-
const llvm::StringMap<llvm::StringRef> &module_name_map);
372-
373367
/// Return the canonicalized Demangle tree for a Swift mangled type name.
374368
swift::Demangle::NodePointer
375369
GetCanonicalDemangleTree(swift::Demangle::Demangler &dem,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
public class Generic<T> {
3+
let t: T
4+
public init(t: T) {
5+
self.t = t
6+
}
7+
}
8+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
SWIFT_SOURCES := main.swift
2+
LD_EXTRAS = -lLibrary -L$(BUILDDIR)
3+
SWIFTFLAGS_EXTRAS = -I$(BUILDDIR)
4+
5+
all: libLibrary.dylib a.out
6+
7+
include Makefile.rules
8+
9+
libLibrary.dylib: Library.swift
10+
$(MAKE) MAKE_DSYM=YES CC=$(CC) SWIFTC=$(SWIFTC) \
11+
ARCH=$(ARCH) DSYMUTIL=$(DSYMUTIL) \
12+
BASENAME=Library \
13+
SWIFTFLAGS_EXTRAS="-I$(BUILDDIR) -enable-library-evolution -emit-library -emit-module -parse-as-library -module-abi-name a" \
14+
VPATH=$(SRCDIR) -I $(SRCDIR) -f $(SRCDIR)/dylib.mk all
15+
16+
clean::
17+
$(MAKE) BASENAME=Library VPATH=$(SRCDIR) -I $(SRCDIR) -f $(SRCDIR)/dylib.mk clean
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import lldb
2+
from lldbsuite.test.lldbtest import *
3+
from lldbsuite.test.decorators import *
4+
import lldbsuite.test.lldbutil as lldbutil
5+
6+
class TestSwiftClashingABIName(TestBase):
7+
@swiftTest
8+
@skipUnlessDarwin
9+
def test(self):
10+
"""Test that expressions with types in modules with clashing abi names works"""
11+
self.build()
12+
13+
lldbutil.run_to_source_breakpoint(
14+
self, 'break here', lldb.SBFileSpec('main.swift'),
15+
extra_images=['Library'])
16+
17+
self.expect('expr --bind-generic-types true -- generic1',
18+
substrs=['a.Generic<a.One>', 't =', 'j = 98'])
19+
20+
self.expect('expr --bind-generic-types true -- generic2',
21+
substrs=['a.Generic2<a.Generic<a.One>>', 't2 =', 't =', 'j = 98'])
22+
23+
self.expect('expr --bind-generic-types true -- generic3',
24+
substrs=['a.Generic2<a.Generic<a.One>>', 't2 =', 't =', 'j = 98'])
25+
@swiftTest
26+
@skipUnlessDarwin
27+
def test_in_self(self):
28+
"""Test a library with a private import for which there is no debug info"""
29+
self.build()
30+
31+
lldbutil.run_to_source_breakpoint(
32+
self, 'break for self', lldb.SBFileSpec('main.swift'))
33+
34+
self.expect('expr --bind-generic-types true -- self',
35+
substrs=['a.Generic<a.One>', 't =', 'j = 98'])
36+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
DYLIB_ONLY := YES
2+
DYLIB_NAME := $(BASENAME)
3+
DYLIB_SWIFT_SOURCES := $(DYLIB_NAME).swift
4+
include Makefile.rules
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Library
2+
3+
public class One {
4+
let j = 98
5+
init() {}
6+
}
7+
8+
public class Generic2<T> {
9+
let t2: T
10+
public init(t: T) {
11+
self.t2 = t
12+
}
13+
14+
func foo() {
15+
print("break for self")
16+
}
17+
}
18+
19+
20+
func main() {
21+
let two = a.One()
22+
let generic1 = Library.Generic<a.One>(t: two)
23+
let generic2 = a.Generic2<Library.Generic<a.One>>(t: generic1)
24+
let generic3 = Library.Generic<a.Generic2<Library.Generic<a.One>>>(t: generic2)
25+
generic2.foo()
26+
print("break here")
27+
}
28+
29+
main()

0 commit comments

Comments
 (0)