Factor: collapse triplicated alloc recovery into one arm#135
Merged
automergerpr-permission-manager[bot] merged 3 commits intomasterfrom Mar 3, 2026
Merged
Factor: collapse triplicated alloc recovery into one arm#135automergerpr-permission-manager[bot] merged 3 commits intomasterfrom
automergerpr-permission-manager[bot] merged 3 commits intomasterfrom
Conversation
builtin_deref takes &self, so the .clone() on kind before calling it is unnecessary.
Replace the terse "unrelated to this regression" comment with a detailed explanation: def_id values are interned compiler indices (same class as alloc_id and adt_def) that are stable within a run but non-deterministic across runs. Downstream consumers need them as cross-reference keys for AggregateKind::Adt joins, so they can't be dropped from the output; the filter strips them only for golden-file comparison.
dkcumming
approved these changes
Mar 3, 2026
Collaborator
dkcumming
left a comment
There was a problem hiding this comment.
Nice! Tested downstream with mir-semantics (682df6b2dfec4ec0516e246f22b70dff09cf57a6) test suite which is passing
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.
This is a follow-up to #131. That PR fixed a real panic (non-builtin-deref Static/VTable allocations), but the fix landed as three nearly identical match arms: Static, VTable, and Function, each repeating the same "try
get_prov_ty, fall back to opaque placeholder" logic. The only meaningful difference between them was a single predicate ("is this type usable directly?") and the debug log string. This PR collapses them back into one arm, makes the predicate explicit, and documents a previously unexplained jq filter.What changed
src/printer/mir_visitor.rsThe three arms now share a single code path. The predicate that actually differs between them is captured in a
needs_recoveryvariable:builtin_deref(true).is_none()(not a reference, raw pointer, or Box)!kind.is_fn_ptr()(outer type isn't already a function pointer)Worth noting: these two predicates are not equivalent (a function pointer passes
builtin_derefbut failsis_fn_ptr), which is why a naive "just combine the arms" without the inner match would have changed behavior for Function allocs. The inner match onglobal_allocmakes this asymmetry visible rather than hiding it across separate arms.The rest of the logic (try
get_prov_ty, fall back to opaque placeholder) is written once. Also dropped an unnecessary.clone()on thebuiltin_derefcall; it takes&self.tests/integration/normalise-filter.jqThe
def_idfilter had a terse comment ("unrelated to this regression") that didn't explain why it exists or why it's safe to strip globally. Replaced it with a proper explanation:def_idvalues are interned compiler indices (same class asalloc_idandadt_def) that are consistent within a single rustc invocation but non-deterministic across runs. Downstream consumers need them as cross-reference keys to joinAggregateKind::Adtin MIR bodies with type metadata entries, so they can't be dropped from the output itself; we only strip them here for golden-file comparison. (See #125 for the full picture on interned-index non-determinism.)Test plan
cargo buildcompiles cleanlymake integration-testpasses (no behavioral change; this is a pure refactor)