Skip to content

Remove DelayedDeclLists from PersistentParserState #29071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions include/swift/Frontend/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -607,14 +607,13 @@ class CompilerInstance {
void performSema();

/// Parses the input file but does no type-checking or module imports.
/// Note that this only supports parsing an invocation with a single file.
void performParseOnly(bool EvaluateConditionals = false,
bool ParseDelayedBodyOnEnd = false);
bool CanDelayBodies = true);

/// Parses and performs name binding on all input files.
///
/// Like a parse-only invocation, a single file is required. Unlike a
/// parse-only invocation, module imports will be processed.
/// This is similar to a parse-only invocation, but module imports will also
/// be processed.
void performParseAndResolveImportsOnly();

/// Performs mandatory, diagnostic, and optimization passes over the SIL.
Expand Down
6 changes: 0 additions & 6 deletions include/swift/Parse/PersistentParserState.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ class PersistentParserState {

std::unique_ptr<CodeCompletionDelayedDeclState> CodeCompletionDelayedDeclStat;

std::vector<IterableDeclContext *> DelayedDeclLists;

/// The local context for all top-level code.
TopLevelContext TopLevelCode;

Expand Down Expand Up @@ -112,10 +110,6 @@ class PersistentParserState {
return std::move(CodeCompletionDelayedDeclStat);
}

void delayDeclList(IterableDeclContext *D);

void parseAllDelayedDeclLists();

TopLevelContext &getTopLevelContext() {
return TopLevelCode;
}
Expand Down
24 changes: 13 additions & 11 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ SourceFile *CompilerInstance::createSourceFileForMainModule(
}

void CompilerInstance::performParseOnly(bool EvaluateConditionals,
bool ParseDelayedBodyOnEnd) {
bool CanDelayBodies) {
const InputFileKind Kind = Invocation.getInputKind();
ModuleDecl *const MainModule = getMainModule();
Context->LoadedModules[MainModule->getName()] = MainModule;
Expand All @@ -1093,36 +1093,38 @@ void CompilerInstance::performParseOnly(bool EvaluateConditionals,
}

PersistentState = llvm::make_unique<PersistentParserState>();
PersistentState->PerformConditionEvaluation = EvaluateConditionals;

auto shouldDelayBodies = [&](unsigned bufferID) -> bool {
if (!CanDelayBodies)
return false;

SWIFT_DEFER {
if (ParseDelayedBodyOnEnd)
PersistentState->parseAllDelayedDeclLists();
// Don't delay bodies in whole module mode or for primary files.
return !(isWholeModuleCompilation() || isPrimaryInput(bufferID));
};
PersistentState->PerformConditionEvaluation = EvaluateConditionals;

// Parse all the library files.
for (auto BufferID : InputSourceCodeBufferIDs) {
if (BufferID == MainBufferID)
continue;

auto IsPrimary = isWholeModuleCompilation() || isPrimaryInput(BufferID);

SourceFile *NextInput = createSourceFileForMainModule(
SourceFileKind::Library, SourceFile::ImplicitModuleImportKind::None,
BufferID);

parseIntoSourceFileFull(*NextInput, BufferID, PersistentState.get(),
/*DelayBodyParsing=*/!IsPrimary);
shouldDelayBodies(BufferID));
}

// Now parse the main file.
if (MainBufferID != NO_SUCH_BUFFER) {
SourceFile &MainFile =
MainModule->getMainSourceFile(Invocation.getSourceFileKind());
MainFile.SyntaxParsingCache = Invocation.getMainFileSyntaxParsingCache();
assert(MainBufferID == MainFile.getBufferID());

parseIntoSourceFileFull(MainFile, MainFile.getBufferID().getValue(),
PersistentState.get(),
/*DelayBodyParsing=*/false);
parseIntoSourceFileFull(MainFile, MainBufferID, PersistentState.get(),
shouldDelayBodies(MainBufferID));
}

assert(Context->LoadedModules.size() == 1 &&
Expand Down
8 changes: 4 additions & 4 deletions lib/FrontendTool/FrontendTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1262,12 +1262,12 @@ static bool performCompile(CompilerInstance &Instance,
return compileLLVMIR(Invocation, Instance, Stats);

if (FrontendOptions::shouldActionOnlyParse(Action)) {
bool ParseDelayedDeclListsOnEnd =
Action == FrontendOptions::ActionType::DumpParse ||
Invocation.getDiagnosticOptions().VerifyMode != DiagnosticOptions::NoVerify;
// Disable delayed parsing of type and function bodies when we've been
// asked to dump the resulting AST.
bool CanDelayBodies = Action != FrontendOptions::ActionType::DumpParse;
Instance.performParseOnly(/*EvaluateConditionals*/
Action == FrontendOptions::ActionType::EmitImportedModules,
ParseDelayedDeclListsOnEnd);
CanDelayBodies);
} else if (Action == FrontendOptions::ActionType::ResolveImports) {
Instance.performParseAndResolveImportsOnly();
} else {
Expand Down
2 changes: 0 additions & 2 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4441,8 +4441,6 @@ bool Parser::delayParsingDeclList(SourceLoc LBLoc, SourceLoc &RBLoc,
RBLoc = Tok.getLoc();
error = true;
}

State->delayDeclList(IDC);
return error;
}

Expand Down
9 changes: 0 additions & 9 deletions lib/Parse/PersistentParserState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,3 @@ void PersistentParserState::restoreCodeCompletionDelayedDeclState(
ScopeInfo.saveCurrentScope(), other.StartOffset, other.EndOffset,
other.PrevOffset));
}

void PersistentParserState::delayDeclList(IterableDeclContext *D) {
DelayedDeclLists.push_back(D);
}

void PersistentParserState::parseAllDelayedDeclLists() {
for (auto IDC : DelayedDeclLists)
IDC->loadAllMembers();
}