Skip to content
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

Merged
merged 6 commits into from
Oct 26, 2018

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Oct 4, 2018

fixes #53201

r? @eddyb

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 4, 2018
@rust-highfive

This comment has been minimized.

@TimNN
Copy link
Contributor

TimNN commented Oct 16, 2018

Ping from triage @eddyb: This PR requires your review.

@oli-obk
Copy link
Contributor Author

oli-obk commented Oct 25, 2018

r? @alexreg

@alexreg
Copy link
Contributor

alexreg commented Oct 25, 2018

@oli-obk I don't have r+ powers. Unless you just want me to review the code...

@oli-obk
Copy link
Contributor Author

oli-obk commented Oct 25, 2018

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

@oli-obk
Copy link
Contributor Author

oli-obk commented Oct 25, 2018

@bors delegate=alexreg

let's see if that works

@bors
Copy link
Contributor

bors commented Oct 25, 2018

✌️ @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
Copy link
Contributor

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?

@alexreg
Copy link
Contributor

alexreg commented Oct 25, 2018

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
Copy link
Contributor

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() {
Copy link
Contributor

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."

Copy link
Contributor Author

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).

Copy link
Contributor

@alexreg alexreg Oct 25, 2018

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();
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.
Copy link
Contributor

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.

@alexreg
Copy link
Contributor

alexreg commented Oct 25, 2018

Looks good, @oli-obk! Thanks for bearing with me.

@alexreg
Copy link
Contributor

alexreg commented Oct 25, 2018

@bors r+

@bors
Copy link
Contributor

bors commented Oct 25, 2018

📌 Commit fd77500 has been approved by alexreg

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 25, 2018
kennytm added a commit to kennytm/rust that referenced this pull request Oct 26, 2018
Don't try to promote already promoted out temporaries

fixes rust-lang#53201

r? @eddyb
kennytm added a commit to kennytm/rust that referenced this pull request Oct 26, 2018
Don't try to promote already promoted out temporaries

fixes rust-lang#53201

r? @eddyb
bors added a commit that referenced this pull request Oct 26, 2018
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)
@bors bors merged commit fd77500 into rust-lang:master Oct 26, 2018
@RalfJung
Copy link
Member

Cc @eddyb this touched const qualification.

@eddyb
Copy link
Member

eddyb commented Nov 21, 2018

@RalfJung I should've said something, but I reviewed this and it appears to be a sound relaxation.

@oli-obk oli-obk deleted the double_promotion branch November 21, 2018 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

miri ICE promote const: impossible case reached
7 participants