Skip to content

Commit 4e25d07

Browse files
committed
[lldb] Make use of target triple in TypeSystemSwiftTypeRef (#6692)
Update `TypeSystemSwiftTypeRef::GetTriple` to make use of an available target. With this change, `GetNameImporter` can work in more cases, since it only needs a triple. And since `GetNameImporter` can be expected to return a `ClangNameImporter` instance, the fallback to using Swift ASTContexts can be removed. This eliminates another case of unnecessarily loading Swift ASTContexts, which incurs a one time overhead that should only be paid when required. Partial follow up to #6654 (cherry-picked from commit f097595)
1 parent 543f052 commit 4e25d07

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

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

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,6 @@ TypeSystemSwiftTypeRef::GetSwiftName(const clang::Decl *clang_decl,
870870
// swiftification rules.
871871
if (auto *importer = GetNameImporter())
872872
return importer->ImportName(named_decl);
873-
if (auto *swift_ast_context = GetSwiftASTContext())
874-
return swift_ast_context->ImportName(named_decl);
875873
return {};
876874
}
877875

@@ -1482,10 +1480,7 @@ swift::DWARFImporterDelegate &TypeSystemSwiftTypeRef::GetDWARFImporterDelegate()
14821480
return *m_dwarf_importer_delegate_up;
14831481
}
14841482

1485-
ClangNameImporter *
1486-
TypeSystemSwiftTypeRef::GetNameImporter() const {
1487-
if (llvm::isa<TypeSystemSwiftTypeRefForExpressions>(this) || !m_module)
1488-
return nullptr;
1483+
ClangNameImporter *TypeSystemSwiftTypeRef::GetNameImporter() const {
14891484
if (!m_name_importer_up) {
14901485
swift::LangOptions lang_opts;
14911486
lang_opts.setTarget(GetTriple());
@@ -1496,8 +1491,13 @@ TypeSystemSwiftTypeRef::GetNameImporter() const {
14961491
}
14971492

14981493
llvm::Triple TypeSystemSwiftTypeRef::GetTriple() const {
1499-
if (m_module)
1500-
return m_module->GetArchitecture().GetTriple();
1494+
if (auto *module = GetModule())
1495+
return module->GetArchitecture().GetTriple();
1496+
else if (auto target_sp = GetTargetWP().lock())
1497+
return target_sp->GetArchitecture().GetTriple();
1498+
LLDB_LOGF(
1499+
GetLog(LLDBLog::Types),
1500+
"Cannot determine triple when no Module or no Target is available.");
15011501
return {};
15021502
}
15031503

@@ -2270,14 +2270,7 @@ bool TypeSystemSwiftTypeRef::IsVoidType(opaque_compiler_type_t type) {
22702270
// AST related queries
22712271
uint32_t TypeSystemSwiftTypeRef::GetPointerByteSize() {
22722272
auto impl = [&]() -> uint32_t {
2273-
llvm::Triple triple;
2274-
if (auto *module = GetModule())
2275-
triple = module->GetArchitecture().GetTriple();
2276-
else if (auto target_sp = GetTargetWP().lock())
2277-
triple = target_sp->GetArchitecture().GetTriple();
2278-
else
2279-
assert(false && "Expected module or target");
2280-
2273+
llvm::Triple triple = GetTriple();
22812274
if (triple.isArch64Bit())
22822275
return 8;
22832276
if (triple.isArch32Bit())

0 commit comments

Comments
 (0)