refactor: swap core::hint::cold_path for a stable #[cold] shim - #102
Merged
Conversation
`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.
This was referenced Jul 13, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
-C target-cpu=nativeIpv4NetworkDiff::nextIpv4NetworkDiff::next_backIpv6NetworkDiff::nextIpv6NetworkDiff::next_backNo
callis emitted at any of the three sites, no register spills appear in the hot loops, and the rescue branch keeps its.text.unlikelyplacement. 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.