Output deterministic AllocIds when emitting MIR - #161768
Conversation
This comment has been minimized.
This comment has been minimized.
e8fc29e to
058b2a1
Compare
058b2a1 to
6e7643a
Compare
| writeln!(w, "// HINT: See also -Z dump-mir for MIR at specific points during compilation.")?; | ||
| writeln!( | ||
| w, | ||
| "// WARNING: Allocation ids were remapped for deterministic output, they may be differ from real ones." |
There was a problem hiding this comment.
How would you show the original alloc ids if you need them for debugging? Also this would lose the ability to tell alloc ids between different mir bodies apart, right?
There was a problem hiding this comment.
How would you show the original alloc ids if you need them for debugging?
Maybe with special --emit mode (like --emit=mir-original).
Also this would lose the ability to tell alloc ids between different mir bodies apart, right?
Yes, and I am now working on it by trying to overwrite tcx.alloc_map.to_alloc for consistent remapping across different bodies and for correct access to allocations through tcx.try_get_global_alloc (unfortunately AllocId can randomly appear in Debug implementations and maybe somewhere else; if it tries to access allocation through remapped allocation id this will lead to an error), however at this stage I don't like the resulting solution from many points of view, so I am not sure that this problem can be solved with this approach.
|
After some experiments from technical side I don't see adequate solution for now, as during MIR dump we use MIR models directly without prior creation of DTO models specifically for printing/dumping, thus we need to adjust regular data structures in the compiler to remap allocation ids, more specifically From logical point of view it seems like we do not need such a remapping, because non-deterministic MIR output is not that critical compared to deterministic binaries or metadata, next for debug purposes it is better to view original MIR that can be obtained from non-parallel compiler. Finally, in tests we have normalization which removes allocation ids, so remapping is not needed. Other option is to make creation of allocation ids deterministic in its core, now it is just a number which gets atomically incremented from different threads, so for determinism we need to alter its structure, which likely to cause perf regressions and seems like not worth doing for the purpose of fixing #154278 (at least for now). |
This can potentially be done in the rustc instead of compiletest. |
Fixes #154278. Blocked by #161450.
r? @petrochenkov