-
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
Don't try to promote already promoted out temporaries #54816
Conversation
This comment has been minimized.
This comment has been minimized.
b62bc2b
to
8b097c4
Compare
Ping from triage @eddyb: This PR requires your review. |
r? @alexreg |
@oli-obk I don't have r+ powers. Unless you just want me to review the code... |
Oh I guess that's why I can't r? you :D Yes a review would be great. You've been in that code a lot lately so I assumed you're the best one to review right now |
@bors delegate=alexreg let's see if that works |
✌️ @alexreg can now approve this pull request |
@@ -974,7 +979,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { | |||
if !constant_arguments.contains(&i) { | |||
return | |||
} | |||
if this.qualif.is_empty() { | |||
// if the argument requires a constant, we care about constness, not |
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 could do with elaboration. What do we mean by "requires a constant"? Where is this checked for?
Generally looks fine otherwise though... |
@@ -332,6 +332,8 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { | |||
let operand = Operand::Copy(promoted_place(ty, span)); | |||
mem::replace(&mut args[index], operand) | |||
} | |||
// already promoted out |
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.
Can we explain how we know the candidate is already promoted out here?
// which happens even without the user requesting it. | ||
// We can error out with a hard error if the argument is not | ||
// constant here. | ||
if (this.qualif - Qualif::NOT_PROMOTABLE).is_empty() { |
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.
Thanks for expanding on this. I still think the terminology is a bit confusing: it seems to suggest "return values are never promotable but we're going to promote one here anyway, because it's const."
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.
Well... yes. The rules for automatic promotion don't include function calls. The rules for constants do include function calls. Since the current function requires a constant here, if we did something like 0usize - 1
we'd get an error. If you just do &(0usize - 1)
in normal runtime code, you get a warning and a panic at runtime (in debug mode).
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 sure, I agree this makes sense, but could we just change the comment to "never promoted for runtime-evaluated/non-const/whatever functions" or such, just to be super-clear and make me happy? :-)
@@ -1003,7 +1021,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { | |||
// Be conservative about the returned value of a const fn. | |||
let tcx = self.tcx; | |||
let ty = dest.ty(self.mir, tcx).to_ty(tcx); | |||
self.qualif = Qualif::empty(); |
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.
Why did you remove this line?
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.
Otherwise we'd be erasing the NOT_PROMOTABLE
qualification we added above.
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.
Yep, but I think you want to reset all fields apart from that one, no? Alternatively, just make sure that's set after self.qualif
is reset.
// already promoted this call away entirely. This case occurs when calling | ||
// a function requiring a constant argument and as that constant value | ||
// providing a value whose computation contains another call to a function | ||
// requiring a constant argument. |
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.
Thanks for adding this. Sorry to nitpick, but this 2nd sentence doesn't parse grammatically.
Looks good, @oli-obk! Thanks for bearing with me. |
@bors r+ |
📌 Commit fd77500 has been approved by |
Don't try to promote already promoted out temporaries fixes rust-lang#53201 r? @eddyb
Don't try to promote already promoted out temporaries fixes rust-lang#53201 r? @eddyb
Rollup of 21 pull requests Successful merges: - #54816 (Don't try to promote already promoted out temporaries) - #54824 (Cleanup rustdoc tests with `@!has` and `@!matches`) - #54921 (Add line numbers option to rustdoc) - #55167 (Add a "cheap" mode for `compute_missing_ctors`.) - #55258 (Fix Rustdoc ICE when checking blanket impls) - #55264 (Compile the libstd we distribute with -Ccodegen-unit=1) - #55271 (Unimplement ExactSizeIterator for MIR traversing iterators) - #55292 (Macro diagnostics tweaks) - #55298 (Point at macro definition when no rules expect token) - #55301 (List allowed tokens after macro fragments) - #55302 (Extend the impl_stable_hash_for! macro for miri.) - #55325 (Fix link to macros chapter) - #55343 (rustbuild: fix remap-debuginfo when building a release) - #55346 (Shrink `Statement`.) - #55358 (Remove redundant clone (2)) - #55370 (Update mailmap for estebank) - #55375 (Typo fixes in configure_cmake comments) - #55378 (rustbuild: use configured linker to build boostrap) - #55379 (validity: assert that unions are non-empty) - #55383 (Use `SmallVec` for the queue in `coerce_unsized`.) - #55391 (bootstrap: clean up a few clippy findings)
Cc @eddyb this touched const qualification. |
@RalfJung I should've said something, but I reviewed this and it appears to be a sound relaxation. |
fixes #53201
r? @eddyb