Requestify ExportedSourceFile parsing

Avoid parsing the syntax tree up-front, and instead
only parse it when required, which happens when either:

1. ASTGen parsing is enabled (currently disabled
   by default)
2. Round trip checking is enabled for a primary
   file (enabled by default in a debug build,
   except when dep scanning or doing an IDE
   operation)
3. We need to evaluate a macro in that file

This change therefore means that we now no longer
need to parse the syntax tree for secondary files
by default unless we specifically need to evaluate
a macro in them (e.g if we need to lookup a member
on a decl with an attached macro). And the same
for primaries in release builds.

rdar://109283847
This commit is contained in:
Hamish Knight
2023-05-22 14:55:19 +01:00
parent 4ce49bd4d2
commit 58d6694783
10 changed files with 263 additions and 101 deletions

View File

@@ -3687,6 +3687,10 @@ SourceFile::getDefaultParsingOptions(const LangOptions &langOpts) {
opts |= ParsingFlags::DisablePoundIfEvaluation;
if (langOpts.CollectParsedToken)
opts |= ParsingFlags::CollectParsedTokens;
if (langOpts.hasFeature(Feature::ParserRoundTrip))
opts |= ParsingFlags::RoundTrip;
if (langOpts.hasFeature(Feature::ParserValidation))
opts |= ParsingFlags::ValidateNewParserDiagnostics;
return opts;
}
@@ -3762,6 +3766,11 @@ ArrayRef<Decl *> SourceFile::getHoistedDecls() const {
return Hoisted;
}
void *SourceFile::getExportedSourceFile() const {
auto &eval = getASTContext().evaluator;
return evaluateOrDefault(eval, ExportedSourceFileRequest{this}, nullptr);
}
void SourceFile::addDeclWithRuntimeDiscoverableAttrs(ValueDecl *decl) {
assert(!decl->getRuntimeDiscoverableAttrs().empty());
DeclsWithRuntimeDiscoverableAttrs.insert(decl);