@@ -771,7 +771,6 @@ SetupASTContext(SwiftASTContextForExpressions &swift_ast_context,
771
771
// TODO: Find a way to get contraint-solver output sent to a stream
772
772
// so we can log it.
773
773
// swift_ast_context.GetLanguageOptions().DebugConstraintSolver = true;
774
- swift_ast_context.ClearDiagnostics ();
775
774
776
775
// No longer part of debugger support, set it separately.
777
776
swift_ast_context.GetLanguageOptions ().EnableDollarIdentifiers = true ;
@@ -1217,15 +1216,15 @@ AddArchetypesTypeAliases(std::unique_ptr<SwiftASTManipulator> &code_manipulator,
1217
1216
// / Attempt to parse an expression and import all the Swift modules
1218
1217
// / the expression and its context depend on.
1219
1218
static llvm::Expected<ParsedExpression> ParseAndImport (
1220
- SwiftASTContextForExpressions &swift_ast_context, Expression &expr,
1219
+ SwiftASTContextForExpressions &swift_ast_context,
1220
+ SwiftASTContext::ScopedDiagnostics &expr_diagnostics, Expression &expr,
1221
1221
SwiftExpressionParser::SILVariableMap &variable_map, unsigned &buffer_id,
1222
1222
DiagnosticManager &diagnostic_manager,
1223
1223
SwiftExpressionParser &swift_expr_parser,
1224
1224
lldb::StackFrameWP &stack_frame_wp, SymbolContext &sc,
1225
- ExecutionContextScope &exe_scope,
1225
+ ExecutionContextScope &exe_scope,
1226
1226
llvm::SmallVectorImpl<SwiftASTManipulator::VariableInfo> &local_variables,
1227
- const EvaluateExpressionOptions &options,
1228
- bool repl, bool playground) {
1227
+ const EvaluateExpressionOptions &options, bool repl, bool playground) {
1229
1228
Log *log = GetLog (LLDBLog::Expressions);
1230
1229
LLDB_SCOPED_TIMER ();
1231
1230
@@ -1373,16 +1372,16 @@ static llvm::Expected<ParsedExpression> ParseAndImport(
1373
1372
// inserting them in.
1374
1373
swift_ast_context.AddDebuggerClient (external_lookup);
1375
1374
1376
- if (swift_ast_context .HasErrors ())
1375
+ if (expr_diagnostics .HasErrors ())
1377
1376
return make_error<SwiftASTContextError>();
1378
1377
1379
1378
// Resolve the file's imports, including the implicit ones returned from
1380
1379
// GetImplicitImports.
1381
1380
swift::performImportResolution (*source_file);
1382
1381
1383
- if (swift_ast_context .HasErrors ())
1382
+ if (expr_diagnostics .HasErrors ())
1384
1383
return make_error<ModuleImportError>(
1385
- swift_ast_context .GetAllErrors ().AsCString (
1384
+ expr_diagnostics .GetAllErrors ().AsCString (
1386
1385
" Explicit module import error" ));
1387
1386
1388
1387
std::unique_ptr<SwiftASTManipulator> code_manipulator;
@@ -1654,20 +1653,24 @@ RedirectCallFromSinkToTrampolineFunction(llvm::Module &module,
1654
1653
SwiftExpressionParser::ParseResult
1655
1654
SwiftExpressionParser::Parse (DiagnosticManager &diagnostic_manager,
1656
1655
uint32_t first_line, uint32_t last_line) {
1656
+ SwiftExpressionParser::SILVariableMap variable_map;
1657
1657
using ParseResult = SwiftExpressionParser::ParseResult;
1658
1658
Log *log = GetLog (LLDBLog::Expressions);
1659
1659
LLDB_SCOPED_TIMER ();
1660
1660
1661
- SwiftExpressionParser::SILVariableMap variable_map;
1661
+ // Get a scoped diagnostics consumer for all diagnostics produced by
1662
+ // this expression.
1663
+ auto expr_diagnostics = m_swift_ast_ctx.getScopedDiagnosticConsumer ();
1664
+ m_swift_ast_ctx.GetDiagnosticEngine ().resetHadAnyError ();
1662
1665
1663
1666
// Helper function to diagnose errors in m_swift_scratch_context.
1664
1667
unsigned buffer_id = UINT32_MAX;
1665
1668
auto DiagnoseSwiftASTContextError = [&]() {
1666
- assert ((m_swift_ast_ctx. HasErrors () ||
1669
+ assert ((expr_diagnostics-> HasErrors () ||
1667
1670
m_swift_ast_ctx.HasClangImporterErrors ()) &&
1668
1671
" error expected" );
1669
- m_swift_ast_ctx. PrintDiagnostics (diagnostic_manager, buffer_id, first_line ,
1670
- last_line);
1672
+ expr_diagnostics-> PrintDiagnostics (diagnostic_manager, buffer_id,
1673
+ first_line, last_line);
1671
1674
};
1672
1675
1673
1676
// In the case of playgrounds, we turn all rewriting functionality off.
@@ -1679,9 +1682,9 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
1679
1682
1680
1683
// Parse the expression and import all nececssary swift modules.
1681
1684
auto parsed_expr = ParseAndImport (
1682
- m_swift_ast_ctx, m_expr, variable_map, buffer_id, diagnostic_manager ,
1683
- *this , m_stack_frame_wp, m_sc, *m_exe_scope, m_local_variables, m_options ,
1684
- repl, playground);
1685
+ m_swift_ast_ctx, *expr_diagnostics, m_expr, variable_map, buffer_id,
1686
+ diagnostic_manager, *this , m_stack_frame_wp, m_sc, *m_exe_scope,
1687
+ m_local_variables, m_options, repl, playground);
1685
1688
1686
1689
if (!parsed_expr) {
1687
1690
bool retry = false ;
@@ -1740,7 +1743,7 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
1740
1743
if (log)
1741
1744
dumpModule (" Module after type checking:" );
1742
1745
1743
- if (m_swift_ast_ctx. HasErrors ()) {
1746
+ if (expr_diagnostics-> HasErrors ()) {
1744
1747
DiagnoseSwiftASTContextError ();
1745
1748
return ParseResult::unrecoverable_error;
1746
1749
}
@@ -1917,7 +1920,7 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
1917
1920
log->PutCString (s.c_str ());
1918
1921
}
1919
1922
1920
- if (m_swift_ast_ctx. HasErrors ()) {
1923
+ if (expr_diagnostics-> HasErrors ()) {
1921
1924
DiagnoseSwiftASTContextError ();
1922
1925
return ParseResult::unrecoverable_error;
1923
1926
}
@@ -1945,7 +1948,7 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
1945
1948
log->PutCString (s.c_str ());
1946
1949
}
1947
1950
1948
- if (m_swift_ast_ctx. HasErrors ()) {
1951
+ if (expr_diagnostics-> HasErrors ()) {
1949
1952
DiagnoseSwiftASTContextError ();
1950
1953
return ParseResult::unrecoverable_error;
1951
1954
}
@@ -1973,7 +1976,8 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
1973
1976
1974
1977
// If IRGen failed without errors, the root cause may be a fatal
1975
1978
// Clang diagnostic.
1976
- if (m_swift_ast_ctx.HasErrors () || m_swift_ast_ctx.HasClangImporterErrors ()) {
1979
+ if (expr_diagnostics->HasErrors () ||
1980
+ m_swift_ast_ctx.HasClangImporterErrors ()) {
1977
1981
diagnostic_manager.PutString (eDiagnosticSeverityRemark,
1978
1982
" couldn't IRGen expression" );
1979
1983
DiagnoseSwiftASTContextError ();
@@ -2029,7 +2033,7 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
2029
2033
nullptr );
2030
2034
}
2031
2035
2032
- if (m_swift_ast_ctx. HasErrors ())
2036
+ if (expr_diagnostics-> HasErrors ())
2033
2037
return ParseResult::unrecoverable_error;
2034
2038
2035
2039
// The Parse succeeded! Now put this module into the context's list
0 commit comments