Skip to content

Replace bun_core::hint::cold with core::hint::cold_path - #39601

Open
robobun wants to merge 3 commits into
mainfrom
farm/6f4e965c/use-core-hint-cold-path
Open

Replace bun_core::hint::cold with core::hint::cold_path#39601
robobun wants to merge 3 commits into
mainfrom
farm/6f4e965c/use-core-hint-cold-path

Conversation

@robobun

@robobun robobun commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Problem

  • src/bun_core/hint.rs has a cold() helper: an empty #[cold] #[inline(never)] function. A call to it marks the calling branch as cold.
  • Its TODO says: replace it with core::hint::cold_path() once Improve UEFI stdio rust-lang/rust#117174 stabilizes. cold_path is stable (and const) since Rust 1.95. The toolchain is nightly-2026-07-20 (rustc 1.99).

Fix

  • Replace the 25 calls to bun_core::hint::cold() (15 files) with core::hint::cold_path(). Delete src/bun_core/hint.rs and its pub mod hint; line.
  • Two branches lost the hint in the port and kept a comment that says stable Rust has no equivalent: MySQLRequestQueue::can_pipeline (its Postgres twin has the hint) and the force_loader_type branch in src/runtime/jsc_hooks.rs. Add cold_path() to both and delete the comments. src/ now has no branchHint or hint::cold left.
  • Both forms give LLVM the same hint. A two-crate sample compiled with rustc -O --emit=llvm-ir emits the same branch_weights (1 vs 2000) either way. The old cross-crate form also leaves a call to the empty function in the cold block. IR is in the notes.
  • Verified: bun bd builds. test/internal/source-lints/port-era-markers.test.ts gets a @branchHint entry. It fails on main (the three comments above) and passes here. The hint swap itself has no observable behavior to test. bun bd test test/js/node/module/require-extensions.test.ts passes too (more in the notes).

Background

  • rustc marks a basic block as cold when it calls a #[cold] function. It emits LLVM branch_weights on each branch into that block. LLVM lays the block out off the hot path.
  • The old helper used this rule with an empty #[cold] function. #[inline(never)] kept the call in place so the rule saw it. Outside bun_core that was a real cross-crate call until LTO removed it.
  • core::hint::cold_path() is an #[inline(always)] #[cold] wrapper around the cold_path intrinsic. The intrinsic is #[cold] too, so the same rule applies. The backend emits no instruction for it.
Notes

Sample (f is the same in both files, only the hint differs):

pub fn f(x: u32, y: &[u8]) -> u32 {
    if y.len() > 1000 {
        hintlib::cold();          // old: `#[cold] #[inline(never)] pub const fn cold() {}` in another crate
        // core::hint::cold_path(); // new
        return slow(x, y);
    }
    x + 1
}

Old (rustc -O --emit=llvm-ir):

start:
  %_3 = icmp samesign ugt i64 %y.1, 1000
  br i1 %_3, label %bb1, label %bb4, !prof !4
bb1:
  tail call void @_RNvCsjRIIex900ii_7hintlib4cold()
  %1 = tail call fastcc noundef i32 @slow(i32 noundef %x, i64 noundef %y.1)
  ...
!4 = !{!"branch_weights", !"expected", i32 1, i32 2000}

New:

start:
  %_3 = icmp samesign ugt i64 %y.1, 1000
  br i1 %_3, label %bb1, label %bb4, !prof !4
bb1:
  %1 = tail call fastcc noundef i32 @slow(i32 noundef %x, i64 noundef %y.1)
  ...
!4 = !{!"branch_weights", !"expected", i32 1, i32 2000}

Other checks: bun bd test also passes for test/js/bun/resolve/import-query.test.ts and test/js/bun/shell/env.positionals.test.ts. The call inside the macro_rules! body in src/bun_core/env_var.rs uses ::core::hint::cold_path(), like the other paths in that macro. rustfmt --check on the touched files is clean. Every touched crate recompiled in the bun bd run (fresh rlib hashes for bun_core, bun_jsc, bun_resolver, bun_http_jsc, bun_sql_jsc, bun_runtime). The grep over src/ is cfg-agnostic, so platform-gated code is covered. The first revision of this PR replaced the 25 calls only. The second commit adds the two restored sites after a review comment pointed at their stale comments. Rebased onto main once: #39575 had moved the first-dial block in js_valkey.rs into a new ensure_dialing(), so the hint call there moved with it. Still 25 replaced sites plus the 2 restored ones.


[review] gate passed · iteration 1 · 20 files touched

fails on main (without fix)
ASAN without fix: 1 FAILED
$ BUN_DEBUG_QUIET_LOGS=1 bun scripts/build.ts --profile=debug --quiet test "--reporter=junit" "--reporter-outfile=/tmp/mechgate.xml" test/internal/source-lints/port-era-markers.test.ts
bun test v1.4.0 (8326d1bd3)

test/internal/source-lints/port-era-markers.test.ts:
(pass) no stale port marker: /\bblocked_on\b/i [4.14ms]
(pass) no stale port marker: /``-gated\b/i [0.42ms]
(pass) no stale port marker: /\bun-gates\b/i [0.28ms]
(pass) no stale port marker: /\bun-gate\b(?!d)/i [0.27ms]
(pass) no stale port marker: /\bre-gated\b/i [0.27ms]
(pass) no stale port marker: /\bungated\b/i [0.26ms]
(pass) no stale port marker: /\bun-gated\b/i [0.32ms]
83 |       throw new Error(
84 |         `Found ${found.length} occurrence(s) of stale port-era marker ${pattern} in src/**/*.rs.\n` +
85 |           `Reason: ${reason}\n` +
86 |           `Locations${found.length > 20 ? ` (first 20 of ${found.length})` : ""}:\n` +
87 |           sample.map(l => `  ${l}`).join("\n"),
88 |       );
           ^
error: Found 3 occurrence(s) of stale port-era marker /@branchHint\b/i in src/**/*.rs.
Reason: '@branchHint' notes describe a hint the port dropped; the Rust spelling is core::hint::cold_pat
... (truncated)

release without fix: 1 FAILED
bun test v1.4.0-canary.1 (eab21d059)

test/internal/source-lints/port-era-markers.test.ts:
(pass) no stale port marker: /\bblocked_on\b/i [0.19ms]
(pass) no stale port marker: /``-gated\b/i
(pass) no stale port marker: /\bun-gates\b/i
(pass) no stale port marker: /\bun-gate\b(?!d)/i
(pass) no stale port marker: /\bre-gated\b/i
(pass) no stale port marker: /\bungated\b/i
(pass) no stale port marker: /\bun-gated\b/i
83 |       throw new Error(
84 |         `Found ${found.length} occurrence(s) of stale port-era marker ${pattern} in src/**/*.rs.\n` +
85 |           `Reason: ${reason}\n` +
86 |           `Locations${found.length > 20 ? ` (first 20 of ${found.length})` : ""}:\n` +
87 |           sample.map(l => `  ${l}`).join("\n"),
88 |       );
           ^
error: Found 3 occurrence(s) of stale port-era marker /@branchHint\b/i in src/**/*.rs.
Reason: '@branchHint' notes describe a hint the port dropped; the Rust spelling is core::hint::cold_path()
Locations:
  src/resolver/resolver.rs:1864
  src/runtime/jsc_hooks.rs:4466
  src/sql_jsc/mysql/MySQLRequestQueue.rs:76
      at <anonymous> (/workspace/bun/test/internal/source-lints/port-era-markers.test.ts:88:7)
(fail) no st
... (truncated)
passes on PR (with fix)
ASAN with fix: all passed
$ BUN_DEBUG_QUIET_LOGS=1 bun scripts/build.ts --profile=debug --quiet test "--reporter=junit" "--reporter-outfile=/tmp/mechgate.xml" test/internal/source-lints/port-era-markers.test.ts
bun test v1.4.0 (8326d1bd3)

test/internal/source-lints/port-era-markers.test.ts:
(pass) no stale port marker: /\bblocked_on\b/i [4.57ms]
(pass) no stale port marker: /``-gated\b/i [0.41ms]
(pass) no stale port marker: /\bun-gates\b/i [0.30ms]
(pass) no stale port marker: /\bun-gate\b(?!d)/i [0.27ms]
(pass) no stale port marker: /\bre-gated\b/i [0.27ms]
(pass) no stale port marker: /\bungated\b/i [0.29ms]
(pass) no stale port marker: /\bun-gated\b/i [0.32ms]
(pass) no stale port marker: /@branchHint\b/i [0.28ms]

 8 pass
 0 fail
 8 expect() calls
Ran 8 tests across 1 file. [66.34s]
__F:0:S:0

release with fix: all passed
$ bun scripts/build.ts --profile=release
[configured] bun-profile → bun (stripped)
  target       linux-x64-gnu
  build type   Release
  build dir    ./build/release
  revision     a61de7f485
  features     baseline

23 deps, 120 codegen, 1144 objects in 712ms

ninja: Entering directory `/workspace/bun/build/release'
[1/26] fetch rust-argon2
[rust-argon2] up to date
[2/26] gen generated_host_exports.rs
generated_host_exports.rs: 92 exports (host=3, lazy=10, generic=79, rust=0); 241 extern-C blocks audited
[3/26] gen BunProcess.lut.h
Generating /workspace/bun/build/release/codegen/BunProcess.lut.h from /workspace/bun/src/jsc/bindings/BunProcess.cpp
[4/26] gen cpp.rs (cppbind)
[5/26] gen JS modules (bundle-modules)
Preprocess modules (8606ms)
Bundle modules (52ms)
Postprocesss modules (223ms)
Bundle Functions (650ms)
Generate Code (33ms)

[9.59s] Bundled "src/js" for production
  2627 kb
  198 internal modules
  13 native modules
  92 internal functions across 17 files
[5/13] cargo bun_bin → libbun_rust.a (--target x86_64-unknown-linux-gnu)

  nightly-2026-07-20-x86_64-unknown-linux-gnu unchanged - rustc 1.99.0-nightly (9f36de775 2026-07-19)

�[1m�[92m   Compiling
... (truncated)
diff hotspot
src/bun_core/env_var.rs                              |  6 +++---
 src/bun_core/hint.rs                                 | 20 --------------------
 src/bun_core/lib.rs                                  |  1 -
 src/bun_core/string/immutable.rs                     |  2 +-
 src/http_jsc/websocket_client.rs                     |  4 ++--
 src/jsc/VirtualMachine.rs                            |  2 +-
 src/jsc/event_loop.rs                                |  2 +-
 src/resolver/resolver.rs                             |  5 ++---
 src/runtime/bake/DevServer.rs                        |  4 ++--
 src/runtime/cli/create/SourceFileProjectGenerator.rs |  2 +-
 src/runtime/ipc.rs                                   |  2 +-
 src/runtime/jsc_hooks.rs                             |  2 +-
 src/runtime/server/server_body.rs                    |  8 ++++----
 src/runtime/shell/EnvStr.rs                          |  2 +-
 src/runtime/valkey_jsc/js_valkey.rs                  |  4 ++--
 src/runtime/valkey_jsc/valkey.rs                     |  4 ++--
 src/sql_jsc/mysql/MySQLRequestQueue.rs               |  2 +-
 src/sql_jsc/postgres/DataCell.rs                     |  2 +-
 src/sql_jsc/postgres/PostgresSQLConnection.rs        |  2 +-
 test/internal/source-lints/port-era-markers.test.ts  |  4 ++++
 20 files changed, 31 insertions(+), 49 deletions(-)

gate history · 2 passed · 1 rejected · iteration 1

evidence per changed file
file                                                  reads  edits  tests
src/bun_core/env_var.rs                                   2      0      0
src/bun_core/hint.rs                                      0      0      0
src/bun_core/lib.rs                                       1      1      0
src/bun_core/string/immutable.rs                          0      0      0
src/http_jsc/websocket_client.rs                          0      0      0
src/jsc/VirtualMachine.rs                                 0      0      0
src/jsc/event_loop.rs                                     0      0      0
src/resolver/resolver.rs                                  1      1      0
src/runtime/bake/DevServer.rs                             0      0      0
src/runtime/cli/create/SourceFileProjectGenerator.rs      0      0      0
src/runtime/ipc.rs                                        0      0      0
src/runtime/jsc_hooks.rs                                  1      1      0
src/runtime/server/server_body.rs                         0      0      0
src/runtime/shell/EnvStr.rs                               0      0      0
src/runtime/valkey_jsc/js_valkey.rs                       1      2      0
src/runtime/valkey_jsc/valkey.rs                          0      0      0
(+ 4 more files)

@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: c5604289-57c1-4362-a884-82c0ca443092

📥 Commits

Reviewing files that changed from the base of the PR and between 681a49b and eab21d0.

📒 Files selected for processing (20)
  • src/bun_core/env_var.rs
  • src/bun_core/hint.rs
  • src/bun_core/lib.rs
  • src/bun_core/string/immutable.rs
  • src/http_jsc/websocket_client.rs
  • src/jsc/VirtualMachine.rs
  • src/jsc/event_loop.rs
  • src/resolver/resolver.rs
  • src/runtime/bake/DevServer.rs
  • src/runtime/cli/create/SourceFileProjectGenerator.rs
  • src/runtime/ipc.rs
  • src/runtime/jsc_hooks.rs
  • src/runtime/server/server_body.rs
  • src/runtime/shell/EnvStr.rs
  • src/runtime/valkey_jsc/js_valkey.rs
  • src/runtime/valkey_jsc/valkey.rs
  • src/sql_jsc/mysql/MySQLRequestQueue.rs
  • src/sql_jsc/postgres/DataCell.rs
  • src/sql_jsc/postgres/PostgresSQLConnection.rs
  • test/internal/source-lints/port-era-markers.test.ts
💤 Files with no reviewable changes (2)
  • src/bun_core/hint.rs
  • src/bun_core/lib.rs

Included review availability: Your plan provides up to 5 included reviews per hour; 1 remains after this review.


Walkthrough

The PR removes bun_core::hint::cold() and replaces its call sites with core::hint::cold_path(). It also adds source-lint detection for stale @branchHint comments.

Changes

Cold-path hint migration

Layer / File(s) Summary
Core hint replacement
src/bun_core/env_var.rs, src/bun_core/string/immutable.rs, src/bun_core/hint.rs, src/bun_core/lib.rs
Core cache and UTF-8 error paths use core::hint::cold_path(). The crate-local hint module and cold() function are removed.
Runtime and resolver migration
src/http_jsc/websocket_client.rs, src/jsc/*, src/resolver/resolver.rs, src/runtime/...
Runtime and resolver cold paths use core::hint::cold_path(). Existing control flow remains unchanged.
SQL paths and stale-marker validation
src/sql_jsc/..., test/internal/source-lints/port-era-markers.test.ts
SQL error and feature-flag paths use core::hint::cold_path(). The source lint detects stale @branchHint comments.

Suggested reviewers: jarred-sumner

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly summarizes the main change from bun_core::hint::cold to core::hint::cold_path().
Description check ✅ Passed The description explains the problem, fix, scope, and verification results, although it does not use the template headings exactly.

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

@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 — mechanical swap of the in-tree #[cold] #[inline(never)] helper for stdlib core::hint::cold_path(), per the TODO in the deleted file. The inline nit about two remaining stale @branchHint comments is optional cleanup and doesn't block.

Extended reasoning...

Overview

This PR resolves a TODO in src/bun_core/hint.rs: replace the hand-rolled #[cold] #[inline(never)] pub const fn cold() {} helper with the now-stable core::hint::cold_path() (Rust 1.95+; toolchain is on 1.99). It touches 17 files: 25 call sites mechanically rewritten from bun_core::hint::cold() / crate::hint::cold() / $crate::hint::cold() to core::hint::cold_path() (with ::core:: inside the macro_rules! body in env_var.rs, matching the file's other absolute-path ::core usages), the module file deleted, its pub mod hint; line removed from lib.rs, and one adjacent stale // @branchHint(.unlikely) comment dropped in resolver.rs.

Security risks

None. This is a compiler-hint-only change with no runtime semantics — both forms emit identical LLVM branch_weights metadata (verified in the PR description with an IR diff). No user input, no auth/crypto, no data handling.

Level of scrutiny

Low. This is exactly the mechanical TODO-resolution the deleted file's own doc comment requested. Every hunk is a one-line s/bun_core::hint::cold()/core::hint::cold_path()/ (or crate:: / $crate:: variant); no surrounding logic changes. The compiler enforces correctness — a wrong path or missed call site would fail bun bd, which the author ran. A post-PR grep for hint::cold and bun_core::hint over src/ confirms no stragglers (including cfg-gated code).

Other factors

  • The one reported finding is a nit: two sibling // @branchHint … no stable Rust equivalent comments in src/sql_jsc/mysql/MySQLRequestQueue.rs:76 and src/runtime/jsc_hooks.rs:4470 are now factually stale. Those sites never called bun_core::hint::cold() (the porters dropped the hint entirely), so the PR's hint::cold grep wouldn't have found them. It's a fair same-class cleanup suggestion but comment-only and non-blocking.
  • No test is added, which is correct per REVIEW.md — there is no observable behavior to test; this is an optimizer hint swap.
  • No prior human or bot review comments to address (CodeRabbit was rate-limited).
  • Delete dead code in the same PR that makes it dead is satisfied: the helper module and its pub mod line are removed.

Comment thread src/resolver/resolver.rs
@robobun

robobun commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

Status: ready for review. Rebased onto main (one trivial conflict in js_valkey.rs, the hint moved into the new ensure_dialing()).

  • 8b59b71: the 25 bun_core::hint::cold() calls now call core::hint::cold_path(), and src/bun_core/hint.rs is deleted.
  • 2932870: the two branches that dropped the hint in the port (MySQLRequestQueue::can_pipeline and the force_loader_type branch in jsc_hooks.rs) get the hint, and their stale comments are gone.
  • a61de7f: test/internal/source-lints/port-era-markers.test.ts bans @branchHint comments. It fails on main (three hits) and passes on this branch.

bun bd builds on the rebased tree. Both bot reviews report nothing left to address.

@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 addressing the two stale @branchHint comments in b3eca49; rg 'branchHint' and rg 'hint::cold' over src/ are now both clean.

What was reviewed:

  • All 25+2 call sites are 1:1 swaps to core::hint::cold_path(); no surrounding logic changed.
  • The macro_rules! site in env_var.rs uses the ::core:: path, matching the neighboring ::core::str::from_utf8 hygiene.
  • hint.rs and its pub mod hint; line are removed; no remaining references in src/ (including cfg-gated code).
  • Toolchain is nightly-2026-07-20 (rustc 1.99); cold_path stabilized in 1.95.
Extended reasoning...

Overview

This PR replaces the in-tree bun_core::hint::cold() helper (an empty #[cold] #[inline(never)] fn) with the now-stable core::hint::cold_path() intrinsic across 25 call sites in 15 files, deletes src/bun_core/hint.rs and its pub mod line, and — in a follow-up commit responding to the prior review — replaces two stale "no stable Rust equivalent" comments with core::hint::cold_path() at jsc_hooks.rs:4470 and MySQLRequestQueue.rs:76.

Security risks

None. This is a compiler-hint swap with no runtime semantics — both forms emit identical branch_weights metadata and the new form emits strictly fewer instructions (no cross-crate call in the cold block). No user input, no allocation, no control-flow change.

Level of scrutiny

Low. Every hunk is a mechanical one-line substitution inside an existing branch body; the enclosing logic is untouched. The helper's own TODO named this exact replacement. rust-toolchain.toml confirms rustc 1.99 (≥ 1.95 where cold_path stabilized), so availability is verified. The macro-body call correctly uses the ::core:: absolute path matching neighboring ::core:: usage in that macro. bun bd was run per the description, so all touched crates compiled.

Other factors

The prior run's 🟡 nit (two remaining @branchHint comments claiming no stable equivalent) has been addressed in commit b3eca49 — both sites now carry core::hint::cold_path();. Post-PR greps for branchHint and hint::cold over src/ return nothing, confirming the sweep is complete including cfg-gated platform code. No tests are added, which is correct: there is no observable behavior to assert on for an optimizer hint. The dead module is deleted in the same PR per REVIEW.md's "delete dead code in the same PR that makes it dead".

@robobun

robobun commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author
Updated 6:45 PM PT - Aug 18th, 2026

@robobun, your commit a61de7f48534919482e4903c828505cb3f54f271 passed in Build #100970! 🎉


🧪   To try this PR locally:

bunx bun-pr 39601

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

bun-39601 --bun

@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 — mechanical swap of the in-tree #[cold] shim for the now-stable core::hint::cold_path(), plus the two restored hints from the earlier review comment.

What was reviewed:

  • Confirmed all 27 call sites now use core::hint::cold_path() and src/ has no remaining hint::cold / bun_core::hint / @branchHint references; pub mod hint; is gone.
  • The macro-body call in env_var.rs correctly uses the ::core:: absolute path like its neighbors.
  • The new lint entry in port-era-markers.test.ts only scans comment lines, so it won't false-positive on the intrinsic itself.
Extended reasoning...

Overview

This PR replaces the in-tree bun_core::hint::cold() shim (an empty #[cold] #[inline(never)] fn whose own TODO said to swap it for core::hint::cold_path() once stabilized) with the stdlib intrinsic across 25 call sites in 15 files, deletes src/bun_core/hint.rs and its pub mod line, restores the hint at two sites that dropped it during the Zig→Rust port with stale "no stable Rust equivalent" comments (MySQLRequestQueue::can_pipeline, jsc_hooks.rs force_loader_type branch), and adds a @branchHint entry to the port-era-markers source lint.

Security risks

None. cold_path() is a codegen hint with no runtime semantics; the change is a 1:1 substitution of one branch-weight annotation mechanism for another that produces identical LLVM branch_weights metadata (verified by the author with --emit=llvm-ir). No user input, no I/O, no control-flow changes.

Level of scrutiny

Low. This is the canonical "delete the shim once stdlib stabilizes the real thing" cleanup — mechanical find-and-replace with no observable behavior change. The two newly-hinted branches (b3eca49) are an env-var feature-flag check and an override-loader fast path, both obviously cold and matching their siblings (the Postgres can_pipeline already had the hint). The lint addition follows the existing pattern in the file exactly and is scoped to comment lines only.

Other factors

The one review comment I left on the first revision (two remaining stale @branchHint comments) was addressed in b3eca49 and the thread is resolved. I re-grepped src/ on the current tree: 27 core::hint::cold_path() sites, zero hint::cold/bun_core::hint/branchHint hits, and pub mod hint is gone from bun_core/lib.rs. bun bd builds per the author, and the new lint test was verified to fail on main and pass here.

core::hint::cold_path is stable since Rust 1.95. The toolchain is
nightly-2026-07-20. Call it directly at the 25 call sites and delete
the bun_core::hint module.
MySQLRequestQueue::can_pipeline now matches its Postgres twin. The
jsc_hooks force_loader branch gets the hint its comment said was
dropped.
This change removes the last three. The lint keeps them out and names
core::hint::cold_path() as the replacement.
@robobun
robobun force-pushed the farm/6f4e965c/use-core-hint-cold-path branch from eab21d0 to a61de7f Compare August 19, 2026 01:11

@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 — mechanical swap of the in-tree #[cold] shim for the now-stable core::hint::cold_path(), plus deletion of the dead module and a lint entry to keep @branchHint comments from reappearing.

What was reviewed:

  • Verified all 27 call sites (25 replaced + 2 restored from stale comments) now use core::hint::cold_path(); no bun_core::hint, hint::cold, or @branchHint remain in src/.
  • The macro-body site in env_var.rs correctly uses the ::core:: absolute path.
  • The two sites flagged in the earlier review round (MySQLRequestQueue::can_pipeline, jsc_hooks.rs force_loader_type) now match their siblings and the stale comments are gone.
Extended reasoning...

Overview

This PR replaces the in-tree bun_core::hint::cold() helper (an empty #[cold] #[inline(never)] function whose call marks the surrounding branch cold) with the now-stable core::hint::cold_path() intrinsic. It touches 20 files: 18 Rust source files where the call is swapped 1:1, src/bun_core/hint.rs (deleted), src/bun_core/lib.rs (pub mod hint; removed), and the port-era-markers source-lint test (new @branchHint pattern). Two additional sites in MySQLRequestQueue.rs and jsc_hooks.rs gain a cold_path() call where the port had dropped the hint and left a now-false "no stable Rust equivalent" comment — these were flagged in an earlier review round and addressed.

Security risks

None. This is a compiler branch-prediction hint with no observable runtime semantics beyond code layout. No inputs are parsed, no data flows change, no allocations or lifetimes are affected.

Level of scrutiny

Low. The change is a mechanical find-and-replace whose equivalence the PR author verified at the LLVM IR level (identical branch_weights metadata; the old form additionally emitted a dead cross-crate call in the cold block that LTO would remove). The helper's own doc comment carried a TODO pointing at exactly this replacement once rust-lang/rust#117174 stabilized, which it has (Rust 1.95; toolchain is 1.99). bun bd builds and the touched crates all recompiled per the PR notes.

Other factors

  • I grepped src/ post-change: 27 core::hint::cold_path() sites, zero remaining bun_core::hint / hint::cold / @branchHint references, and lib.rs no longer mentions hint.
  • The macro expansion in env_var.rs correctly uses ::core::hint::cold_path() (absolute path) matching the other ::core:: uses in that macro body.
  • The added lint entry follows the existing pattern in port-era-markers.test.ts exactly and only inspects lines containing //, so it cannot false-positive on identifiers or string literals.
  • The prior inline comment I left about the two sibling @branchHint comments has been addressed and the thread resolved.
  • The mechanical gate confirms the lint test fails on main (3 hits) and passes here, and both debug/ASAN and release builds succeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants