Skip to content

Commit dc8e172

Browse files
Merge pull request #3933 from adrian-prantl/scratchctxreader
Rename SwiftASTContextReader -> SwiftScratchContextReader (NFC)
2 parents ebe9411 + a51ddb3 commit dc8e172

File tree

15 files changed

+116
-114
lines changed

15 files changed

+116
-114
lines changed

lldb/include/lldb/Core/SwiftASTContextReader.h renamed to lldb/include/lldb/Core/SwiftScratchContextReader.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,19 @@ class SharedMutex {
5353
/// RAII acquisition of a reader lock.
5454
struct ScopedSharedMutexReader {
5555
SharedMutex *m_mutex;
56-
ScopedSharedMutexReader(const ScopedSharedMutexReader&) = default;
5756
explicit ScopedSharedMutexReader(SharedMutex *m) : m_mutex(m) {
5857
if (m_mutex)
5958
m_mutex->lock_shared();
6059
}
60+
ScopedSharedMutexReader(const ScopedSharedMutexReader&) = default;
6161

6262
~ScopedSharedMutexReader() {
6363
if (m_mutex)
6464
m_mutex->unlock_shared();
6565
}
6666
};
6767

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

9797
public:
98-
SwiftASTContextReader(SharedMutex &mutex, SwiftASTContextForExpressions &ctx)
98+
SwiftScratchContextReader(SharedMutex &mutex,
99+
SwiftASTContextForExpressions &ctx)
99100
: ScopedSharedMutexReader(&mutex), m_ptr(&ctx) {
100101
assert(m_ptr && "invalid context");
101102
}
102103

103-
SwiftASTContextReader(const SwiftASTContextReader &copy)
104+
SwiftScratchContextReader(const SwiftScratchContextReader &copy)
104105
: ScopedSharedMutexReader(copy.m_mutex), m_ptr(copy.m_ptr) {}
105106

106107
SwiftASTContextForExpressions *get() {
@@ -109,14 +110,13 @@ class SwiftASTContextReader : ScopedSharedMutexReader {
109110
}
110111

111112
SwiftASTContextForExpressions *operator->() { return get(); }
112-
113113
SwiftASTContextForExpressions &operator*() { return *get(); }
114114
};
115115

116116
/// An RAII object that just acquires the reader lock.
117-
struct SwiftASTContextLock : ScopedSharedMutexReader {
118-
SwiftASTContextLock(const ExecutionContextRef *exe_ctx_ref);
119-
SwiftASTContextLock(const ExecutionContext *exe_ctx);
117+
struct SwiftScratchContextLock : ScopedSharedMutexReader {
118+
SwiftScratchContextLock(const ExecutionContextRef *exe_ctx_ref);
119+
SwiftScratchContextLock(const ExecutionContext *exe_ctx);
120120
};
121121

122122
} // namespace lldb_private

lldb/include/lldb/Core/ValueObject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef LLDB_CORE_VALUEOBJECT_H
1010
#define LLDB_CORE_VALUEOBJECT_H
1111

12-
#include "lldb/Core/SwiftASTContextReader.h"
12+
#include "lldb/Core/SwiftScratchContextReader.h"
1313
#include "lldb/Core/Value.h"
1414
#include "lldb/Symbol/CompilerType.h"
1515
#include "lldb/Symbol/Type.h"
@@ -601,7 +601,7 @@ class ValueObject {
601601
virtual bool HasSyntheticValue();
602602

603603
#ifdef LLDB_ENABLE_SWIFT
604-
llvm::Optional<SwiftASTContextReader> GetScratchSwiftASTContext();
604+
llvm::Optional<SwiftScratchContextReader> GetSwiftScratchContext();
605605
#endif // LLDB_ENABLE_SWIFT
606606

607607
virtual bool IsSynthetic() { return false; }

lldb/include/lldb/Target/Target.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "lldb/Core/ModuleList.h"
2525
#include "lldb/Core/StructuredDataImpl.h"
2626
#include "lldb/Core/UserSettingsController.h"
27-
#include "lldb/Core/SwiftASTContextReader.h"
27+
#include "lldb/Core/SwiftScratchContextReader.h"
2828
#include "lldb/Expression/Expression.h"
2929
#include "lldb/Host/ProcessLaunchInfo.h"
3030
#include "lldb/Interpreter/OptionValueBoolean.h"
@@ -1161,9 +1161,9 @@ class Target : public std::enable_shared_from_this<Target>,
11611161
return m_scratch_typesystem_lock;
11621162
}
11631163

1164-
llvm::Optional<SwiftASTContextReader>
1165-
GetScratchSwiftASTContext(Status &error, ExecutionContextScope &exe_scope,
1166-
bool create_on_demand = true);
1164+
llvm::Optional<SwiftScratchContextReader>
1165+
GetSwiftScratchContext(Status &error, ExecutionContextScope &exe_scope,
1166+
bool create_on_demand = true);
11671167

11681168
/// Return whether this is the Swift REPL.
11691169
bool IsSwiftREPL();

lldb/source/Core/ValueObject.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,14 +1639,14 @@ bool ValueObject::GetDeclaration(Declaration &decl) {
16391639
}
16401640

16411641
#ifdef LLDB_ENABLE_SWIFT
1642-
llvm::Optional<SwiftASTContextReader> ValueObject::GetScratchSwiftASTContext() {
1642+
llvm::Optional<SwiftScratchContextReader> ValueObject::GetSwiftScratchContext() {
16431643
lldb::TargetSP target_sp(GetTargetSP());
16441644
if (!target_sp)
16451645
return llvm::None;
16461646
Status error;
16471647
ExecutionContext ctx = GetExecutionContextRef().Lock(false);
16481648
auto *exe_scope = ctx.GetBestExecutionContextScope();
1649-
return target_sp->GetScratchSwiftASTContext(error, *exe_scope);
1649+
return target_sp->GetSwiftScratchContext(error, *exe_scope);
16501650
}
16511651
#endif // LLDB_ENABLE_SWIFT
16521652

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

26622662
void ValueObject::Dump(Stream &s, const DumpValueObjectOptions &options) {
26632663
#ifdef LLDB_ENABLE_SWIFT
2664-
auto swift_scratch_ctx_lock = SwiftASTContextLock(GetSwiftExeCtx(*this));
2664+
auto swift_scratch_ctx_lock = SwiftScratchContextLock(GetSwiftExeCtx(*this));
26652665
#endif // LLDB_ENABLE_SWIFT
26662666
ValueObjectPrinter printer(this, &s, options);
26672667
printer.PrintValueObject();

lldb/source/Core/ValueObjectDynamicValue.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ bool ValueObjectDynamicValue::UpdateValue() {
152152
}
153153

154154
#ifdef LLDB_ENABLE_SWIFT
155-
auto swift_scratch_ctx_lock = SwiftASTContextLock(&exe_ctx);
155+
auto swift_scratch_ctx_lock = SwiftScratchContextLock(&exe_ctx);
156156
#endif // LLDB_ENABLE_SWIFT
157157

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

442442
#ifdef LLDB_ENABLE_SWIFT
443443
auto *cached_ctx = m_value.GetCompilerType().GetTypeSystem();
444-
llvm::Optional<SwiftASTContextReader> scratch_ctx =
445-
GetScratchSwiftASTContext();
444+
llvm::Optional<SwiftScratchContextReader> scratch_ctx =
445+
GetSwiftScratchContext();
446446

447447
if (!scratch_ctx || !cached_ctx)
448448
return true;

lldb/source/Expression/Materializer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -924,8 +924,8 @@ class EntityResultVariable : public Materializer::Entity {
924924
if (m_type.GetMinimumLanguage() == lldb::eLanguageTypeSwift) {
925925
#ifdef LLDB_ENABLE_SWIFT
926926
Status status;
927-
llvm::Optional<SwiftASTContextReader> maybe_type_system =
928-
target_sp->GetScratchSwiftASTContext(status, *exe_scope);
927+
llvm::Optional<SwiftScratchContextReader> maybe_type_system =
928+
target_sp->GetSwiftScratchContext(status, *exe_scope);
929929
if (!maybe_type_system) {
930930
err.SetErrorStringWithFormat("Couldn't dematerialize a result variable: "
931931
"couldn't get the corresponding type "

lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ SwiftExpressionParser::SwiftExpressionParser(
110110

111111
if (target_sp) {
112112
Status error;
113-
llvm::Optional<SwiftASTContextReader> scratch_ctx =
114-
target_sp->GetScratchSwiftASTContext(error, *exe_scope, true);
113+
llvm::Optional<SwiftScratchContextReader> scratch_ctx =
114+
target_sp->GetSwiftScratchContext(error, *exe_scope, true);
115115
if (scratch_ctx)
116116
m_swift_ast_context =
117-
std::make_unique<SwiftASTContextReader>(scratch_ctx.getValue());
117+
std::make_unique<SwiftScratchContextReader>(scratch_ctx.getValue());
118118
}
119119
}
120120

lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class SwiftExpressionParser : public ExpressionParser {
162162
/// The container for the IR, to be JIT-compiled or interpreted.
163163
lldb::IRExecutionUnitSP m_execution_unit_sp;
164164
/// The AST context to build the expression into.
165-
std::unique_ptr<SwiftASTContextReader> m_swift_ast_context;
165+
std::unique_ptr<SwiftScratchContextReader> m_swift_ast_context;
166166
/// Used to manage the memory of a potential on-off context.
167167
//lldb::TypeSystemSP m_typesystem_sp;
168168
/// The symbol context to use when parsing.

lldb/source/Plugins/ExpressionParser/Swift/SwiftUserExpression.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ void SwiftUserExpression::ScanContext(ExecutionContext &exe_ctx, Status &err) {
186186

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

300300
// Make sure the target's SwiftASTContext has been setup before doing any
301301
// Swift name lookups.
302-
llvm::Optional<SwiftASTContextReader> maybe_swift_ast_ctx =
303-
target->GetScratchSwiftASTContext(err, *frame);
302+
llvm::Optional<SwiftScratchContextReader> maybe_swift_ast_ctx =
303+
target->GetSwiftScratchContext(err, *frame);
304304
if (!maybe_swift_ast_ctx) {
305305
LLDB_LOG(log, "no Swift AST Context");
306306
return false;

lldb/source/Plugins/Language/Swift/SwiftHashedContainer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ HashedCollectionConfig::StorageObjectAtAddress(
294294
// same address.
295295
Status error;
296296
ExecutionContextScope *exe_scope = exe_ctx.GetBestExecutionContextScope();
297-
llvm::Optional<SwiftASTContextReader> reader =
298-
process_sp->GetTarget().GetScratchSwiftASTContext(error, *exe_scope);
297+
llvm::Optional<SwiftScratchContextReader> reader =
298+
process_sp->GetTarget().GetSwiftScratchContext(error, *exe_scope);
299299
if (!reader)
300300
return nullptr;
301301
if (error.Fail())
@@ -456,7 +456,8 @@ NativeHashedStorageHandler::NativeHashedStorageHandler(
456456
m_value_stride = value_type_stride ? *value_type_stride : 0;
457457
if (TypeSystemSwift *type_system =
458458
llvm::dyn_cast_or_null<TypeSystemSwift>(key_type.GetTypeSystem())) {
459-
llvm::Optional<SwiftASTContextReader> scratch_ctx_reader = nativeStorage_sp->GetScratchSwiftASTContext();
459+
llvm::Optional<SwiftScratchContextReader> scratch_ctx_reader =
460+
nativeStorage_sp->GetSwiftScratchContext();
460461
if (!scratch_ctx_reader)
461462
return;
462463
auto *runtime = SwiftLanguageRuntime::Get(m_process);

0 commit comments

Comments
 (0)