Skip to content

Commit a7a06d7

Browse files
committed
FrontendTool: parse all delayed member decls when we're dumping parse tree or verifying parse diagnostics.
1 parent 3f03202 commit a7a06d7

File tree

6 files changed

+28
-3
lines changed

6 files changed

+28
-3
lines changed

include/swift/AST/LazyResolver.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ class LazyMemberParser {
104104

105105
/// Return whether the iterable decl context needs parsing.
106106
virtual bool hasUnparsedMembers(const IterableDeclContext *IDC) = 0;
107+
108+
/// Parse all delayed decl list members.
109+
virtual void parseAllDelayedDeclLists() = 0;
107110
};
108111

109112
/// Context data for generic contexts.

include/swift/Frontend/Frontend.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,8 @@ class CompilerInstance {
552552

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

557558
/// Parses and performs name binding on all input files.
558559
///

include/swift/Parse/PersistentParserState.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ class PersistentParserState: public LazyMemberParser {
178178
return DelayedDeclListStates.find(IDC) != DelayedDeclListStates.end();
179179
}
180180

181+
void parseAllDelayedDeclLists() override;
182+
181183
TopLevelContext &getTopLevelContext() {
182184
return TopLevelCode;
183185
}

lib/Frontend/Frontend.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,8 @@ SourceFile *CompilerInstance::createSourceFileForMainModule(
925925
return inputFile;
926926
}
927927

928-
void CompilerInstance::performParseOnly(bool EvaluateConditionals) {
928+
void CompilerInstance::performParseOnly(bool EvaluateConditionals,
929+
bool ParseDelayedBodyOnEnd) {
929930
const InputFileKind Kind = Invocation.getInputKind();
930931
ModuleDecl *const MainModule = getMainModule();
931932
Context->LoadedModules[MainModule->getName()] = MainModule;
@@ -947,6 +948,10 @@ void CompilerInstance::performParseOnly(bool EvaluateConditionals) {
947948
}
948949

949950
PersistentParserState PersistentState(getASTContext());
951+
SWIFT_DEFER {
952+
if (ParseDelayedBodyOnEnd)
953+
PersistentState.parseAllDelayedDeclLists();
954+
};
950955
PersistentState.PerformConditionEvaluation = EvaluateConditionals;
951956
// Parse all the library files.
952957
for (auto BufferID : InputSourceCodeBufferIDs) {

lib/FrontendTool/FrontendTool.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,8 +902,12 @@ static bool performCompile(CompilerInstance &Instance,
902902
return compileLLVMIR(Invocation, Instance, Stats);
903903

904904
if (FrontendOptions::shouldActionOnlyParse(Action)) {
905+
bool ParseDelayedDeclListsOnEnd =
906+
Action == FrontendOptions::ActionType::DumpParse ||
907+
Invocation.getDiagnosticOptions().VerifyMode != DiagnosticOptions::NoVerify;
905908
Instance.performParseOnly(/*EvaluateConditionals*/
906-
Action == FrontendOptions::ActionType::EmitImportedModules);
909+
Action == FrontendOptions::ActionType::EmitImportedModules,
910+
ParseDelayedDeclListsOnEnd);
907911
} else if (Action == FrontendOptions::ActionType::ResolveImports) {
908912
Instance.performParseAndResolveImportsOnly();
909913
} else {

lib/Parse/PersistentParserState.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ void PersistentParserState::delayDeclList(IterableDeclContext* D,
8181
ParentContext, BodyRange, PreviousLoc, ScopeInfo.saveCurrentScope());
8282
}
8383

84+
void PersistentParserState::parseAllDelayedDeclLists() {
85+
std::vector<IterableDeclContext*> AllDelayed;
86+
for (auto &P: DelayedDeclListStates) {
87+
AllDelayed.push_back(P.first);
88+
}
89+
for (auto *D: AllDelayed) {
90+
parseMembers(D);
91+
}
92+
}
93+
8494
void PersistentParserState::delayTopLevel(TopLevelCodeDecl *TLCD,
8595
SourceRange BodyRange,
8696
SourceLoc PreviousLoc) {

0 commit comments

Comments
 (0)