Skip to content

Commit fb0fbc0

Browse files
committed
Parse: Rename DisableDelayedParsing to DelayBodyParsing and change polarity
1 parent d540682 commit fb0fbc0

File tree

5 files changed

+30
-20
lines changed

5 files changed

+30
-20
lines changed

include/swift/Parse/Parser.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,15 @@ class Parser {
207207
/// Always empty if !SF.shouldBuildSyntaxTree().
208208
ParsedTrivia TrailingTrivia;
209209

210-
/// Whether we should disable delayed parsing.
211-
bool DisableDelayedParsing;
210+
/// Whether we should delay parsing nominal type and extension bodies,
211+
/// and skip function bodies.
212+
///
213+
/// This is false in primary files, since we want to type check all
214+
/// declarations and function bodies.
215+
///
216+
/// This is true for non-primary files, where declarations only need to be
217+
/// lazily parsed and type checked.
218+
bool DelayBodyParsing;
212219

213220
/// The receiver to collect all consumed tokens.
214221
ConsumeTokenReceiver *TokReceiver;
@@ -357,16 +364,16 @@ class Parser {
357364
SILParserTUStateBase *SIL,
358365
PersistentParserState *PersistentState,
359366
std::shared_ptr<SyntaxParseActions> SPActions = nullptr,
360-
bool DisableDelayedParsing = false);
367+
bool DelayBodyParsing = true);
361368
Parser(unsigned BufferID, SourceFile &SF, SILParserTUStateBase *SIL,
362369
PersistentParserState *PersistentState = nullptr,
363370
std::shared_ptr<SyntaxParseActions> SPActions = nullptr,
364-
bool DisableDelayedParsing = false);
371+
bool DelayBodyParsing = true);
365372
Parser(std::unique_ptr<Lexer> Lex, SourceFile &SF,
366373
SILParserTUStateBase *SIL = nullptr,
367374
PersistentParserState *PersistentState = nullptr,
368375
std::shared_ptr<SyntaxParseActions> SPActions = nullptr,
369-
bool DisableDelayedParsing = false);
376+
bool DelayBodyParsing = true);
370377
~Parser();
371378

372379
bool isInSILMode() const { return SIL != nullptr; }

include/swift/Subsystems.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ namespace swift {
122122
SILParserState *SIL = nullptr,
123123
PersistentParserState *PersistentState = nullptr,
124124
DelayedParsingCallbacks *DelayedParseCB = nullptr,
125-
bool DisableDelayedParsing = false);
125+
bool DelayBodyParsing = true);
126126

127127
/// Parse a single buffer into the given source file, until the full source
128128
/// contents are parsed.
@@ -131,7 +131,7 @@ namespace swift {
131131
bool parseIntoSourceFileFull(SourceFile &SF, unsigned BufferID,
132132
PersistentParserState *PersistentState = nullptr,
133133
DelayedParsingCallbacks *DelayedParseCB = nullptr,
134-
bool DisableDelayedParsing = false);
134+
bool DelayBodyParsing = true);
135135

136136
/// Finish the parsing by going over the nodes that were delayed
137137
/// during the first parsing pass.

lib/Parse/ParseDecl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3496,7 +3496,7 @@ bool Parser::parseDeclList(SourceLoc LBLoc, SourceLoc &RBLoc,
34963496

34973497
bool Parser::canDelayMemberDeclParsing() {
34983498
// If explicitly disabled, respect the flag.
3499-
if (DisableDelayedParsing)
3499+
if (!DelayBodyParsing)
35003500
return false;
35013501
// There's no fundamental reasons that SIL cannnot be lasily parsed. We need
35023502
// to keep SILParserTUStateBase persistent to make it happen.
@@ -3520,6 +3520,9 @@ bool Parser::canDelayMemberDeclParsing() {
35203520
// so we cannot lazily parse members.
35213521
if (isCodeCompletionFirstPass())
35223522
return false;
3523+
3524+
// Skip until the matching right curly bracket; if we find a pound directive,
3525+
// we can't lazily parse.
35233526
BacktrackingScope BackTrack(*this);
35243527
bool HasPoundDirective;
35253528
skipUntilMatchingRBrace(*this, HasPoundDirective, SyntaxContext);

lib/Parse/Parser.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,15 +346,15 @@ swift::tokenizeWithTrivia(const LangOptions &LangOpts, const SourceManager &SM,
346346
Parser::Parser(unsigned BufferID, SourceFile &SF, SILParserTUStateBase *SIL,
347347
PersistentParserState *PersistentState,
348348
std::shared_ptr<SyntaxParseActions> SPActions,
349-
bool DisableDelayedParsing)
349+
bool DelayBodyParsing)
350350
: Parser(BufferID, SF, &SF.getASTContext().Diags, SIL, PersistentState,
351-
std::move(SPActions), DisableDelayedParsing) {}
351+
std::move(SPActions), DelayBodyParsing) {}
352352

353353
Parser::Parser(unsigned BufferID, SourceFile &SF, DiagnosticEngine* LexerDiags,
354354
SILParserTUStateBase *SIL,
355355
PersistentParserState *PersistentState,
356356
std::shared_ptr<SyntaxParseActions> SPActions,
357-
bool DisableDelayedParsing)
357+
bool DelayBodyParsing)
358358
: Parser(
359359
std::unique_ptr<Lexer>(new Lexer(
360360
SF.getASTContext().LangOpts, SF.getASTContext().SourceMgr,
@@ -369,7 +369,7 @@ Parser::Parser(unsigned BufferID, SourceFile &SF, DiagnosticEngine* LexerDiags,
369369
SF.shouldBuildSyntaxTree()
370370
? TriviaRetentionMode::WithTrivia
371371
: TriviaRetentionMode::WithoutTrivia)),
372-
SF, SIL, PersistentState, std::move(SPActions), DisableDelayedParsing) {}
372+
SF, SIL, PersistentState, std::move(SPActions), DelayBodyParsing) {}
373373

374374
namespace {
375375

@@ -490,15 +490,15 @@ Parser::Parser(std::unique_ptr<Lexer> Lex, SourceFile &SF,
490490
SILParserTUStateBase *SIL,
491491
PersistentParserState *PersistentState,
492492
std::shared_ptr<SyntaxParseActions> SPActions,
493-
bool DisableDelayedParsing)
493+
bool DelayBodyParsing)
494494
: SourceMgr(SF.getASTContext().SourceMgr),
495495
Diags(SF.getASTContext().Diags),
496496
SF(SF),
497497
L(Lex.release()),
498498
SIL(SIL),
499499
CurDeclContext(&SF),
500500
Context(SF.getASTContext()),
501-
DisableDelayedParsing(DisableDelayedParsing),
501+
DelayBodyParsing(DelayBodyParsing),
502502
TokReceiver(SF.shouldCollectToken() ?
503503
new TokenRecorder(SF) :
504504
new ConsumeTokenReceiver()),

lib/ParseSIL/ParseSIL.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static bool parseIntoSourceFileImpl(SourceFile &SF,
116116
PersistentParserState *PersistentState,
117117
DelayedParsingCallbacks *DelayedParseCB,
118118
bool FullParse,
119-
bool DisableDelayedParsing) {
119+
bool DelayBodyParsing) {
120120
assert((!FullParse || (SF.canBeParsedInFull() && !SIL)) &&
121121
"cannot parse in full with the given parameters!");
122122

@@ -129,7 +129,7 @@ static bool parseIntoSourceFileImpl(SourceFile &SF,
129129

130130
SharedTimer timer("Parsing");
131131
Parser P(BufferID, SF, SIL ? SIL->Impl.get() : nullptr,
132-
PersistentState, STreeCreator, DisableDelayedParsing);
132+
PersistentState, STreeCreator, DelayBodyParsing);
133133
PrettyStackTraceParser StackTrace(P);
134134

135135
llvm::SaveAndRestore<bool> S(P.IsParsingInterfaceTokens,
@@ -158,21 +158,21 @@ bool swift::parseIntoSourceFile(SourceFile &SF,
158158
SILParserState *SIL,
159159
PersistentParserState *PersistentState,
160160
DelayedParsingCallbacks *DelayedParseCB,
161-
bool DisableDelayedParsing) {
161+
bool DelayBodyParsing) {
162162
return parseIntoSourceFileImpl(SF, BufferID, Done, SIL,
163163
PersistentState, DelayedParseCB,
164164
/*FullParse=*/SF.shouldBuildSyntaxTree(),
165-
DisableDelayedParsing);
165+
DelayBodyParsing);
166166
}
167167

168168
bool swift::parseIntoSourceFileFull(SourceFile &SF, unsigned BufferID,
169169
PersistentParserState *PersistentState,
170170
DelayedParsingCallbacks *DelayedParseCB,
171-
bool DisableDelayedParsing) {
171+
bool DelayBodyParsing) {
172172
bool Done = false;
173173
return parseIntoSourceFileImpl(SF, BufferID, &Done, /*SIL=*/nullptr,
174174
PersistentState, DelayedParseCB,
175-
/*FullParse=*/true, DisableDelayedParsing);
175+
/*FullParse=*/true, DelayBodyParsing);
176176
}
177177

178178

0 commit comments

Comments
 (0)