From 3b58a94ad5b8a332f6b79ff5cf9a64fa5b415e6e Mon Sep 17 00:00:00 2001 From: Charles Zablit Date: Thu, 2 Apr 2026 17:26:35 +0100 Subject: [PATCH] [lldb][windows] fix a deadlock when a module fails to import --- .../Swift/SwiftExpressionParser.cpp | 3 -- .../TypeSystem/Swift/SwiftASTContext.cpp | 29 +++++++++++-------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp index be3777ca2fac9..83fc97447e367 100644 --- a/lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp +++ b/lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp @@ -1800,9 +1800,6 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager, retry = true; return; } - // There are no fallback contexts in REPL and playgrounds. - if (repl || playground) - return; // The fatal error causes a new compiler to be instantiated on retry. m_swift_ast_ctx.RaiseFatalError(MIE.message()); }, diff --git a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp index 55e75fed61e41..0fd28e94bf91e 100644 --- a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp +++ b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp @@ -4477,24 +4477,29 @@ SwiftASTContext::GetModule(const SourceModule &module, bool *cached) { return *module_decl; } - ThreadSafeASTContext ast = GetASTContext(); - if (!ast) { - LOG_PRINTF(GetLog(LLDBLog::Types), "(\"%s\") invalid ASTContext", - module.path.front().GetCString()); + swift::ASTContext *raw_ast = nullptr; + { + ThreadSafeASTContext ast = GetASTContext(); + if (!ast) { + LOG_PRINTF(GetLog(LLDBLog::Types), "(\"%s\") invalid ASTContext", + module.path.front().GetCString()); - return llvm::createStringError("invalid swift::ASTContext"); - } + return llvm::createStringError("invalid swift::ASTContext"); + } - if (HasFatalErrors()) { - return llvm::createStringError( - llvm::formatv("failed to get module \"{0}\" from AST context:\n" - "AST context is in a fatal error state", - module_name)); + if (HasFatalErrors()) { + return llvm::createStringError( + llvm::formatv("failed to get module \"{0}\" from AST context:\n" + "AST context is in a fatal error state", + module_name)); + } + + raw_ast = *ast; } // Create a diagnostic consumer for the diagnostics produced by the import. auto import_diags = getScopedDiagnosticConsumer(); - swift::ModuleDecl *module_decl = ast->getModuleByName(module_name); + swift::ModuleDecl *module_decl = raw_ast->getModuleByName(module_name); // Error handling. if (import_diags->HasErrors()) {