You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Drop Elaboration debug-ICEs when SimplifyCfg is disabled #160945
A-mir-optArea: MIR optimizationsI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️requires-debug-assertionsThis issue requires a build of rustc or tooling with debug-assertions in some way
The explanation I have heard in the past is that this assertion exists because forbidding unreachable blocks is helpful for dataflow analysis.
It really doesn't make sense to forbid unreachable blocks in the middle of an optimization pipeline. So I don't think the assertion is worth it, but I am not an expert on the dataflow code.
Let's remove the assert. Since this is an easy issue, to any new contributors who pick this up: do not use an LLM in any part of solving this issue, it's meant to teach you how to use our tooling, as the change itself is trivial.
FYI: The assertion prevents querying results from unreachable blocks by default because results are usually nonsensical. The result at the start of an unreachable block is a bottom value, but for locations within a block it still has a transfer function applied to it. To obtain bottom value consistently one can use MaybeReachable<T> as a lattice and call allow_unreachable().
I think it's quite fragile to expect the input MIR to be in a state of "no unreachable blocks".
Is there a better way to make MIR passes robust against such MIR?
I think it's quite fragile to expect the input MIR to be in a state of "no unreachable blocks".
No one is suggesting otherwise.
Is there a better way to make MIR passes robust against such MIR?
I was primarily interested in describing why those asserts are there in the first place. That being said, my comment did suggest two alternatives in addition to simply removing the asserts. To make it more explicit:
Make explicit decision how to handle unreachable blocks by querying results only for reachable blocks.
Make explicit decision how to handle unreachable blocks by using MaybeReachable lattice and allow querying unreachable blocks (this perhaps should be property of an Analysis).
One could expect that results for unreachable blocks shouldn't matter at all. Historically this was demonstrated to be false, which is why we use MaybeReachable.
I don't understand how those proposals avoid the footgun of MIR opts running into this panic. Sure, we can fix up the passes we have today to avoid querying unreachable blocks or to use MaybeReachable, but if that's the only thing we do we'll inevitably see this ICE again.
Or are you implying there is some way to do this systematically in the core analysis API without needing to audit each pass? You didn't say that so I don't expect this to be the case, but then I am left confused about your proposal.
OTOH I also don't understand the failures that can arise if a mir-opt queries the results for unreachable blocks without being prepared for that. You say "Historically this was demonstrated to be false" -- what are examples of things that go wrong? Is the argument that it's better to ICE the compiler in such cases rather than do whatever nonsense used to happen instead?
I am left guessing about what you actually want to say. Please be a bit more explicit. :)
As for fixing the issue, I think the best way forward is to change data flow results to consistently return bottom value for unreachable locations (e.g., by using MaybeReachable internally) and remove the asserts.
A-mir-optArea: MIR optimizationsI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️requires-debug-assertionsThis issue requires a build of rustc or tooling with debug-assertions in some way
Activity
clubby789 commentedon Aug 11, 2026
cc @RalfJung
saethlin commentedon Aug 13, 2026
The explanation I have heard in the past is that this assertion exists because forbidding unreachable blocks is helpful for dataflow analysis.
It really doesn't make sense to forbid unreachable blocks in the middle of an optimization pipeline. So I don't think the assertion is worth it, but I am not an expert on the dataflow code.
RalfJung commentedon Aug 16, 2026
Yeah I tend to agree, unreachable blocks are a perfectly natural thing to have in valid well-formed MIR so we shouldn't panic on that.
Cc @rust-lang/wg-mir-opt
oli-obk commentedon Aug 19, 2026
Let's remove the assert. Since this is an easy issue, to any new contributors who pick this up: do not use an LLM in any part of solving this issue, it's meant to teach you how to use our tooling, as the change itself is trivial.
tmiasko commentedon Aug 19, 2026
FYI: The assertion prevents querying results from unreachable blocks by default because results are usually nonsensical. The result at the start of an unreachable block is a bottom value, but for locations within a block it still has a transfer function applied to it. To obtain bottom value consistently one can use
MaybeReachable<T>as a lattice and callallow_unreachable().RalfJung commentedon Aug 19, 2026
I think it's quite fragile to expect the input MIR to be in a state of "no unreachable blocks".
Is there a better way to make MIR passes robust against such MIR?
tmiasko commentedon Aug 19, 2026
No one is suggesting otherwise.
I was primarily interested in describing why those asserts are there in the first place. That being said, my comment did suggest two alternatives in addition to simply removing the asserts. To make it more explicit:
MaybeReachablelattice and allow querying unreachable blocks (this perhaps should be property of anAnalysis).One could expect that results for unreachable blocks shouldn't matter at all. Historically this was demonstrated to be false, which is why we use
MaybeReachable.RalfJung commentedon Aug 19, 2026
I don't understand how those proposals avoid the footgun of MIR opts running into this panic. Sure, we can fix up the passes we have today to avoid querying unreachable blocks or to use
MaybeReachable, but if that's the only thing we do we'll inevitably see this ICE again.Or are you implying there is some way to do this systematically in the core analysis API without needing to audit each pass? You didn't say that so I don't expect this to be the case, but then I am left confused about your proposal.
OTOH I also don't understand the failures that can arise if a mir-opt queries the results for unreachable blocks without being prepared for that. You say "Historically this was demonstrated to be false" -- what are examples of things that go wrong? Is the argument that it's better to ICE the compiler in such cases rather than do whatever nonsense used to happen instead?
I am left guessing about what you actually want to say. Please be a bit more explicit. :)
tmiasko commentedon Aug 19, 2026
As for fixing the issue, I think the best way forward is to change data flow results to consistently return bottom value for unreachable locations (e.g., by using
MaybeReachableinternally) and remove the asserts.Catskhi commentedon Aug 23, 2026
@rustbot claim
Ratnesh5 commentedon Sep 13, 2026
If noone is working on it, can I work on this issue?
Catskhi commentedon Sep 13, 2026
Hi @Ratnesh5, I'm working on this issue