@@ -194,23 +194,11 @@ Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
194194 continue ;
195195 }
196196
197- // If this module file is being installed into the main module, it's treated
198- // as a partial module.
199- auto isPartialModule = M->isMainModule ();
200-
201- if (dependency.isImplementationOnly () &&
202- !(isPartialModule || ctx.LangOpts .DebuggerSupport )) {
203- // When building normally (and not merging partial modules), we don't
204- // want to bring in the implementation-only module, because that might
205- // change the set of visible declarations. However, when debugging we
206- // want to allow getting at the internals of this module when possible,
207- // and so we'll try to reference the implementation-only module if it's
208- // available.
209- continue ;
210- }
197+ ModuleLoadingBehavior transitiveBehavior =
198+ getTransitiveLoadingBehavior (dependency);
211199
212- if (dependency. isPackageOnly () &&
213- ctx. LangOpts . PackageName != this -> getModulePackageName () )
200+ // Skip this dependency?
201+ if (transitiveBehavior == ModuleLoadingBehavior::Ignored )
214202 continue ;
215203
216204 ImportPath::Builder builder (ctx, dependency.Core .RawPath ,
@@ -230,11 +218,13 @@ Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
230218 modulePath.front ().Item == file->getParentModule ()->getName ()) {
231219 return error (Status::MissingUnderlyingModule);
232220 }
233-
234221 // Otherwise, continue trying to load dependencies, so that we can list
235222 // everything that's missing.
236- if (!(dependency.isImplementationOnly () && ctx.LangOpts .DebuggerSupport ))
223+
224+ // Report a missing dependency only when really needed.
225+ if (transitiveBehavior == ModuleLoadingBehavior::Required)
237226 missingDependency = true ;
227+
238228 continue ;
239229 }
240230
@@ -269,6 +259,21 @@ Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
269259 return status;
270260}
271261
262+ ModuleLoadingBehavior
263+ ModuleFile::getTransitiveLoadingBehavior (const Dependency &dependency) const {
264+ ASTContext &ctx = getContext ();
265+ ModuleDecl *mod = FileContext->getParentModule ();
266+
267+ // If this module file is being installed into the main module, it's treated
268+ // as a partial module.
269+ auto isPartialModule = mod->isMainModule ();
270+
271+ return Core->getTransitiveLoadingBehavior (dependency.Core ,
272+ ctx.LangOpts .DebuggerSupport ,
273+ isPartialModule,
274+ ctx.LangOpts .PackageName );
275+ }
276+
272277bool ModuleFile::mayHaveDiagnosticsPointingAtBuffer () const {
273278 if (!hasError ())
274279 return false ;
@@ -463,6 +468,10 @@ void ModuleFile::getImportedModules(SmallVectorImpl<ImportedModule> &results,
463468 continue ;
464469 }
465470
471+ } else if (dep.isPackageOnly ()) {
472+ if (!filter.contains (ModuleDecl::ImportFilterKind::PackageOnly))
473+ continue ;
474+
466475 } else {
467476 if (!filter.contains (ModuleDecl::ImportFilterKind::Default))
468477 continue ;
0 commit comments