Skip to content

Commit 97f6808

Browse files
authored
[lldb] Remove use of SwiftASTContext in GetPointerByteSize (#6654)
When `TypeSystemSwiftTypeRef` instance doesn't correspond to a `Module`, it should have a `Target`. Either are sufficient to get the pointer size. This avoids loading and constructing Swift ASTContexts, which can be slow and unnecessary in this case.
1 parent 003820d commit 97f6808

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,19 +2279,21 @@ bool TypeSystemSwiftTypeRef::IsVoidType(opaque_compiler_type_t type) {
22792279
// AST related queries
22802280
uint32_t TypeSystemSwiftTypeRef::GetPointerByteSize() {
22812281
auto impl = [&]() -> uint32_t {
2282-
if (auto *module = GetModule()) {
2283-
auto &triple = module->GetArchitecture().GetTriple();
2284-
if (triple.isArch64Bit())
2285-
return 8;
2286-
if (triple.isArch32Bit())
2287-
return 4;
2288-
if (triple.isArch16Bit())
2289-
return 2;
2290-
}
2291-
// An expression context has no module. Since it's for expression
2292-
// evaluation we might as well defer to the SwiftASTContext.
2293-
if (auto *swift_ast_context = GetSwiftASTContext())
2294-
return swift_ast_context->GetPointerByteSize();
2282+
llvm::Triple triple;
2283+
if (auto *module = GetModule())
2284+
triple = module->GetArchitecture().GetTriple();
2285+
else if (auto target_sp = GetTargetWP().lock())
2286+
triple = target_sp->GetArchitecture().GetTriple();
2287+
else
2288+
assert(false && "Expected module or target");
2289+
2290+
if (triple.isArch64Bit())
2291+
return 8;
2292+
if (triple.isArch32Bit())
2293+
return 4;
2294+
if (triple.isArch16Bit())
2295+
return 2;
2296+
22952297
return 0;
22962298
};
22972299
VALIDATE_AND_RETURN_STATIC(impl, GetPointerByteSize);

0 commit comments

Comments
 (0)