@@ -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
@@ -2067,13 +2072,34 @@ lldb::Encoding TypeSystemSwiftTypeRef::GetEncoding(opaque_compiler_type_t type,
2067
2072
lldb::Format TypeSystemSwiftTypeRef::GetFormat (opaque_compiler_type_t type) {
2068
2073
return m_swift_ast_context->GetFormat (ReconstructType (type));
2069
2074
}
2075
+
2070
2076
uint32_t
2071
2077
TypeSystemSwiftTypeRef::GetNumChildren (opaque_compiler_type_t type,
2072
2078
bool omit_empty_base_classes,
2073
2079
const ExecutionContext *exe_ctx) {
2074
- return m_swift_ast_context->GetNumChildren (ReconstructType (type),
2075
- omit_empty_base_classes, exe_ctx);
2080
+ if (exe_ctx)
2081
+ if (auto *exe_scope = exe_ctx->GetBestExecutionContextScope ())
2082
+ if (auto *runtime =
2083
+ SwiftLanguageRuntime::Get (exe_scope->CalculateProcess ()))
2084
+ if (auto num_children =
2085
+ runtime->GetNumChildren (GetCanonicalType (type), nullptr )) {
2086
+ // Use a lambda to intercept and unwrap the `Optional` return value.
2087
+ return [&]() {
2088
+ auto impl = [&]() { return num_children; };
2089
+ VALIDATE_AND_RETURN (
2090
+ impl, GetNumChildren, type,
2091
+ (ReconstructType (type), omit_empty_base_classes, exe_ctx));
2092
+ }().getValue ();
2093
+ }
2094
+
2095
+ LLDB_LOGF (GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES),
2096
+ " Using SwiftASTContext::GetNumChildren fallback for type %s" ,
2097
+ AsMangledName (type));
2098
+
2099
+ return m_swift_ast_context->GetNumChildren (
2100
+ ReconstructType (type), omit_empty_base_classes, exe_ctx);
2076
2101
}
2102
+
2077
2103
uint32_t TypeSystemSwiftTypeRef::GetNumFields (opaque_compiler_type_t type) {
2078
2104
return m_swift_ast_context->GetNumFields (ReconstructType (type));
2079
2105
}
0 commit comments