@@ -139,8 +139,7 @@ LLDBNameLookup::LLDBNameLookup(
139
139
SwiftExpressionParser::SILVariableMap &variable_map, SymbolContext &sc,
140
140
ExecutionContextScope &exe_scope)
141
141
: SILDebuggerClient(source_file.getASTContext()),
142
- m_log(GetLog(LLDBLog::Expressions)), m_source_file(source_file),
143
- m_variable_map(variable_map), m_sc(sc) {
142
+ m_source_file(source_file), m_variable_map(variable_map), m_sc(sc) {
144
143
source_file.getParentModule ()->setDebugClient (this );
145
144
146
145
if (!m_sc.target_sp )
@@ -178,11 +177,15 @@ void LLDBNameLookup::RegisterTypeAliases(
178
177
179
178
// / A name lookup class for debugger expr mode.
180
179
class LLDBExprNameLookup : public LLDBNameLookup {
180
+ const SwiftASTContextForExpressions *m_this_context;
181
+
181
182
public:
182
183
LLDBExprNameLookup (swift::SourceFile &source_file,
183
184
SwiftExpressionParser::SILVariableMap &variable_map,
184
- SymbolContext &sc, ExecutionContextScope &exe_scope)
185
- : LLDBNameLookup(source_file, variable_map, sc, exe_scope) {}
185
+ SymbolContext &sc, ExecutionContextScope &exe_scope,
186
+ const SwiftASTContextForExpressions *this_context)
187
+ : LLDBNameLookup(source_file, variable_map, sc, exe_scope),
188
+ m_this_context (this_context) {}
186
189
187
190
bool shouldGlobalize (swift::Identifier Name, swift::DeclKind Kind) override {
188
191
// Extensions have to be globalized, there's no way to mark them
@@ -196,7 +199,7 @@ class LLDBExprNameLookup : public LLDBNameLookup {
196
199
return true ;
197
200
198
201
if (Name.str ().starts_with (" $" )) {
199
- LLDB_LOG (m_log ,
202
+ LLDB_LOG (GetLog (LLDBLog::Expressions) ,
200
203
" [LLDBExprNameLookup::shouldGlobalize] Returning true to "
201
204
" globalizing {0}" ,
202
205
Name.str ());
@@ -224,7 +227,7 @@ class LLDBExprNameLookup : public LLDBNameLookup {
224
227
static unsigned counter = 0 ;
225
228
unsigned count = counter++;
226
229
227
- LLDB_LOG (m_log ,
230
+ LLDB_LOG (GetLog (LLDBLog::Expressions) ,
228
231
" [LLDBExprNameLookup::lookupOverrides({0})] Searching for \" {1}\" " ,
229
232
count, Name.getIdentifier ().get ());
230
233
@@ -235,6 +238,8 @@ class LLDBExprNameLookup : public LLDBNameLookup {
235
238
swift::SourceLoc Loc, bool IsTypeLookup,
236
239
ResultVector &RV) override {
237
240
LLDB_SCOPED_TIMER ();
241
+ assert (SwiftASTContext::GetSwiftASTContext (&DC->getASTContext ()) ==
242
+ m_this_context);
238
243
static unsigned counter = 0 ;
239
244
unsigned count = counter++;
240
245
@@ -243,7 +248,7 @@ class LLDBExprNameLookup : public LLDBNameLookup {
243
248
return false ;
244
249
245
250
LLDB_LOG (
246
- m_log ,
251
+ GetLog (LLDBLog::Expressions) ,
247
252
" [LLDBExprNameLookup::lookupAdditions ({0})] Searching for \" {1}\" " ,
248
253
count, NameStr);
249
254
@@ -291,9 +296,10 @@ class LLDBExprNameLookup : public LLDBNameLookup {
291
296
persistent_results);
292
297
293
298
for (CompilerDecl & decl : persistent_results) {
294
- if (decl.GetTypeSystem () !=
295
- SwiftASTContext::GetSwiftASTContext (&DC->getASTContext ())) {
296
- LLDB_LOG (m_log, " ignoring persistent result from other context" );
299
+ if (decl.GetTypeSystem () != m_this_context) {
300
+ LLDB_LOG (GetLog (LLDBLog::Expressions),
301
+ " Ignoring persistent result from other context: {0}" ,
302
+ NameStr);
297
303
continue ;
298
304
}
299
305
auto *value_decl =
@@ -369,11 +375,15 @@ class LLDBExprNameLookup : public LLDBNameLookup {
369
375
370
376
// / A name lookup class for REPL and Playground mode.
371
377
class LLDBREPLNameLookup : public LLDBNameLookup {
378
+ const SwiftASTContextForExpressions *m_this_context;
379
+
372
380
public:
373
381
LLDBREPLNameLookup (swift::SourceFile &source_file,
374
382
SwiftExpressionParser::SILVariableMap &variable_map,
375
- SymbolContext &sc, ExecutionContextScope &exe_scope)
376
- : LLDBNameLookup(source_file, variable_map, sc, exe_scope) {}
383
+ SymbolContext &sc, ExecutionContextScope &exe_scope,
384
+ const SwiftASTContextForExpressions *this_context)
385
+ : LLDBNameLookup(source_file, variable_map, sc, exe_scope),
386
+ m_this_context (this_context) {}
377
387
378
388
bool shouldGlobalize (swift::Identifier Name, swift::DeclKind kind) override {
379
389
return false ;
@@ -391,6 +401,9 @@ class LLDBREPLNameLookup : public LLDBNameLookup {
391
401
swift::SourceLoc Loc, bool IsTypeLookup,
392
402
ResultVector &RV) override {
393
403
LLDB_SCOPED_TIMER ();
404
+
405
+ assert (SwiftASTContext::GetSwiftASTContext (&DC->getASTContext ()) ==
406
+ m_this_context);
394
407
static unsigned counter = 0 ;
395
408
unsigned count = counter++;
396
409
@@ -399,7 +412,7 @@ class LLDBREPLNameLookup : public LLDBNameLookup {
399
412
return false ;
400
413
401
414
LLDB_LOG (
402
- m_log ,
415
+ GetLog (LLDBLog::Expressions) ,
403
416
" [LLDBREPLNameLookup::lookupAdditions ({0})] Searching for \" {1}\" " ,
404
417
count, NameStr);
405
418
@@ -421,6 +434,12 @@ class LLDBREPLNameLookup : public LLDBNameLookup {
421
434
422
435
// Append the persistent decls that we found to the result vector.
423
436
for (auto result : persistent_decl_results) {
437
+ if (result.GetTypeSystem () != m_this_context) {
438
+ LLDB_LOG (GetLog (LLDBLog::Expressions),
439
+ " Ignoring persistent result from other context: {0}" , NameStr);
440
+ continue ;
441
+ }
442
+
424
443
// No import required.
425
444
auto *result_decl =
426
445
static_cast <swift::ValueDecl *>(result.GetOpaqueDecl ());
@@ -1380,11 +1399,11 @@ SwiftExpressionParser::ParseAndImport(
1380
1399
1381
1400
LLDBNameLookup *external_lookup;
1382
1401
if (m_options.GetPlaygroundTransformEnabled () || m_options.GetREPLEnabled ()) {
1383
- external_lookup =
1384
- new LLDBREPLNameLookup (*source_file, variable_map, m_sc, *m_exe_scope);
1402
+ external_lookup = new LLDBREPLNameLookup (*source_file, variable_map, m_sc,
1403
+ *m_exe_scope, &m_swift_ast_ctx );
1385
1404
} else {
1386
- external_lookup =
1387
- new LLDBExprNameLookup (*source_file, variable_map, m_sc, *m_exe_scope);
1405
+ external_lookup = new LLDBExprNameLookup (*source_file, variable_map, m_sc,
1406
+ *m_exe_scope, &m_swift_ast_ctx );
1388
1407
}
1389
1408
1390
1409
// FIXME: This call is here just so that the we keep the
@@ -1769,8 +1788,15 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
1769
1788
1770
1789
// Signal that we want to retry the expression exactly once with a
1771
1790
// fresh SwiftASTContext.
1772
- if (retry)
1791
+ if (retry) {
1792
+ if (auto *persistent_state =
1793
+ llvm::cast_or_null<SwiftPersistentExpressionState>(
1794
+ m_sc.target_sp ->GetPersistentExpressionStateForLanguage (
1795
+ lldb::eLanguageTypeSwift)))
1796
+ persistent_state->Clear ();
1797
+
1773
1798
return ParseResult::retry_fresh_context;
1799
+ }
1774
1800
1775
1801
// Unrecoverable error.
1776
1802
return parse_result_failure;
@@ -2033,6 +2059,11 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
2033
2059
return parse_result_failure;
2034
2060
}
2035
2061
2062
+ if (m_swift_ast_ctx.GetASTContext ()->hadError ()) {
2063
+ DiagnoseSwiftASTContextError ();
2064
+ return ParseResult::unrecoverable_error;
2065
+ }
2066
+
2036
2067
{
2037
2068
std::lock_guard<std::recursive_mutex> global_context_locker (
2038
2069
IRExecutionUnit::GetLLVMGlobalContextMutex ());
0 commit comments