Skip to content

Rename SwiftASTContextReader -> SwiftScratchContextReader (NFC) #3933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ class SharedMutex {
/// RAII acquisition of a reader lock.
struct ScopedSharedMutexReader {
SharedMutex *m_mutex;
ScopedSharedMutexReader(const ScopedSharedMutexReader&) = default;
explicit ScopedSharedMutexReader(SharedMutex *m) : m_mutex(m) {
if (m_mutex)
m_mutex->lock_shared();
}
ScopedSharedMutexReader(const ScopedSharedMutexReader&) = default;

~ScopedSharedMutexReader() {
if (m_mutex)
m_mutex->unlock_shared();
}
};

/// A scratch Swift AST context pointer and its reader lock.
/// A scratch Swift context pointer and its reader lock.
/// The Swift scratch context may need to be replaced when it gets corrupted,
/// for example due to incompatible ClangImporter options. This locking
/// mechanism guarantees that this won't happen while a client is using the
Expand All @@ -87,20 +87,21 @@ struct ScopedSharedMutexReader {
/// Because expressions and dynamic type resolution may trigger the
/// import of another module, the scratch context may become
/// unusable. When a scratch context is in a fatal error state,
/// GetScratchSwiftASTContext() will create a fresh global context,
/// GetSwiftScratchContext() will create a fresh global context,
/// or even separate scratch contexts for each lldb::Module. But it
/// will only do this if no client holds on to a read lock on \b
/// m_scratch_typesystem_lock.
class SwiftASTContextReader : ScopedSharedMutexReader {
class SwiftScratchContextReader : ScopedSharedMutexReader {
SwiftASTContextForExpressions *m_ptr;

public:
SwiftASTContextReader(SharedMutex &mutex, SwiftASTContextForExpressions &ctx)
SwiftScratchContextReader(SharedMutex &mutex,
SwiftASTContextForExpressions &ctx)
: ScopedSharedMutexReader(&mutex), m_ptr(&ctx) {
assert(m_ptr && "invalid context");
}

SwiftASTContextReader(const SwiftASTContextReader &copy)
SwiftScratchContextReader(const SwiftScratchContextReader &copy)
: ScopedSharedMutexReader(copy.m_mutex), m_ptr(copy.m_ptr) {}

SwiftASTContextForExpressions *get() {
Expand All @@ -109,14 +110,13 @@ class SwiftASTContextReader : ScopedSharedMutexReader {
}

SwiftASTContextForExpressions *operator->() { return get(); }

SwiftASTContextForExpressions &operator*() { return *get(); }
};

/// An RAII object that just acquires the reader lock.
struct SwiftASTContextLock : ScopedSharedMutexReader {
SwiftASTContextLock(const ExecutionContextRef *exe_ctx_ref);
SwiftASTContextLock(const ExecutionContext *exe_ctx);
struct SwiftScratchContextLock : ScopedSharedMutexReader {
SwiftScratchContextLock(const ExecutionContextRef *exe_ctx_ref);
SwiftScratchContextLock(const ExecutionContext *exe_ctx);
};

} // namespace lldb_private
Expand Down
4 changes: 2 additions & 2 deletions lldb/include/lldb/Core/ValueObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef LLDB_CORE_VALUEOBJECT_H
#define LLDB_CORE_VALUEOBJECT_H

#include "lldb/Core/SwiftASTContextReader.h"
#include "lldb/Core/SwiftScratchContextReader.h"
#include "lldb/Core/Value.h"
#include "lldb/Symbol/CompilerType.h"
#include "lldb/Symbol/Type.h"
Expand Down Expand Up @@ -601,7 +601,7 @@ class ValueObject {
virtual bool HasSyntheticValue();

#ifdef LLDB_ENABLE_SWIFT
llvm::Optional<SwiftASTContextReader> GetScratchSwiftASTContext();
llvm::Optional<SwiftScratchContextReader> GetSwiftScratchContext();
#endif // LLDB_ENABLE_SWIFT

virtual bool IsSynthetic() { return false; }
Expand Down
8 changes: 4 additions & 4 deletions lldb/include/lldb/Target/Target.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "lldb/Core/ModuleList.h"
#include "lldb/Core/StructuredDataImpl.h"
#include "lldb/Core/UserSettingsController.h"
#include "lldb/Core/SwiftASTContextReader.h"
#include "lldb/Core/SwiftScratchContextReader.h"
#include "lldb/Expression/Expression.h"
#include "lldb/Host/ProcessLaunchInfo.h"
#include "lldb/Interpreter/OptionValueBoolean.h"
Expand Down Expand Up @@ -1161,9 +1161,9 @@ class Target : public std::enable_shared_from_this<Target>,
return m_scratch_typesystem_lock;
}

llvm::Optional<SwiftASTContextReader>
GetScratchSwiftASTContext(Status &error, ExecutionContextScope &exe_scope,
bool create_on_demand = true);
llvm::Optional<SwiftScratchContextReader>
GetSwiftScratchContext(Status &error, ExecutionContextScope &exe_scope,
bool create_on_demand = true);

/// Return whether this is the Swift REPL.
bool IsSwiftREPL();
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Core/ValueObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1639,14 +1639,14 @@ bool ValueObject::GetDeclaration(Declaration &decl) {
}

#ifdef LLDB_ENABLE_SWIFT
llvm::Optional<SwiftASTContextReader> ValueObject::GetScratchSwiftASTContext() {
llvm::Optional<SwiftScratchContextReader> ValueObject::GetSwiftScratchContext() {
lldb::TargetSP target_sp(GetTargetSP());
if (!target_sp)
return llvm::None;
Status error;
ExecutionContext ctx = GetExecutionContextRef().Lock(false);
auto *exe_scope = ctx.GetBestExecutionContextScope();
return target_sp->GetScratchSwiftASTContext(error, *exe_scope);
return target_sp->GetSwiftScratchContext(error, *exe_scope);
}
#endif // LLDB_ENABLE_SWIFT

Expand Down Expand Up @@ -2661,7 +2661,7 @@ void ValueObject::Dump(Stream &s) { Dump(s, DumpValueObjectOptions(*this)); }

void ValueObject::Dump(Stream &s, const DumpValueObjectOptions &options) {
#ifdef LLDB_ENABLE_SWIFT
auto swift_scratch_ctx_lock = SwiftASTContextLock(GetSwiftExeCtx(*this));
auto swift_scratch_ctx_lock = SwiftScratchContextLock(GetSwiftExeCtx(*this));
#endif // LLDB_ENABLE_SWIFT
ValueObjectPrinter printer(this, &s, options);
printer.PrintValueObject();
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Core/ValueObjectDynamicValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ bool ValueObjectDynamicValue::UpdateValue() {
}

#ifdef LLDB_ENABLE_SWIFT
auto swift_scratch_ctx_lock = SwiftASTContextLock(&exe_ctx);
auto swift_scratch_ctx_lock = SwiftScratchContextLock(&exe_ctx);
#endif // LLDB_ENABLE_SWIFT

// First make sure our Type and/or Address haven't changed:
Expand Down Expand Up @@ -441,8 +441,8 @@ bool ValueObjectDynamicValue::DynamicValueTypeInfoNeedsUpdate() {

#ifdef LLDB_ENABLE_SWIFT
auto *cached_ctx = m_value.GetCompilerType().GetTypeSystem();
llvm::Optional<SwiftASTContextReader> scratch_ctx =
GetScratchSwiftASTContext();
llvm::Optional<SwiftScratchContextReader> scratch_ctx =
GetSwiftScratchContext();

if (!scratch_ctx || !cached_ctx)
return true;
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Expression/Materializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,8 +924,8 @@ class EntityResultVariable : public Materializer::Entity {
if (m_type.GetMinimumLanguage() == lldb::eLanguageTypeSwift) {
#ifdef LLDB_ENABLE_SWIFT
Status status;
llvm::Optional<SwiftASTContextReader> maybe_type_system =
target_sp->GetScratchSwiftASTContext(status, *exe_scope);
llvm::Optional<SwiftScratchContextReader> maybe_type_system =
target_sp->GetSwiftScratchContext(status, *exe_scope);
if (!maybe_type_system) {
err.SetErrorStringWithFormat("Couldn't dematerialize a result variable: "
"couldn't get the corresponding type "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ SwiftExpressionParser::SwiftExpressionParser(

if (target_sp) {
Status error;
llvm::Optional<SwiftASTContextReader> scratch_ctx =
target_sp->GetScratchSwiftASTContext(error, *exe_scope, true);
llvm::Optional<SwiftScratchContextReader> scratch_ctx =
target_sp->GetSwiftScratchContext(error, *exe_scope, true);
if (scratch_ctx)
m_swift_ast_context =
std::make_unique<SwiftASTContextReader>(scratch_ctx.getValue());
std::make_unique<SwiftScratchContextReader>(scratch_ctx.getValue());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class SwiftExpressionParser : public ExpressionParser {
/// The container for the IR, to be JIT-compiled or interpreted.
lldb::IRExecutionUnitSP m_execution_unit_sp;
/// The AST context to build the expression into.
std::unique_ptr<SwiftASTContextReader> m_swift_ast_context;
std::unique_ptr<SwiftScratchContextReader> m_swift_ast_context;
/// Used to manage the memory of a potential on-off context.
//lldb::TypeSystemSP m_typesystem_sp;
/// The symbol context to use when parsing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ void SwiftUserExpression::ScanContext(ExecutionContext &exe_ctx, Status &err) {

// Make sure the target's SwiftASTContext has been setup before doing any
// Swift name lookups.
llvm::Optional<SwiftASTContextReader> maybe_swift_ast_ctx =
m_target->GetScratchSwiftASTContext(err, *frame);
llvm::Optional<SwiftScratchContextReader> maybe_swift_ast_ctx =
m_target->GetSwiftScratchContext(err, *frame);
if (!maybe_swift_ast_ctx) {
LLDB_LOG(log, " [SUE::SC] NULL Swift AST Context");
return;
Expand Down Expand Up @@ -299,8 +299,8 @@ bool SwiftUserExpression::Parse(DiagnosticManager &diagnostic_manager,

// Make sure the target's SwiftASTContext has been setup before doing any
// Swift name lookups.
llvm::Optional<SwiftASTContextReader> maybe_swift_ast_ctx =
target->GetScratchSwiftASTContext(err, *frame);
llvm::Optional<SwiftScratchContextReader> maybe_swift_ast_ctx =
target->GetSwiftScratchContext(err, *frame);
if (!maybe_swift_ast_ctx) {
LLDB_LOG(log, "no Swift AST Context");
return false;
Expand Down
7 changes: 4 additions & 3 deletions lldb/source/Plugins/Language/Swift/SwiftHashedContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ HashedCollectionConfig::StorageObjectAtAddress(
// same address.
Status error;
ExecutionContextScope *exe_scope = exe_ctx.GetBestExecutionContextScope();
llvm::Optional<SwiftASTContextReader> reader =
process_sp->GetTarget().GetScratchSwiftASTContext(error, *exe_scope);
llvm::Optional<SwiftScratchContextReader> reader =
process_sp->GetTarget().GetSwiftScratchContext(error, *exe_scope);
if (!reader)
return nullptr;
if (error.Fail())
Expand Down Expand Up @@ -456,7 +456,8 @@ NativeHashedStorageHandler::NativeHashedStorageHandler(
m_value_stride = value_type_stride ? *value_type_stride : 0;
if (TypeSystemSwift *type_system =
llvm::dyn_cast_or_null<TypeSystemSwift>(key_type.GetTypeSystem())) {
llvm::Optional<SwiftASTContextReader> scratch_ctx_reader = nativeStorage_sp->GetScratchSwiftASTContext();
llvm::Optional<SwiftScratchContextReader> scratch_ctx_reader =
nativeStorage_sp->GetSwiftScratchContext();
if (!scratch_ctx_reader)
return;
auto *runtime = SwiftLanguageRuntime::Get(m_process);
Expand Down
Loading