Skip to content

Commit 1c18d12

Browse files
Merge pull request #3346 from adrian-prantl/lazy_ast
Avoid unconditionally calling into SwiftASTContext (NFC)
2 parents 02a248d + 2efaeca commit 1c18d12

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2507,8 +2507,14 @@ CompilerType TypeSystemSwiftTypeRef::GetChildCompilerTypeAtIndex(
25072507
child_byte_size, child_byte_offset, child_bitfield_bit_size,
25082508
child_bitfield_bit_offset, child_is_base_class,
25092509
child_is_deref_of_parent, valobj, language_flags));
2510-
auto ast_num_children = m_swift_ast_context->GetNumChildren(
2511-
ReconstructType(type), omit_empty_base_classes, exe_ctx);
2510+
llvm::Optional<unsigned> ast_num_children;
2511+
auto get_ast_num_children = [&]() {
2512+
if (ast_num_children)
2513+
return *ast_num_children;
2514+
ast_num_children = m_swift_ast_context->GetNumChildren(
2515+
ReconstructType(type), omit_empty_base_classes, exe_ctx);
2516+
return *ast_num_children;
2517+
};
25122518
auto impl = [&]() -> CompilerType {
25132519
ExecutionContextScope *exe_scope = nullptr;
25142520
if (exe_ctx)
@@ -2529,7 +2535,8 @@ CompilerType TypeSystemSwiftTypeRef::GetChildCompilerTypeAtIndex(
25292535
.endswith("sSo18NSNotificationNameaD"))
25302536
return GetTypeFromMangledTypename(ConstString("$sSo8NSStringCD"));
25312537
if (result.GetMangledTypeName().GetStringRef().count('$') > 1 &&
2532-
ast_num_children == runtime->GetNumChildren({this, type}, valobj))
2538+
get_ast_num_children() ==
2539+
runtime->GetNumChildren({this, type}, valobj))
25332540
// If available, prefer the AST for private types. Private
25342541
// identifiers are not ABI; the runtime returns anonymous private
25352542
// identifiers (using a '$' prefix) which cannot match identifiers
@@ -2635,7 +2642,7 @@ CompilerType TypeSystemSwiftTypeRef::GetChildCompilerTypeAtIndex(
26352642
// Because the API deals out an index into a list of children we
26362643
// can't mix&match between the two typesystems if there is such a
26372644
// divergence. We'll need to replace all calls at once.
2638-
if (ast_num_children <
2645+
if (get_ast_num_children() <
26392646
runtime->GetNumChildren({this, type}, valobj).getValueOr(0))
26402647
return impl();
26412648

0 commit comments

Comments
 (0)