Skip to content

refactor(rust): use stabilized ptr::as_ref_unchecked#24381

Merged
graphite-app[bot] merged 1 commit into
mainfrom
refactor-as-ref-unchecked
Jul 11, 2026
Merged

refactor(rust): use stabilized ptr::as_ref_unchecked#24381
graphite-app[bot] merged 1 commit into
mainfrom
refactor-as-ref-unchecked

Conversation

@Boshen

@Boshen Boshen commented Jul 11, 2026

Copy link
Copy Markdown
Member

Rust 1.95 stabilized <*const T>::as_ref_unchecked (MSRV bumped in #24359). This replaces the ptr.as_ref().unwrap_unchecked() idiom at its 5 call sites:

  • oxc_parser lexer/source.rs read()/read2() — the doc comment there explains the idiom exists because producing a &u8 carries nonnull/dereferenceable LLVM metadata that a raw deref does not (7% lexer speedup). as_ref_unchecked is implemented as exactly that reference production (&*self), so codegen is unchanged — it just skips the Option detour. Comment updated to name the new method.
  • oxc_codegen lib.rs</script search loop.
  • oxc_ast_visit utf8_to_utf16/translation.rs — chunk read.
  • oxc_ast generated/ast_kind.rs AstKind::ty — changed via its generator in tasks/ast_tools, regenerated with just ast.

Verified: cargo test for the touched crates, and parser/semantic/codegen conformance (test262 / babel / typescript / misc) with zero snapshot diffs. CodSpeed should show this perf-neutral.

🤖 Generated with Claude Code

@github-actions github-actions Bot added A-parser Area - Parser A-ast Area - AST A-codegen Area - Code Generation A-ast-tools Area - AST tools labels Jul 11, 2026
@codspeed-hq

codspeed-hq Bot commented Jul 11, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 62 untouched benchmarks
⏩ 9 skipped benchmarks1


Comparing refactor-as-ref-unchecked (7fbc9aa) with main (d117011)

Open in CodSpeed

Footnotes

  1. 9 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.

@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Jul 11, 2026

overlookmotel commented Jul 11, 2026

Copy link
Copy Markdown
Member

Merge activity

Rust 1.95 stabilized [`<*const T>::as_ref_unchecked`](https://doc.rust-lang.org/std/primitive.pointer.html#method.as_ref_unchecked) (MSRV bumped in #24359). This replaces the `ptr.as_ref().unwrap_unchecked()` idiom at its 5 call sites:

- `oxc_parser` `lexer/source.rs` `read()`/`read2()` — the doc comment there explains the idiom exists because producing a `&u8` carries `nonnull`/`dereferenceable` LLVM metadata that a raw deref does not (7% lexer speedup). `as_ref_unchecked` is implemented as exactly that reference production (`&*self`), so codegen is unchanged — it just skips the `Option` detour. Comment updated to name the new method.
- `oxc_codegen` `lib.rs` — `</script` search loop.
- `oxc_ast_visit` `utf8_to_utf16/translation.rs` — chunk read.
- `oxc_ast` `generated/ast_kind.rs` `AstKind::ty` — changed via its generator in `tasks/ast_tools`, regenerated with `just ast`.

Verified: `cargo test` for the touched crates, and parser/semantic/codegen conformance (test262 / babel / typescript / misc) with **zero snapshot diffs**. CodSpeed should show this perf-neutral.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@graphite-app
graphite-app Bot force-pushed the refactor-as-ref-unchecked branch from 7fbc9aa to a82a400 Compare July 11, 2026 17:45
@graphite-app
graphite-app Bot merged commit a82a400 into main Jul 11, 2026
30 checks passed
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Jul 11, 2026
@graphite-app
graphite-app Bot deleted the refactor-as-ref-unchecked branch July 11, 2026 17:51
graphite-app Bot pushed a commit that referenced this pull request Jul 11, 2026
Follow-on after #24381. When casting a `&` reference, it's preferable to use `NonNull` - that safely gains the "pointer is not null" fact, rather than unsafely promising it with `as_ref_unchecked` on a raw pointer.
graphite-app Bot pushed a commit that referenced this pull request Jul 11, 2026
Follow-on after #24381. `AstKind::ty` is pure static code. It doesn't need to be generated. Move it out of the generated code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast Area - AST A-ast-tools Area - AST tools A-codegen Area - Code Generation A-parser Area - Parser

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants