@@ -1019,6 +1019,20 @@ void SwiftASTContext::SetCompilerInvocationLLDBOverrides() {
1019
1019
swift::LangOptions &lang_opts = m_compiler_invocation_ap->getLangOptions ();
1020
1020
lang_opts.AllowDeserializingImplementationOnly = true ;
1021
1021
lang_opts.DebuggerSupport = true ;
1022
+
1023
+ // ModuleFileSharedCore::getTransitiveLoadingBehavior() has a
1024
+ // best-effort mode that is enabled when debugger support is turned
1025
+ // on that will try to import implementation-only imports of Swift
1026
+ // modules, but won't treat import failures as errors. When explicit
1027
+ // modules are on, this has the unwanted side-effect of potentially
1028
+ // triggering an implicit Clang module build if one of the internal
1029
+ // dependencies of a library was not used to build the target. It
1030
+ // can also lead to additional Swift modules being pulled in that
1031
+ // through their dependencies can lead to dependency cycles that
1032
+ // were not a problem at build time.
1033
+ bool is_precise = ModuleList::GetGlobalModuleListProperties ()
1034
+ .GetUseSwiftPreciseCompilerInvocation ();
1035
+ lang_opts.ImportNonPublicDependencies = is_precise ? false : true ;
1022
1036
// When loading Swift types that conform to ObjC protocols that have
1023
1037
// been renamed with NS_SWIFT_NAME the DwarfImporterDelegate will crash
1024
1038
// during protocol conformance checks as the underlying type cannot be
@@ -9213,42 +9227,6 @@ bool SwiftASTContext::GetCompileUnitImportsImpl(
9213
9227
9214
9228
LOG_PRINTF (GetLog (LLDBLog::Types), " Importing dependencies of current CU" );
9215
9229
9216
- // Turn off implicit clang modules while importing CU dependencies.
9217
- // ModuleFileSharedCore::getTransitiveLoadingBehavior() has a
9218
- // best-effort mode that is enabled when debugger support is turned
9219
- // on that will try to import implementation-only imports of Swift
9220
- // modules, but won't treat import failures as errors. When explicit
9221
- // modules are on, this has the unwanted side-effect of potentially
9222
- // triggering an implicit Clang module build if one of the internal
9223
- // dependencies of a library was not used to build the target. To
9224
- // avoid these costly and potentially dangerous imports we turn off
9225
- // implicit modules while importing the CU imports only. If a user
9226
- // manually evaluates an expression that contains an import
9227
- // statement that can still trigger an implict import. Implicit
9228
- // imports can be dangerous if an implicit module depends on a
9229
- // module that also exists as an explicit input: In this case, a
9230
- // subsequent explicit import of said dependency will error because
9231
- // Clang now knows about two versions of the same module.
9232
- clang::LangOptions *clang_lang_opts = nullptr ;
9233
- auto reset = llvm::make_scope_exit ([&] {
9234
- if (clang_lang_opts) {
9235
- LOG_PRINTF (GetLog (LLDBLog::Types), " Turning on implicit Clang modules" );
9236
- clang_lang_opts->ImplicitModules = true ;
9237
- }
9238
- });
9239
- if (auto *clang_importer = GetClangImporter ()) {
9240
- if (m_has_explicit_modules) {
9241
- auto &clang_instance = const_cast <clang::CompilerInstance &>(
9242
- clang_importer->getClangInstance ());
9243
- clang_lang_opts = &clang_instance.getLangOpts ();
9244
- // AddExtraArgs is supposed to always turn implicit modules on.
9245
- assert (clang_lang_opts->ImplicitModules &&
9246
- " ClangImporter implicit module support is off" );
9247
- LOG_PRINTF (GetLog (LLDBLog::Types), " Turning off implicit Clang modules" );
9248
- clang_lang_opts->ImplicitModules = false ;
9249
- }
9250
- }
9251
-
9252
9230
std::string category = " Importing Swift module dependencies for " ;
9253
9231
category += compile_unit->GetPrimaryFile ().GetFilename ().GetString ();
9254
9232
Progress progress (category, " " , cu_imports.size ());
0 commit comments