-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
[MIR] use mir::repr::Constant in ExprKind::Repeat, close #29789 #30944
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Well the whole point of that issue was that you’d have a type-system assisted guarantee to get Which, thinking now, also points to a very trivial solution of simply using |
r? @nagisa |
// its contained data. Currently this should only contain expression of ExprKind::Literal | ||
// kind. | ||
count: ExprRef<'tcx>, | ||
count: Constant<'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.
Probably should just use the ConstVal
here.
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.
Makes sense I guess. Thought the same thing, but this is my first contact with the MIR stuff. I'll update the PR
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.
The problem with chaning it to ConstVal
is that this leads to a problem with the MIR visitor, which does only have a visit_constant
function. Of course we could just try to construct a Constant
object there, but that seems not too nice, but so does the alternative, adding a new method to the visitor.
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.
MIR visitor does not really walk through hair::ExprKind
s, does it? There’s no pressing reason to visit the ConstVal
repetition count either, were you put it into repr::Rvalue::Repeat
as well, because it can be inspected as part of the whole Rvalue::Repeat
inside the visit_rvalue
(similarly as it is done with the visit_literal(Literal::Value)
).
The issues with using ConstVal
I could think of are loss of span and constant type information (later being not really important now, because repetition count is always usize
, but might be important in the future, for e.g. analysis passes). With @oli-obk’s work, ConstVal
is expected to eventually become typed, so loss of type would also, eventually, be fixed in time, leaving us with the span problem.
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.
Then after all, maybe it still make sense to add a new hair::Constant
struct which contains the value as u64 as suggested by @oli-obk and the span (we could also store the type of the constant there of course)
While using |
That is certainly true, and, I think, a pretty good change to make now (provided we decide against (That being said, I probably should update the aforementioned issue with more information on why it exists in the first place.) |
Why not simply const eval and extract the integer and store it as a u64? Once I have typestrong const ints, I will put the usize enum there which will respect the target bitwidth. |
So I've thought (and dug around my memory) about it more and here’s some clarifications/thoughts:
The original point (as indicated in this PR) was that repeat count must be a constant expression. Any of the proposals currently floating around (
A possible option as well, but I don’t see any real improvement over just storing a Using
I also am a little bit reluctant about making cc @nikomatsakis, because MIR. |
Actually, that makes it simpler to remember, since the extraction will break (there'll be no more |
@nagisa do I understand correctly that creating a |
That seems to be the best option, yes.
|
fa17488
to
47556f4
Compare
I've pushed a new commit, which introduces |
☔ The latest upstream changes (presumably #31010) made this pull request unmergeable. Please resolve the merge conflicts. |
@@ -143,9 +143,8 @@ impl<'a, 'tcx> EraseRegions<'a, 'tcx> { | |||
Rvalue::Use(ref mut operand) => { | |||
self.erase_regions_operand(operand) | |||
} | |||
Rvalue::Repeat(ref mut operand, ref mut constant) => { | |||
Rvalue::Repeat(ref mut operand, _) => { | |||
self.erase_regions_operand(operand); |
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.
Since a Ty
is stored in TypedConstVal
, you’ll have to erase regions in the type. Erasing them inline (similarly to what’s done in SwitchTy
case above) is fine, I think.
I think things certainly look better than they did before. r=me with the two comments resolved. |
47556f4
to
b88cb7a
Compare
@nagisa thanks for the feedback. I've pushed a new commit adressing the two comments. |
b88cb7a
to
9884ff1
Compare
This PR for #29789 uses `rustc::repr::mir::Constant` in `ExprKind::Repeat`, which seems to fit quite nicely. Is there a reason for not re-using that type?
This PR for #29789 uses
rustc::repr::mir::Constant
inExprKind::Repeat
, which seems to fit quite nicely. Is there a reason for not re-using that type?