Skip to content

parser: Collapse parser and tokenizer. - #456

Merged
emilio merged 2 commits into
mainfrom
collapse-tokenizer
Sep 21, 2026
Merged

emilio merged 2 commits into
mainfrom
collapse-tokenizer

Conversation

@emilio

@emilio emilio commented Sep 15, 2026

Copy link
Copy Markdown
Member

Now they are 1:1 so the distinction is mostly internal. This allows
state tracking to be a bit simpler.

Now they are 1:1 so the distinction is mostly internal. This allows
state tracking to be a bit simpler.
@emilio
emilio requested a review from SimonSapin September 15, 2026 10:56
@emilio

emilio commented Sep 15, 2026

Copy link
Copy Markdown
Member Author

@SimonSapin not sure how you feel about this, the main point I wanted to get out of this is to be able to not track at_start_of separately, but I think it makes sense in general now that Parser and Tokenizer are effectively 1:1.

@SimonSapin

Copy link
Copy Markdown
Member

Aren’t there tests that run the tokenizer by itsef?

@emilio

emilio commented Sep 15, 2026

Copy link
Copy Markdown
Member Author

Aren’t there tests that run the tokenizer by itsef?

Not really

@emilio

emilio commented Sep 15, 2026

Copy link
Copy Markdown
Member Author

Fixed CI (msrv didn't support the if foo && let Some(bar) = ... { syntax.

@emilio
emilio requested review from nicoburns and tiaanl September 20, 2026 15:30
@emilio emilio mentioned this pull request Sep 20, 2026

@emilio emilio left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimonSapin does this look reasonable to you? The comment below is the only change that I think is potentially dubious / objectionable in practice, but I'd rather do either nothing (this patch), or the look_for_arbitrary_substitution_functions bit suggested below, than the existing thing which penalizes all tokens all the time.

Comment thread src/parser.rs
self.tokenizer.reset(&cached_token.end_state);
if let Token::Function(ref name) = cached_token.token {
self.tokenizer.see_function(name)
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this removal is an intentional change, I want to make the cached token path add as little overhead as possible. This required a change in servo when parsing declaration blocks but I think this is ok. The alternative would be to make look_for_arbitrary_substitution_functions invalidate the cached token, at least if it's a function (but we'd need the same change anyway to avoid the performance regression).

@tiaanl

tiaanl commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Tests would be nice, which would also show how using the Parser now changes.

@emilio

emilio commented Sep 21, 2026

Copy link
Copy Markdown
Member Author

Tests would be nice, which would also show how using the Parser now changes.

Tests for what? The public API doesn't change at all.

@emilio

emilio commented Sep 21, 2026

Copy link
Copy Markdown
Member Author

FWIW I have a try run with this patch green on Firefox which include all of WPT and mochitests, etc so not too concerned about introducing regressions here. But happy to add coverage for any particular area that you think might deserve it? But seems tangential / worth a separate PR in any case.

@tiaanl tiaanl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the caching change handled elsewhere, I don't see issues with it.

@SimonSapin

Copy link
Copy Markdown
Member

It’s been years since I’ve properly looked at cssparser code so this isn’t a full review (sorry!) but I’m not opposed to this in principle. Especially having already ported Firefox to this change with green test sounds good. Since that includes Stylo, I assume Servo should be mostly fine too.

@emilio

emilio commented Sep 21, 2026

Copy link
Copy Markdown
Member Author

Yeah pretty sure this change is a no-op except for that very specific see_function bit and should be fine for servo. Thanks!

@emilio
emilio added this pull request to the merge queue Sep 21, 2026
Merged via the queue into main with commit 106021c Sep 21, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants