@@ -1765,6 +1765,16 @@ static bool IsDWARFImported(swift::ModuleDecl &module) {
17651765 });
17661766}
17671767
1768+ // / Detect whether this is a proper Swift module.
1769+ static bool IsSerializedAST (swift::ModuleDecl &module ) {
1770+ return std::any_of (module .getFiles ().begin (), module .getFiles ().end (),
1771+ [](swift::FileUnit *file_unit) {
1772+ return (file_unit->getKind () ==
1773+ swift::FileUnitKind::SerializedAST);
1774+ });
1775+ }
1776+
1777+
17681778lldb::TypeSystemSP
17691779SwiftASTContext::CreateInstance (lldb::LanguageType language, Module &module ,
17701780 TypeSystemSwiftTypeRef &typeref_typesystem,
@@ -1871,7 +1881,7 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
18711881 bool got_serialized_options = false ;
18721882 llvm::SmallString<0 > error;
18731883 llvm::raw_svector_ostream errs (error);
1874- // Implicit search paths will be discoverd by ValidateSecionModules().
1884+ // Implicit search paths will be discovered by ValidateSecionModules().
18751885 bool discover_implicit_search_paths = false ;
18761886
18771887 auto ast_file_datas = module .GetASTData (eLanguageTypeSwift);
@@ -8363,10 +8373,42 @@ bool SwiftASTContextForExpressions::CacheUserImports(
83638373 LOG_PRINTF (GetLog (LLDBLog::Types | LLDBLog::Expressions),
83648374 " Performing auto import on found module: %s.\n " ,
83658375 module_name.c_str ());
8366- if (!LoadOneModule (module_info, *this , process_sp,
8367- /* import_dylibs=*/ true , error))
8376+ auto *module_decl = LoadOneModule (module_info, *this , process_sp,
8377+ /* import_dylibs=*/ true , error);
8378+ if (!module_decl)
83688379 return false ;
8369-
8380+ if (IsSerializedAST (*module_decl)) {
8381+ // Parse additional search paths from the module.
8382+ StringRef ast_file = module_decl->getModuleLoadedFilename ();
8383+ if (llvm::sys::path::is_absolute (ast_file)) {
8384+ auto file_or_err =
8385+ llvm::MemoryBuffer::getFile (ast_file, /* IsText=*/ false ,
8386+ /* RequiresNullTerminator=*/ false );
8387+ if (!file_or_err.getError () && file_or_err->get ()) {
8388+ PathMappingList path_remap;
8389+ llvm::SmallString<0 > error;
8390+ bool found_swift_modules = false ;
8391+ bool got_serialized_options = false ;
8392+ llvm::raw_svector_ostream errs (error);
8393+ bool discover_implicit_search_paths = false ;
8394+ swift::CompilerInvocation &invocation = GetCompilerInvocation ();
8395+
8396+ LOG_PRINTF (GetLog (LLDBLog::Types),
8397+ " Scanning for search paths in %s" ,
8398+ ast_file.str ().c_str ());
8399+ if (DeserializeAllCompilerFlags (
8400+ invocation, ast_file, {file_or_err->get ()->getBuffer ()},
8401+ path_remap, discover_implicit_search_paths,
8402+ m_description.str ().str (), errs, got_serialized_options,
8403+ found_swift_modules)) {
8404+ LOG_PRINTF (GetLog (LLDBLog::Types), " Could not parse %s: %s" ,
8405+ ast_file.str ().c_str (), error.str ().str ().c_str ());
8406+ }
8407+ if (got_serialized_options)
8408+ LogConfiguration ();
8409+ }
8410+ }
8411+ }
83708412 // How do we tell we are in REPL or playground mode?
83718413 AddHandLoadedModule (module_const_str, attributed_import);
83728414 }
0 commit comments