[Dependency Scanning] Have the scanner cache answer queries relevant to current search paths only.

The dependency scanner's cache persists across different queries and answering a subsequent query's module lookup with a module not in the query's search path is not correct.

For example, suppose we are looking for a Swift module `Foo` with a set of search paths `SP`.
And dependency scanner cache already contains a module `Foo`, for which we found an interface file at location `L`. If `L`∉`SP`, then we cannot re-use the cached entry because we’d be resolving the scanning query to a filesystem location that the current scanning context is not aware of.

Resolves rdar://81175942
This commit is contained in:
Artem Chikin
2021-07-29 10:46:48 -07:00
parent 77cb4b639c
commit 6a12dc0070
11 changed files with 480 additions and 141 deletions

View File

@@ -88,18 +88,10 @@ Optional<bool> forEachModuleSearchPath(
// Apple platforms have extra implicit framework search paths:
// $SDKROOT/System/Library/Frameworks/ and $SDKROOT/Library/Frameworks/.
if (Ctx.LangOpts.Target.isOSDarwin()) {
SmallString<128> scratch;
scratch = Ctx.SearchPathOpts.SDKPath;
llvm::sys::path::append(scratch, "System", "Library", "Frameworks");
if (auto result =
callback(scratch, SearchPathKind::Framework, /*isSystem=*/true))
return result;
scratch = Ctx.SearchPathOpts.SDKPath;
llvm::sys::path::append(scratch, "Library", "Frameworks");
if (auto result =
callback(scratch, SearchPathKind::Framework, /*isSystem=*/true))
return result;
for (const auto &path : Ctx.getDarwinImplicitFrameworkSearchPaths())
if (auto result =
callback(path, SearchPathKind::Framework, /*isSystem=*/true))
return result;
}
for (auto importPath : Ctx.SearchPathOpts.RuntimeLibraryImportPaths) {