refactor(rust): use stabilized ptr::as_ref_unchecked#24381
Merged
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
overlookmotel
approved these changes
Jul 11, 2026
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
Bot
force-pushed
the
refactor-as-ref-unchecked
branch
from
July 11, 2026 17:45
7fbc9aa to
a82a400
Compare
This was referenced Jul 11, 2026
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rust 1.95 stabilized
<*const T>::as_ref_unchecked(MSRV bumped in #24359). This replaces theptr.as_ref().unwrap_unchecked()idiom at its 5 call sites:oxc_parserlexer/source.rsread()/read2()— the doc comment there explains the idiom exists because producing a&u8carriesnonnull/dereferenceableLLVM metadata that a raw deref does not (7% lexer speedup).as_ref_uncheckedis implemented as exactly that reference production (&*self), so codegen is unchanged — it just skips theOptiondetour. Comment updated to name the new method.oxc_codegenlib.rs—</scriptsearch loop.oxc_ast_visitutf8_to_utf16/translation.rs— chunk read.oxc_astgenerated/ast_kind.rsAstKind::ty— changed via its generator intasks/ast_tools, regenerated withjust ast.Verified:
cargo testfor 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