Skip to content

Commit 6b87dce

Browse files
committed
Remove DelayedDeclLists from PersistentParserState
Rather than parsing all delayed bodies for `-dump-parse` once we finish parsing, tell the parser not to delay any bodies. This then allows us to remove `DelayedDeclLists` from PersistentParserState.
1 parent 7e7c799 commit 6b87dce

File tree

6 files changed

+8
-28
lines changed

6 files changed

+8
-28
lines changed

include/swift/Frontend/Frontend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ class CompilerInstance {
609609
/// Parses the input file but does no type-checking or module imports.
610610
/// Note that this only supports parsing an invocation with a single file.
611611
void performParseOnly(bool EvaluateConditionals = false,
612-
bool ParseDelayedBodyOnEnd = false);
612+
bool CanDelayBodies = true);
613613

614614
/// Parses and performs name binding on all input files.
615615
///

include/swift/Parse/PersistentParserState.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ class PersistentParserState {
7878

7979
std::unique_ptr<CodeCompletionDelayedDeclState> CodeCompletionDelayedDeclStat;
8080

81-
std::vector<IterableDeclContext *> DelayedDeclLists;
82-
8381
/// The local context for all top-level code.
8482
TopLevelContext TopLevelCode;
8583

@@ -112,10 +110,6 @@ class PersistentParserState {
112110
return std::move(CodeCompletionDelayedDeclStat);
113111
}
114112

115-
void delayDeclList(IterableDeclContext *D);
116-
117-
void parseAllDelayedDeclLists();
118-
119113
TopLevelContext &getTopLevelContext() {
120114
return TopLevelCode;
121115
}

lib/Frontend/Frontend.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ SourceFile *CompilerInstance::createSourceFileForMainModule(
10711071
}
10721072

10731073
void CompilerInstance::performParseOnly(bool EvaluateConditionals,
1074-
bool ParseDelayedBodyOnEnd) {
1074+
bool CanDelayBodies) {
10751075
const InputFileKind Kind = Invocation.getInputKind();
10761076
ModuleDecl *const MainModule = getMainModule();
10771077
Context->LoadedModules[MainModule->getName()] = MainModule;
@@ -1093,12 +1093,8 @@ void CompilerInstance::performParseOnly(bool EvaluateConditionals,
10931093
}
10941094

10951095
PersistentState = llvm::make_unique<PersistentParserState>();
1096-
1097-
SWIFT_DEFER {
1098-
if (ParseDelayedBodyOnEnd)
1099-
PersistentState->parseAllDelayedDeclLists();
1100-
};
11011096
PersistentState->PerformConditionEvaluation = EvaluateConditionals;
1097+
11021098
// Parse all the library files.
11031099
for (auto BufferID : InputSourceCodeBufferIDs) {
11041100
if (BufferID == MainBufferID)
@@ -1111,7 +1107,7 @@ void CompilerInstance::performParseOnly(bool EvaluateConditionals,
11111107
BufferID);
11121108

11131109
parseIntoSourceFileFull(*NextInput, BufferID, PersistentState.get(),
1114-
/*DelayBodyParsing=*/!IsPrimary);
1110+
/*DelayBodyParsing=*/!IsPrimary && CanDelayBodies);
11151111
}
11161112

11171113
// Now parse the main file.

lib/FrontendTool/FrontendTool.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,11 +1262,12 @@ static bool performCompile(CompilerInstance &Instance,
12621262
return compileLLVMIR(Invocation, Instance, Stats);
12631263

12641264
if (FrontendOptions::shouldActionOnlyParse(Action)) {
1265-
bool ParseDelayedDeclListsOnEnd =
1266-
Action == FrontendOptions::ActionType::DumpParse;
1265+
// Disable delayed parsing of type and function bodies when we've been
1266+
// asked to dump the resulting AST.
1267+
bool CanDelayBodies = Action != FrontendOptions::ActionType::DumpParse;
12671268
Instance.performParseOnly(/*EvaluateConditionals*/
12681269
Action == FrontendOptions::ActionType::EmitImportedModules,
1269-
ParseDelayedDeclListsOnEnd);
1270+
CanDelayBodies);
12701271
} else if (Action == FrontendOptions::ActionType::ResolveImports) {
12711272
Instance.performParseAndResolveImportsOnly();
12721273
} else {

lib/Parse/ParseDecl.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4441,8 +4441,6 @@ bool Parser::delayParsingDeclList(SourceLoc LBLoc, SourceLoc &RBLoc,
44414441
RBLoc = Tok.getLoc();
44424442
error = true;
44434443
}
4444-
4445-
State->delayDeclList(IDC);
44464444
return error;
44474445
}
44484446

lib/Parse/PersistentParserState.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,3 @@ void PersistentParserState::restoreCodeCompletionDelayedDeclState(
5050
ScopeInfo.saveCurrentScope(), other.StartOffset, other.EndOffset,
5151
other.PrevOffset));
5252
}
53-
54-
void PersistentParserState::delayDeclList(IterableDeclContext *D) {
55-
DelayedDeclLists.push_back(D);
56-
}
57-
58-
void PersistentParserState::parseAllDelayedDeclLists() {
59-
for (auto IDC : DelayedDeclLists)
60-
IDC->loadAllMembers();
61-
}

0 commit comments

Comments
 (0)