Skip to content

refactor: swap core::hint::cold_path for a stable #[cold] shim - #102

Merged
3Hren merged 1 commit into
mainfrom
refactor/cold-path-stable
Jul 13, 2026
Merged

refactor: swap core::hint::cold_path for a stable #[cold] shim#102
3Hren merged 1 commit into
mainfrom
refactor/cold-path-stable

Conversation

@3Hren

@3Hren 3Hren commented Jul 13, 2026

Copy link
Copy Markdown
Member

core::hint::cold_path() is stable only since Rust 1.95, which made it the single reason the library could not build on any earlier toolchain. It is replaced by a private empty #[cold] #[inline(never)] function: LLVM proves the empty body side-effect free and deletes the call, so all that survives is the block-placement hint the attribute carries — exactly what the intrinsic provides.

The three call sites sit in the hot loops of the difference iterators, where the hint keeps the rare rescue scan off the loop-carried dependency chain, so the swap was verified by disassembly rather than by inspection.

Verification

Emitted code for the four affected functions, before vs after:

Function baseline x86-64 -C target-cpu=native
Ipv4NetworkDiff::next identical identical
Ipv4NetworkDiff::next_back identical identical
Ipv6NetworkDiff::next identical identical
Ipv6NetworkDiff::next_back identical identical

No call is emitted at any of the three sites, no register spills appear in the hot loops, and the rescue branch keeps its .text.unlikely placement. The only change to the object file is the never-called stub itself — byte-identical machine code makes benchmarking moot.

With this the library compiles on Rust 1.88 (cargo +1.88.0 check --lib); declaring the MSRV follows in a separate PR.

`core::hint::cold_path()` is stable only since Rust 1.95, which made it the
single reason the library could not build on any earlier toolchain. It is
replaced by a private empty `#[cold] #[inline(never)]` function: LLVM proves
the empty body side-effect free and deletes the call, so all that survives is
the block-placement hint the attribute carries — exactly what the intrinsic
provides.

The three call sites sit in the hot loops of the difference iterators, where
the hint keeps the rare rescue scan off the loop-carried dependency chain, so
the swap was verified by disassembly rather than by inspection: the emitted
code for `Ipv4NetworkDiff::next`/`next_back` and `Ipv6NetworkDiff::next`/
`next_back` is byte-identical before and after, under both baseline x86-64 and
`-C target-cpu=native`. The only change to the object file is the (never
called) stub itself.

With this the library compiles on Rust 1.88.
@3Hren
3Hren merged commit 90c581a into main Jul 13, 2026
5 checks passed
@3Hren
3Hren deleted the refactor/cold-path-stable branch July 14, 2026 07:00
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.

1 participant