Skip to content

Commit f097595

Browse files
authored
[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
1 parent 637f306 commit f097595

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
@@ -891,8 +891,6 @@ TypeSystemSwiftTypeRef::GetSwiftName(const clang::Decl *clang_decl,
891891
// swiftification rules.
892892
if (auto *importer = GetNameImporter())
893893
return importer->ImportName(named_decl);
894-
if (auto *swift_ast_context = GetSwiftASTContext())
895-
return swift_ast_context->ImportName(named_decl);
896894
return {};
897895
}
898896

@@ -1495,10 +1493,7 @@ swift::DWARFImporterDelegate &TypeSystemSwiftTypeRef::GetDWARFImporterDelegate()
14951493
return *m_dwarf_importer_delegate_up;
14961494
}
14971495

1498-
ClangNameImporter *
1499-
TypeSystemSwiftTypeRef::GetNameImporter() const {
1500-
if (llvm::isa<TypeSystemSwiftTypeRefForExpressions>(this) || !m_module)
1501-
return nullptr;
1496+
ClangNameImporter *TypeSystemSwiftTypeRef::GetNameImporter() const {
15021497
if (!m_name_importer_up) {
15031498
swift::LangOptions lang_opts;
15041499
lang_opts.setTarget(GetTriple());
@@ -1509,8 +1504,13 @@ TypeSystemSwiftTypeRef::GetNameImporter() const {
15091504
}
15101505

15111506
llvm::Triple TypeSystemSwiftTypeRef::GetTriple() const {
1512-
if (m_module)
1513-
return m_module->GetArchitecture().GetTriple();
1507+
if (auto *module = GetModule())
1508+
return module->GetArchitecture().GetTriple();
1509+
else if (auto target_sp = GetTargetWP().lock())
1510+
return target_sp->GetArchitecture().GetTriple();
1511+
LLDB_LOGF(
1512+
GetLog(LLDBLog::Types),
1513+
"Cannot determine triple when no Module or no Target is available.");
15141514
return {};
15151515
}
15161516

@@ -2282,14 +2282,7 @@ bool TypeSystemSwiftTypeRef::IsVoidType(opaque_compiler_type_t type) {
22822282
// AST related queries
22832283
uint32_t TypeSystemSwiftTypeRef::GetPointerByteSize() {
22842284
auto impl = [&]() -> uint32_t {
2285-
llvm::Triple triple;
2286-
if (auto *module = GetModule())
2287-
triple = module->GetArchitecture().GetTriple();
2288-
else if (auto target_sp = GetTargetWP().lock())
2289-
triple = target_sp->GetArchitecture().GetTriple();
2290-
else
2291-
assert(false && "Expected module or target");
2292-
2285+
llvm::Triple triple = GetTriple();
22932286
if (triple.isArch64Bit())
22942287
return 8;
22952288
if (triple.isArch32Bit())

0 commit comments

Comments
 (0)