@@ -138,8 +138,7 @@ LLDBNameLookup::LLDBNameLookup(
138
138
SwiftExpressionParser::SILVariableMap &variable_map, SymbolContext &sc,
139
139
ExecutionContextScope &exe_scope)
140
140
: SILDebuggerClient(source_file.getASTContext()),
141
- m_log(GetLog(LLDBLog::Expressions)), m_source_file(source_file),
142
- m_variable_map(variable_map), m_sc(sc) {
141
+ m_source_file(source_file), m_variable_map(variable_map), m_sc(sc) {
143
142
source_file.getParentModule ()->setDebugClient (this );
144
143
145
144
if (!m_sc.target_sp )
@@ -177,11 +176,15 @@ void LLDBNameLookup::RegisterTypeAliases(
177
176
178
177
// / A name lookup class for debugger expr mode.
179
178
class LLDBExprNameLookup : public LLDBNameLookup {
179
+ const SwiftASTContextForExpressions *m_this_context;
180
+
180
181
public:
181
182
LLDBExprNameLookup (swift::SourceFile &source_file,
182
183
SwiftExpressionParser::SILVariableMap &variable_map,
183
- SymbolContext &sc, ExecutionContextScope &exe_scope)
184
- : LLDBNameLookup(source_file, variable_map, sc, exe_scope) {}
184
+ SymbolContext &sc, ExecutionContextScope &exe_scope,
185
+ const SwiftASTContextForExpressions *this_context)
186
+ : LLDBNameLookup(source_file, variable_map, sc, exe_scope),
187
+ m_this_context (this_context) {}
185
188
186
189
bool shouldGlobalize (swift::Identifier Name, swift::DeclKind Kind) override {
187
190
// Extensions have to be globalized, there's no way to mark them
@@ -195,7 +198,7 @@ class LLDBExprNameLookup : public LLDBNameLookup {
195
198
return true ;
196
199
197
200
if (Name.str ().starts_with (" $" )) {
198
- LLDB_LOG (m_log ,
201
+ LLDB_LOG (GetLog (LLDBLog::Expressions) ,
199
202
" [LLDBExprNameLookup::shouldGlobalize] Returning true to "
200
203
" globalizing {0}" ,
201
204
Name.str ());
@@ -223,7 +226,7 @@ class LLDBExprNameLookup : public LLDBNameLookup {
223
226
static unsigned counter = 0 ;
224
227
unsigned count = counter++;
225
228
226
- LLDB_LOG (m_log ,
229
+ LLDB_LOG (GetLog (LLDBLog::Expressions) ,
227
230
" [LLDBExprNameLookup::lookupOverrides({0})] Searching for \" {1}\" " ,
228
231
count, Name.getIdentifier ().get ());
229
232
@@ -234,6 +237,8 @@ class LLDBExprNameLookup : public LLDBNameLookup {
234
237
swift::SourceLoc Loc, bool IsTypeLookup,
235
238
ResultVector &RV) override {
236
239
LLDB_SCOPED_TIMER ();
240
+ assert (SwiftASTContext::GetSwiftASTContext (&DC->getASTContext ()) ==
241
+ m_this_context);
237
242
static unsigned counter = 0 ;
238
243
unsigned count = counter++;
239
244
@@ -242,7 +247,7 @@ class LLDBExprNameLookup : public LLDBNameLookup {
242
247
return false ;
243
248
244
249
LLDB_LOG (
245
- m_log ,
250
+ GetLog (LLDBLog::Expressions) ,
246
251
" [LLDBExprNameLookup::lookupAdditions ({0})] Searching for \" {1}\" " ,
247
252
count, NameStr);
248
253
@@ -290,9 +295,10 @@ class LLDBExprNameLookup : public LLDBNameLookup {
290
295
persistent_results);
291
296
292
297
for (CompilerDecl & decl : persistent_results) {
293
- if (decl.GetTypeSystem () !=
294
- SwiftASTContext::GetSwiftASTContext (&DC->getASTContext ())) {
295
- LLDB_LOG (m_log, " ignoring persistent result from other context" );
298
+ if (decl.GetTypeSystem () != m_this_context) {
299
+ LLDB_LOG (GetLog (LLDBLog::Expressions),
300
+ " Ignoring persistent result from other context: {0}" ,
301
+ NameStr);
296
302
continue ;
297
303
}
298
304
auto *value_decl =
@@ -368,11 +374,15 @@ class LLDBExprNameLookup : public LLDBNameLookup {
368
374
369
375
// / A name lookup class for REPL and Playground mode.
370
376
class LLDBREPLNameLookup : public LLDBNameLookup {
377
+ const SwiftASTContextForExpressions *m_this_context;
378
+
371
379
public:
372
380
LLDBREPLNameLookup (swift::SourceFile &source_file,
373
381
SwiftExpressionParser::SILVariableMap &variable_map,
374
- SymbolContext &sc, ExecutionContextScope &exe_scope)
375
- : LLDBNameLookup(source_file, variable_map, sc, exe_scope) {}
382
+ SymbolContext &sc, ExecutionContextScope &exe_scope,
383
+ const SwiftASTContextForExpressions *this_context)
384
+ : LLDBNameLookup(source_file, variable_map, sc, exe_scope),
385
+ m_this_context (this_context) {}
376
386
377
387
bool shouldGlobalize (swift::Identifier Name, swift::DeclKind kind) override {
378
388
return false ;
@@ -390,6 +400,9 @@ class LLDBREPLNameLookup : public LLDBNameLookup {
390
400
swift::SourceLoc Loc, bool IsTypeLookup,
391
401
ResultVector &RV) override {
392
402
LLDB_SCOPED_TIMER ();
403
+
404
+ assert (SwiftASTContext::GetSwiftASTContext (&DC->getASTContext ()) ==
405
+ m_this_context);
393
406
static unsigned counter = 0 ;
394
407
unsigned count = counter++;
395
408
@@ -398,7 +411,7 @@ class LLDBREPLNameLookup : public LLDBNameLookup {
398
411
return false ;
399
412
400
413
LLDB_LOG (
401
- m_log ,
414
+ GetLog (LLDBLog::Expressions) ,
402
415
" [LLDBREPLNameLookup::lookupAdditions ({0})] Searching for \" {1}\" " ,
403
416
count, NameStr);
404
417
@@ -420,6 +433,12 @@ class LLDBREPLNameLookup : public LLDBNameLookup {
420
433
421
434
// Append the persistent decls that we found to the result vector.
422
435
for (auto result : persistent_decl_results) {
436
+ if (result.GetTypeSystem () != m_this_context) {
437
+ LLDB_LOG (GetLog (LLDBLog::Expressions),
438
+ " Ignoring persistent result from other context: {0}" , NameStr);
439
+ continue ;
440
+ }
441
+
423
442
// No import required.
424
443
auto *result_decl =
425
444
static_cast <swift::ValueDecl *>(result.GetOpaqueDecl ());
@@ -1375,11 +1394,11 @@ SwiftExpressionParser::ParseAndImport(
1375
1394
1376
1395
LLDBNameLookup *external_lookup;
1377
1396
if (m_options.GetPlaygroundTransformEnabled () || m_options.GetREPLEnabled ()) {
1378
- external_lookup =
1379
- new LLDBREPLNameLookup (*source_file, variable_map, m_sc, *m_exe_scope);
1397
+ external_lookup = new LLDBREPLNameLookup (*source_file, variable_map, m_sc,
1398
+ *m_exe_scope, &m_swift_ast_ctx );
1380
1399
} else {
1381
- external_lookup =
1382
- new LLDBExprNameLookup (*source_file, variable_map, m_sc, *m_exe_scope);
1400
+ external_lookup = new LLDBExprNameLookup (*source_file, variable_map, m_sc,
1401
+ *m_exe_scope, &m_swift_ast_ctx );
1383
1402
}
1384
1403
1385
1404
// FIXME: This call is here just so that the we keep the
@@ -1758,8 +1777,15 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
1758
1777
1759
1778
// Signal that we want to retry the expression exactly once with a
1760
1779
// fresh SwiftASTContext.
1761
- if (retry)
1780
+ if (retry) {
1781
+ if (auto *persistent_state =
1782
+ llvm::cast_or_null<SwiftPersistentExpressionState>(
1783
+ m_sc.target_sp ->GetPersistentExpressionStateForLanguage (
1784
+ lldb::eLanguageTypeSwift)))
1785
+ persistent_state->Clear ();
1786
+
1762
1787
return ParseResult::retry_fresh_context;
1788
+ }
1763
1789
1764
1790
// Unrecoverable error.
1765
1791
return ParseResult::unrecoverable_error;
@@ -2023,6 +2049,11 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
2023
2049
return ParseResult::unrecoverable_error;
2024
2050
}
2025
2051
2052
+ if (m_swift_ast_ctx.GetASTContext ()->hadError ()) {
2053
+ DiagnoseSwiftASTContextError ();
2054
+ return ParseResult::unrecoverable_error;
2055
+ }
2056
+
2026
2057
{
2027
2058
std::lock_guard<std::recursive_mutex> global_context_locker (
2028
2059
IRExecutionUnit::GetLLVMGlobalContextMutex ());
0 commit comments