Skip to content

bun_alloc: delete unused MimallocHeapRef, TypedArena, BumpWithFallback#31542

Merged
dylan-conway merged 2 commits into
mainfrom
claude/dead-code-bun-alloc
May 29, 2026
Merged

bun_alloc: delete unused MimallocHeapRef, TypedArena, BumpWithFallback#31542
dylan-conway merged 2 commits into
mainfrom
claude/dead-code-bun-alloc

Conversation

@dylan-conway

@dylan-conway dylan-conway commented May 29, 2026

Copy link
Copy Markdown
Member

Dead-code sweep of bun_alloc. None referenced outside their own definitions.

cargo check --workspace passes.

Why this code exists

Item Zig original Zig callers Status
MimallocHeapRef none (0 hits in *.zig) n/a Rust-port artifact — speculative Allocator impl over raw *mut mi_heap_t, added in 9532c84; superseded by ArenaPtr, never referenced outside src/bun_alloc/
TypedArena<T> none (0 hits for typed_arena/TypedArena in *.zig) n/a Rust-port artifact — re-export of typed_arena::Arena added in 76a5089, never referenced
BumpWithFallback none n/a Rust-port artifact — was the original struct name in 9532c84, renamed to StackFallback in 4075846 leaving this "back-compat alias"; no external caller ever existed
StackFallback::fallback_mut none — Zig std.heap.StackFallbackAllocator exposes fallback_allocator as a public field (e.g. src/js_printer/renamer.zig:496,532), no method accessor n/a Rust-port artifact — Rust-idiom getter (fields are private in the Rust port); the immutable fallback() is used, this &mut variant never was
init_default<T> src/bun_alloc/memory.zig:36 (initDefault) 15 — e.g. src/ptr/owned.zig:58,64,111,147, src/ptr/shared.zig:100, src/collections/array_list.zig:70,81,165, src/threading/guarded.zig:19 Rust callers were rewritten to plain T::default() over 1f86fa6 / 87d8efd / 98ba4b1 / 21daace; the wrapper is now identity
MaybeOwned::into_parent src/bun_alloc/maybe_owned.zig:76 (intoParent) 0 external — only called internally by deinit at :48 dead in Zig too (public but only self-consumed)

@robobun

robobun commented May 29, 2026

Copy link
Copy Markdown
Collaborator
Updated 12:08 AM PT - May 29th, 2026

@dylan-conway, your commit 3b1c8cc has 1 failures in Build #58864 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 31542

That installs a local version of the PR into your bun-31542 executable, so you can run:

bun-31542 --bun

@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@dylan-conway, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 13 minutes and 6 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: ff743c33-ed1f-47ec-a3ec-6e4183658a7e

📥 Commits

Reviewing files that changed from the base of the PR and between 7c5c330 and 3b1c8cc.

📒 Files selected for processing (1)
  • src/bun_alloc/memory.rs

Walkthrough

This PR removes several unused or deprecated public APIs from the bun_alloc module, including the BumpWithFallback type alias, MimallocHeapRef allocator wrapper, TypedArena type alias, and helper methods into_parent() and init_default(). The crate's public re-export surface is narrowed to only ArenaPtr and StackFallback.

Changes

Allocator API cleanup and deprecation

Layer / File(s) Summary
Stack/fallback allocator module cleanup
src/bun_alloc/stack_fallback.rs
BumpWithFallback type alias, StackFallback::fallback_mut method, and MimallocHeapRef allocator wrapper with its Allocator trait implementation are removed.
Crate API surface narrowing
src/bun_alloc/lib.rs
TypedArena type alias is removed from crate root, and stack_fallback re-exports are narrowed to only ArenaPtr and StackFallback, removing BumpWithFallback and MimallocHeapRef.
Supporting API removals
src/bun_alloc/maybe_owned.rs, src/bun_alloc/memory.rs
into_parent() consuming method is removed from MaybeOwned<A>, and init_default() helper function is removed from the memory module.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically identifies the main change: removal of three unused type aliases (MimallocHeapRef, TypedArena, BumpWithFallback) from bun_alloc.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description is well-structured and provides comprehensive justification for removing dead code, with a detailed table documenting each item's origin and why it's no longer needed.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@claude claude Bot 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.

LGTM — pure dead-code removal; just clean up the two leftover doc-comment lines in memory.rs noted inline.

Extended reasoning...

Overview

This PR is a dead-code sweep of the bun_alloc crate, removing six items: the MimallocHeapRef struct and its Allocator impl, the TypedArena<T> type alias, the BumpWithFallback back-compat alias, StackFallback::fallback_mut, the trivial init_default<T> wrapper, and MaybeOwned::into_parent. The diff is purely subtractive (no logic added or modified), plus a corresponding trim of the pub use stack_fallback::{...} re-export list in lib.rs.

I grepped the full repo for MimallocHeapRef|TypedArena|BumpWithFallback|fallback_mut|init_default|into_parent and confirmed there are no remaining references outside unrelated libarchive patch text and a stale comment. The PR description's claim that cargo check --workspace passes is consistent with this — if any caller had remained, the build would have failed on the removed re-exports.

Security risks

None. This is removal of unused allocator-adapter types and helpers; no input handling, auth, crypto, or permission surfaces are touched. Deleting an unused unsafe impl Allocator strictly reduces the unsafe surface area.

Level of scrutiny

Low. Pure deletions where the compiler is the ground truth — if anything were still referenced, cargo check would fail. The only behavioral question ("is this really dead?") is mechanically verifiable and I verified it.

Other factors

The bug hunter flagged one nit: the init_default deletion left the first two lines of its /// doc comment behind in memory.rs, which now silently attach to rebase_slice via rustdoc's outer-attribute rules. This is a real but cosmetic docs-only issue — worth fixing, but not a reason to block. There's also a now-stale comment at src/bun_alloc/maybe_owned.rs:84 that still mentions into_parent(self); harmless, but could be tidied in the same pass. Neither affects runtime behavior, so I'm approving.

Comment thread src/bun_alloc/memory.rs Outdated

@claude claude Bot 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.

LGTM — thanks for fixing the orphaned doc-comment in 3b1c8cc; the two remaining inline notes are non-blocking nits (stale comment text + unused Cargo dep).

Extended reasoning...

Overview

This PR is a pure dead-code sweep of bun_alloc: it deletes MimallocHeapRef (a speculative Allocator impl superseded by ArenaPtr), the TypedArena<T> re-export alias, the BumpWithFallback back-compat alias, StackFallback::fallback_mut, memory::init_default<T>, and MaybeOwned::into_parent. The diff is deletion-only across four files plus narrowing one pub use line. The PR description includes a per-item provenance table tracing each removal to its origin commit and confirming zero external callers.

Security risks

None. Every change is a removal of an unreferenced public item; no remaining code path is modified. The retained unsafe code in stack_fallback.rs (StackFallback, ArenaPtr) and memory.rs (rebase_slice) is unchanged. No allocator behavior, FFI surface, or memory-safety invariant is touched.

Level of scrutiny

Low. This is mechanical dead-code deletion in an internal allocator support crate, verified by cargo check --workspace and confirmed by grep — the only remaining hit on any deleted name in the workspace is the stale prose comment flagged inline. There are no design decisions, no behavioral changes, and no test regressions possible from removing code that nothing calls.

Other factors

I previously flagged leftover init_default doc-comment lines on commit 7c5c330; the author addressed that in follow-up commit 3b1c8cc, and the current memory.rs is clean. The two new inline findings from this run are both explicitly nits: (1) a trailing comment clause in maybe_owned.rs that still mentions the deleted into_parent, and (2) the now-unused typed-arena.workspace = true entry in src/bun_alloc/Cargo.toml. Neither affects compilation, runtime, or docs rendering — they're cleanup-completeness suggestions that don't block merging.

Comment on lines 72 to 74
/// Used by smart pointer types and allocator wrappers. See `crate::borrow`.
pub fn borrow(&self) -> MaybeOwnedBorrowed {
// Borrowed view carries no allocator state — just the owned/borrowed bit.

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.

🟡 The trailing comment block at the bottom of this file still says "keeping one would also forbid moving self._parent out in into_parent(self)" — but into_parent is deleted in this PR. Drop that clause; the preceding sentence about field drop glue stands on its own. Same class of leftover as the init_default doc-comment fixed in 3b1c8cc.

Extended reasoning...

What the issue is

This PR deletes MaybeOwned::into_parent(self) -> Option<A> from src/bun_alloc/maybe_owned.rs. However, the rationale comment at the bottom of the file (post-diff lines 81-84) still references it:

Per PORTING.md (Idiom map: pub fn deinit), that is exactly field drop glue on _parent: Option<A>, so no explicit Drop impl — keeping one would also forbid moving self._parent out in into_parent(self).

The bolded clause cites into_parent(self) as a second reason for omitting an explicit Drop impl. With into_parent gone, that reason no longer exists in the codebase, so the comment now points readers at a method they cannot find.

Step-by-step proof

  1. Pre-PR, maybe_owned.rs defined pub fn into_parent(self) -> Option<A> { self._parent } at lines 72-76.
  2. The diff for this PR shows that block removed (the - pub fn into_parent(self) -> Option<A> { … hunk).
  3. Post-PR, the file ends with the comment block at lines 81-84, whose final clause reads verbatim: "keeping one would also forbid moving self._parent out in into_parent(self)."
  4. grep -rn into_parent src/ after the PR returns only this comment line — there is no longer any into_parent definition or call site for it to refer to.
  5. Therefore the clause is dangling: it justifies a design choice by appeal to a constraint that has been deleted.

Why nothing catches it

This is a plain // line comment, not a doc comment, so neither cargo check nor cargo doc parses its contents. There is no intra-doc link to break. The PR description's "cargo check --workspace passes" is consistent with this being purely a prose artifact.

Impact

No runtime or compile-time effect. The cost is reader confusion: someone auditing why MaybeOwned has no Drop impl will go looking for into_parent and not find it. Since this PR is explicitly a dead-artifact sweep — and the same class of leftover (the orphaned init_default doc-comment lines in memory.rs) was already cleaned up in follow-up commit 3b1c8cc — it's worth removing for consistency.

Fix

Trim the trailing clause so the comment ends after the first reason, e.g.:

// Zig `deinit` only forwarded to `bun.memory.deinit(parent_alloc)` on the owned field.
// Per PORTING.md (Idiom map: `pub fn deinit`), that is exactly field drop glue on
// `_parent: Option<A>`, so no explicit `Drop` impl.

The field-drop-glue rationale is sufficient on its own; the into_parent clause was always a secondary "and besides" point.

Comment thread src/bun_alloc/lib.rs
Comment on lines 326 to 327
__s
}};

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.

🟡 Removing the TypedArena<T> alias drops the only reference to the typed_arena crate inside bun_alloc, but src/bun_alloc/Cargo.toml:30 still declares typed-arena.workspace = true. Since this PR is a dead-code sweep, drop the now-unused crate-level dependency too (the workspace root entry stays — ast, js_parser, css, etc. depend on it directly).

Extended reasoning...

What the issue is

The PR deletes pub type TypedArena<T> = typed_arena::Arena<T>; from src/bun_alloc/lib.rs. That line was the only reference to the typed_arena crate anywhere under src/bun_alloc/. However, the crate manifest still lists it:

# src/bun_alloc/Cargo.toml:30
typed-arena.workspace = true

After this PR, that dependency entry is dead weight in bun_alloc's Cargo.toml.

Step-by-step proof

  1. Before the PR, rg -i 'typed.arena' src/bun_alloc/ returned two hits: the Cargo.toml dependency line and the pub type TypedArena<T> = typed_arena::Arena<T>; re-export in lib.rs.
  2. This PR's diff removes the lib.rs line (the only .rs reference).
  3. After the PR, the same grep returns only src/bun_alloc/Cargo.toml:30:typed-arena.workspace = true — verified against the checked-out PR head. No use typed_arena, no path references, no extern crate, nothing in lib.rs or any submodule.
  4. Therefore typed-arena is compiled into bun_alloc's dependency graph but never used by it.

Why nothing catches it

cargo check --workspace (which the PR description cites as passing) does not warn on unused [dependencies] entries — that's the domain of cargo-udeps / cargo-machete, neither of which runs in this CI. So the leftover entry silently survives the build.

Also note: typed-arena remains a legitimate workspace dependency — ast, js_parser, css, and others list it in their own Cargo.tomls and use typed_arena::Arena directly (not via the removed bun_alloc::TypedArena alias, which the PR description confirms was "never referenced"). So only the bun_alloc crate-level entry should go; the [workspace.dependencies] root entry stays.

Impact

None at runtime. The only cost is a spurious edge in bun_alloc's build graph and a stale manifest line that contradicts the PR's stated goal ("dead-code sweep of bun_alloc. None referenced outside their own definitions"). Flagging it because incomplete cleanup in a cleanup PR is exactly the kind of thing that's easier to fix now than to rediscover later.

Fix

Delete line 30 from src/bun_alloc/Cargo.toml:

-typed-arena.workspace = true

@dylan-conway dylan-conway merged commit a3e0d1f into main May 29, 2026
74 of 75 checks passed
@dylan-conway dylan-conway deleted the claude/dead-code-bun-alloc branch May 29, 2026 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants