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

Do leak check after function pointer coercion #97206

Merged
merged 1 commit into from May 22, 2022

Conversation

jackh726
Copy link
Contributor

cc #73154

I still need to clean diagnostics just a tad, but figured I would put this up anyways.

This change is made in order to make match arm coercion order-independent.

Basically, any time we do function pointer coercion, we follow it by doing a leak check. This is necessary because the LUB code doesn't handler higher-ranked things correctly, leading us to "coerce", but use the wrong type. A proper fix is to actually fix that code (so the type returned by unify_and is a supertype of both a and b if Ok). However, that requires a more in-depth fix, likely heavily overlapping with the new subtyping changes.

Here, I've been conservative and error early if we generate unsatisfiable constraints. Note, this should mostly only affect NLL, since migrate mode falls back to the LUB implementation (followed by leak check), whereas NLL only does sub.

There could be other coercion code that has an order-dependence where a leak check in the coercion code might be useful. However, this is more of a spot-fix for #73154 than a "permanent" fix, since we likely want to go the other way long-term, and allow this pattern without error.

r? @nikomatsakis

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 20, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 20, 2022
// want the coerced type to be the actual supertype of these two,
// but for now, we want to just error to ensure we don't lock
// ourselves into a specific behavior with NLL.
self.leak_check(false, snapshot)?;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will admit that I have no idea if this should be false or true.

Copy link
Contributor

Choose a reason for hiding this comment

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

The name is not very good. It only affects diagnostics. I think the idea is that you say true if the "placeholders" result from the "actual type" and false if they come from the expected type.

In this instance, B is the expected type, I think, and the placeholders would come from B, so I guess that makes false the proper value. (i.e., the value you are supplying is insufficiently polymorphic to be cast to the type required).

src/test/ui/hrtb/hrtb-exists-forall-fn.stderr Outdated Show resolved Hide resolved
@@ -11,23 +11,20 @@ fn b<'a, 'b>(x: &mut &'a isize, y: &mut &'b isize) {
// Illegal now because there is no `'b:'a` declaration.
*x = *y;
//[base]~^ ERROR E0623
//[nll]~^^ ERROR lifetime may not live long enough
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think these errors disappear because they are borrowck errors, but we now error and bail in typeck.

@@ -11,23 +11,20 @@ fn b<'a, 'b>(x: &mut &'a isize, y: &mut &'b isize) {
// Illegal now because there is no `'b:'a` declaration.
*x = *y;
//[base]~^ ERROR lifetime mismatch [E0623]
//[nll]~^^ ERROR lifetime may not live long enough
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same here.

Comment on lines -55 to +8
found fn pointer `for<'r, 's, 't0> fn(&'r mut &isize, &'s mut &isize, &'t0 mut &isize)`
found fn item `for<'r, 's, 't0> fn(&'r mut &isize, &'s mut &isize, &'t0 mut &isize) {a::<'_, '_, '_>}`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is nice.

Comment on lines +11 to +15
note: function defined here
--> $DIR/regions-fn-subtyping-return-static-fail.rs:24:4
|
LL | fn want_G(f: G) {}
| ^^^^^^ ----
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This too.

@jackh726 jackh726 changed the title [WIP] Do leak check after function pointer coercion Do leak check after function pointer coercion May 20, 2022
@jackh726 jackh726 force-pushed the issue-73154 branch 2 times, most recently from 8a1dc74 to a9decbe Compare May 20, 2022 14:30
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@nikomatsakis
Copy link
Contributor

@bors r+

cc @lcnr -- the work we are doing on improving subtyping will eventually make this unnecessary, if I'm not mistaken.

@bors
Copy link
Contributor

bors commented May 20, 2022

📌 Commit 719ef0d has been approved by nikomatsakis

@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 May 20, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request May 21, 2022
Do leak check after function pointer coercion

cc rust-lang#73154

I still need to clean diagnostics just a tad, but figured I would put this up anyways.

This change is made in order to make match arm coercion order-independent.

Basically, any time we do function pointer coercion, we follow it by doing a leak check. This is necessary because the LUB code doesn't handler higher-ranked things correctly, leading us to "coerce", but use the wrong type. A proper fix is to actually fix that code (so the type returned by `unify_and` is a supertype of both `a` and `b` if `Ok`). However, that requires a more in-depth fix, likely heavily overlapping with the new subtyping changes.

Here, I've been conservative and error early if we generate unsatisfiable constraints. Note, this should *mostly* only affect NLL, since migrate mode falls back to the LUB implementation (followed by leak check), whereas NLL only does sub.

There could be other coercion code that has an order-dependence where a leak check in the coercion code might be useful. However, this is more of a spot-fix for rust-lang#73154 than a "permanent" fix, since we likely want to go the other way long-term, and allow this pattern without error.

r? `@nikomatsakis`
@bors
Copy link
Contributor

bors commented May 21, 2022

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

@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 May 21, 2022
@jackh726
Copy link
Contributor Author

@bors r+

@bors
Copy link
Contributor

bors commented May 21, 2022

📌 Commit baf1966b3c75fff6174c31da4a0574793bc2ace8 has been approved by jackh726

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 21, 2022
@lcnr
Copy link
Contributor

lcnr commented May 21, 2022

@bors r-
@bors r=nikomatsakis

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

bors commented May 21, 2022

📌 Commit baf1966b3c75fff6174c31da4a0574793bc2ace8 has been approved by nikomatsakis

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 21, 2022
@jackh726
Copy link
Contributor Author

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented May 21, 2022

💡 This pull request was already approved, no need to approve it again.

@bors
Copy link
Contributor

bors commented May 21, 2022

📌 Commit baf1966b3c75fff6174c31da4a0574793bc2ace8 has been approved by nikomatsakis

@jackh726
Copy link
Contributor Author

Oh thanks @lcnr :) missed that

@bors
Copy link
Contributor

bors commented May 22, 2022

⌛ Testing commit baf1966b3c75fff6174c31da4a0574793bc2ace8 with merge 66e5c5953352dd6ce2a6cbae77dd187880e38510...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented May 22, 2022

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 22, 2022
@jackh726
Copy link
Contributor Author

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented May 22, 2022

📌 Commit 683a9c8 has been approved by nikomatsakis

@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 May 22, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request May 22, 2022
Rollup of 5 pull requests

Successful merges:

 - rust-lang#97043 (Move some tests to more reasonable directories)
 - rust-lang#97206 (Do leak check after function pointer coercion)
 - rust-lang#97275 (small change)
 - rust-lang#97277 (Avoid accidentally enabling unstable features in compilers (take 2))
 - rust-lang#97280 (Quote replace target in bootstrap configure)

Failed merges:

 - rust-lang#97214 (Finish bumping stage0)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 4f97de8 into rust-lang:master May 22, 2022
@rustbot rustbot added this to the 1.63.0 milestone May 22, 2022
@jackh726 jackh726 deleted the issue-73154 branch May 22, 2022 19:22
bors added a commit to rust-lang-ci/rust that referenced this pull request May 22, 2022
Move remaining tests with NLL differences to revisions

Based on rust-lang#97206

I've already filed issues for any important differences that I've spotted: rust-lang#97252 rust-lang#97253 rust-lang#97256 rust-lang#97267

There is a lot here, but each commit is self-contained as a separate directory. I can split into separate PRs as wanted or needed.
dario23 added a commit to dario23/rust-semverver that referenced this pull request May 28, 2022
bors added a commit to rust-lang/rust-semverver that referenced this pull request May 28, 2022
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants