Skip to content

Commit df110cd

Browse files
authored
Merge pull request #9180 from augusto2112/remove-abi-name
[lldb] Remove functionality to rename module names before reconstruction
2 parents ddcbf4c + b102270 commit df110cd

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
@@ -3986,29 +3986,6 @@ void SwiftASTContext::CacheModule(swift::ModuleDecl *module) {
39863986
m_swift_module_cache.insert({ID, module});
39873987
}
39883988

3989-
void SwiftASTContext::RegisterModuleABINameToRealName(
3990-
swift::ModuleDecl *module) {
3991-
if (module->getABIName() == module->getName())
3992-
return;
3993-
3994-
// Ignore _Concurrency, which is hardcoded in the compiler and should be
3995-
// looked up using its ABI name "Swift"
3996-
if (module->getName().str() == swift::SWIFT_CONCURRENCY_NAME)
3997-
return;
3998-
3999-
// Also ignore modules with the special "Compiler" prefix.
4000-
if (module->getABIName().str().starts_with(
4001-
swift::SWIFT_MODULE_ABI_NAME_PREFIX))
4002-
return;
4003-
4004-
LOG_PRINTF(GetLog(LLDBLog::Types),
4005-
"Mapping module ABI name \"%s\" to its regular name \"%s\"",
4006-
module->getABIName().str().str().c_str(),
4007-
module->getName().str().str().c_str());
4008-
m_module_abi_to_regular_name.insert({module->getABIName().str(),
4009-
module->getName().str()});
4010-
}
4011-
40123989
swift::ModuleDecl *SwiftASTContext::GetModule(const SourceModule &module,
40133990
Status &error, bool *cached) {
40143991
if (cached)
@@ -4118,7 +4095,6 @@ swift::ModuleDecl *SwiftASTContext::GetModule(const SourceModule &module,
41184095
module.path.front().GetCString(),
41194096
module_decl->getName().str().str().c_str());
41204097

4121-
RegisterModuleABINameToRealName(module_decl);
41224098
m_swift_module_cache[module.path.front().GetStringRef()] = module_decl;
41234099
return module_decl;
41244100
}
@@ -4173,7 +4149,6 @@ swift::ModuleDecl *SwiftASTContext::GetModule(const FileSpec &module_spec,
41734149
module_spec.GetPath().c_str(),
41744150
module->getName().str().str().c_str());
41754151

4176-
RegisterModuleABINameToRealName(module);
41774152
m_swift_module_cache[module_basename.GetCString()] = module;
41784153
return module;
41794154
} else {
@@ -4842,7 +4817,7 @@ SwiftASTContext::ReconstructTypeOrWarn(ConstString mangled_typename) {
48424817
}
48434818

48444819
llvm::Expected<swift::TypeBase *>
4845-
SwiftASTContext::ReconstructTypeImpl(ConstString mangled_typename) {
4820+
SwiftASTContext::ReconstructType(ConstString mangled_typename) {
48464821
VALID_OR_RETURN(nullptr);
48474822

48484823
const char *mangled_cstr = mangled_typename.AsCString();
@@ -4948,43 +4923,6 @@ SwiftASTContext::ReconstructTypeImpl(ConstString mangled_typename) {
49484923
"\" was not found");
49494924
}
49504925

4951-
llvm::Expected<swift::TypeBase *>
4952-
SwiftASTContext::ReconstructType(ConstString mangled_typename) {
4953-
VALID_OR_RETURN(nullptr);
4954-
4955-
// Mangled names are encoded with the ABI module name in debug info, but with
4956-
// the regular module name in the swift module. When reconstructing these
4957-
// types, SwiftASTContext must first substitute the ABI module name with the
4958-
// regular one on the type's mangled name before attempting to reconstruct
4959-
// them.
4960-
auto mangling = TypeSystemSwiftTypeRef::TransformModuleName(
4961-
mangled_typename, m_module_abi_to_regular_name);
4962-
ConstString module_adjusted_mangled_typename;
4963-
if (mangling.isSuccess())
4964-
module_adjusted_mangled_typename = ConstString(mangling.result());
4965-
4966-
if (mangled_typename == module_adjusted_mangled_typename)
4967-
return ReconstructTypeImpl(mangled_typename);
4968-
4969-
// If the mangles names don't match, try the one with the module's regular
4970-
// name first.
4971-
auto result = ReconstructTypeImpl(module_adjusted_mangled_typename);
4972-
4973-
if (result)
4974-
return result;
4975-
4976-
auto error = llvm::toString(result.takeError());
4977-
LOG_PRINTF(
4978-
GetLog(LLDBLog::Types),
4979-
"Reconstruct type failed for adjusted type: \"%s\" with error: \"%s\"",
4980-
module_adjusted_mangled_typename.GetCString(), error.c_str());
4981-
4982-
// If the mangled name with the regular name fails, try the one with the ABI
4983-
// name. This could happen if a module's ABI name is the same as another
4984-
// module's regular name.
4985-
return ReconstructTypeImpl(mangled_typename);
4986-
}
4987-
49884926
CompilerType SwiftASTContext::GetAnyObjectType() {
49894927
VALID_OR_RETURN(CompilerType());
49904928
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);
@@ -908,10 +904,6 @@ class SwiftASTContext : public TypeSystemSwift {
908904

909905
CompilerType GetAsClangType(ConstString mangled_name);
910906

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

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

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
@@ -365,12 +365,6 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift {
365365
CanonicalizeSugar(swift::Demangle::Demangler &dem,
366366
swift::Demangle::NodePointer node);
367367

368-
/// Transforms the module name in the mangled type name using module_name_map
369-
/// as the mapping source.
370-
static swift::Demangle::ManglingErrorOr<std::string>
371-
TransformModuleName(llvm::StringRef mangled_name,
372-
const llvm::StringMap<llvm::StringRef> &module_name_map);
373-
374368
/// Return the canonicalized Demangle tree for a Swift mangled type name.
375369
swift::Demangle::NodePointer
376370
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)