Commit 6d02243
authored
Factor: collapse triplicated alloc recovery into one arm (#135)
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.rs`**
The three arms now share a single code path. The predicate that actually
differs between them is captured in a `needs_recovery` variable:
- Static/VTable: `builtin_deref(true).is_none()` (not a reference, raw
pointer, or Box)
- Function: `!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_deref` but fails `is_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 on `global_alloc` makes
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
the `builtin_deref` call; it takes `&self`.
**`tests/integration/normalise-filter.jq`**
The `def_id` filter 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_id` values are interned
compiler indices (same class as `alloc_id` and `adt_def`) that are
consistent within a single rustc invocation but non-deterministic across
runs. Downstream consumers need them as cross-reference keys to join
`AggregateKind::Adt` in 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 build` compiles cleanly
- [ ] `make integration-test` passes (no behavioral change; this is a
pure refactor)1 parent 047ca6a commit 6d02243
2 files changed
Lines changed: 22 additions & 61 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
265 | 265 | | |
266 | 266 | | |
267 | 267 | | |
268 | | - | |
269 | | - | |
270 | | - | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
271 | 279 | | |
272 | 280 | | |
273 | | - | |
| 281 | + | |
| 282 | + | |
274 | 283 | | |
275 | 284 | | |
276 | 285 | | |
| |||
288 | 297 | | |
289 | 298 | | |
290 | 299 | | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
| 300 | + | |
347 | 301 | | |
348 | 302 | | |
349 | 303 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
33 | 40 | | |
0 commit comments