compat(nightly-2025-07-05): IndexedVal goes private#147
Open
cds-amal wants to merge 3 commits intostack/pr5-cifrom
Open
compat(nightly-2025-07-05): IndexedVal goes private#147cds-amal wants to merge 3 commits intostack/pr5-cifrom
cds-amal wants to merge 3 commits intostack/pr5-cifrom
Conversation
16efe7e to
ae12130
Compare
ae12130 to
9e0b227
Compare
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.
Nightly 2025-07-05 makes the
IndexedValtraitpub(crate), which means external code (that's us) can no longer callto_index()orto_val()on types likeTy,Span,AllocId, andVariantIdx. These calls are scattered across the codebase: the printer uses them for deterministic sorting, the graph renderer uses them for index labels, and the receipts system needs them for interned-index detection.The fix is a compat shim (
src/compat/indexed_val.rs) that provides free functionsto_indexandto_valworking on both sides of the breakpoint:to_indexuses a minimal serdeSerializerthat extracts the innerusizefrom the newtype's#[derive(Serialize)]implementation.to_valgoes the other direction viatransmute_copywith a compile-time size assertion. These types are all single-field newtypes aroundusize, so the layout is guaranteed; the size check is belt-and-suspenders.The serde trick deserves a moment's pause: rather than reaching into rustc internals or duplicating private type definitions, we exploit the fact that
Ty(42)serializes as42through serde's derive machinery. ASerializerthat only implementsserialize_newtype_structandserialize_u64can recover the inner value with zero unsafe code on the extraction side. Thetransmute_copyfor reconstruction is the one unavoidableunsafeblock, and it's constrained to types that pass the size assertion. @dkcumming, please fact check me here.All call sites (
collect.rs,mir_visitor.rs,types.rs,mk_graph/context.rs,mk_graph/index.rs,mk_graph/util.rs) are updated to use the free functions instead of the trait methods.Test plan
cargo buildpasses with nightly-2025-07-05cargo clippy -- -Dwarningspassesmake integration-testpasses (golden files for nightly-2025-07-05 included)cargo buildstill passes with nightly-2025-03-01 (backward compat)