Skip to content

Commit 3dad37a

Browse files
committed
improve fallback logic for private child types
1 parent 511d858 commit 3dad37a

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,6 +2315,8 @@ CompilerType TypeSystemSwiftTypeRef::GetChildCompilerTypeAtIndex(
23152315
child_bitfield_bit_offset, child_is_base_class,
23162316
child_is_deref_of_parent, valobj, language_flags);
23172317
};
2318+
auto ast_num_children = m_swift_ast_context->GetNumChildren(
2319+
ReconstructType(type), omit_empty_base_classes, exe_ctx);
23182320
auto impl = [&]() -> CompilerType {
23192321
ExecutionContextScope *exe_scope = nullptr;
23202322
if (exe_ctx)
@@ -2334,6 +2336,15 @@ CompilerType TypeSystemSwiftTypeRef::GetChildCompilerTypeAtIndex(
23342336
if (llvm::StringRef(AsMangledName(type))
23352337
.endswith("sSo18NSNotificationNameaD"))
23362338
return GetTypeFromMangledTypename(ConstString("$sSo8NSStringCD"));
2339+
if (result.GetMangledTypeName().GetStringRef().count('$') > 1 &&
2340+
ast_num_children == runtime->GetNumChildren({this, type}, valobj))
2341+
// If available, prefer the AST for private types. Private
2342+
// identifiers are not ABI; the runtime returns anonymous private
2343+
// identifiers (using a '$' prefix) which cannot match identifiers
2344+
// in the AST. Because these private types can't be used in an AST
2345+
// context, prefer the AST type if available.
2346+
if (auto ast_type = fallback())
2347+
return ast_type;
23372348
return result;
23382349
}
23392350
}
@@ -2432,8 +2443,7 @@ CompilerType TypeSystemSwiftTypeRef::GetChildCompilerTypeAtIndex(
24322443
// Because the API deals out an index into a list of children we
24332444
// can't mix&match between the two typesystems if there is such a
24342445
// divergence. We'll need to replace all calls at once.
2435-
if (m_swift_ast_context->GetNumChildren(ReconstructType(type),
2436-
omit_empty_base_classes, exe_ctx) <
2446+
if (ast_num_children <
24372447
runtime->GetNumChildren({this, type}, valobj).getValueOr(0))
24382448
return impl();
24392449

0 commit comments

Comments
 (0)