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