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 promotion candidate gathering and checking from qualify_consts.rs #66066

Merged

Conversation

ecstatic-morse
Copy link
Contributor

@ecstatic-morse ecstatic-morse commented Nov 3, 2019

This makes promotion candidate gathering and checking the exclusive domain of promote_consts, but the QualifyAndPromoteConsts pass is still responsible for both const-checking and creating promoted MIR fragments.

This should not be merged until the beta branches on Nov. 5.

r? @eddyb

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 3, 2019
@ecstatic-morse
Copy link
Contributor Author

This is more easily reviewed commit-by-commit, and hiding whitespace changes will make the first commit more intelligible.

@rust-highfive

This comment has been minimized.

@ecstatic-morse
Copy link
Contributor Author

ecstatic-morse commented Nov 3, 2019

It looks like removing IsNotPromotable will require adding some additional logic to set the qualifs in the return place when an expression that is forbidden in a const context is encountered. Do you want me to do this @eddyb? I'm still trying to avoid making non-trivial modifications to this code since it will go away soon, and I'm not 100% sure how this change will manifest. Alternatively I could revert the last commit.

@ecstatic-morse ecstatic-morse force-pushed the remove-promotion-from-qualify-consts branch 2 times, most recently from 5b09205 to 5e23e46 Compare November 3, 2019 22:43
@ecstatic-morse
Copy link
Contributor Author

Interestingly, just removing it does not cause any test errors. I think this code-path will only be important if we try to promote a reference to a const for which const-checking has failed? I still think we should leave IsNotPromotable in until qualify_consts.rs is removed completely.

@ecstatic-morse
Copy link
Contributor Author

ecstatic-morse commented Nov 5, 2019

Specifically, this is the code I'm worried about. It looks for IsNotPromotable in the return place and sets NeedsDrop and HasMutInterior if they are possible for the type (as a side effect, this clears IsNotPromotable and IsNotImplicitlyPromotable, which was maybe not intended?). This prevents promotion of complex or errorful consts. I was never sure about the purpose or correctness of this code: all named variables should have IsNotPromotable, so this branch will also trigger if a named variable is returned from a const. Is this intended?

I plan to approximate this behavior in the new const-checker by setting qualifs conservatively (as well as setting an error bit) if there are errors during const-checking. I think this is roughly what was intended in this code? We'll need a crater run anyways when switching to the new const-checker, which should give us more confidence.

I still think we should just leave this in for now (and erase the last commit in this PR). I would rather work on improving the final version, which will replace this entirely, than spend time on this.

@bors
Copy link
Contributor

bors commented Nov 6, 2019

☔ The latest upstream changes (presumably #66143) made this pull request unmergeable. Please resolve the merge conflicts.

@eddyb
Copy link
Member

eddyb commented Nov 6, 2019

I don't think there's any reason to care about const-checking errors, compilation will fail anyway, I was likely trying to avoid weird ICEs but nowadays everything is so much more robust that it's pointless.

// promote anything, since that can cause errors in a `const` if e.g. rvalue static
// promotion is attempted within a loop body.
let unleash_miri = self.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you;
let promotion_candidates = if has_controlflow_error && !unleash_miri {
Copy link
Member

Choose a reason for hiding this comment

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

I was going to say that this isn't needed (since IIRC the reason I added it was because there would be mismatches since qualify_consts doesn't see as many candidates as there are in the body, because it stops looking at BBs) but you did replace my HACK comment so I'm guessing you hit some other issue?

Actually, I'm still not sure this check is needed, promotion within fn bodies works just fine without it, so what gives?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't do rvalue-static promotion in a loop with the current "storage dead removal" system for consts; it results in broken MIR and ultimately an ICE as the stack slot for the temp is never cleaned up:

const X: () = loop {
    let x = &4;
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, there's no ICE on the test that hits this (sorry, it's been a few days since I ran them). There's just a regular error. I vaguely remember hitting something worse, but maybe we just always try promotion?

+	error[E0384]: cannot assign twice to immutable variable `_`
+	  --> $DIR/issue-52475.rs:10:18
+	   |
+	LL |             x = &0; // Materialize a new AllocId
+	   |                  ^ cannot assign twice to immutable variable
+	

Copy link
Member

@eddyb eddyb left a comment

Choose a reason for hiding this comment

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

r=me after a rebase and figuring out that one comment

We no longer compare the results of
`promote_consts::validate_candidates` with
`checker.promotion_candidates`, and `promote_consts` becomes the
canonical source for determining promotability.
Also removes any code used only to populate `promotion_candidates`
during const checking.
The former was cleared from `qualifs_in_return_place`, and the latter
was never checked. `QUALIF_ERROR_BIT` no longer corresponds to a real
`Qualif`, however.
The old const-checker conservatively reset qualifs when
`IsNotPromotable` was in the return place. Unfortunately, named
variables have `IsNotPromotable`, so this could cause promotion to fail.
This should work now.
@ecstatic-morse ecstatic-morse force-pushed the remove-promotion-from-qualify-consts branch from 5e23e46 to ec5ba54 Compare November 6, 2019 15:11
@eddyb
Copy link
Member

eddyb commented Nov 6, 2019

@bors r+

@bors
Copy link
Contributor

bors commented Nov 6, 2019

📌 Commit ec5ba54 has been approved by eddyb

@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 Nov 6, 2019
@bors
Copy link
Contributor

bors commented Nov 8, 2019

⌛ Testing commit ec5ba54 with merge 76ade3e...

bors added a commit that referenced this pull request Nov 8, 2019
…onsts, r=eddyb

Remove promotion candidate gathering and checking from `qualify_consts.rs`

This makes promotion candidate gathering and checking the exclusive domain of `promote_consts`, but the `QualifyAndPromoteConsts` pass is still responsible for both const-checking and creating promoted MIR fragments.

This should not be merged until the beta branches on Nov. 5.

r? @eddyb
@bors
Copy link
Contributor

bors commented Nov 8, 2019

☀️ Test successful - checks-azure
Approved by: eddyb
Pushing 76ade3e to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 8, 2019
@bors bors merged commit ec5ba54 into rust-lang:master Nov 8, 2019
@ecstatic-morse ecstatic-morse deleted the remove-promotion-from-qualify-consts branch October 6, 2020 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants