Skip to content

Commit 0a86741

Browse files
committed
call newly stubbed SwiftLanguageRuntime::GetIndexOfChildMemberWithName
1 parent 95dd368 commit 0a86741

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed

lldb/include/lldb/Target/SwiftLanguageRuntime.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ class SwiftLanguageRuntime : public LanguageRuntime {
256256
llvm::Optional<unsigned> GetNumChildren(CompilerType type,
257257
ValueObject *valobj);
258258

259+
llvm::Optional<size_t> GetIndexOfChildMemberWithName(
260+
CompilerType type, const char *name, ExecutionContext *exe_ctx,
261+
bool omit_empty_base_classes, std::vector<uint32_t> &child_indexes);
262+
259263
/// Ask Remote Mirrors about a child of a composite type.
260264
CompilerType GetChildCompilerTypeAtIndex(
261265
CompilerType type, size_t idx, bool transparent_pointers,

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
#include "clang/APINotes/APINotesManager.h"
3636
#include "clang/APINotes/APINotesReader.h"
3737

38+
#include <algorithm>
39+
#include <sstream>
40+
3841
using namespace lldb;
3942
using namespace lldb_private;
4043

@@ -1538,6 +1541,24 @@ bool Equivalent(llvm::Optional<T> l, T r) {
15381541
return Equivalent(l, llvm::Optional<T>(r));
15391542
}
15401543

1544+
template <typename T>
1545+
bool Equivalent(const std::vector<T> &l, const std::vector<T> &r) {
1546+
if (std::equal(l.begin(), l.end(), r.begin(), r.end()))
1547+
return true;
1548+
1549+
auto join = [](const std::vector<T> &v) -> std::string {
1550+
if (v.empty())
1551+
return {};
1552+
std::ostringstream buf;
1553+
buf << v[0];
1554+
for (size_t i = 1; i < v.size(); ++i)
1555+
buf << ", " << v[i];
1556+
return buf.str();
1557+
};
1558+
llvm::dbgs() << join(l) << " != " << join(r) << "\n";
1559+
return false;
1560+
}
1561+
15411562
} // namespace
15421563
#endif
15431564

@@ -2367,6 +2388,37 @@ CompilerType TypeSystemSwiftTypeRef::GetChildCompilerTypeAtIndex(
23672388
size_t TypeSystemSwiftTypeRef::GetIndexOfChildMemberWithName(
23682389
opaque_compiler_type_t type, const char *name, ExecutionContext *exe_ctx,
23692390
bool omit_empty_base_classes, std::vector<uint32_t> &child_indexes) {
2391+
if (auto *exe_scope = exe_ctx->GetBestExecutionContextScope())
2392+
if (auto *runtime =
2393+
SwiftLanguageRuntime::Get(exe_scope->CalculateProcess()))
2394+
if (auto index_size = runtime->GetIndexOfChildMemberWithName(
2395+
GetCanonicalType(type), name, exe_ctx, omit_empty_base_classes,
2396+
child_indexes)) {
2397+
#ifndef NDEBUG
2398+
// This block is a custom VALIDATE_AND_RETURN implementation to support
2399+
// checking the return value, plus the by-ref `child_indexes`.
2400+
if (!m_swift_ast_context)
2401+
return *index_size;
2402+
auto v_type = ReconstructType(type);
2403+
std::vector<uint32_t> v_child_indexes;
2404+
auto v_index_size = m_swift_ast_context->GetIndexOfChildMemberWithName(
2405+
v_type, name, exe_ctx, omit_empty_base_classes, v_child_indexes);
2406+
bool equivalent =
2407+
!v_type || (Equivalent(*index_size, v_index_size) &&
2408+
Equivalent(child_indexes, v_child_indexes));
2409+
if (!equivalent)
2410+
llvm::dbgs() << "failing type was " << (const char *)type << "\n";
2411+
assert(equivalent &&
2412+
"TypeSystemSwiftTypeRef diverges from SwiftASTContext");
2413+
#endif
2414+
return *index_size;
2415+
}
2416+
2417+
LLDB_LOGF(GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES),
2418+
"Using SwiftASTContext::GetIndexOfChildMemberWithName fallback for "
2419+
"type %s",
2420+
AsMangledName(type));
2421+
23702422
return m_swift_ast_context->GetIndexOfChildMemberWithName(
23712423
ReconstructType(type), name, exe_ctx, omit_empty_base_classes,
23722424
child_indexes);

lldb/source/Target/SwiftLanguageRuntime.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,13 @@ class SwiftLanguageRuntimeStub {
257257
return {};
258258
}
259259

260+
llvm::Optional<size_t> GetIndexOfChildMemberWithName(
261+
CompilerType type, const char *name, ExecutionContext *exe_ctx,
262+
bool omit_empty_base_classes, std::vector<uint32_t> &child_indexes) {
263+
STUB_LOG();
264+
return {};
265+
}
266+
260267
CompilerType GetChildCompilerTypeAtIndex(
261268
CompilerType type, size_t idx, bool transparent_pointers,
262269
bool omit_empty_base_classes, bool ignore_array_bounds,
@@ -2144,6 +2151,13 @@ SwiftLanguageRuntime::GetNumChildren(CompilerType type, ValueObject *valobj) {
21442151
FORWARD(GetNumChildren, type, valobj);
21452152
}
21462153

2154+
llvm::Optional<size_t> SwiftLanguageRuntime::GetIndexOfChildMemberWithName(
2155+
CompilerType type, const char *name, ExecutionContext *exe_ctx,
2156+
bool omit_empty_base_classes, std::vector<uint32_t> &child_indexes) {
2157+
FORWARD(GetIndexOfChildMemberWithName, type, name, exe_ctx,
2158+
omit_empty_base_classes, child_indexes);
2159+
}
2160+
21472161
CompilerType SwiftLanguageRuntime::GetChildCompilerTypeAtIndex(
21482162
CompilerType type, size_t idx, bool transparent_pointers,
21492163
bool omit_empty_base_classes, bool ignore_array_bounds,

lldb/source/Target/SwiftLanguageRuntimeDynamicTypeResolution.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,12 @@ GetTypeFromTypeRef(TypeSystemSwiftTypeRef &ts,
11421142
return ts.RemangleAsType(dem, node);
11431143
}
11441144

1145+
llvm::Optional<size_t> SwiftLanguageRuntimeImpl::GetIndexOfChildMemberWithName(
1146+
CompilerType type, const char *name, ExecutionContext *exe_ctx,
1147+
bool omit_empty_base_classes, std::vector<uint32_t> &child_indexes) {
1148+
return {};
1149+
}
1150+
11451151
CompilerType SwiftLanguageRuntimeImpl::GetChildCompilerTypeAtIndex(
11461152
CompilerType type, size_t idx, bool transparent_pointers,
11471153
bool omit_empty_base_classes, bool ignore_array_bounds,

lldb/source/Target/SwiftLanguageRuntimeImpl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ class SwiftLanguageRuntimeImpl {
120120
llvm::Optional<unsigned> GetNumChildren(CompilerType type,
121121
ValueObject *valobj);
122122

123+
llvm::Optional<size_t> GetIndexOfChildMemberWithName(
124+
CompilerType type, const char *name, ExecutionContext *exe_ctx,
125+
bool omit_empty_base_classes, std::vector<uint32_t> &child_indexes);
126+
123127
CompilerType GetChildCompilerTypeAtIndex(
124128
CompilerType type, size_t idx, bool transparent_pointers,
125129
bool omit_empty_base_classes, bool ignore_array_bounds,

0 commit comments

Comments
 (0)