Skip to content

Commit c7323d2

Browse files
committed
[lldb] Don't lock ThreadSafeASTContext in entire ParseAndImport
1 parent 93c97e8 commit c7323d2

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

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

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,9 +1259,6 @@ SwiftExpressionParser::ParseAndImport(
12591259
Log *log = GetLog(LLDBLog::Expressions);
12601260
LLDB_SCOPED_TIMER();
12611261

1262-
ThreadSafeASTContext ast_context = GetASTContext(diagnostic_manager);
1263-
if (!ast_context)
1264-
return make_error<SwiftASTContextError>();
12651262

12661263
bool repl = m_options.GetREPLEnabled();
12671264
bool playground = m_options.GetPlaygroundTransformEnabled();
@@ -1317,22 +1314,28 @@ SwiftExpressionParser::ParseAndImport(
13171314
for (auto &attributed_import : additional_imports)
13181315
importInfo.AdditionalImports.emplace_back(attributed_import);
13191316

1320-
auto module_id = ast_context->getIdentifier(expr_name_buf);
1321-
auto &module =
1322-
*swift::ModuleDecl::create(module_id, **ast_context, importInfo);
1317+
swift::ModuleDecl *module = nullptr;
1318+
swift::SourceFile *source_file = nullptr;
1319+
{
1320+
ThreadSafeASTContext ast_context = GetASTContext(diagnostic_manager);
1321+
if (!ast_context)
1322+
return make_error<SwiftASTContextError>();
13231323

1324-
swift::SourceFileKind source_file_kind = swift::SourceFileKind::Library;
1325-
if (playground || repl) {
1326-
source_file_kind = swift::SourceFileKind::Main;
1327-
}
1324+
auto module_id = ast_context->getIdentifier(expr_name_buf);
1325+
module = swift::ModuleDecl::create(module_id, **ast_context, importInfo);
13281326

1329-
// Create the source file. Note, we disable delayed parsing for the
1330-
// swift expression parser.
1331-
swift::SourceFile *source_file = new (**ast_context)
1332-
swift::SourceFile(module, source_file_kind, buffer_id,
1333-
swift::SourceFile::ParsingFlags::DisableDelayedBodies);
1334-
module.addFile(*source_file);
1327+
swift::SourceFileKind source_file_kind = swift::SourceFileKind::Library;
1328+
if (playground || repl) {
1329+
source_file_kind = swift::SourceFileKind::Main;
1330+
}
13351331

1332+
// Create the source file. Note, we disable delayed parsing for the
1333+
// swift expression parser.
1334+
source_file = new (**ast_context) swift::SourceFile(
1335+
*module, source_file_kind, buffer_id,
1336+
swift::SourceFile::ParsingFlags::DisableDelayedBodies);
1337+
module->addFile(*source_file);
1338+
}
13361339
// Swift Modules that rely on shared libraries (not frameworks)
13371340
// don't record the link information in the swiftmodule file, so we
13381341
// can't really make them work without outside information.
@@ -1487,8 +1490,7 @@ SwiftExpressionParser::ParseAndImport(
14871490

14881491
ParsedExpression result = {
14891492
std::move(code_manipulator),
1490-
std::move(ast_context),
1491-
module,
1493+
*module,
14921494
*external_lookup,
14931495
*source_file,
14941496
std::move(main_filename),
@@ -2109,7 +2111,10 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
21092111
// part of the parse from the staging area in the external lookup
21102112
// object into the SwiftPersistentExpressionState.
21112113
swift::ModuleDecl *module = &parsed_expr->module;
2112-
parsed_expr->ast_context->addLoadedModule(module);
2114+
{
2115+
ThreadSafeASTContext ast_context = GetASTContext(diagnostic_manager);
2116+
ast_context->addLoadedModule(module);
2117+
}
21132118
m_swift_ast_ctx.CacheModule(module);
21142119
if (m_sc.target_sp) {
21152120
auto *persistent_state =

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ class SwiftExpressionParser : public ExpressionParser {
185185
/// This holds the result of ParseAndImport.
186186
struct ParsedExpression {
187187
std::unique_ptr<SwiftASTManipulator> code_manipulator;
188-
ThreadSafeASTContext ast_context;
189188
swift::ModuleDecl &module;
190189
LLDBNameLookup &external_lookup;
191190
swift::SourceFile &source_file;

0 commit comments

Comments
 (0)