Skip to content
This repository was archived by the owner on Apr 2, 2020. It is now read-only.

Commit c091272

Browse files
committed
[Target] Centralize creation of scratch SwiftASTContexts
I don't think it makes sense for ValueObject to know about SwiftASTContexts, so we should centralize the creation logic into Target.
1 parent cc6d266 commit c091272

File tree

7 files changed

+29
-24
lines changed

7 files changed

+29
-24
lines changed

include/lldb/Core/ValueObject.h

-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef liblldb_ValueObject_h_
1010
#define liblldb_ValueObject_h_
1111

12-
#include "lldb/Core/SwiftASTContextReader.h"
1312
#include "lldb/Core/Value.h"
1413
#include "lldb/Symbol/CompilerType.h"
1514
#include "lldb/Symbol/Type.h"
@@ -614,8 +613,6 @@ class ValueObject : public UserID {
614613

615614
virtual bool HasSyntheticValue();
616615

617-
SwiftASTContextReader GetScratchSwiftASTContext();
618-
619616
virtual bool IsSynthetic() { return false; }
620617

621618
lldb::ValueObjectSP

include/lldb/Target/Target.h

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "lldb/Core/Architecture.h"
2525
#include "lldb/Core/Disassembler.h"
2626
#include "lldb/Core/ModuleList.h"
27+
#include "lldb/Core/SwiftASTContextReader.h"
2728
#include "lldb/Core/UserSettingsController.h"
2829
#include "lldb/Expression/Expression.h"
2930
#include "lldb/Interpreter/OptionValueBoolean.h"
@@ -1211,6 +1212,9 @@ class Target : public std::enable_shared_from_this<Target>,
12111212
GetScratchSwiftASTContext(Status &error, ExecutionContextScope &exe_scope,
12121213
bool create_on_demand = true);
12131214

1215+
SwiftASTContextReader GetScratchSwiftASTContext(ValueObject &valobj,
1216+
bool create_on_demand = true);
1217+
12141218
private:
12151219
void DisplayFallbackSwiftContextErrors(SwiftASTContext *swift_ast_ctx);
12161220
public:

source/Core/ValueObject.cpp

+1-11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "lldb/Core/Address.h"
1212
#include "lldb/Core/Module.h"
13+
#include "lldb/Core/SwiftASTContextReader.h"
1314
#include "lldb/Core/ValueObjectCast.h"
1415
#include "lldb/Core/ValueObjectChild.h"
1516
#include "lldb/Core/ValueObjectConstResult.h"
@@ -28,7 +29,6 @@
2829
#include "lldb/Symbol/ClangASTContext.h"
2930
#include "lldb/Symbol/CompileUnit.h"
3031
#include "lldb/Symbol/CompilerType.h"
31-
#include "lldb/Symbol/SwiftASTContext.h"
3232
#include "lldb/Symbol/Declaration.h"
3333
#include "lldb/Symbol/SymbolContext.h"
3434
#include "lldb/Symbol/Type.h"
@@ -1732,16 +1732,6 @@ LanguageType ValueObject::GetObjectRuntimeLanguage() {
17321732
return lldb::eLanguageTypeUnknown;
17331733
}
17341734

1735-
SwiftASTContextReader ValueObject::GetScratchSwiftASTContext() {
1736-
lldb::TargetSP target_sp(GetTargetSP());
1737-
if (!target_sp)
1738-
return {};
1739-
Status error;
1740-
ExecutionContext ctx = GetExecutionContextRef().Lock(false);
1741-
auto *exe_scope = ctx.GetBestExecutionContextScope();
1742-
return target_sp->GetScratchSwiftASTContext(error, *exe_scope);
1743-
}
1744-
17451735
void ValueObject::AddSyntheticChild(ConstString key,
17461736
ValueObject *valobj) {
17471737
m_synthetic_children[key] = valobj;

source/Core/ValueObjectDynamicValue.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "lldb/Core/SwiftASTContextReader.h"
910
#include "lldb/Core/ValueObjectDynamicValue.h"
1011
#include "lldb/Core/Value.h"
1112
#include "lldb/Core/ValueObject.h"
@@ -420,7 +421,6 @@ bool ValueObjectDynamicValue::DynamicValueTypeInfoNeedsUpdate() {
420421
if (!m_dynamic_type_info.HasType())
421422
return false;
422423

423-
auto *cached_ctx =
424-
static_cast<SwiftASTContext *>(m_value.GetCompilerType().GetTypeSystem());
425-
return cached_ctx == GetScratchSwiftASTContext().get();
424+
auto *cached_ctx = m_value.GetCompilerType().GetTypeSystem();
425+
return cached_ctx == GetTargetSP()->GetScratchSwiftASTContext(*this).get();
426426
}

source/Plugins/Language/Swift/SwiftHashedContainer.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,8 @@ NativeHashedStorageHandler::NativeHashedStorageHandler(
446446
m_value_stride = value_type.GetByteStride();
447447
if (SwiftASTContext *swift_ast =
448448
llvm::dyn_cast_or_null<SwiftASTContext>(key_type.GetTypeSystem())) {
449-
auto scratch_ctx_reader = nativeStorage_sp->GetScratchSwiftASTContext();
449+
auto scratch_ctx_reader =
450+
m_process->GetTarget().GetScratchSwiftASTContext(*nativeStorage_sp.get());
450451
auto scratch_ctx = scratch_ctx_reader.get();
451452
if (!scratch_ctx)
452453
return;

source/Target/SwiftLanguageRuntime.cpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,8 @@ SwiftLanguageRuntime::MetadataPromise::FulfillTypePromise(Status *error) {
14441444
if (m_compiler_type.hasValue())
14451445
return m_compiler_type.getValue();
14461446

1447-
auto swift_ast_ctx = m_for_object_sp->GetScratchSwiftASTContext();
1447+
TargetSP target_sp = m_for_object_sp->GetTargetSP();
1448+
auto swift_ast_ctx = target_sp->GetScratchSwiftASTContext(*m_for_object_sp);
14481449
if (!swift_ast_ctx) {
14491450
error->SetErrorString("couldn't get Swift scratch context");
14501451
return CompilerType();
@@ -1486,7 +1487,8 @@ SwiftLanguageRuntime::MetadataPromise::FulfillKindPromise(Status *error) {
14861487
if (m_metadata_kind.hasValue())
14871488
return m_metadata_kind;
14881489

1489-
auto swift_ast_ctx = m_for_object_sp->GetScratchSwiftASTContext();
1490+
TargetSP target_sp = m_for_object_sp->GetTargetSP();
1491+
auto swift_ast_ctx = target_sp->GetScratchSwiftASTContext(*m_for_object_sp);
14901492
if (!swift_ast_ctx) {
14911493
error->SetErrorString("couldn't get Swift scratch context");
14921494
return llvm::None;
@@ -1530,7 +1532,8 @@ bool SwiftLanguageRuntime::MetadataPromise::IsStaticallyDetermined() {
15301532
SwiftLanguageRuntime::MetadataPromiseSP
15311533
SwiftLanguageRuntime::GetMetadataPromise(lldb::addr_t addr,
15321534
ValueObject &for_object) {
1533-
auto swift_ast_ctx = for_object.GetScratchSwiftASTContext();
1535+
auto swift_ast_ctx =
1536+
m_process->GetTarget().GetScratchSwiftASTContext(for_object);
15341537
if (!swift_ast_ctx || swift_ast_ctx->HasFatalErrors())
15351538
return nullptr;
15361539

@@ -1619,7 +1622,7 @@ SwiftLanguageRuntime::GetMemberVariableOffset(CompilerType instance_type,
16191622

16201623
llvm::Optional<SwiftASTContextReader> scratch_ctx;
16211624
if (instance) {
1622-
scratch_ctx = instance->GetScratchSwiftASTContext();
1625+
scratch_ctx = m_process->GetTarget().GetScratchSwiftASTContext(*instance);
16231626
if (!scratch_ctx)
16241627
return llvm::None;
16251628
}
@@ -2350,7 +2353,8 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress(
23502353
// use the scratch context where such operations are legal and safe.
23512354
assert(IsScratchContextLocked(in_value.GetTargetSP()) &&
23522355
"Swift scratch context not locked ahead of dynamic type resolution");
2353-
auto scratch_ctx = in_value.GetScratchSwiftASTContext();
2356+
auto scratch_ctx =
2357+
m_process->GetTarget().GetScratchSwiftASTContext(in_value);
23542358
if (!scratch_ctx)
23552359
return false;
23562360

@@ -3748,7 +3752,8 @@ SwiftLanguageRuntime::GetBridgedSyntheticChildProvider(ValueObject &valobj) {
37483752
ProjectionSyntheticChildren::TypeProjectionUP type_projection(
37493753
new ProjectionSyntheticChildren::TypeProjectionUP::element_type());
37503754

3751-
if (auto swift_ast_ctx = valobj.GetScratchSwiftASTContext()) {
3755+
if (auto swift_ast_ctx =
3756+
m_process->GetTarget().GetScratchSwiftASTContext(valobj)) {
37523757
Status error;
37533758
CompilerType swift_type =
37543759
swift_ast_ctx->GetTypeFromMangledTypename(type_name, error);

source/Target/Target.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -2538,6 +2538,14 @@ SwiftASTContextReader Target::GetScratchSwiftASTContext(
25382538
return SwiftASTContextReader(GetSwiftScratchContextLock(), swift_ast_ctx);
25392539
}
25402540

2541+
SwiftASTContextReader Target::GetScratchSwiftASTContext(ValueObject &valobj,
2542+
bool create_on_demand) {
2543+
Status error;
2544+
ExecutionContext ctx = valobj.GetExecutionContextRef().Lock(false);
2545+
auto *exe_scope = ctx.GetBestExecutionContextScope();
2546+
return GetScratchSwiftASTContext(error, *exe_scope);
2547+
}
2548+
25412549
static SharedMutex *
25422550
GetSwiftScratchContextMutex(const ExecutionContext *exe_ctx) {
25432551
if (!exe_ctx)

0 commit comments

Comments
 (0)