@@ -1259,9 +1259,6 @@ SwiftExpressionParser::ParseAndImport(
1259
1259
Log *log = GetLog (LLDBLog::Expressions);
1260
1260
LLDB_SCOPED_TIMER ();
1261
1261
1262
- ThreadSafeASTContext ast_context = GetASTContext (diagnostic_manager);
1263
- if (!ast_context)
1264
- return make_error<SwiftASTContextError>();
1265
1262
1266
1263
bool repl = m_options.GetREPLEnabled ();
1267
1264
bool playground = m_options.GetPlaygroundTransformEnabled ();
@@ -1317,22 +1314,28 @@ SwiftExpressionParser::ParseAndImport(
1317
1314
for (auto &attributed_import : additional_imports)
1318
1315
importInfo.AdditionalImports .emplace_back (attributed_import);
1319
1316
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>();
1323
1323
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);
1328
1326
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
+ }
1335
1331
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
+ }
1336
1339
// Swift Modules that rely on shared libraries (not frameworks)
1337
1340
// don't record the link information in the swiftmodule file, so we
1338
1341
// can't really make them work without outside information.
@@ -1487,8 +1490,7 @@ SwiftExpressionParser::ParseAndImport(
1487
1490
1488
1491
ParsedExpression result = {
1489
1492
std::move (code_manipulator),
1490
- std::move (ast_context),
1491
- module ,
1493
+ *module ,
1492
1494
*external_lookup,
1493
1495
*source_file,
1494
1496
std::move (main_filename),
@@ -2109,7 +2111,10 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
2109
2111
// part of the parse from the staging area in the external lookup
2110
2112
// object into the SwiftPersistentExpressionState.
2111
2113
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
+ }
2113
2118
m_swift_ast_ctx.CacheModule (module );
2114
2119
if (m_sc.target_sp ) {
2115
2120
auto *persistent_state =
0 commit comments