Skip to content

refactor(ast): use NonNull for ref casting#24389

Merged
graphite-app[bot] merged 1 commit into
mainfrom
om/07-11-refactor_ast_use_nonnull_for_ref_casting
Jul 11, 2026
Merged

refactor(ast): use NonNull for ref casting#24389
graphite-app[bot] merged 1 commit into
mainfrom
om/07-11-refactor_ast_use_nonnull_for_ref_casting

Conversation

@overlookmotel

@overlookmotel overlookmotel commented Jul 11, 2026

Copy link
Copy Markdown
Member

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.

@github-actions github-actions Bot added A-ast Area - AST A-ast-tools Area - AST tools labels Jul 11, 2026

Copy link
Copy Markdown
Member Author

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 changes, fast-track this PR to the front of the merge queue

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.

@overlookmotel
overlookmotel marked this pull request as ready for review July 11, 2026 17:58
Copilot AI review requested due to automatic review settings July 11, 2026 17:58

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.

Pull request overview

Refactors the AstKind::ty discriminant read to use std::ptr::NonNull when casting a &AstKind to &AstType, encoding the non-null guarantee in the pointer type rather than relying on as_ref_unchecked on a raw pointer. This aligns with the post-#24381 direction of making unsafe ref-casts more structurally sound.

Changes:

  • Update the AstKind generator to emit NonNull::from_ref(self).cast::<AstType>().as_ref() for the ty() fast-path.
  • Regenerate crates/oxc_ast/src/generated/ast_kind.rs to apply the same change in the produced code.

Reviewed changes

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

File Description
tasks/ast_tools/src/generators/ast_kind.rs Switch generator output from ptr::from_ref(...).as_ref_unchecked() to NonNull::from_ref(...).as_ref() for the AstKind::ty discriminant read.
crates/oxc_ast/src/generated/ast_kind.rs Apply the regenerated NonNull-based cast in AstKind::ty and update imports accordingly.

@overlookmotel overlookmotel self-assigned this Jul 11, 2026
@graphite-app graphite-app Bot added the 0-merge Merge with Graphite Merge Queue label Jul 11, 2026
@graphite-app

graphite-app Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Merge activity

@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 om/07-11-refactor_ast_use_nonnull_for_ref_casting (4aaaccc) with main (a82a400)

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.

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
graphite-app Bot force-pushed the om/07-11-refactor_ast_use_nonnull_for_ref_casting branch from 4aaaccc to 347c61b Compare July 11, 2026 18:03
@graphite-app
graphite-app Bot merged commit 347c61b into main Jul 11, 2026
29 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 om/07-11-refactor_ast_use_nonnull_for_ref_casting branch July 11, 2026 18:07
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants