Skip to content

Commit 1106164

Browse files
authored
[lldb] Handle BuiltinTypeInfo instance in SwiftLanguageRuntimeImpl::GetNumChildren (#6758)
This logic supports Swift Builtin types in `GetNumChildren`. By handling them directly, the unnecessary subsequent loading of ASTContexts can be avoided. Builtin types are assumed to be internal "leaf" types, having no children. Note that the API of `BuiltinTypeInfo` provides no means for determining the number of children. However, some imported Clang types (specifically enums) will also produce `BuiltinTypeInfo` instances. These types are not to be handled in `SwiftLanguageRuntimeImpl::GetNumChildren`.
1 parent e284d9e commit 1106164

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeDynamicTypeResolution.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,24 @@ SwiftLanguageRuntimeImpl::GetNumChildren(CompilerType type,
10421042
type.GetMangledTypeName().GetCString());
10431043
return {};
10441044
}
1045+
if (llvm::isa<swift::reflection::BuiltinTypeInfo>(ti)) {
1046+
// This logic handles Swift Builtin types. By handling them now, the cost of
1047+
// unnecessarily loading ASTContexts can be avoided. Builtin types are
1048+
// assumed to be internal "leaf" types, having no children. Or,
1049+
// alternatively, opaque types.
1050+
//
1051+
// However, some imported Clang types (specifically enums) will also produce
1052+
// `BuiltinTypeInfo` instances. These types are not to be handled here.
1053+
swift::Demangle::Context dem;
1054+
NodePointer root = SwiftLanguageRuntime::DemangleSymbolAsNode(
1055+
type.GetMangledTypeName().GetStringRef(), dem);
1056+
using Kind = Node::Kind;
1057+
auto *builtin_type =
1058+
swift_demangle::nodeAtPath(root, {Kind::Global, Kind::TypeMangling,
1059+
Kind::Type, Kind::BuiltinTypeName});
1060+
if (builtin_type)
1061+
return 0;
1062+
}
10451063
// Structs and Tuples.
10461064
if (auto *rti = llvm::dyn_cast<swift::reflection::RecordTypeInfo>(ti)) {
10471065
LLDB_LOGF(GetLog(LLDBLog::Types), "%s: RecordTypeInfo(num_fields=%i)",

0 commit comments

Comments
 (0)