Skip to content

fix(codegen): avoid sourcemap panic on U+2028/U+2029#19548

Merged
graphite-app[bot] merged 1 commit intomainfrom
c/02-19-fix_codegen_avoid_sourcemap_panic_on_u_2028___u_2029_
Feb 20, 2026
Merged

fix(codegen): avoid sourcemap panic on U+2028/U+2029#19548
graphite-app[bot] merged 1 commit intomainfrom
c/02-19-fix_codegen_avoid_sourcemap_panic_on_u_2028___u_2029_

Conversation

@camc314
Copy link
Contributor

@camc314 camc314 commented Feb 19, 2026

Copy link
Contributor Author

camc314 commented Feb 19, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions bot added the A-codegen Area - Code Generation label Feb 19, 2026
@github-actions github-actions bot added the C-bug Category - Bug label Feb 19, 2026
@camc314 camc314 marked this pull request as ready for review February 19, 2026 17:02
Copilot AI review requested due to automatic review settings February 19, 2026 17:02
@camc314 camc314 force-pushed the c/02-19-fix_codegen_avoid_sourcemap_panic_on_u_2028___u_2029_ branch from 6ea895a to f2146ad Compare February 19, 2026 17:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds regression coverage in the sourcemap builder test suite for JavaScript line-separator characters U+2028 (LS) and U+2029 (PS), which are valid line terminators and previously triggered sourcemap-related panics.

Changes:

  • Extend add_source_mapping tests to include inputs containing U+2028/U+2029.
  • Validate generated line/column tracking for LS/PS alone and when surrounded by other characters.

@camc314 camc314 requested a review from Copilot February 19, 2026 17:08
Copy link
Contributor

Copilot AI commented Feb 19, 2026

@camc314 I've opened a new pull request, #19549, to work on those changes. Once the pull request is ready, I'll request review from you.

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 19, 2026

Merging this PR will not alter performance

✅ 47 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing c/02-19-fix_codegen_avoid_sourcemap_panic_on_u_2028___u_2029_ (cb59c95) with main (b5fa195)2

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (ad43ccc) during the generation of this report, so b5fa195 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@overlookmotel overlookmotel force-pushed the c/02-19-fix_codegen_avoid_sourcemap_panic_on_u_2028___u_2029_ branch from f2146ad to cb59c95 Compare February 20, 2026 14:12
Copy link
Member

@overlookmotel overlookmotel left a comment

Choose a reason for hiding this comment

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

I've pushed a commit which reverts most of the changes and just fixes the actual bug with minimum of changes.

The advantage of not introducing a separate line_break_byte_len var is it that increases the chances that all the calculations can be done in registers, without having to spill onto the stack. The most important thing in this hot loop is that the fast paths for ASCII chars and \n remain as streamlined as possible. The code which handles irregular line breaks will rarely be hit, so it's fine to add 1 operation there.

This is a micro-optimization, but as the previous PR which touched this code demonstrated (#13903), this code is very perf-sensitive.

There was one other good change in this PR. I'll split that out into a separate perf PR, with some other small improvements I noticed while reviewing this.

@overlookmotel
Copy link
Member

@camc314 Please take a look at my changes, and merge if you're happy with it.

Copy link
Contributor Author

@camc314 camc314 left a comment

Choose a reason for hiding this comment

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

Thanks! - looks good to me

@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label Feb 20, 2026
Copy link
Contributor Author

camc314 commented Feb 20, 2026

Merge activity

@graphite-app graphite-app bot force-pushed the c/02-19-fix_codegen_avoid_sourcemap_panic_on_u_2028___u_2029_ branch from cb59c95 to e316694 Compare February 20, 2026 14:23
@graphite-app graphite-app bot merged commit e316694 into main Feb 20, 2026
21 checks passed
@graphite-app graphite-app bot deleted the c/02-19-fix_codegen_avoid_sourcemap_panic_on_u_2028___u_2029_ branch February 20, 2026 14:29
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Feb 20, 2026
graphite-app bot pushed a commit that referenced this pull request Feb 20, 2026
Follow-on after #19548.

Remove a bounds check from hot loop in `SourcemapBuilder::update_generated_line_and_column` by doing only 1 bounds check to get next 2 bytes, instead of 2 bounds checks for each byte.

This optimization was taken from @cam314's original version of PR #19548.

While reviewing that PR I also thought I'd spied 2 other optimizations, but on reflection, I realized they were better left as is. Add comments to explain why.
camc314 pushed a commit that referenced this pull request Feb 23, 2026
### 🚀 Features

- e814049 oxc_data_structure/rope: Add `get_offset_from_line_and_column`
(#18133) (Sysix)

### 🐛 Bug Fixes

- 7958b56 linter: Fix syntax error reporting in some output formatters.
(#19590) (connorshea)
- e316694 codegen: Avoid sourcemap panic on `U+2028`/`U+2029` (#19548)
(camc314)
- 933ff72 semantic: Emit correct error code for reserved type name
(#19545) (camc314)

### ⚡ Performance

- b5fa195 codegen: Remove bounds check from `SourcemapBuilder` (#19578)
(overlookmotel)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-codegen Area - Code Generation C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Panic]: Sourcemap generation panics with U+2028/U+2029 (LINE/PARAGRAPH SEPARATOR) characters

4 participants