Skip to content

refactor(allocator): improve safety of dealloc_chunk_list#21779

Merged
graphite-app[bot] merged 1 commit intomainfrom
om/04-26-refactor_allocator_improve_safety_of_dealloc_chunk_list_
Apr 26, 2026
Merged

refactor(allocator): improve safety of dealloc_chunk_list#21779
graphite-app[bot] merged 1 commit intomainfrom
om/04-26-refactor_allocator_improve_safety_of_dealloc_chunk_list_

Conversation

@overlookmotel
Copy link
Copy Markdown
Member

@overlookmotel overlookmotel commented Apr 26, 2026

Improve the safety of Arena's dealloc_chunk_list function:

  • Ensure &ChunkFooter reference is not live when the chunk containing that ChunkFooter is deallocated.
  • Scope unsafe { ... } blocks to cover just the statements that require them.
  • Document the safety invariants.

I don't believe there was a soundness issue here (as &ChunkFooter references were short-lived), but this change makes the importance of avoiding live references clear, and explicitly guards against it.

Copy link
Copy Markdown
Member Author

overlookmotel commented Apr 26, 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 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.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 26, 2026

Merging this PR will not alter performance

✅ 48 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing om/04-26-refactor_allocator_improve_safety_of_dealloc_chunk_list_ (5e7dbac) with om/04-26-refactor_allocator_reduce_scope_of_unsafe_blocks_in_arena_chunk_iterators (6889c46)

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.

@overlookmotel overlookmotel force-pushed the om/04-26-refactor_allocator_reduce_scope_of_unsafe_blocks_in_arena_chunk_iterators branch from 67ff1f2 to a82c143 Compare April 26, 2026 12:27
@overlookmotel overlookmotel force-pushed the om/04-26-refactor_allocator_improve_safety_of_dealloc_chunk_list_ branch from 8f6d4d9 to a44ec68 Compare April 26, 2026 12:27
@overlookmotel overlookmotel marked this pull request as ready for review April 26, 2026 18:46
Copilot AI review requested due to automatic review settings April 26, 2026 18:46
Copy link
Copy Markdown
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

This PR refactors Arena’s chunk deallocation helper to make aliasing/lifetime boundaries around ChunkFooter references explicit, reduce the scope of unsafe blocks, and document the safety assumptions involved in freeing arena chunks.

Changes:

  • Refactors dealloc_chunk_list to ensure &ChunkFooter borrows are not live across dealloc.
  • Narrows unsafe blocks to only the operations that require them.
  • Adds safety documentation/comments explaining required invariants.

Comment thread crates/oxc_allocator/src/arena/drop.rs
Comment thread crates/oxc_allocator/src/arena/drop.rs Outdated
@overlookmotel overlookmotel changed the base branch from om/04-26-refactor_allocator_reduce_scope_of_unsafe_blocks_in_arena_chunk_iterators to graphite-base/21779 April 26, 2026 20:47
@overlookmotel overlookmotel force-pushed the om/04-26-refactor_allocator_improve_safety_of_dealloc_chunk_list_ branch from a44ec68 to e689974 Compare April 26, 2026 20:48
@overlookmotel overlookmotel changed the base branch from graphite-base/21779 to om/04-26-refactor_allocator_reduce_scope_of_unsafe_blocks_in_arena_chunk_iterators April 26, 2026 20:48
@overlookmotel overlookmotel force-pushed the om/04-26-refactor_allocator_improve_safety_of_dealloc_chunk_list_ branch from e689974 to 75bb873 Compare April 26, 2026 21:15
@graphite-app
Copy link
Copy Markdown
Contributor

graphite-app Bot commented Apr 26, 2026

Merge activity

Improve the safety of `Arena`'s `dealloc_chunk_list` function:

- Ensure `&ChunkFooter` reference is not live when the chunk containing that `ChunkFooter` is deallocated.
- Scope `unsafe { ... }` blocks to cover just the statements that require them.
- Document the safety invariants.

I don't believe there was a soundness issue here (as `&ChunkFooter` references were short-lived), but this change makes the importance of avoiding live references clear, and explicitly guards against it.
@graphite-app graphite-app Bot force-pushed the om/04-26-refactor_allocator_reduce_scope_of_unsafe_blocks_in_arena_chunk_iterators branch from 1d77796 to 6889c46 Compare April 26, 2026 21:52
@graphite-app graphite-app Bot requested a review from camc314 as a code owner April 26, 2026 21:52
@graphite-app graphite-app Bot force-pushed the om/04-26-refactor_allocator_improve_safety_of_dealloc_chunk_list_ branch from 75bb873 to 5e7dbac Compare April 26, 2026 21:53
Base automatically changed from om/04-26-refactor_allocator_reduce_scope_of_unsafe_blocks_in_arena_chunk_iterators to main April 26, 2026 22:09
@graphite-app graphite-app Bot merged commit 5e7dbac into main Apr 26, 2026
38 checks passed
@graphite-app graphite-app Bot deleted the om/04-26-refactor_allocator_improve_safety_of_dealloc_chunk_list_ branch April 26, 2026 22:10
@overlookmotel overlookmotel added C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior A-allocator Area - Allocator labels Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-allocator Area - Allocator C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants