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

remove this weird special case from promotion #78363

Merged
merged 3 commits into from
Dec 9, 2020

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Oct 25, 2020

Promotion has a special case to ignore interior mutability under some specific circumstances. The purpose of this PR is to figure out what changes if we remove that. Since Cell::new and friends only get promoted inside const/static initializers these days, it actually is not easy to exploit this case: you need something like

const TEST_INTERIOR_MUT: () = {
    // The "0." case is already ruled out by not permitting any interior mutability in `const`.
    let _val: &'static _ = &(Cell::new(1), 2).1;
};

I assume something like &Some(&(Cell::new(1), 2).1) would hit the nested case inside validate_rvalue... though I am not sure why that would not just trigger nested promotion, first promoting the inner reference and then the outer one?

Fixes #67534 (by simply rejecting that code^^)

r? @oli-obk (but for now this is not meant to be merged!)
Cc @rust-lang/wg-const-eval

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 25, 2020
fn main() {
// We must not promote things with interior mutability. Not even if we "project it away".
let _val: &'static _ = &(Cell::new(1), 2).0; //~ ERROR temporary value dropped while borrowed
let _val: &'static _ = &(Cell::new(1), 2).1; //~ ERROR temporary value dropped while borrowed
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two already failed before.

Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this maybe a leftover of the fact that promotion checking and const checking used to be one huge spaghetti monster? Or is it "just because" our promotion rules in const contexts kind of follow explicit promotion rules?

@RalfJung
Copy link
Member Author

Ah, here is another case that is affected:

const FIVE: Cell<i32> = Cell::new(5);

#[inline(never)]
fn tuple_field() -> &'static u32 {
    // This test is MIR-borrowck-only because the old borrowck
    // doesn't agree that borrows of "frozen" (i.e., without any
    // interior mutability) fields of non-frozen temporaries,
    // should be promoted, while MIR promotion does promote them.
    &(FIVE, 42).1
}

(I wish we would have sticked to what the old borrowck allows.^^)

@RalfJung
Copy link
Member Author

Is this maybe a leftover of the fact that promotion checking and const checking used to be one huge spaghetti monster? Or is it "just because" our promotion rules in const contexts kind of follow explicit promotion rules?

I think it is a "because we can" that was added when promotion was ported to MIR (probably it was natural to add given that it was the same code as const checking, where such precision is probably useful and less of a problem).

@oli-obk
Copy link
Contributor

oli-obk commented Oct 25, 2020

a check-only crater run should suffice, please feel free to start it whenever you think the PR is ready. I really hope we can get away with this change

@RalfJung
Copy link
Member Author

RalfJung commented Oct 25, 2020

@bors r-
(trying to de-confuse bors)

@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, 2020
@RalfJung
Copy link
Member Author

eh...
@bors try

@bors
Copy link
Contributor

bors commented Oct 25, 2020

⌛ Trying commit dfd3ec06104aaaa23cecde2f24fedac2d5fb156b with merge b2c2190fa7bf856bb0ed5e8806266e3a2135c6f8...

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 25, 2020
@bors
Copy link
Contributor

bors commented Oct 25, 2020

☀️ Try build successful - checks-actions
Build commit: b2c2190fa7bf856bb0ed5e8806266e3a2135c6f8 (b2c2190fa7bf856bb0ed5e8806266e3a2135c6f8)

@RalfJung
Copy link
Member Author

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-78363 created and queued.
🤖 Automatically detected try build b2c2190fa7bf856bb0ed5e8806266e3a2135c6f8
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 25, 2020
@jyn514 jyn514 changed the title Crater expeximent: can we remove this weird special case from promotion? Crater experiment: can we remove this weird special case from promotion? Oct 25, 2020
@craterbot
Copy link
Collaborator

🚧 Experiment pr-78363 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-78363 is completed!
📊 11 regressed and 10 fixed (127561 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the blacklist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Oct 31, 2020
@RalfJung
Copy link
Member Author

All of these regressions are false positives. :)

@oli-obk oli-obk added T-lang Relevant to the language team, which will review and decide on the PR/issue. I-nominated and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 1, 2020
@joshtriplett
Copy link
Member

🎉
@rfcbot merge

@rfcbot
Copy link

rfcbot commented Nov 15, 2020

Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Nov 15, 2020
@nikomatsakis
Copy link
Contributor

@rfcbot reviewed

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Nov 29, 2020
@rfcbot
Copy link

rfcbot commented Nov 29, 2020

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Dec 9, 2020
@rfcbot
Copy link

rfcbot commented Dec 9, 2020

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

The RFC will be merged soon.

@RalfJung
Copy link
Member Author

RalfJung commented Dec 9, 2020

Rebased on newer master.

@oli-obk this PR is now awaiting your review. :)

@oli-obk
Copy link
Contributor

oli-obk commented Dec 9, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Dec 9, 2020

📌 Commit d057a93 has been approved by oli-obk

@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-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). labels Dec 9, 2020
@bors
Copy link
Contributor

bors commented Dec 9, 2020

⌛ Testing commit d057a93 with merge c0bfe34...

@bors
Copy link
Contributor

bors commented Dec 9, 2020

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing c0bfe34 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 9, 2020
@bors bors merged commit c0bfe34 into rust-lang:master Dec 9, 2020
@rustbot rustbot added this to the 1.50.0 milestone Dec 9, 2020
@RalfJung RalfJung deleted the promotion branch December 9, 2020 15:56
@spastorino spastorino removed the to-announce Announce this issue on triage meeting label Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Promotion creates invalid constants that are never used in invalid ways