@@ -2507,8 +2507,14 @@ CompilerType TypeSystemSwiftTypeRef::GetChildCompilerTypeAtIndex(
2507
2507
child_byte_size, child_byte_offset, child_bitfield_bit_size,
2508
2508
child_bitfield_bit_offset, child_is_base_class,
2509
2509
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
+ };
2512
2518
auto impl = [&]() -> CompilerType {
2513
2519
ExecutionContextScope *exe_scope = nullptr ;
2514
2520
if (exe_ctx)
@@ -2529,7 +2535,8 @@ CompilerType TypeSystemSwiftTypeRef::GetChildCompilerTypeAtIndex(
2529
2535
.endswith (" sSo18NSNotificationNameaD" ))
2530
2536
return GetTypeFromMangledTypename (ConstString (" $sSo8NSStringCD" ));
2531
2537
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))
2533
2540
// If available, prefer the AST for private types. Private
2534
2541
// identifiers are not ABI; the runtime returns anonymous private
2535
2542
// identifiers (using a '$' prefix) which cannot match identifiers
@@ -2635,7 +2642,7 @@ CompilerType TypeSystemSwiftTypeRef::GetChildCompilerTypeAtIndex(
2635
2642
// Because the API deals out an index into a list of children we
2636
2643
// can't mix&match between the two typesystems if there is such a
2637
2644
// divergence. We'll need to replace all calls at once.
2638
- if (ast_num_children <
2645
+ if (get_ast_num_children () <
2639
2646
runtime->GetNumChildren ({this , type}, valobj).getValueOr (0 ))
2640
2647
return impl ();
2641
2648
0 commit comments