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

Commit

Permalink
[Target] Centralize creation of scratch SwiftASTContexts
Browse files Browse the repository at this point in the history
I don't think it makes sense for ValueObject to know about SwiftASTContexts, so
we should centralize the creation logic into Target.
  • Loading branch information
bulbazord committed Jul 3, 2019
1 parent cc6d266 commit c091272
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 24 deletions.
3 changes: 0 additions & 3 deletions include/lldb/Core/ValueObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#ifndef liblldb_ValueObject_h_
#define liblldb_ValueObject_h_

#include "lldb/Core/SwiftASTContextReader.h"
#include "lldb/Core/Value.h"
#include "lldb/Symbol/CompilerType.h"
#include "lldb/Symbol/Type.h"
Expand Down Expand Up @@ -614,8 +613,6 @@ class ValueObject : public UserID {

virtual bool HasSyntheticValue();

SwiftASTContextReader GetScratchSwiftASTContext();

virtual bool IsSynthetic() { return false; }

lldb::ValueObjectSP
Expand Down
4 changes: 4 additions & 0 deletions include/lldb/Target/Target.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "lldb/Core/Architecture.h"
#include "lldb/Core/Disassembler.h"
#include "lldb/Core/ModuleList.h"
#include "lldb/Core/SwiftASTContextReader.h"
#include "lldb/Core/UserSettingsController.h"
#include "lldb/Expression/Expression.h"
#include "lldb/Interpreter/OptionValueBoolean.h"
Expand Down Expand Up @@ -1211,6 +1212,9 @@ class Target : public std::enable_shared_from_this<Target>,
GetScratchSwiftASTContext(Status &error, ExecutionContextScope &exe_scope,
bool create_on_demand = true);

SwiftASTContextReader GetScratchSwiftASTContext(ValueObject &valobj,
bool create_on_demand = true);

private:
void DisplayFallbackSwiftContextErrors(SwiftASTContext *swift_ast_ctx);
public:
Expand Down
12 changes: 1 addition & 11 deletions source/Core/ValueObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "lldb/Core/Address.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/SwiftASTContextReader.h"
#include "lldb/Core/ValueObjectCast.h"
#include "lldb/Core/ValueObjectChild.h"
#include "lldb/Core/ValueObjectConstResult.h"
Expand All @@ -28,7 +29,6 @@
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/CompilerType.h"
#include "lldb/Symbol/SwiftASTContext.h"
#include "lldb/Symbol/Declaration.h"
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Symbol/Type.h"
Expand Down Expand Up @@ -1732,16 +1732,6 @@ LanguageType ValueObject::GetObjectRuntimeLanguage() {
return lldb::eLanguageTypeUnknown;
}

SwiftASTContextReader ValueObject::GetScratchSwiftASTContext() {
lldb::TargetSP target_sp(GetTargetSP());
if (!target_sp)
return {};
Status error;
ExecutionContext ctx = GetExecutionContextRef().Lock(false);
auto *exe_scope = ctx.GetBestExecutionContextScope();
return target_sp->GetScratchSwiftASTContext(error, *exe_scope);
}

void ValueObject::AddSyntheticChild(ConstString key,
ValueObject *valobj) {
m_synthetic_children[key] = valobj;
Expand Down
6 changes: 3 additions & 3 deletions source/Core/ValueObjectDynamicValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include "lldb/Core/SwiftASTContextReader.h"
#include "lldb/Core/ValueObjectDynamicValue.h"
#include "lldb/Core/Value.h"
#include "lldb/Core/ValueObject.h"
Expand Down Expand Up @@ -420,7 +421,6 @@ bool ValueObjectDynamicValue::DynamicValueTypeInfoNeedsUpdate() {
if (!m_dynamic_type_info.HasType())
return false;

auto *cached_ctx =
static_cast<SwiftASTContext *>(m_value.GetCompilerType().GetTypeSystem());
return cached_ctx == GetScratchSwiftASTContext().get();
auto *cached_ctx = m_value.GetCompilerType().GetTypeSystem();
return cached_ctx == GetTargetSP()->GetScratchSwiftASTContext(*this).get();
}
3 changes: 2 additions & 1 deletion source/Plugins/Language/Swift/SwiftHashedContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@ NativeHashedStorageHandler::NativeHashedStorageHandler(
m_value_stride = value_type.GetByteStride();
if (SwiftASTContext *swift_ast =
llvm::dyn_cast_or_null<SwiftASTContext>(key_type.GetTypeSystem())) {
auto scratch_ctx_reader = nativeStorage_sp->GetScratchSwiftASTContext();
auto scratch_ctx_reader =
m_process->GetTarget().GetScratchSwiftASTContext(*nativeStorage_sp.get());
auto scratch_ctx = scratch_ctx_reader.get();
if (!scratch_ctx)
return;
Expand Down
17 changes: 11 additions & 6 deletions source/Target/SwiftLanguageRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,8 @@ SwiftLanguageRuntime::MetadataPromise::FulfillTypePromise(Status *error) {
if (m_compiler_type.hasValue())
return m_compiler_type.getValue();

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

auto swift_ast_ctx = m_for_object_sp->GetScratchSwiftASTContext();
TargetSP target_sp = m_for_object_sp->GetTargetSP();
auto swift_ast_ctx = target_sp->GetScratchSwiftASTContext(*m_for_object_sp);
if (!swift_ast_ctx) {
error->SetErrorString("couldn't get Swift scratch context");
return llvm::None;
Expand Down Expand Up @@ -1530,7 +1532,8 @@ bool SwiftLanguageRuntime::MetadataPromise::IsStaticallyDetermined() {
SwiftLanguageRuntime::MetadataPromiseSP
SwiftLanguageRuntime::GetMetadataPromise(lldb::addr_t addr,
ValueObject &for_object) {
auto swift_ast_ctx = for_object.GetScratchSwiftASTContext();
auto swift_ast_ctx =
m_process->GetTarget().GetScratchSwiftASTContext(for_object);
if (!swift_ast_ctx || swift_ast_ctx->HasFatalErrors())
return nullptr;

Expand Down Expand Up @@ -1619,7 +1622,7 @@ SwiftLanguageRuntime::GetMemberVariableOffset(CompilerType instance_type,

llvm::Optional<SwiftASTContextReader> scratch_ctx;
if (instance) {
scratch_ctx = instance->GetScratchSwiftASTContext();
scratch_ctx = m_process->GetTarget().GetScratchSwiftASTContext(*instance);
if (!scratch_ctx)
return llvm::None;
}
Expand Down Expand Up @@ -2350,7 +2353,8 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress(
// use the scratch context where such operations are legal and safe.
assert(IsScratchContextLocked(in_value.GetTargetSP()) &&
"Swift scratch context not locked ahead of dynamic type resolution");
auto scratch_ctx = in_value.GetScratchSwiftASTContext();
auto scratch_ctx =
m_process->GetTarget().GetScratchSwiftASTContext(in_value);
if (!scratch_ctx)
return false;

Expand Down Expand Up @@ -3748,7 +3752,8 @@ SwiftLanguageRuntime::GetBridgedSyntheticChildProvider(ValueObject &valobj) {
ProjectionSyntheticChildren::TypeProjectionUP type_projection(
new ProjectionSyntheticChildren::TypeProjectionUP::element_type());

if (auto swift_ast_ctx = valobj.GetScratchSwiftASTContext()) {
if (auto swift_ast_ctx =
m_process->GetTarget().GetScratchSwiftASTContext(valobj)) {
Status error;
CompilerType swift_type =
swift_ast_ctx->GetTypeFromMangledTypename(type_name, error);
Expand Down
8 changes: 8 additions & 0 deletions source/Target/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2538,6 +2538,14 @@ SwiftASTContextReader Target::GetScratchSwiftASTContext(
return SwiftASTContextReader(GetSwiftScratchContextLock(), swift_ast_ctx);
}

SwiftASTContextReader Target::GetScratchSwiftASTContext(ValueObject &valobj,
bool create_on_demand) {
Status error;
ExecutionContext ctx = valobj.GetExecutionContextRef().Lock(false);
auto *exe_scope = ctx.GetBestExecutionContextScope();
return GetScratchSwiftASTContext(error, *exe_scope);
}

static SharedMutex *
GetSwiftScratchContextMutex(const ExecutionContext *exe_ctx) {
if (!exe_ctx)
Expand Down

0 comments on commit c091272

Please sign in to comment.