-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Layout and MIR field accesses are incoherent #69763
Comments
I wrote #69753 (comment), before taking another look at the code, which revealed the problem: So this is the relevant code, that (I thought) would kick in and compute the right number of fields: rust/src/librustc/ty/layout.rs Lines 2025 to 2044 in 4a1b69d
However, just before it we have: rust/src/librustc/ty/layout.rs Line 2023 in 4a1b69d
So what's happening is the first variant of every uninhabited
|
Glad to hear that we agree on this invariant. :)
Doesn't the fact that codegen, borrowck and so on didn't ICE here indicate that they all still contain some "is_uninhabited" check that ought to be unnecessary? If we can find and remove that check, it would mean we'd see such issues much earlier (we'd see them on any MIR statement that codegen runs on, not just any statement that const-prop runs on). |
I was wrong when I said that, in that it's still broken for variant index
I'm not sure I could see how that factors into this too much. In case you didn't see it, I edited #69763 (comment) with the right fix, AFAICT. Long-term we'll want to change the layout to use
(we'd probably have to move |
So looks like #66250 removed the assertion that demonstrates the incoherence, instead of fixing the issue -- and no issue was opened to track the problem so it just got forgotten until someone re-discovered the ICE. :( |
…lfJung Compute the correct layout for variants of uninhabited enums r? @eddyb cc @RalfJung fixes rust-lang#69191 cc rust-lang#69763
…lfJung Compute the correct layout for variants of uninhabited enums r? @eddyb cc @RalfJung fixes rust-lang#69191 cc rust-lang#69763
…lfJung Compute the correct layout for variants of uninhabited enums r? @eddyb cc @RalfJung fixes rust-lang#69191 cc rust-lang#69763
…lfJung Compute the correct layout for variants of uninhabited enums r? @eddyb cc @RalfJung fixes rust-lang#69191 cc rust-lang#69763
…lfJung Compute the correct layout for variants of uninhabited enums r? @eddyb cc @RalfJung fixes rust-lang#69191 cc rust-lang#69763
…lfJung Compute the correct layout for variants of uninhabited enums r? @eddyb cc @RalfJung fixes rust-lang#69191 cc rust-lang#69763
…lfJung Compute the correct layout for variants of uninhabited enums r? @eddyb cc @RalfJung fixes rust-lang#69191 cc rust-lang#69763
…lfJung Compute the correct layout for variants of uninhabited enums r? @eddyb cc @RalfJung fixes rust-lang#69191 cc rust-lang#69763
The fixes for asserting field access sanity in Miri and codegen have landed. So, I think this can be closed. :) |
@RalfJung What about the second half of #69763 (comment)? Right now the layouts for |
Agreed, but that sounds like a separate issue to me? At least there aren't field accesses to variants that don't exist, or stuff like that. Would that proposal also help with |
If the whole If a specific variant is uninhabited, you could probably let the regular discriminant writing code handle it, although there's always the risk that the way that code is implemented would write a different variant's tag/niche (e.g. by truncation, if the uninhabited variant is just outside).
Hmm I thought you wanted to keep this open until layout reflected what MIR could access more directly, instead of faking it with |
I was mostly concerned with fields for this issue, not variants. I guess I got used to variants being a mess. ;) None of the text in the OP makes sense for the variant case though, I think? And then there's also the thing where primitives are "fieldless unions", and maybe instead there should be |
Variants are what contain fields. The reason for any oddities with fields is because the variants they're in aren't actually in the layout so they have to be faked on the spot (which is what I think we should fix). |
Okay, I made a new issue for that: #70399 |
I propose that we should have the following invariant: Whenever, anywhere in MIR, there is a field projection with some index
i
, theni
is actually a valid field index in the (statically known) layout of the type being projected into.Right now, this is not the case. This code:
generates the following MIR:
but the layout of
_Variant
is that of a union with 0 fields.A consequence of this incoherence is that all codegen backends and Miri (and possibly more MIR consumers) all need to be on their guard when considering field projections, always protecting against the case where the projection is ill-formed (usually that happens by special-casing uninhabited types before considering the projection).
I think instead of putting that burden on every MIR consumer, we should fix either the layout or the MIR to not violate the invariant in the first place.
Cc @eddyb with whom I anyway recently talked about those odd
Union
layouts. Is there some fundamental issue with the invariant I am proposing? Also Cc @oli-obk @wesleywiserIf we decide to go with this, we should
The text was updated successfully, but these errors were encountered: