Skip to content

Avoid unconditionally calling into SwiftASTContext (NFC) #3346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2506,8 +2506,14 @@ CompilerType TypeSystemSwiftTypeRef::GetChildCompilerTypeAtIndex(
child_byte_size, child_byte_offset, child_bitfield_bit_size,
child_bitfield_bit_offset, child_is_base_class,
child_is_deref_of_parent, valobj, language_flags));
auto ast_num_children = m_swift_ast_context->GetNumChildren(
ReconstructType(type), omit_empty_base_classes, exe_ctx);
llvm::Optional<unsigned> ast_num_children;
auto get_ast_num_children = [&]() {
if (ast_num_children)
return *ast_num_children;
ast_num_children = m_swift_ast_context->GetNumChildren(
ReconstructType(type), omit_empty_base_classes, exe_ctx);
return *ast_num_children;
};
auto impl = [&]() -> CompilerType {
ExecutionContextScope *exe_scope = nullptr;
if (exe_ctx)
Expand All @@ -2528,7 +2534,8 @@ CompilerType TypeSystemSwiftTypeRef::GetChildCompilerTypeAtIndex(
.endswith("sSo18NSNotificationNameaD"))
return GetTypeFromMangledTypename(ConstString("$sSo8NSStringCD"));
if (result.GetMangledTypeName().GetStringRef().count('$') > 1 &&
ast_num_children == runtime->GetNumChildren({this, type}, valobj))
get_ast_num_children() ==
runtime->GetNumChildren({this, type}, valobj))
// If available, prefer the AST for private types. Private
// identifiers are not ABI; the runtime returns anonymous private
// identifiers (using a '$' prefix) which cannot match identifiers
Expand Down Expand Up @@ -2634,7 +2641,7 @@ CompilerType TypeSystemSwiftTypeRef::GetChildCompilerTypeAtIndex(
// Because the API deals out an index into a list of children we
// can't mix&match between the two typesystems if there is such a
// divergence. We'll need to replace all calls at once.
if (ast_num_children <
if (get_ast_num_children() <
runtime->GetNumChildren({this, type}, valobj).getValueOr(0))
return impl();

Expand Down