Skip to content

[v2] fix(lexer): lex /// lines separately and merge them in the tok… - #2255

Merged
teofr merged 2 commits into
mainfrom
teofr/split-single-line-comments
Nov 2, 2026
Merged

teofr merged 2 commits into
mainfrom
teofr/split-single-line-comments

Conversation

@teofr

@teofr teofr commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Single line comments (regular and natspec) are lexed separately, essentially rolling back #2226, the natspec module now is in charge of filtering out trivia from the lexer stream, while collecting relevant NatSpec comment (that may span several lexemes in the case of single line) on a NatSpecStack.

This PR degrades the parser between 1% and 3% in Ir, #2254 improves on that and brings down regressions to around 1.5%-2%. #2269 further improves on it with only a handful of benchmarks regressing around 1%, however I'm not sure placing such a strong restriction on a public function is a good idea, and it may be targetting the benchmarks too much.

@OmarTawfik what do you think of the tradeoff? I think some of the regression is real work, a lot of it is hindering the optimiser by making the parser/lexer loop more complex, as shown by the two other PRs

@teofr
teofr added this pull request to stack #2256 October 9, 2026 15:33
@teofr
teofr requested a balanced review from Copilot October 9, 2026 15:33
@changeset-bot

changeset-bot Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: c8e0e5b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

A local doc comment triggers a warning that becomes a compilation failure under CI’s -Dwarnings configuration.

1 open finding
What changed in this PR

Restores per-line lexing for single-line comments while merging consecutive NatSpec lines during parser token filtering.

Changes:

  • Simplifies comment lexer definitions across Solidity, pragma, and Yul contexts.
  • Introduces parser-side NatSpec collection and merging.
  • Updates lexer and parser coverage for comments and line endings.
File Description
parser/​tests.rs Tests merged NatSpec lines and separators.
parser/​natspec.rs Implements NatSpec collection and token filtering.
parser/​natspec_stack.rs Removes the superseded stack module.
parser/​mod.rs Integrates the new NatSpec token stream.
lexer/​tests.rs Updates expectations for per-line comments.
lexer/​mod.rs Exposes lexemes internally.
lexer/​contexts.generated.rs Regenerates simplified lexer patterns.
definition.rs Defines per-line comment scanners.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchteofr/split-single-line-comments
Testbedci

⚠️ WARNING: Truncated view!

The full continuous benchmarking report exceeds the maximum length allowed on this platform.

🚨 2 Alerts

🐰 View full continuous benchmarking report in Bencher

@teofr
teofr force-pushed the teofr/split-single-line-comments branch 2 times, most recently from 5bddce3 to 378ee3b Compare October 9, 2026 16:43
@teofr
teofr removed this pull request from stack #2256 October 9, 2026 16:43
@teofr
teofr changed the base branch from teofr/inline-lexer to main October 9, 2026 16:43
@teofr
teofr force-pushed the teofr/split-single-line-comments branch from 378ee3b to 78b9e52 Compare October 13, 2026 08:29
@teofr
teofr added this pull request to stack #2268 October 13, 2026 09:03
@teofr
teofr force-pushed the teofr/split-single-line-comments branch from 78b9e52 to 2c90dfc Compare October 13, 2026 09:11
@teofr
teofr marked this pull request as ready for review October 13, 2026 10:22
@teofr
teofr requested review from a team as code owners October 13, 2026 10:22
@teofr
teofr force-pushed the teofr/split-single-line-comments branch from 2c90dfc to 5ac9047 Compare October 30, 2026 15:38
@teofr

teofr commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Rebased and spent some more time looking into this.


  1. Keeping the /// comment actual range, without the line break. Nothing needs it, and memory_safety.rs trims it twice today already.

is implemented, it's the right call.


After #2280 (comment), next_lexeme is already not inlined, so this PR is now "free" (or rather, #2280 paid the price).

Given that, I left this PR to be a functional change, without performance work. I think we may be spending too much time into how rustc and LLVM are arranging our code in library benchmarks, that is also not a faithful representation of how a final application binary will behave.

cc @OmarTawfik what do you think?


As a note, and a learning from this, the skip feature in logos is not really well behaved, since it creates a chance for stack overflow on recursive regex matching functions. This can be fixed with the state_machine_codegen, but the resulting lexer is not as performant.

@teofr
teofr added this pull request to the merge queue Nov 2, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 2, 2026
@teofr
teofr force-pushed the teofr/split-single-line-comments branch from 03992b3 to c8e0e5b Compare November 2, 2026 12:05
@teofr
teofr enabled stacked auto-merge November 2, 2026 12:06
@teofr
teofr added this pull request to the merge queue Nov 2, 2026
Merged via the queue into main with commit fb5ead5 Nov 2, 2026
18 of 19 checks passed
@teofr
teofr deleted the teofr/split-single-line-comments branch November 2, 2026 12:41
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