-
Notifications
You must be signed in to change notification settings - Fork 13k
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
What is the behavior of a place-to-value/reference conversion of a variant place? #120369
Comments
We could use pattern types to represent enum variant types (which would also make it clear that they have the same representation (modulo niches)) |
Yeah that sounds pretty nice long-term. Though short term I wonder if "have a combined Variant+Field projection for accessing enum fields" isn't the best choice -- basically, equip the field projection with an @rust-lang/wg-mir-opt would that work reasonably well for MIR opts or not? |
As a first step, let's declare the programs above invalid by requiring |
…jection, r=compiler-errors MIR validation: ensure that downcast projection is followed by field projection Cc rust-lang#120369
…jection, r=compiler-errors MIR validation: ensure that downcast projection is followed by field projection Cc rust-lang#120369
Rollup merge of rust-lang#125616 - RalfJung:mir-validate-downcast-projection, r=compiler-errors MIR validation: ensure that downcast projection is followed by field projection Cc rust-lang#120369
…r=compiler-errors MIR validation: ensure that downcast projection is followed by field projection Cc rust-lang/rust#120369
MIR in principle can represent code like this (but custom MIR currently cannot):
I think things would explode in all sorts of ways if such MIR was fed to Miri: enum variants can have ABIs that are entirely different from the enum they are contained in, so the projection can produce
ImmTy
that are incoherent. Currently this works because it seems to only affect enum variants without fields / uninhabited variants (but maybe I just haven't found the right example yet), and rustc only generates variant projections that are immediately followed by field projections.But this is not very satisfying. We have an invariant (an
Immediate::Scalar
must haveScalar
type, and similar forScalarPair
), and that invariant is blatantly violated by valid MIR -- or at least MIR that does not break any documented rule I am aware of. It's also unclear what code like the above should even mean: given that enum variants have no type, what should the type of _2 and _3 be?I can think of two proper solutions here:
Cc @oli-obk @JakobDegen @tmiasko @cjgillot
The text was updated successfully, but these errors were encountered: