Skip to content

Commit 1aa9508

Browse files
authored
Remove DelayedDeclLists from PersistentParserState (#29071)
Remove DelayedDeclLists from PersistentParserState
2 parents 222b9de + 86cc73d commit 1aa9508

File tree

6 files changed

+20
-36
lines changed

6 files changed

+20
-36
lines changed

include/swift/Frontend/Frontend.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -607,14 +607,13 @@ class CompilerInstance {
607607
void performSema();
608608

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

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

620619
/// Performs mandatory, diagnostic, and optimization passes over the SIL.

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: 13 additions & 11 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,36 +1093,38 @@ void CompilerInstance::performParseOnly(bool EvaluateConditionals,
10931093
}
10941094

10951095
PersistentState = llvm::make_unique<PersistentParserState>();
1096+
PersistentState->PerformConditionEvaluation = EvaluateConditionals;
1097+
1098+
auto shouldDelayBodies = [&](unsigned bufferID) -> bool {
1099+
if (!CanDelayBodies)
1100+
return false;
10961101

1097-
SWIFT_DEFER {
1098-
if (ParseDelayedBodyOnEnd)
1099-
PersistentState->parseAllDelayedDeclLists();
1102+
// Don't delay bodies in whole module mode or for primary files.
1103+
return !(isWholeModuleCompilation() || isPrimaryInput(bufferID));
11001104
};
1101-
PersistentState->PerformConditionEvaluation = EvaluateConditionals;
1105+
11021106
// Parse all the library files.
11031107
for (auto BufferID : InputSourceCodeBufferIDs) {
11041108
if (BufferID == MainBufferID)
11051109
continue;
11061110

1107-
auto IsPrimary = isWholeModuleCompilation() || isPrimaryInput(BufferID);
1108-
11091111
SourceFile *NextInput = createSourceFileForMainModule(
11101112
SourceFileKind::Library, SourceFile::ImplicitModuleImportKind::None,
11111113
BufferID);
11121114

11131115
parseIntoSourceFileFull(*NextInput, BufferID, PersistentState.get(),
1114-
/*DelayBodyParsing=*/!IsPrimary);
1116+
shouldDelayBodies(BufferID));
11151117
}
11161118

11171119
// Now parse the main file.
11181120
if (MainBufferID != NO_SUCH_BUFFER) {
11191121
SourceFile &MainFile =
11201122
MainModule->getMainSourceFile(Invocation.getSourceFileKind());
11211123
MainFile.SyntaxParsingCache = Invocation.getMainFileSyntaxParsingCache();
1124+
assert(MainBufferID == MainFile.getBufferID());
11221125

1123-
parseIntoSourceFileFull(MainFile, MainFile.getBufferID().getValue(),
1124-
PersistentState.get(),
1125-
/*DelayBodyParsing=*/false);
1126+
parseIntoSourceFileFull(MainFile, MainBufferID, PersistentState.get(),
1127+
shouldDelayBodies(MainBufferID));
11261128
}
11271129

11281130
assert(Context->LoadedModules.size() == 1 &&

lib/FrontendTool/FrontendTool.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,12 +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 ||
1267-
Invocation.getDiagnosticOptions().VerifyMode != DiagnosticOptions::NoVerify;
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;
12681268
Instance.performParseOnly(/*EvaluateConditionals*/
12691269
Action == FrontendOptions::ActionType::EmitImportedModules,
1270-
ParseDelayedDeclListsOnEnd);
1270+
CanDelayBodies);
12711271
} else if (Action == FrontendOptions::ActionType::ResolveImports) {
12721272
Instance.performParseAndResolveImportsOnly();
12731273
} 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)