@@ -1508,10 +1508,9 @@ template <> bool Equivalent<ConstString>(ConstString l, ConstString r) {
1508
1508
return l == r;
1509
1509
}
1510
1510
1511
- // / Version taylored to GetBitSize & friends.
1512
- template <>
1513
- bool Equivalent<llvm::Optional<uint64_t >>(llvm::Optional<uint64_t > l,
1514
- llvm::Optional<uint64_t > r) {
1511
+ // / Version tailored to GetBitSize & friends.
1512
+ template <typename T>
1513
+ bool Equivalent (llvm::Optional<T> l, llvm::Optional<T> r) {
1515
1514
if (l == r)
1516
1515
return true ;
1517
1516
// There are situations where SwiftASTContext incorrectly returns
@@ -1526,6 +1525,12 @@ bool Equivalent<llvm::Optional<uint64_t>>(llvm::Optional<uint64_t> l,
1526
1525
return false ;
1527
1526
}
1528
1527
1528
+ // Introduced for `GetNumChildren`.
1529
+ template <typename T>
1530
+ bool Equivalent (llvm::Optional<T> l, T r) {
1531
+ return Equivalent (l, llvm::Optional<T>(r));
1532
+ }
1533
+
1529
1534
} // namespace
1530
1535
#endif
1531
1536
@@ -2066,13 +2071,34 @@ lldb::Encoding TypeSystemSwiftTypeRef::GetEncoding(opaque_compiler_type_t type,
2066
2071
lldb::Format TypeSystemSwiftTypeRef::GetFormat (opaque_compiler_type_t type) {
2067
2072
return m_swift_ast_context->GetFormat (ReconstructType (type));
2068
2073
}
2074
+
2069
2075
uint32_t
2070
2076
TypeSystemSwiftTypeRef::GetNumChildren (opaque_compiler_type_t type,
2071
2077
bool omit_empty_base_classes,
2072
2078
const ExecutionContext *exe_ctx) {
2073
- return m_swift_ast_context->GetNumChildren (ReconstructType (type),
2074
- omit_empty_base_classes, exe_ctx);
2079
+ if (exe_ctx)
2080
+ if (auto *exe_scope = exe_ctx->GetBestExecutionContextScope ())
2081
+ if (auto *runtime =
2082
+ SwiftLanguageRuntime::Get (exe_scope->CalculateProcess ()))
2083
+ if (auto num_children =
2084
+ runtime->GetNumChildren (GetCanonicalType (type), nullptr )) {
2085
+ // Use a lambda to intercept and unwrap the `Optional` return value.
2086
+ return [&]() {
2087
+ auto impl = [&]() { return num_children; };
2088
+ VALIDATE_AND_RETURN (
2089
+ impl, GetNumChildren, type,
2090
+ (ReconstructType (type), omit_empty_base_classes, exe_ctx));
2091
+ }().getValue ();
2092
+ }
2093
+
2094
+ LLDB_LOGF (GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES),
2095
+ " Using SwiftASTContext::GetNumChildren fallback for type %s" ,
2096
+ AsMangledName (type));
2097
+
2098
+ return m_swift_ast_context->GetNumChildren (
2099
+ ReconstructType (type), omit_empty_base_classes, exe_ctx);
2075
2100
}
2101
+
2076
2102
uint32_t TypeSystemSwiftTypeRef::GetNumFields (opaque_compiler_type_t type) {
2077
2103
return m_swift_ast_context->GetNumFields (ReconstructType (type));
2078
2104
}
0 commit comments