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