@@ -3611,8 +3611,9 @@ SwiftASTContext::GetCachedModule(const SourceModule &module) {
3611
3611
return nullptr ;
3612
3612
}
3613
3613
3614
- swift::ModuleDecl *SwiftASTContext::CreateModule (const SourceModule &module ,
3615
- Status &error) {
3614
+ swift::ModuleDecl *
3615
+ SwiftASTContext::CreateModule (const SourceModule &module , Status &error,
3616
+ swift::ImplicitImportInfo importInfo) {
3616
3617
VALID_OR_RETURN (nullptr );
3617
3618
if (!module .path .size ()) {
3618
3619
error.SetErrorStringWithFormat (" invalid module name (empty)" );
@@ -3633,7 +3634,7 @@ swift::ModuleDecl *SwiftASTContext::CreateModule(const SourceModule &module,
3633
3634
3634
3635
swift::Identifier module_id (
3635
3636
ast->getIdentifier (module .path .front ().GetCString ()));
3636
- auto *module_decl = swift::ModuleDecl::create (module_id, *ast);
3637
+ auto *module_decl = swift::ModuleDecl::create (module_id, *ast, importInfo );
3637
3638
if (!module_decl) {
3638
3639
error.SetErrorStringWithFormat (" failed to create module for \" %s\" " ,
3639
3640
module .path .front ().GetCString ());
@@ -8355,14 +8356,12 @@ static void GetNameFromModule(swift::ModuleDecl *module, std::string &result) {
8355
8356
}
8356
8357
}
8357
8358
8358
- static bool
8359
- LoadOneModule (const SourceModule &module , SwiftASTContext &swift_ast_context,
8360
- lldb::StackFrameWP &stack_frame_wp,
8361
- llvm::SmallVectorImpl<swift::SourceFile::ImportedModuleDesc>
8362
- &additional_imports,
8363
- Status &error) {
8359
+ static swift::ModuleDecl *LoadOneModule (const SourceModule &module ,
8360
+ SwiftASTContext &swift_ast_context,
8361
+ lldb::StackFrameWP &stack_frame_wp,
8362
+ Status &error) {
8364
8363
if (!module .path .size ())
8365
- return false ;
8364
+ return nullptr ;
8366
8365
8367
8366
error.Clear ();
8368
8367
ConstString toplevel = module .path .front ();
@@ -8401,7 +8400,7 @@ LoadOneModule(const SourceModule &module, SwiftASTContext &swift_ast_context,
8401
8400
toplevel.AsCString (), error.AsCString ());
8402
8401
8403
8402
if (!swift_module || swift_ast_context.HasFatalErrors ()) {
8404
- return false ;
8403
+ return nullptr ;
8405
8404
}
8406
8405
}
8407
8406
@@ -8412,23 +8411,42 @@ LoadOneModule(const SourceModule &module, SwiftASTContext &swift_ast_context,
8412
8411
LOG_PRINTF (LIBLLDB_LOG_EXPRESSIONS, " Imported module %s from {%s}" ,
8413
8412
module .path .front ().AsCString (), ss.GetData ());
8414
8413
}
8414
+ return swift_module;
8415
+ }
8416
+
8417
+ bool SwiftASTContext::GetImplicitImports (
8418
+ SwiftASTContext &swift_ast_context, SymbolContext &sc,
8419
+ ExecutionContextScope &exe_scope, lldb::StackFrameWP &stack_frame_wp,
8420
+ llvm::SmallVectorImpl<swift::ModuleDecl *> &modules, Status &error) {
8421
+ if (!GetCompileUnitImports (swift_ast_context, sc, stack_frame_wp, modules,
8422
+ error)) {
8423
+ return false ;
8424
+ }
8425
+
8426
+ auto *persistent_expression_state =
8427
+ sc.target_sp ->GetSwiftPersistentExpressionState (exe_scope);
8415
8428
8416
- additional_imports.push_back (swift::SourceFile::ImportedModuleDesc (
8417
- std::make_pair (swift::ModuleDecl::AccessPathTy (), swift_module),
8418
- swift::SourceFile::ImportOptions ()));
8429
+ // Get the hand-loaded modules from the SwiftPersistentExpressionState.
8430
+ for (ConstString name : persistent_expression_state->GetHandLoadedModules ()) {
8431
+ SourceModule module_info;
8432
+ module_info.path .push_back (name);
8433
+ auto *module = LoadOneModule (module_info, swift_ast_context, stack_frame_wp,
8434
+ error);
8435
+ if (!module )
8436
+ return false ;
8437
+
8438
+ modules.push_back (module );
8439
+ }
8419
8440
return true ;
8420
8441
}
8421
8442
8422
- bool SwiftASTContext::PerformUserImport (SwiftASTContext &swift_ast_context,
8423
- SymbolContext &sc,
8424
- ExecutionContextScope &exe_scope,
8425
- lldb::StackFrameWP &stack_frame_wp,
8426
- swift::SourceFile &source_file,
8427
- Status &error) {
8443
+ bool SwiftASTContext::CacheUserImports (SwiftASTContext &swift_ast_context,
8444
+ SymbolContext &sc,
8445
+ ExecutionContextScope &exe_scope,
8446
+ lldb::StackFrameWP &stack_frame_wp,
8447
+ swift::SourceFile &source_file,
8448
+ Status &error) {
8428
8449
llvm::SmallString<1 > m_description;
8429
- llvm::SmallVector<swift::SourceFile::ImportedModuleDesc, 2 >
8430
- additional_imports;
8431
-
8432
8450
llvm::SmallVector<swift::ModuleDecl::ImportedModule, 2 > parsed_imports;
8433
8451
8434
8452
swift::ModuleDecl::ImportFilter import_filter;
@@ -8452,62 +8470,51 @@ bool SwiftASTContext::PerformUserImport(SwiftASTContext &swift_ast_context,
8452
8470
" Performing auto import on found module: %s.\n " ,
8453
8471
module_name.c_str ());
8454
8472
if (!LoadOneModule (module_info, swift_ast_context, stack_frame_wp,
8455
- additional_imports, error))
8473
+ error))
8456
8474
return false ;
8457
8475
8458
8476
// How do we tell we are in REPL or playground mode?
8459
8477
persistent_expression_state->AddHandLoadedModule (module_const_str);
8460
8478
}
8461
8479
}
8462
8480
}
8463
- // Finally get the hand-loaded modules from the
8464
- // SwiftPersistentExpressionState and load them into this context:
8465
- for (ConstString name : persistent_expression_state->GetHandLoadedModules ()) {
8466
- SourceModule module_info;
8467
- module_info.path .push_back (name);
8468
- if (!LoadOneModule (module_info, swift_ast_context, stack_frame_wp,
8469
- additional_imports, error))
8470
- return false ;
8471
- }
8472
-
8473
- source_file.addImports (additional_imports);
8474
8481
return true ;
8475
8482
}
8476
8483
8477
- bool SwiftASTContext::PerformAutoImport (SwiftASTContext &swift_ast_context,
8478
- SymbolContext &sc,
8479
- lldb::StackFrameWP &stack_frame_wp,
8480
- swift::SourceFile *source_file,
8481
- Status &error) {
8482
- llvm::SmallVector<swift::SourceFile::ImportedModuleDesc, 2 >
8483
- additional_imports;
8484
-
8485
- // Import the Swift standard library and its dependecies.
8484
+ bool SwiftASTContext::GetCompileUnitImports (
8485
+ SwiftASTContext &swift_ast_context, SymbolContext &sc,
8486
+ lldb::StackFrameWP &stack_frame_wp,
8487
+ llvm::SmallVectorImpl<swift::ModuleDecl *> &modules, Status &error) {
8488
+ // Import the Swift standard library and its dependencies.
8486
8489
SourceModule swift_module;
8487
8490
swift_module.path .push_back (ConstString (" Swift" ));
8488
- if (!LoadOneModule (swift_module, swift_ast_context, stack_frame_wp,
8489
- additional_imports, error))
8491
+ auto *stdlib =
8492
+ LoadOneModule (swift_module, swift_ast_context, stack_frame_wp, error);
8493
+ if (!stdlib)
8490
8494
return false ;
8491
8495
8496
+ modules.push_back (stdlib);
8497
+
8492
8498
CompileUnit *compile_unit = sc.comp_unit ;
8493
- if (compile_unit && compile_unit->GetLanguage () == lldb::eLanguageTypeSwift)
8494
- for (const SourceModule &module : compile_unit->GetImportedModules ()) {
8495
- // When building the Swift stdlib with debug info these will
8496
- // show up in "Swift.o", but we already imported them and
8497
- // manually importing them will fail.
8498
- if (module .path .size () &&
8499
- llvm::StringSwitch<bool >(module .path .front ().GetStringRef ())
8500
- .Cases (" Swift" , " SwiftShims" , " Builtin" , true )
8501
- .Default (false ))
8502
- continue ;
8499
+ if (!compile_unit || compile_unit->GetLanguage () != lldb::eLanguageTypeSwift)
8500
+ return true ;
8503
8501
8504
- if (!LoadOneModule (module , swift_ast_context, stack_frame_wp,
8505
- additional_imports, error))
8506
- return false ;
8507
- }
8508
- // source_file might be NULL outside of the expression parser, where
8509
- // we don't need to notify the source file of additional imports.
8510
- if (source_file)
8511
- source_file->addImports (additional_imports);
8502
+ for (const SourceModule &module : compile_unit->GetImportedModules ()) {
8503
+ // When building the Swift stdlib with debug info these will
8504
+ // show up in "Swift.o", but we already imported them and
8505
+ // manually importing them will fail.
8506
+ if (module .path .size () &&
8507
+ llvm::StringSwitch<bool >(module .path .front ().GetStringRef ())
8508
+ .Cases (" Swift" , " SwiftShims" , " Builtin" , true )
8509
+ .Default (false ))
8510
+ continue ;
8511
+
8512
+ auto *loaded_module =
8513
+ LoadOneModule (module , swift_ast_context, stack_frame_wp, error);
8514
+ if (!loaded_module)
8515
+ return false ;
8516
+
8517
+ modules.push_back (loaded_module);
8518
+ }
8512
8519
return true ;
8513
8520
}
0 commit comments