-
Notifications
You must be signed in to change notification settings - Fork 13.3k
change ConstInt
impl to not rely on ScalarInt
#96789
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
Some changes occured to the CTFE / Miri engine cc @rust-lang/miri |
r? @oli-obk (rust-highfive has picked a reviewer for you, use r? to override) |
|
The job Click to see the possible cause of the failure (guessed by this bot)
|
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.
r=me with ICE fixed
use std::convert::{TryFrom, TryInto}; | ||
use std::fmt; | ||
|
||
use crate::ty::TyCtxt; | ||
#[derive(Copy, Clone)] | ||
enum IntegerTy { |
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 checked, but there seem to be no existing enums like this. Surprising...
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.
We might want to refactor Ty
to have a single Int
variant with a field of this type, rather than 2 top-level Int
and Uint
variants.
|
||
#[derive(Copy, Clone)] | ||
/// A type for representing any integer. Only used for printing. | ||
pub struct ConstInt { | ||
/// The "untyped" variant of `ConstInt`. | ||
int: ScalarInt, |
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 thought this was going to get more reuse, looks like it never did
This is surprising to me. ScalarInt was created to share the Scalar integer handling with const representation. And now we say we don't want that sharing...? |
signed: bool, | ||
/// Whether the value is a `usize` or `isize` type. | ||
is_ptr_sized_integral: bool, | ||
pointer_width: u32, |
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 does this field do/mean? Please add a doc comment to each field.
Note that ConstInt isn't used anywhere but printing. Which is probably why there are no uses of the ScalarInt field. As apparent from the diff, all creation sites of ConstInt had to jump through hoops to get a ScalarInt to feed into the new function |
ConstInt::new_with_width( | ||
int.assert_bits(int.size()), | ||
self.layout.ty, | ||
int.size().bytes() as u32, |
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.
Please don't use as
casts in the interpreter.
☔ The latest upstream changes (presumably #96883) made this pull request unmergeable. Please resolve the merge conflicts. |
I don't really like the current state of this PR and don't have the capacity to work on it (or to work on the reason why I needed it in the first place). Going to close it for now |
This allows us to use it in the thir pattern code in the future without having to first go through
ScalarInt
. Patterns currently useu128
instead ofScalarInt
and moving away from that seems more challenging than this while maybe even impacting perf.