-
Notifications
You must be signed in to change notification settings - Fork 13.3k
rustc_target: use Integer instead of Primitive for discriminants and niches. #63450
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
Conversation
r? @cramertj (rust_highfive has picked a reviewer for you, use r? to override) |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@@ -619,18 +619,23 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |||
Err(_) => | |||
throw_unsup!(InvalidDiscriminant(raw_discr.erase_tag())), | |||
}; | |||
let real_discr = if discr_val.layout.ty.is_signed() { | |||
let (discr_ty_signed, discr_ty_size) = match &rval.layout.ty.sty { | |||
ty::Adt(adt, _) => { |
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 seems fishy. In my experience it is basically never correct to look at the Ty
of something in Miri, with very few exceptions.
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.
OTOH, this looks like you basically inlined old discr_type
? Why can't we use that any more / extend that to also return signedness?
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.
What old discr_type
? I hoisted the discr_type
call, and note that it only made sense for ADTs, whereas generators can also have discriminants (but they're not signed, so they wouldn't hit the signed logic previously).
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.
Oh, discr_type
only works for ADTs, of course.
Maybe this match here should move to Ty
, so that we can just do layout.ty.discr_type()
? Its return type IntType
(yet another one, next to layout::Integer
, IntTy
and UintTy
) seems to have just the right amount of freedom.
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 we already have something for variant names, so this seems... okay-ish?
Maybe the generator case can just be a _ =>
so we really only special-case ADTs with signed discriminants.
I don't know, I really don't like signed integers :(.
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'll review again later. I'm obviously not awake enough to realize trivial things, but lgtm
Note that this is broken right now, likely because of how signedness is handled. |
r? @oli-obk |
Ping from triage, @eddyb any update on this? Some check are failing. Thanks. |
@gagan0723 See #63450 (comment). Overall, I think I want this discussed by the compiler-team. We should figure out how precisely we want to keep track of the discriminant encoding (tag/niche) "type", we have 3 options AFAICT:
Going for 2. instead of 3. would fix the signedness problems more directly, and result in a more straight-forward patch, but it doesn't feel like it goes far enough. If we want 3., it should be possible to fix all the signedness issues, since the information can be extracted from the |
☔ The latest upstream changes (presumably #63873) made this pull request unmergeable. Please resolve the merge conflicts. |
Ping from triage |
(adding self to assignee list; i want to better acquaint myself with the issued here) |
Wow, somehow I'd missed that using just pub enum Foo {
A = 0,
B = 255,
}
pub enum Bar {
A = 0,
B = -128,
C = 127,
} |
Given #63450 (comment) I'll just abandon this PR for now. |
Instead of signed/unsigned integers or pointers, discriminants (tag/niche-filling) and niches are now always unsigned integers (signedness is handled when reading them as signed values).
This does seems like a simplification, but only slightly (perhaps I haven't cleaned up everything that had to special-case signed integers or pointers).
To avoid some duplication,
Scalar
was made generic over the type of itsvalue
field.See #62138 (comment) for some of the discussion that led to me trying this out.
cc @RalfJung @oli-obk @nagisa
(As I wrote this, just noticed 3 tests failed, AFAICT all because of signedness)