Skip to content

Commit 91bcf92

Browse files
Merge pull request #6113 from adrian-prantl/getnumchildren
Change SwiftLanguageRuntime::GetNumChildren() to take an exe_scope
2 parents b7d5598 + 1aaa123 commit 91bcf92

File tree

6 files changed

+22
-18
lines changed

6 files changed

+22
-18
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ class SwiftLanguageRuntimeStub {
289289
}
290290

291291
llvm::Optional<unsigned> GetNumChildren(CompilerType type,
292-
ValueObject *valobj) {
292+
ExecutionContextScope *exe_scopej) {
293293
STUB_LOG();
294294
return {};
295295
}
@@ -2309,8 +2309,9 @@ llvm::Optional<uint64_t> SwiftLanguageRuntime::GetMemberVariableOffset(
23092309
}
23102310

23112311
llvm::Optional<unsigned>
2312-
SwiftLanguageRuntime::GetNumChildren(CompilerType type, ValueObject *valobj) {
2313-
FORWARD(GetNumChildren, type, valobj);
2312+
SwiftLanguageRuntime::GetNumChildren(CompilerType type,
2313+
ExecutionContextScope *exe_scope) {
2314+
FORWARD(GetNumChildren, type, exe_scope);
23142315
}
23152316

23162317
llvm::Optional<std::string> SwiftLanguageRuntime::GetEnumCaseName(

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ class SwiftLanguageRuntime : public LanguageRuntime {
277277

278278
/// Ask Remote Mirrors about the children of a composite type.
279279
llvm::Optional<unsigned> GetNumChildren(CompilerType type,
280-
ValueObject *valobj);
280+
ExecutionContextScope *exe_scope);
281281

282282
/// Determine the enum case name for the \p data value of the enum \p type.
283283
/// This is performed using Swift reflection.

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -978,17 +978,15 @@ static CompilerType GetWeakReferent(TypeSystemSwiftTypeRef &ts,
978978

979979
llvm::Optional<unsigned>
980980
SwiftLanguageRuntimeImpl::GetNumChildren(CompilerType type,
981-
ValueObject *valobj) {
981+
ExecutionContextScope *exe_scope) {
982982
LLDB_SCOPED_TIMER();
983983
auto ts = type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwiftTypeRef>();
984984
if (!ts)
985985
return {};
986986

987987
// Try the static type metadata.
988-
auto frame =
989-
valobj ? valobj->GetExecutionContextRef().GetFrameSP().get() : nullptr;
990988
const swift::reflection::TypeRef *tr = nullptr;
991-
auto *ti = GetSwiftRuntimeTypeInfo(type, frame, &tr);
989+
auto *ti = GetSwiftRuntimeTypeInfo(type, exe_scope, &tr);
992990
if (!ti) {
993991
LLDB_LOG(GetLog(LLDBLog::Types), "GetSwiftRuntimeTypeInfo() failed for {0}",
994992
type.GetMangledTypeName());
@@ -1074,7 +1072,8 @@ SwiftLanguageRuntimeImpl::GetNumFields(CompilerType type,
10741072
using namespace swift::reflection;
10751073
// Try the static type metadata.
10761074
const TypeRef *tr = nullptr;
1077-
auto *ti = GetSwiftRuntimeTypeInfo(type, exe_ctx->GetFramePtr(), &tr);
1075+
auto *ti = GetSwiftRuntimeTypeInfo(
1076+
type, exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr, &tr);
10781077
if (!ti)
10791078
return {};
10801079
// Structs and Tuples.
@@ -1335,9 +1334,12 @@ CompilerType SwiftLanguageRuntimeImpl::GetChildCompilerTypeAtIndex(
13351334
};
13361335

13371336
// Try the static type metadata.
1338-
auto frame =
1339-
valobj ? valobj->GetExecutionContextRef().GetFrameSP().get() : nullptr;
1340-
auto *ti = GetSwiftRuntimeTypeInfo(type, frame);
1337+
ExecutionContext exe_ctx;
1338+
if (valobj)
1339+
exe_ctx = valobj->GetExecutionContextRef();
1340+
1341+
auto *ti =
1342+
GetSwiftRuntimeTypeInfo(type, exe_ctx.GetBestExecutionContextScope());
13411343
if (!ti)
13421344
return {};
13431345
// Structs and Tuples.

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class SwiftLanguageRuntimeImpl {
123123
Status *error);
124124

125125
llvm::Optional<unsigned> GetNumChildren(CompilerType type,
126-
ValueObject *valobj);
126+
ExecutionContextScope *exe_scope);
127127

128128
llvm::Optional<unsigned> GetNumFields(CompilerType type,
129129
ExecutionContext *exe_ctx);

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2680,7 +2680,7 @@ TypeSystemSwiftTypeRef::GetNumChildren(opaque_compiler_type_t type,
26802680
if (auto *exe_scope = exe_ctx->GetBestExecutionContextScope())
26812681
if (auto *runtime =
26822682
SwiftLanguageRuntime::Get(exe_scope->CalculateProcess()))
2683-
return runtime->GetNumChildren(GetCanonicalType(type), nullptr);
2683+
return runtime->GetNumChildren(GetCanonicalType(type), exe_scope);
26842684

26852685
if (CompilerType clang_type = GetAsClangTypeOrNull(type)) {
26862686
bool is_signed;
@@ -2844,7 +2844,7 @@ CompilerType TypeSystemSwiftTypeRef::GetChildCompilerTypeAtIndex(
28442844
return GetTypeFromMangledTypename(ConstString("$sSo8NSStringCD"));
28452845
if (result.GetMangledTypeName().GetStringRef().count('$') > 1 &&
28462846
get_ast_num_children() ==
2847-
runtime->GetNumChildren({weak_from_this(), type}, valobj))
2847+
runtime->GetNumChildren({weak_from_this(), type}, exe_scope))
28482848
// If available, prefer the AST for private types. Private
28492849
// identifiers are not ABI; the runtime returns anonymous private
28502850
// identifiers (using a '$' prefix) which cannot match identifiers
@@ -2950,7 +2950,8 @@ CompilerType TypeSystemSwiftTypeRef::GetChildCompilerTypeAtIndex(
29502950
// can't mix&match between the two typesystems if there is such a
29512951
// divergence. We'll need to replace all calls at once.
29522952
if (get_ast_num_children() <
2953-
runtime->GetNumChildren({weak_from_this(), type}, valobj).getValueOr(0))
2953+
runtime->GetNumChildren({weak_from_this(), type}, exe_scope)
2954+
.getValueOr(0))
29542955
return impl();
29552956
if (ShouldSkipValidation(type))
29562957
return impl();
@@ -3554,6 +3555,7 @@ bool TypeSystemSwiftTypeRef::DumpTypeValue(
35543555
bitfield_bit_size, bitfield_bit_offset,
35553556
exe_scope);
35563557
}
3558+
case Node::Kind::DynamicSelf:
35573559
case Node::Kind::Unmanaged:
35583560
case Node::Kind::Unowned:
35593561
case Node::Kind::Weak: {

lldb/test/API/lang/swift/dynamic_self/TestSwiftDynamicSelf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def test_dynamic_self(self):
4949

5050
lldbutil.continue_to_breakpoint(process, bkpt) # Stop in Child.show.
5151
frame = thread.frames[0]
52-
# When stopped in Child.show(), 'self' doesn't have a child.
53-
self.assertEqual(frame.FindVariable("self", lldb.eNoDynamicValues).GetNumChildren(), 0)
52+
self.assertEqual(frame.FindVariable("self", lldb.eNoDynamicValues).GetNumChildren(), 1)
5453
self.check_members(self.get_self_as_Base_from_Child_method(frame),
5554
"100", "220")

0 commit comments

Comments
 (0)