-
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
Add tag_for_variant
query
#122784
Add tag_for_variant
query
#122784
Conversation
Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went over the interpreter changes only.
tag_field, | ||
.. | ||
} => { | ||
let (tag, tag_field) = match self.tag_for_variant(dest.layout().ty, variant_index)? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like only one of the match arms falls through. I think the code would become more readable if you just took the code after the match and put it into that arm. Then you can remove the return
, the match becomes the tail expression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
use rustc_target::abi::{self, TagEncoding}; | ||
use rustc_target::abi::{VariantIdx, Variants}; | ||
|
||
use super::{ImmTy, InterpCx, InterpResult, Machine, Readable, Scalar, Writeable}; | ||
|
||
/// The tag of an enum discriminant. | ||
pub(crate) enum Tag { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This enum is only useful for writing the tag, not for reading it. I feel like that should somehow be reflected? At least in the docs, maybe in the name. In MiniRust we'd call this the "tagger" for this variant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, by removing Tag
altogether.
/// The variant is tagged. | ||
Tagged { tag: ScalarInt, tag_field: usize }, | ||
/// No tag; the variant is identified by its validity. | ||
Untagged, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Untagged
is the name you should use for Single
-encoded variants.
Not sure what to do with the case of "no tagging needed as the value is outside the niche and that's enough". One option would be to just merge that case with Untagged
. In both cases, there's nothing to be done for writing the tag.
Does the transmutability analysis need to distinguish these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the transmutability analysis need to distinguish these?
Transmutability analysis doesn't, but write_discriminant
does: it has an extra validity check in the Untagged
case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it does the read of the discriminant to verify that "doing nothing" makes sense. But we can just do that for Single
-encoded enums as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that simplifies things quite a bit, then. I've updated this PR to forego the the Tag
enum altogether in favor of Option<(tag_value, tag_field)>
, and made the suggested changes to the match
.
9179e1b
to
5342c6a
Compare
This query allows for sharing code between `rustc_const_eval` and `rustc_transmutability`. Also moves `DummyMachine` to `rustc_const_eval`.
5342c6a
to
2de9010
Compare
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was extracted wholesale from compiler/rustc_mir_transform/src/dataflow_const_prop.rs
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, great, I wanted this to be moved for a while. :)
@bors r+ |
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#114009 (compiler: allow transmute of ZST arrays with generics) - rust-lang#122195 (Note that the caller chooses a type for type param) - rust-lang#122651 (Suggest `_` for missing generic arguments in turbofish) - rust-lang#122784 (Add `tag_for_variant` query) - rust-lang#122839 (Split out `PredicatePolarity` from `ImplPolarity`) - rust-lang#122873 (Merge my contributor emails into one using mailmap) - rust-lang#122885 (Adjust better spastorino membership to triagebot's adhoc_groups) - rust-lang#122888 (add a couple more tests) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#114009 (compiler: allow transmute of ZST arrays with generics) - rust-lang#122195 (Note that the caller chooses a type for type param) - rust-lang#122651 (Suggest `_` for missing generic arguments in turbofish) - rust-lang#122784 (Add `tag_for_variant` query) - rust-lang#122839 (Split out `PredicatePolarity` from `ImplPolarity`) - rust-lang#122873 (Merge my contributor emails into one using mailmap) - rust-lang#122885 (Adjust better spastorino membership to triagebot's adhoc_groups) - rust-lang#122888 (add a couple more tests) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#122784 - jswrenn:tag_for_variant, r=compiler-errors Add `tag_for_variant` query This query allows for sharing code between `rustc_const_eval` and `rustc_transmutability`. It's a precursor to a PR I'm working on to entirely replace the bespoke layout computations in `rustc_transmutability`. r? `@compiler-errors`
@@ -243,6 +243,24 @@ pub(crate) fn turn_into_const_value<'tcx>( | |||
op_to_const(&ecx, &mplace.into(), /* for diagnostics */ false) | |||
} | |||
|
|||
/// Computes the tag (if any) for a given type and variant. | |||
#[instrument(skip(tcx), level = "debug")] | |||
pub fn tag_for_variant_provider<'tcx>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't really an "eval" query, so mod.rs
may have been a better place... but overall, 🤷 not that important
tag_for_variant follow-ups Follow-up to rust-lang#122784, mostly to clarify the doc comment.
Rollup merge of rust-lang#122933 - RalfJung:tag_for_variant, r=oli-obk tag_for_variant follow-ups Follow-up to rust-lang#122784, mostly to clarify the doc comment.
tag_for_variant follow-ups Follow-up to rust-lang#122784, mostly to clarify the doc comment.
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#114009 (compiler: allow transmute of ZST arrays with generics) - rust-lang#122195 (Note that the caller chooses a type for type param) - rust-lang#122651 (Suggest `_` for missing generic arguments in turbofish) - rust-lang#122784 (Add `tag_for_variant` query) - rust-lang#122839 (Split out `PredicatePolarity` from `ImplPolarity`) - rust-lang#122873 (Merge my contributor emails into one using mailmap) - rust-lang#122885 (Adjust better spastorino membership to triagebot's adhoc_groups) - rust-lang#122888 (add a couple more tests) r? `@ghost` `@rustbot` modify labels: rollup
This query allows for sharing code between
rustc_const_eval
andrustc_transmutability
. It's a precursor to a PR I'm working on to entirely replace the bespoke layout computations inrustc_transmutability
.r? @compiler-errors