[AST] Make IsNonUserModuleRequest consider SourceFile inputs as well.

We're using a small custom frontend tool to generate indexstore data for `.swiftinterface` files in the SDKs. We do this by treating the `.swiftinterface` file as the input of an interface compilation, but this exits early because it treats it as a `SourceFile` instead of an external `LoadedFile`. This happens even if we call `setIsSystemModule(true)` unless we skip setting the SDK path, but that causes other problems. It seems harmless to check for `SourceFile`s as well, so that a tool processing an SDK interface as a direct input still gets the right state.
This commit is contained in:
Tony Allevato
2024-09-13 11:48:12 -04:00
parent 6236b258d2
commit 67d9eecd50
5 changed files with 33 additions and 8 deletions

View File

@@ -4039,11 +4039,15 @@ bool IsNonUserModuleRequest::evaluate(Evaluator &evaluator, ModuleDecl *mod) con
if (!mod->hasName() || mod->getFiles().empty())
return false;
auto *LF = dyn_cast_or_null<LoadedFile>(mod->getFiles().front());
if (!LF)
return false;
StringRef modulePath = LF->getSourceFilename();
StringRef modulePath;
auto fileUnit = mod->getFiles().front();
if (auto *LF = dyn_cast_or_null<LoadedFile>(fileUnit)) {
modulePath = LF->getSourceFilename();
} else if (auto *SF = dyn_cast_or_null<SourceFile>(fileUnit)) {
// Checking for SourceFiles lets custom tools get the correct is-system
// state for index units when compiling a textual interface directly.
modulePath = SF->getFilename();
}
if (modulePath.empty())
return false;