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