@@ -186,25 +186,51 @@ ErrorOr<ModuleDependencyInfo> ModuleDependencyScanner::scanInterfaceFile(
186186 Result->addModuleImport (import .module .getModulePath (), &alreadyAddedModules);
187187 }
188188
189- // Check the adjacent binary module, if one is found,
190- // for additional "optional" dependencies .
189+ // For a `@testable` direct dependency, read in the dependencies
190+ // from an adjacent binary module, for completeness .
191191 if (isTestableImport) {
192- auto adjacentBinaryCandidate = std::find_if (
192+ auto adjacentBinaryModule = std::find_if (
193193 compiledCandidates.begin (), compiledCandidates.end (),
194194 [moduleInterfacePath](const std::string &candidate) {
195195 return llvm::sys::path::parent_path (candidate) ==
196196 llvm::sys::path::parent_path (moduleInterfacePath.str ());
197197 });
198- if (adjacentBinaryCandidate != compiledCandidates.end ()) {
199- auto adjacentBinaryCandidateModules = getModuleImportsOfModule (
200- *adjacentBinaryCandidate, ModuleLoadingBehavior::Optional,
201- isFramework, isRequiredOSSAModules (), Ctx.LangOpts .SDKName ,
198+ if (adjacentBinaryModule != compiledCandidates.end ()) {
199+ // Required modules.
200+ auto adjacentBinaryModuleRequiredImports = getModuleImportsOfModule (
201+ *adjacentBinaryModule, ModuleLoadingBehavior::Required, isFramework,
202+ isRequiredOSSAModules (), Ctx.LangOpts .SDKName ,
202203 Ctx.LangOpts .PackageName , Ctx.SourceMgr .getFileSystem ().get (),
203204 Ctx.SearchPathOpts .DeserializedPathRecoverer );
204- if (!adjacentBinaryCandidateModules)
205- return adjacentBinaryCandidateModules.getError ();
206- for (const auto &t : *adjacentBinaryCandidateModules)
207- Result->addOptionalModuleImport (t.getKey (), &alreadyAddedModules);
205+ if (!adjacentBinaryModuleRequiredImports)
206+ return adjacentBinaryModuleRequiredImports.getError ();
207+
208+ #ifndef NDEBUG
209+ // Verify that the set of required modules read out from the binary
210+ // module is a super-set of module imports identified in the
211+ // textual interface.
212+ for (const auto &requiredImport : Result->getModuleImports ()) {
213+ assert (adjacentBinaryModuleRequiredImports->contains (requiredImport) &&
214+ " Expected adjacent binary module's import set to contain all "
215+ " textual interface imports." );
216+ }
217+ #endif
218+
219+ for (const auto &requiredImport : *adjacentBinaryModuleRequiredImports)
220+ Result->addModuleImport (requiredImport.getKey (),
221+ &alreadyAddedModules);
222+
223+ // Optional modules. Will be looked-up on a best-effort basis
224+ auto adjacentBinaryModuleOptionalImports = getModuleImportsOfModule (
225+ *adjacentBinaryModule, ModuleLoadingBehavior::Optional, isFramework,
226+ isRequiredOSSAModules (), Ctx.LangOpts .SDKName ,
227+ Ctx.LangOpts .PackageName , Ctx.SourceMgr .getFileSystem ().get (),
228+ Ctx.SearchPathOpts .DeserializedPathRecoverer );
229+ if (!adjacentBinaryModuleOptionalImports)
230+ return adjacentBinaryModuleOptionalImports.getError ();
231+ for (const auto &optionalImport : *adjacentBinaryModuleOptionalImports)
232+ Result->addOptionalModuleImport (optionalImport.getKey (),
233+ &alreadyAddedModules);
208234 }
209235 }
210236
0 commit comments