Skip to content

Commit

Permalink
Auto merge of #13794 - jonas-schievink:reset-step-limit-after-bump, r…
Browse files Browse the repository at this point in the history
…=jonas-schievink

fix: fix "parser seems stuck" panic when parsing colossal files

The parser step count is incremented every time the parser inspects a token. It's purpose is to ensure the parser doesn't get stuck in infinite loops. But since `self.pos` grows monotonically when parsing source code, it gives a better idea for whether the parser is stuck or not: if `self.pos` is changed, we know that the parser cannot be stuck, so it is safe to reset the step count to 0. This makes the limit check scale with the size of the file, and so should fix #13788.
  • Loading branch information
bors committed Dec 19, 2022
2 parents 9ed1829 + c110481 commit 9ae0b0c
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions crates/parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ impl<'t> Parser<'t> {

fn do_bump(&mut self, kind: SyntaxKind, n_raw_tokens: u8) {
self.pos += n_raw_tokens as usize;
self.steps.set(0);
self.push_event(Event::Token { kind, n_raw_tokens });
}

Expand Down

0 comments on commit 9ae0b0c

Please sign in to comment.