Skip to content

Commit 30f3fda

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. (cherry picked from commit b102270)
1 parent d0e406e commit 30f3fda

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
@@ -3813,29 +3813,6 @@ void SwiftASTContext::CacheModule(swift::ModuleDecl *module) {
38133813
m_swift_module_cache.insert({ID, module});
38143814
}
38153815

3816-
void SwiftASTContext::RegisterModuleABINameToRealName(
3817-
swift::ModuleDecl *module) {
3818-
if (module->getABIName() == module->getName())
3819-
return;
3820-
3821-
// Ignore _Concurrency, which is hardcoded in the compiler and should be
3822-
// looked up using its ABI name "Swift"
3823-
if (module->getName().str() == swift::SWIFT_CONCURRENCY_NAME)
3824-
return;
3825-
3826-
// Also ignore modules with the special "Compiler" prefix.
3827-
if (module->getABIName().str().starts_with(
3828-
swift::SWIFT_MODULE_ABI_NAME_PREFIX))
3829-
return;
3830-
3831-
LOG_PRINTF(GetLog(LLDBLog::Types),
3832-
"Mapping module ABI name \"%s\" to its regular name \"%s\"",
3833-
module->getABIName().str().str().c_str(),
3834-
module->getName().str().str().c_str());
3835-
m_module_abi_to_regular_name.insert({module->getABIName().str(),
3836-
module->getName().str()});
3837-
}
3838-
38393816
swift::ModuleDecl *SwiftASTContext::GetModule(const SourceModule &module,
38403817
Status &error, bool *cached) {
38413818
if (cached)
@@ -3945,7 +3922,6 @@ swift::ModuleDecl *SwiftASTContext::GetModule(const SourceModule &module,
39453922
module.path.front().GetCString(),
39463923
module_decl->getName().str().str().c_str());
39473924

3948-
RegisterModuleABINameToRealName(module_decl);
39493925
m_swift_module_cache[module.path.front().GetStringRef()] = module_decl;
39503926
return module_decl;
39513927
}
@@ -4000,7 +3976,6 @@ swift::ModuleDecl *SwiftASTContext::GetModule(const FileSpec &module_spec,
40003976
module_spec.GetPath().c_str(),
40013977
module->getName().str().str().c_str());
40023978

4003-
RegisterModuleABINameToRealName(module);
40043979
m_swift_module_cache[module_basename.GetCString()] = module;
40053980
return module;
40063981
} else {
@@ -4670,7 +4645,7 @@ SwiftASTContext::ReconstructTypeOrWarn(ConstString mangled_typename) {
46704645
}
46714646

46724647
llvm::Expected<swift::TypeBase *>
4673-
SwiftASTContext::ReconstructTypeImpl(ConstString mangled_typename) {
4648+
SwiftASTContext::ReconstructType(ConstString mangled_typename) {
46744649
VALID_OR_RETURN(nullptr);
46754650

46764651
const char *mangled_cstr = mangled_typename.AsCString();
@@ -4770,43 +4745,6 @@ SwiftASTContext::ReconstructTypeImpl(ConstString mangled_typename) {
47704745
"\" was not found");
47714746
}
47724747

4773-
llvm::Expected<swift::TypeBase *>
4774-
SwiftASTContext::ReconstructType(ConstString mangled_typename) {
4775-
VALID_OR_RETURN(nullptr);
4776-
4777-
// Mangled names are encoded with the ABI module name in debug info, but with
4778-
// the regular module name in the swift module. When reconstructing these
4779-
// types, SwiftASTContext must first substitute the ABI module name with the
4780-
// regular one on the type's mangled name before attempting to reconstruct
4781-
// them.
4782-
auto mangling = TypeSystemSwiftTypeRef::TransformModuleName(
4783-
mangled_typename, m_module_abi_to_regular_name);
4784-
ConstString module_adjusted_mangled_typename;
4785-
if (mangling.isSuccess())
4786-
module_adjusted_mangled_typename = ConstString(mangling.result());
4787-
4788-
if (mangled_typename == module_adjusted_mangled_typename)
4789-
return ReconstructTypeImpl(mangled_typename);
4790-
4791-
// If the mangles names don't match, try the one with the module's regular
4792-
// name first.
4793-
auto result = ReconstructTypeImpl(module_adjusted_mangled_typename);
4794-
4795-
if (result)
4796-
return result;
4797-
4798-
auto error = llvm::toString(result.takeError());
4799-
LOG_PRINTF(
4800-
GetLog(LLDBLog::Types),
4801-
"Reconstruct type failed for adjusted type: \"%s\" with error: \"%s\"",
4802-
module_adjusted_mangled_typename.GetCString(), error.c_str());
4803-
4804-
// If the mangled name with the regular name fails, try the one with the ABI
4805-
// name. This could happen if a module's ABI name is the same as another
4806-
// module's regular name.
4807-
return ReconstructTypeImpl(mangled_typename);
4808-
}
4809-
48104748
CompilerType SwiftASTContext::GetAnyObjectType() {
48114749
VALID_OR_RETURN(CompilerType());
48124750
ThreadSafeASTContext ast = GetASTContext();

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

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

435431
protected:
436432
swift::Type GetSwiftType(lldb::opaque_compiler_type_t opaque_type);
@@ -902,10 +898,6 @@ class SwiftASTContext : public TypeSystemSwift {
902898

903899
CompilerType GetAsClangType(ConstString mangled_name);
904900

905-
/// Inserts the mapping from the module's ABI name to it's regular name into
906-
/// m_module_abi_to_regular_name if they're different.
907-
void RegisterModuleABINameToRealName(swift::ModuleDecl *module);
908-
909901
/// Data members.
910902
/// @{
911903
// Always non-null outside of unit tests.
@@ -969,9 +961,6 @@ class SwiftASTContext : public TypeSystemSwift {
969961
mutable bool m_reported_fatal_error = false;
970962
mutable bool m_logged_fatal_error = false;
971963

972-
/// Holds the source module name (value) for all modules with a custom ABI
973-
/// name (key).
974-
llvm::StringMap<llvm::StringRef> m_module_abi_to_regular_name;
975964
/// Whether this is a scratch or a module AST context.
976965
bool m_is_scratch_context = false;
977966

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)