Skip to content

Commit f7178a3

Browse files
authored
Merge pull request #9405 from augusto2112/rebranch-remove-abi-name
[lldb] Remove functionality to rename module names before reconstruction
2 parents d17f9d8 + 30f3fda commit f7178a3

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
@@ -3820,29 +3820,6 @@ void SwiftASTContext::CacheModule(swift::ModuleDecl *module) {
38203820
m_swift_module_cache.insert({ID, module});
38213821
}
38223822

3823-
void SwiftASTContext::RegisterModuleABINameToRealName(
3824-
swift::ModuleDecl *module) {
3825-
if (module->getABIName() == module->getName())
3826-
return;
3827-
3828-
// Ignore _Concurrency, which is hardcoded in the compiler and should be
3829-
// looked up using its ABI name "Swift"
3830-
if (module->getName().str() == swift::SWIFT_CONCURRENCY_NAME)
3831-
return;
3832-
3833-
// Also ignore modules with the special "Compiler" prefix.
3834-
if (module->getABIName().str().starts_with(
3835-
swift::SWIFT_MODULE_ABI_NAME_PREFIX))
3836-
return;
3837-
3838-
LOG_PRINTF(GetLog(LLDBLog::Types),
3839-
"Mapping module ABI name \"%s\" to its regular name \"%s\"",
3840-
module->getABIName().str().str().c_str(),
3841-
module->getName().str().str().c_str());
3842-
m_module_abi_to_regular_name.insert({module->getABIName().str(),
3843-
module->getName().str()});
3844-
}
3845-
38463823
swift::ModuleDecl *SwiftASTContext::GetModule(const SourceModule &module,
38473824
Status &error, bool *cached) {
38483825
if (cached)
@@ -3952,7 +3929,6 @@ swift::ModuleDecl *SwiftASTContext::GetModule(const SourceModule &module,
39523929
module.path.front().GetCString(),
39533930
module_decl->getName().str().str().c_str());
39543931

3955-
RegisterModuleABINameToRealName(module_decl);
39563932
m_swift_module_cache[module.path.front().GetStringRef()] = module_decl;
39573933
return module_decl;
39583934
}
@@ -4007,7 +3983,6 @@ swift::ModuleDecl *SwiftASTContext::GetModule(const FileSpec &module_spec,
40073983
module_spec.GetPath().c_str(),
40083984
module->getName().str().str().c_str());
40093985

4010-
RegisterModuleABINameToRealName(module);
40113986
m_swift_module_cache[module_basename.GetCString()] = module;
40123987
return module;
40133988
} else {
@@ -4677,7 +4652,7 @@ SwiftASTContext::ReconstructTypeOrWarn(ConstString mangled_typename) {
46774652
}
46784653

46794654
llvm::Expected<swift::TypeBase *>
4680-
SwiftASTContext::ReconstructTypeImpl(ConstString mangled_typename) {
4655+
SwiftASTContext::ReconstructType(ConstString mangled_typename) {
46814656
VALID_OR_RETURN(nullptr);
46824657

46834658
const char *mangled_cstr = mangled_typename.AsCString();
@@ -4777,43 +4752,6 @@ SwiftASTContext::ReconstructTypeImpl(ConstString mangled_typename) {
47774752
"\" was not found");
47784753
}
47794754

4780-
llvm::Expected<swift::TypeBase *>
4781-
SwiftASTContext::ReconstructType(ConstString mangled_typename) {
4782-
VALID_OR_RETURN(nullptr);
4783-
4784-
// Mangled names are encoded with the ABI module name in debug info, but with
4785-
// the regular module name in the swift module. When reconstructing these
4786-
// types, SwiftASTContext must first substitute the ABI module name with the
4787-
// regular one on the type's mangled name before attempting to reconstruct
4788-
// them.
4789-
auto mangling = TypeSystemSwiftTypeRef::TransformModuleName(
4790-
mangled_typename, m_module_abi_to_regular_name);
4791-
ConstString module_adjusted_mangled_typename;
4792-
if (mangling.isSuccess())
4793-
module_adjusted_mangled_typename = ConstString(mangling.result());
4794-
4795-
if (mangled_typename == module_adjusted_mangled_typename)
4796-
return ReconstructTypeImpl(mangled_typename);
4797-
4798-
// If the mangles names don't match, try the one with the module's regular
4799-
// name first.
4800-
auto result = ReconstructTypeImpl(module_adjusted_mangled_typename);
4801-
4802-
if (result)
4803-
return result;
4804-
4805-
auto error = llvm::toString(result.takeError());
4806-
LOG_PRINTF(
4807-
GetLog(LLDBLog::Types),
4808-
"Reconstruct type failed for adjusted type: \"%s\" with error: \"%s\"",
4809-
module_adjusted_mangled_typename.GetCString(), error.c_str());
4810-
4811-
// If the mangled name with the regular name fails, try the one with the ABI
4812-
// name. This could happen if a module's ABI name is the same as another
4813-
// module's regular name.
4814-
return ReconstructTypeImpl(mangled_typename);
4815-
}
4816-
48174755
CompilerType SwiftASTContext::GetAnyObjectType() {
48184756
VALID_OR_RETURN(CompilerType());
48194757
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);
@@ -901,10 +897,6 @@ class SwiftASTContext : public TypeSystemSwift {
901897

902898
CompilerType GetAsClangType(ConstString mangled_name);
903899

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

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

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)