Skip to content

Comments

feat(linter): convert spans to UTF-16 in JS plugins#13344

Merged
graphite-app[bot] merged 1 commit intomainfrom
08-27-fix_napi_oxlint_convert_spans_to_utf-16
Aug 28, 2025
Merged

feat(linter): convert spans to UTF-16 in JS plugins#13344
graphite-app[bot] merged 1 commit intomainfrom
08-27-fix_napi_oxlint_convert_spans_to_utf-16

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Aug 27, 2025

The AST on JS side in linter JS plugins previously had start and end as UTF-8 offsets.

Convert the AST to UTF-16 offsets prior to transferring it to JS, and convert offsets in any errors/warnings returned from JS side back to UTF-8 before creating OxcDiagnostics from them.

The tricky part is that it's not possible to mutate the AST (convert offsets to UTF-16) while Semantic is alive, because you can't obtain a &mut Program due to aliasing rules. Work around this with some pointer juggling and by dropping Semantic before creating a &mut Program.

This is a bit sketchy, but is not (I believe) UB. Hopefully we can remove the need for this workaround later on by performing offset conversion during serialization / raw transfer deserialization, and so avoid the need to mutate the AST.

Copy link
Member Author

overlookmotel commented Aug 27, 2025


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 C-enhancement Category - New feature or request label Aug 27, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Aug 27, 2025

CodSpeed Instrumentation Performance Report

Merging #13344 will not alter performance

Comparing 08-27-fix_napi_oxlint_convert_spans_to_utf-16 (d1c9db5) with main (9a828de)1

Summary

✅ 34 untouched benchmarks

Footnotes

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

@overlookmotel overlookmotel marked this pull request as ready for review August 27, 2025 23:44
@overlookmotel overlookmotel requested a review from camc314 as a code owner August 27, 2025 23:44
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Aug 28, 2025
@graphite-app
Copy link
Contributor

graphite-app bot commented Aug 28, 2025

Merge activity

@graphite-app graphite-app bot changed the base branch from 08-27-feat_semantic_derive_default_for_semantic_ to graphite-base/13344 August 28, 2025 09:25
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Aug 28, 2025
@graphite-app graphite-app bot changed the base branch from graphite-base/13344 to main August 28, 2025 09:32
@graphite-app graphite-app bot requested a review from Dunqing as a code owner August 28, 2025 09:32
The AST on JS side in linter JS plugins previously had `start` and `end` as UTF-8 offsets.

Convert the AST to UTF-16 offsets prior to transferring it to JS, and convert offsets in any errors/warnings returned from JS side back to UTF-8 before creating `OxcDiagnostic`s from them.

The tricky part is that it's not possible to mutate the AST (convert offsets to UTF-16) while `Semantic` is alive, because you can't obtain a `&mut Program` due to aliasing rules. Work around this with some pointer juggling and by dropping `Semantic` before creating a `&mut Program`.

This is a bit sketchy, but is not (I believe) UB. Hopefully we can remove the need for this workaround later on by performing offset conversion during serialization / raw transfer deserialization, and so avoid the need to mutate the AST.
@github-actions github-actions bot added the A-semantic Area - Semantic label Aug 28, 2025
@graphite-app graphite-app bot force-pushed the 08-27-fix_napi_oxlint_convert_spans_to_utf-16 branch from 9ba81d3 to d1c9db5 Compare August 28, 2025 09:32
@graphite-app graphite-app bot merged commit d1c9db5 into main Aug 28, 2025
24 checks passed
@graphite-app graphite-app bot deleted the 08-27-fix_napi_oxlint_convert_spans_to_utf-16 branch August 28, 2025 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter A-semantic Area - Semantic C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant