Skip to content

[Parser] Expose a flag to allow users explicitly disable delayed parsing. NFC #21750

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 1 commit into from
Jan 10, 2019
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
12 changes: 9 additions & 3 deletions include/swift/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ class Parser {
/// Always empty if !SF.shouldBuildSyntaxTree().
syntax::Trivia TrailingTrivia;

/// Whether we should disable delayed parsing.
bool DisableDelayedParsing;

/// The receiver to collect all consumed tokens.
ConsumeTokenReceiver *TokReceiver;

Expand Down Expand Up @@ -352,14 +355,17 @@ class Parser {
Parser(unsigned BufferID, SourceFile &SF, DiagnosticEngine* LexerDiags,
SILParserTUStateBase *SIL,
PersistentParserState *PersistentState,
std::shared_ptr<SyntaxParseActions> SPActions = nullptr);
std::shared_ptr<SyntaxParseActions> SPActions = nullptr,
bool DisableDelayedParsing = false);
Parser(unsigned BufferID, SourceFile &SF, SILParserTUStateBase *SIL,
PersistentParserState *PersistentState = nullptr,
std::shared_ptr<SyntaxParseActions> SPActions = nullptr);
std::shared_ptr<SyntaxParseActions> SPActions = nullptr,
bool DisableDelayedParsing = false);
Parser(std::unique_ptr<Lexer> Lex, SourceFile &SF,
SILParserTUStateBase *SIL = nullptr,
PersistentParserState *PersistentState = nullptr,
std::shared_ptr<SyntaxParseActions> SPActions = nullptr);
std::shared_ptr<SyntaxParseActions> SPActions = nullptr,
bool DisableDelayedParsing = false);
~Parser();

bool isInSILMode() const { return SIL != nullptr; }
Expand Down
6 changes: 4 additions & 2 deletions include/swift/Subsystems.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,17 @@ namespace swift {
bool parseIntoSourceFile(SourceFile &SF, unsigned BufferID, bool *Done,
SILParserState *SIL = nullptr,
PersistentParserState *PersistentState = nullptr,
DelayedParsingCallbacks *DelayedParseCB = nullptr);
DelayedParsingCallbacks *DelayedParseCB = nullptr,
bool DisableDelayedParsing = false);

/// Parse a single buffer into the given source file, until the full source
/// contents are parsed.
///
/// \return true if the parser found code with side effects.
bool parseIntoSourceFileFull(SourceFile &SF, unsigned BufferID,
PersistentParserState *PersistentState = nullptr,
DelayedParsingCallbacks *DelayedParseCB = nullptr);
DelayedParsingCallbacks *DelayedParseCB = nullptr,
bool DisableDelayedParsing = false);

/// Finish the parsing by going over the nodes that were delayed
/// during the first parsing pass.
Expand Down
3 changes: 3 additions & 0 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3495,6 +3495,9 @@ bool Parser::parseDeclList(SourceLoc LBLoc, SourceLoc &RBLoc,
}

bool Parser::canDelayMemberDeclParsing() {
// If explicitly disabled, respect the flag.
if (DisableDelayedParsing)
return false;
// There's no fundamental reasons that SIL cannnot be lasily parsed. We need
// to keep SILParserTUStateBase persistent to make it happen.
if (isInSILMode())
Expand Down
14 changes: 9 additions & 5 deletions lib/Parse/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,16 @@ swift::tokenizeWithTrivia(const LangOptions &LangOpts, const SourceManager &SM,

Parser::Parser(unsigned BufferID, SourceFile &SF, SILParserTUStateBase *SIL,
PersistentParserState *PersistentState,
std::shared_ptr<SyntaxParseActions> SPActions)
std::shared_ptr<SyntaxParseActions> SPActions,
bool DisableDelayedParsing)
: Parser(BufferID, SF, &SF.getASTContext().Diags, SIL, PersistentState,
std::move(SPActions)) {}
std::move(SPActions), DisableDelayedParsing) {}

Parser::Parser(unsigned BufferID, SourceFile &SF, DiagnosticEngine* LexerDiags,
SILParserTUStateBase *SIL,
PersistentParserState *PersistentState,
std::shared_ptr<SyntaxParseActions> SPActions)
std::shared_ptr<SyntaxParseActions> SPActions,
bool DisableDelayedParsing)
: Parser(
std::unique_ptr<Lexer>(new Lexer(
SF.getASTContext().LangOpts, SF.getASTContext().SourceMgr,
Expand All @@ -357,7 +359,7 @@ Parser::Parser(unsigned BufferID, SourceFile &SF, DiagnosticEngine* LexerDiags,
SF.shouldBuildSyntaxTree()
? TriviaRetentionMode::WithTrivia
: TriviaRetentionMode::WithoutTrivia)),
SF, SIL, PersistentState, std::move(SPActions)) {}
SF, SIL, PersistentState, std::move(SPActions), DisableDelayedParsing) {}

namespace {

Expand Down Expand Up @@ -477,14 +479,16 @@ class TokenRecorder: public ConsumeTokenReceiver {
Parser::Parser(std::unique_ptr<Lexer> Lex, SourceFile &SF,
SILParserTUStateBase *SIL,
PersistentParserState *PersistentState,
std::shared_ptr<SyntaxParseActions> SPActions)
std::shared_ptr<SyntaxParseActions> SPActions,
bool DisableDelayedParsing)
: SourceMgr(SF.getASTContext().SourceMgr),
Diags(SF.getASTContext().Diags),
SF(SF),
L(Lex.release()),
SIL(SIL),
CurDeclContext(&SF),
Context(SF.getASTContext()),
DisableDelayedParsing(DisableDelayedParsing),
TokReceiver(SF.shouldCollectToken() ?
new TokenRecorder(SF) :
new ConsumeTokenReceiver()),
Expand Down
16 changes: 10 additions & 6 deletions lib/ParseSIL/ParseSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ static bool parseIntoSourceFileImpl(SourceFile &SF,
SILParserState *SIL,
PersistentParserState *PersistentState,
DelayedParsingCallbacks *DelayedParseCB,
bool FullParse) {
bool FullParse,
bool DisableDelayedParsing) {
assert((!FullParse || (SF.canBeParsedInFull() && !SIL)) &&
"cannot parse in full with the given parameters!");

Expand All @@ -127,7 +128,7 @@ static bool parseIntoSourceFileImpl(SourceFile &SF,

SharedTimer timer("Parsing");
Parser P(BufferID, SF, SIL ? SIL->Impl.get() : nullptr,
PersistentState, STreeCreator);
PersistentState, STreeCreator, DisableDelayedParsing);
PrettyStackTraceParser StackTrace(P);

llvm::SaveAndRestore<bool> S(P.IsParsingInterfaceTokens,
Expand Down Expand Up @@ -155,19 +156,22 @@ bool swift::parseIntoSourceFile(SourceFile &SF,
bool *Done,
SILParserState *SIL,
PersistentParserState *PersistentState,
DelayedParsingCallbacks *DelayedParseCB) {
DelayedParsingCallbacks *DelayedParseCB,
bool DisableDelayedParsing) {
return parseIntoSourceFileImpl(SF, BufferID, Done, SIL,
PersistentState, DelayedParseCB,
/*FullParse=*/SF.shouldBuildSyntaxTree());
/*FullParse=*/SF.shouldBuildSyntaxTree(),
DisableDelayedParsing);
}

bool swift::parseIntoSourceFileFull(SourceFile &SF, unsigned BufferID,
PersistentParserState *PersistentState,
DelayedParsingCallbacks *DelayedParseCB) {
DelayedParsingCallbacks *DelayedParseCB,
bool DisableDelayedParsing) {
bool Done = false;
return parseIntoSourceFileImpl(SF, BufferID, &Done, /*SIL=*/nullptr,
PersistentState, DelayedParseCB,
/*FullParse=*/true);
/*FullParse=*/true, DisableDelayedParsing);
}


Expand Down