Skip to content

Commit 94d9cd1

Browse files
Merge pull request #9613 from adrian-prantl/retire-astcontext-reader
[lldb] Retire the SwiftASTContextReader lock manager.
2 parents 7a76ea7 + 05f909d commit 94d9cd1

22 files changed

+224
-549
lines changed

lldb/include/lldb/Core/SwiftScratchContextReader.h

Lines changed: 0 additions & 74 deletions
This file was deleted.

lldb/include/lldb/Target/Target.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "lldb/Core/ModuleList.h"
2525
#include "lldb/Core/StructuredDataImpl.h"
2626
#include "lldb/Core/UserSettingsController.h"
27-
#include "lldb/Core/SwiftScratchContextReader.h"
2827
#include "lldb/Expression/Expression.h"
2928
#include "lldb/Host/ProcessLaunchInfo.h"
3029
#include "lldb/Interpreter/OptionValueBoolean.h"
@@ -52,7 +51,10 @@ namespace lldb_private {
5251
class ClangModulesDeclVendor;
5352
class SwiftPersistentExpressionState;
5453
class SharedMutex;
55-
class SwiftASTContextForExpressions;
54+
class TypeSystemSwiftTypeRefForExpressions;
55+
typedef std::shared_ptr<TypeSystemSwiftTypeRefForExpressions>
56+
TypeSystemSwiftTypeRefForExpressionsSP;
57+
5658

5759
OptionEnumValues GetDynamicValueTypes();
5860

@@ -1303,7 +1305,7 @@ class Target : public std::enable_shared_from_this<Target>,
13031305
return m_scratch_typesystem_lock;
13041306
}
13051307

1306-
std::optional<SwiftScratchContextReader>
1308+
TypeSystemSwiftTypeRefForExpressionsSP
13071309
GetSwiftScratchContext(Status &error, ExecutionContextScope &exe_scope,
13081310
bool create_on_demand = true,
13091311
bool for_playground = false);
@@ -1314,9 +1316,6 @@ class Target : public std::enable_shared_from_this<Target>,
13141316
bool IsSwiftCxxInteropEnabled();
13151317

13161318
bool IsEmbeddedSwift();
1317-
private:
1318-
void DisplayFallbackSwiftContextErrors(
1319-
SwiftASTContextForExpressions *swift_ast_ctx);
13201319
#endif // LLDB_ENABLE_SWIFT
13211320

13221321
public:
@@ -1722,11 +1721,7 @@ class Target : public std::enable_shared_from_this<Target>,
17221721
/// signals you will have.
17231722
llvm::StringMap<DummySignalValues> m_dummy_signals;
17241723

1725-
bool m_use_scratch_typesystem_per_module = false;
17261724
bool m_did_display_scratch_fallback_warning = false;
1727-
typedef std::pair<lldb_private::Module *, char> ModuleLanguage;
1728-
llvm::DenseMap<ModuleLanguage, lldb::TypeSystemSP>
1729-
m_scratch_typesystem_for_module;
17301725

17311726
/// Guards the scratch typesystem from being re-initialized.
17321727
std::shared_mutex m_scratch_typesystem_lock;

lldb/include/lldb/ValueObject/ValueObject.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef LLDB_VALUEOBJECT_VALUEOBJECT_H
1010
#define LLDB_VALUEOBJECT_VALUEOBJECT_H
1111

12-
#include "lldb/Core/SwiftScratchContextReader.h"
1312
#include "lldb/Core/Value.h"
1413
#include "lldb/Symbol/CompilerType.h"
1514
#include "lldb/Symbol/Type.h"
@@ -615,7 +614,7 @@ class ValueObject {
615614
virtual bool HasSyntheticValue();
616615

617616
#ifdef LLDB_ENABLE_SWIFT
618-
std::optional<SwiftScratchContextReader> GetSwiftScratchContext();
617+
TypeSystemSwiftTypeRefForExpressionsSP GetSwiftScratchContext();
619618
#endif // LLDB_ENABLE_SWIFT
620619

621620
virtual bool IsSynthetic() { return false; }

lldb/source/Expression/Materializer.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,17 +1064,6 @@ class EntityResultVariable : public Materializer::Entity {
10641064

10651065
if (m_type.GetMinimumLanguage() == lldb::eLanguageTypeSwift) {
10661066
#ifdef LLDB_ENABLE_SWIFT
1067-
Status status;
1068-
std::optional<SwiftScratchContextReader> maybe_type_system =
1069-
target_sp->GetSwiftScratchContext(status, *exe_scope);
1070-
if (!maybe_type_system) {
1071-
err = Status::FromErrorStringWithFormat(
1072-
"Couldn't dematerialize a result variable: "
1073-
"couldn't get the corresponding type "
1074-
"system: %s",
1075-
status.AsCString());
1076-
return;
1077-
}
10781067
persistent_state = target_sp->GetPersistentExpressionStateForLanguage(
10791068
lldb::eLanguageTypeSwift);
10801069
#endif // LLDB_ENABLE_SWIFT

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ bool SwiftUserExpression::Parse(DiagnosticManager &diagnostic_manager,
743743
target->GetExecutableModule());
744744
else
745745
sc = frame->GetSymbolContext(lldb::eSymbolContextFunction);
746-
auto *swift_ast_ctx = m_swift_scratch_ctx->get()->GetSwiftASTContext(sc);
746+
auto *swift_ast_ctx = m_swift_scratch_ctx->GetSwiftASTContext(sc);
747747
m_swift_ast_ctx =
748748
llvm::dyn_cast_or_null<SwiftASTContextForExpressions>(swift_ast_ctx);
749749

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class SwiftUserExpression : public LLVMUserExpression {
189189
void DidDematerialize(lldb::ExpressionVariableSP &variable) override;
190190
};
191191

192-
std::optional<SwiftScratchContextReader> m_swift_scratch_ctx;
192+
TypeSystemSwiftSP m_swift_scratch_ctx;
193193
SwiftASTContextForExpressions *m_swift_ast_ctx;
194194
PersistentVariableDelegate m_persistent_variable_delegate;
195195
std::unique_ptr<SwiftExpressionParser> m_parser;

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,7 @@ SwiftArrayBufferHandler::CreateBufferHandler(ValueObject &static_valobj) {
330330

331331
// Get the type of the array elements.
332332
CompilerType argument_type;
333-
auto scratch_ctx_reader = valobj.GetSwiftScratchContext();
334-
if (!scratch_ctx_reader)
335-
return nullptr;
336-
auto *ts = scratch_ctx_reader->get();
333+
auto ts = valobj.GetSwiftScratchContext();
337334
if (!ts)
338335
return nullptr;
339336
auto *swift_runtime = SwiftLanguageRuntime::Get(process_sp);

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,12 @@ HashedCollectionConfig::StorageObjectAtAddress(
291291
// same address.
292292
Status error;
293293
ExecutionContextScope *exe_scope = exe_ctx.GetBestExecutionContextScope();
294-
std::optional<SwiftScratchContextReader> reader =
295-
process_sp->GetTarget().GetSwiftScratchContext(error, *exe_scope);
296-
if (!reader)
294+
auto scratch_ctx =
295+
process_sp->GetTarget().GetSwiftScratchContext(error, *exe_scope);
296+
if (!scratch_ctx)
297297
return nullptr;
298298
if (error.Fail())
299299
return nullptr;
300-
auto scratch_ctx = reader->get();
301-
if (!scratch_ctx)
302-
return nullptr;
303300
CompilerType rawStorage_type =
304301
scratch_ctx->GetTypeFromMangledTypename(m_nativeStorageRoot_mangled);
305302
if (!rawStorage_type.IsValid())

0 commit comments

Comments
 (0)