Merge pull request #30190 from hamishknight/the-beginning-of-the-pipeline-end

Requestify SourceFile parsing
This commit is contained in:
Hamish Knight
2020-03-05 11:17:24 -08:00
committed by GitHub
21 changed files with 235 additions and 147 deletions

View File

@@ -32,6 +32,7 @@
#include "swift/AST/ModuleLoader.h"
#include "swift/AST/NameLookup.h"
#include "swift/AST/ReferencedNameTracker.h"
#include "swift/AST/ParseRequests.h"
#include "swift/AST/PrettyStackTrace.h"
#include "swift/AST/PrintOptions.h"
#include "swift/AST/ProtocolConformance.h"
@@ -674,7 +675,8 @@ void ModuleDecl::getTopLevelDeclsWhereAttributesMatch(
}
void SourceFile::getTopLevelDecls(SmallVectorImpl<Decl*> &Results) const {
Results.append(Decls.begin(), Decls.end());
auto decls = getTopLevelDecls();
Results.append(decls.begin(), decls.end());
}
void ModuleDecl::getPrecedenceGroups(
@@ -1190,7 +1192,14 @@ void ModuleDecl::getImportedModules(SmallVectorImpl<ImportedModule> &modules,
void
SourceFile::getImportedModules(SmallVectorImpl<ModuleDecl::ImportedModule> &modules,
ModuleDecl::ImportFilter filter) const {
assert(ASTStage >= Parsed || Kind == SourceFileKind::SIL);
// FIXME: Ideally we should assert that the file has been name bound before
// calling this function. However unfortunately that can cause issues for
// overlays which can depend on a Clang submodule for the underlying framework
// they are overlaying, which causes us to attempt to load the overlay again.
// We need to find a way to ensure that an overlay dependency with the same
// name as the overlay always loads the underlying Clang module. We currently
// handle this for a direct import from the overlay, but not when it happens
// through other imports.
assert(filter && "no imports requested?");
for (auto desc : Imports) {
ModuleDecl::ImportFilter requiredFilter;
@@ -1688,7 +1697,7 @@ void SourceFile::print(raw_ostream &OS, const PrintOptions &PO) {
void SourceFile::print(ASTPrinter &Printer, const PrintOptions &PO) {
std::set<DeclKind> MajorDeclKinds = {DeclKind::Class, DeclKind::Enum,
DeclKind::Extension, DeclKind::Protocol, DeclKind::Struct};
for (auto decl : Decls) {
for (auto decl : getTopLevelDecls()) {
if (!decl->shouldPrintInContext(PO))
continue;
// For a major decl, we print an empty line before it.
@@ -2024,6 +2033,13 @@ bool SourceFile::hasDelayedBodyParsing() const {
return true;
}
ArrayRef<Decl *> SourceFile::getTopLevelDecls() const {
auto &ctx = getASTContext();
auto *mutableThis = const_cast<SourceFile *>(this);
return evaluateOrDefault(ctx.evaluator, ParseSourceFileRequest{mutableThis},
{});
}
bool FileUnit::walk(ASTWalker &walker) {
SmallVector<Decl *, 64> Decls;
getTopLevelDecls(Decls);
@@ -2057,7 +2073,7 @@ bool FileUnit::walk(ASTWalker &walker) {
bool SourceFile::walk(ASTWalker &walker) {
llvm::SaveAndRestore<ASTWalker::ParentTy> SAR(walker.Parent,
getParentModule());
for (Decl *D : Decls) {
for (Decl *D : getTopLevelDecls()) {
#ifndef NDEBUG
PrettyStackTraceDecl debugStack("walking into decl", D);
#endif