Skip to content

Commit 3f4a4c0

Browse files
rintaroJan Svoboda
authored andcommitted
[SyntaxParse] Don't record tokens while skipping
1 parent a5cb907 commit 3f4a4c0

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

include/swift/Parse/SyntaxParsingContext.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,9 @@ class alignas(1 << SyntaxAlignInBits) SyntaxParsingContext {
355355

356356
void setShouldDefer(bool Value = true) { ShouldDefer = Value; }
357357

358-
bool shouldDefer() const { return ShouldDefer || IsBacktracking; }
358+
bool shouldDefer() const {
359+
return ShouldDefer || IsBacktracking || Mode == AccumulationMode::Discard;
360+
}
359361

360362
/// Explicitly finalizing syntax tree creation.
361363
/// This function will be called during the destroying of a root syntax

lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2706,6 +2706,8 @@ bool Parser::isStartOfDecl() {
27062706
void Parser::consumeDecl(ParserPosition BeginParserPosition,
27072707
ParseDeclOptions Flags,
27082708
bool IsTopLevel) {
2709+
SyntaxParsingContext Discarding(SyntaxContext);
2710+
Discarding.setDiscard();
27092711
SourceLoc CurrentLoc = Tok.getLoc();
27102712

27112713
SourceLoc EndLoc = PreviousLoc;

lib/Parse/ParseStmt.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ bool Parser::isTerminatorForBraceItemListKind(BraceItemListKind Kind,
249249

250250
void Parser::consumeTopLevelDecl(ParserPosition BeginParserPosition,
251251
TopLevelCodeDecl *TLCD) {
252+
SyntaxParsingContext Discarding(SyntaxContext);
253+
Discarding.setDiscard();
252254
SourceLoc EndLoc = PreviousLoc;
253255
backtrackToPosition(BeginParserPosition);
254256
SourceLoc BeginLoc = Tok.getLoc();

0 commit comments

Comments
 (0)