Skip to content

Commit 4eef276

Browse files
committed
[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. (cherry-picked from commit 97f6808)
1 parent 59ca59c commit 4eef276

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
@@ -2267,19 +2267,21 @@ bool TypeSystemSwiftTypeRef::IsVoidType(opaque_compiler_type_t type) {
22672267
// AST related queries
22682268
uint32_t TypeSystemSwiftTypeRef::GetPointerByteSize() {
22692269
auto impl = [&]() -> uint32_t {
2270-
if (auto *module = GetModule()) {
2271-
auto &triple = module->GetArchitecture().GetTriple();
2272-
if (triple.isArch64Bit())
2273-
return 8;
2274-
if (triple.isArch32Bit())
2275-
return 4;
2276-
if (triple.isArch16Bit())
2277-
return 2;
2278-
}
2279-
// An expression context has no module. Since it's for expression
2280-
// evaluation we might as well defer to the SwiftASTContext.
2281-
if (auto *swift_ast_context = GetSwiftASTContext())
2282-
return swift_ast_context->GetPointerByteSize();
2270+
llvm::Triple triple;
2271+
if (auto *module = GetModule())
2272+
triple = module->GetArchitecture().GetTriple();
2273+
else if (auto target_sp = GetTargetWP().lock())
2274+
triple = target_sp->GetArchitecture().GetTriple();
2275+
else
2276+
assert(false && "Expected module or target");
2277+
2278+
if (triple.isArch64Bit())
2279+
return 8;
2280+
if (triple.isArch32Bit())
2281+
return 4;
2282+
if (triple.isArch16Bit())
2283+
return 2;
2284+
22832285
return 0;
22842286
};
22852287
VALIDATE_AND_RETURN_STATIC(impl, GetPointerByteSize);

0 commit comments

Comments
 (0)