[Dependency Scanner] Do not re-use prior source dependencies in successive scans

If a scanner instance is used for multiple scans, the `SwiftDependencyScanningService` will have collected prior scans' main source modules' dependency info.
Suppose the scanner first scans a source module `A` and records its dependencies. If a successive scan of some source module `B` finds that it depends on `A`, it would get a cache hit on the source module from a prior scan and re-use dependency information. This change no longer allows such re-use of the prior source module scan dependencies. Said prior scan may have had an entirely different context and therefore different set of dependencies on `A` than may be visible otherwise. Instead, all scanning actions must rely on such modules being re-discovered on the filesystem.
This commit is contained in:
Artem Chikin
2023-01-24 15:36:02 -08:00
parent eecde02dde
commit e2eb8c8f47

View File

@@ -422,7 +422,19 @@ ModuleDependenciesCache::ModuleDependenciesCache(
Optional<const ModuleDependencyInfo*>
ModuleDependenciesCache::findDependency(
StringRef moduleName, Optional<ModuleDependencyKind> kind) const {
return globalScanningService.findDependency(moduleName, kind);
auto optionalDep = globalScanningService.findDependency(moduleName, kind);
// During a scan, only produce the cached source module info for the current module
// under scan.
if (optionalDep.hasValue()) {
auto dep = optionalDep.getValue();
if (dep->getAsSwiftSourceModule() &&
moduleName != mainScanModuleName &&
moduleName != "DummyMainModuleForResolvingCrossImportOverlays") {
return None;
}
}
return optionalDep;
}
bool ModuleDependenciesCache::hasDependency(