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

Normalize opaques w/ bound vars #100980

Merged
merged 4 commits into from
Sep 22, 2022

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Aug 25, 2022

First, we reenable normalization of opaque types with escaping late bound regions to fix rust-lang/miri#2433. This essentially reverts #89285.

Second, we mitigate the perf regression found in #88862 by simplifying the way that we relate (sub and eq) GeneratorWitness types.

This relies on the fact that we construct these GeneratorWitness types somewhat particularly (with all free regions found in the witness types replaced with late bound regions) -- but those bound regions really should be treated as existential regions, not universal ones. Those two facts leads me to believe that we do not need to use the full higher_ranked_sub machinery to relate two generator witnesses. I'm pretty confident that this is correct, but I'm glad to discuss this further.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Aug 25, 2022
@compiler-errors
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 25, 2022
@bors
Copy link
Contributor

bors commented Aug 25, 2022

⌛ Trying commit 9e54f90d09293845fda4a881eabd40d78d5d0a95 with merge a4aab122ee1970839d7697c919e2c222d4260af2...

@bors
Copy link
Contributor

bors commented Aug 25, 2022

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

@rust-timer
Copy link
Collaborator

Queued a4aab122ee1970839d7697c919e2c222d4260af2 with parent addacb5, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (a4aab122ee1970839d7697c919e2c222d4260af2): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
128.2% [0.8%, 203.6%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.0% [-1.0%, -0.9%] 2
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
21.8% [6.8%, 27.4%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
117.4% [3.6%, 186.9%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.0% [-2.0%, -2.0%] 1
All ❌✅ (primary) - - 0

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

@rustbot rustbot added perf-regression Performance regression. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Aug 25, 2022
@compiler-errors
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 26, 2022
@bors
Copy link
Contributor

bors commented Aug 26, 2022

⌛ Trying commit 156c5cae434d88a89c8b6b84544dd9964b850842 with merge 47f3dd411b2c7ef6a2728fc318238097436b567e...

@bors
Copy link
Contributor

bors commented Aug 26, 2022

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

@rust-timer
Copy link
Collaborator

Queued 47f3dd411b2c7ef6a2728fc318238097436b567e with parent 76f3b89, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (47f3dd411b2c7ef6a2728fc318238097436b567e): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.0% [0.7%, 1.6%] 8
Improvements ✅
(primary)
-0.4% [-0.7%, -0.3%] 29
Improvements ✅
(secondary)
-1.1% [-1.6%, -0.4%] 10
All ❌✅ (primary) -0.4% [-0.7%, -0.3%] 29

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.0% [3.0%, 3.0%] 1
Improvements ✅
(primary)
-3.3% [-3.3%, -3.3%] 1
Improvements ✅
(secondary)
-2.3% [-3.2%, -1.2%] 8
All ❌✅ (primary) -3.3% [-3.3%, -3.3%] 1

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.3% [2.3%, 2.3%] 1
Improvements ✅
(primary)
-5.9% [-5.9%, -5.9%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -5.9% [-5.9%, -5.9%] 1

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 26, 2022
@compiler-errors compiler-errors marked this pull request as ready for review August 27, 2022 02:37
@compiler-errors
Copy link
Member Author

@bors try @rust-timer queue

r? types

cc @rust-lang/types I could use some help gauging the correctness of the last commit.

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 27, 2022
@bors
Copy link
Contributor

bors commented Aug 27, 2022

⌛ Trying commit c7c5a1bdd19dfee669a5e460a1e7ec3f085c0d64 with merge 4bf67d41f0d4a2f98e2ed48f7a0b7a61bada64b9...

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 22, 2022
@lcnr
Copy link
Contributor

lcnr commented Sep 22, 2022

forgot about this and thought it was already merged 😁

@bors r+ rollup=never

happy to finally see this landing

@bors
Copy link
Contributor

bors commented Sep 22, 2022

📌 Commit 3fc328d has been approved by lcnr

It is now in the queue for this repository.

@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 Sep 22, 2022
@bors
Copy link
Contributor

bors commented Sep 22, 2022

⌛ Testing commit 3fc328d with merge 8ab71ab...

@bors
Copy link
Contributor

bors commented Sep 22, 2022

☀️ Test successful - checks-actions
Approved by: lcnr
Pushing 8ab71ab to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 22, 2022
@bors bors merged commit 8ab71ab into rust-lang:master Sep 22, 2022
@rustbot rustbot added this to the 1.66.0 milestone Sep 22, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (8ab71ab): comparison URL.

Overall result: ❌✅ regressions and improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.8% [0.7%, 2.2%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.9% [-0.9%, -0.9%] 2
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.0% [-4.7%, -1.8%] 3
All ❌✅ (primary) - - 0

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.2% [3.1%, 3.4%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.8% [-2.8%, -2.8%] 1
All ❌✅ (primary) - - 0

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

@rustbot rustbot removed the perf-regression Performance regression. label Sep 22, 2022
@aliemjay
Copy link
Member

I wonder if nll_relate needs a similar optimization? I'm not sure if it's relevant in the borrowck context. Cc @compiler-errors who may have more insight.

@compiler-errors
Copy link
Member Author

@aliemjay I don't think so? We handle binders differently there, so I suspect the same pathological case where we create way too many region variables just doesn't happen.

@compiler-errors compiler-errors deleted the normalize-opaque-w-bound-vars branch November 2, 2022 03:00
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 19, 2022
…-r-hard, r=oli-obk

Revert "Normalize opaques with escaping bound vars"

This caused a perf regression in rust-lang#103423, cc `@skyzh` this should fix rust-lang#103423.

reverts rust-lang#100980

r? `@oli-obk`
Aaron1011 pushed a commit to Aaron1011/rust that referenced this pull request Jan 6, 2023
…-r-hard, r=oli-obk

Revert "Normalize opaques with escaping bound vars"

This caused a perf regression in rust-lang#103423, cc `@skyzh` this should fix rust-lang#103423.

reverts rust-lang#100980

r? `@oli-obk`
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 29, 2023
…th-late-bound-vars-again, r=jackh726

Normalize opaques with late-bound vars again

We have a hack in the compiler where if an opaque has escaping late-bound vars, we skip revealing it even though we *could* reveal it from a technical perspective. First of all, this is weird, since we really should be revealing all opaques in `Reveal::All` mode. Second of all, it causes subtle bugs (linked below).

I attempted to fix this in rust-lang#100980, which was unfortunately reverted due to perf regressions on codebases that used really deeply nested futures in some interesting ways. The worst of which was rust-lang#103423, which caused the project to hang on build. Another one was rust-lang#104842, which was just a slow-down, but not a hang. I took some time afterwards to investigate how to rework `normalize_erasing_regions` to take advantage of better caching, but that effort kinda fizzled out (rust-lang#104133).

However, recently, I was made aware of more bugs whose root cause is not revealing opaques during codegen. That made me want to fix this again -- in the process, interestingly, I took the the minimized example from rust-lang#103423 (comment), and it doesn't seem to hang any more...

Thinking about this harder, there have been some changes to the way we lower and typecheck async futures that may have reduced the pathologically large number of outlives obligations (see description of rust-lang#103423) that we were encountering when normalizing opaques with bound vars the last time around:
* rust-lang#104321 (lower `async { .. }` directly as a generator that implements `Future`, removing the `from_generator` shim)
* rust-lang#104833 (removing an `identity_future` fn that was wrapping desugared future generators)

... so given that I can see:
* No significant regression on rust perf bot (rust-lang#107620 (comment))
* No timeouts in crater run I did (rust-lang#107620 (comment), rechecked failing crates in rust-lang#107620 (comment))

... and given that this PR:
* Fixes rust-lang#104601
* Fixes rust-lang#107557
* Fixes rust-lang#109464
* Allows us to remove a `DefiningAnchor::Bubble` from codegen (75a8f68)

I'm inclined to give this another shot at landing this. Best case, it just works -- worst case, we get more examples to study how we need to improve the compiler to make this work.

r? types
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. perf-regression-triaged The performance regression has been triaged. 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.

ICE: Failed to normalize <[closure] as std::ops::FnOnce<(&S,)>>::Output
9 participants