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

Compute NLL loan scopes using the polonius model #113218

Merged
merged 7 commits into from
Oct 11, 2023

Conversation

lqd
Copy link
Member

@lqd lqd commented Jun 30, 2023

For a location-insensitive analysis (that is, without expressiveness improvements for users yet), this PR implements loans going out of scope using reachability and liveness, rather than checking if the issuing region's values contain a given CFG point. This is equivalent to NLL scopes and computes the same data.

r? @matthewjasper

A couple of notes:

  • there are some assumptions about SCC representatives, placeholders, free regions, and member constraints that I believe hold, and they're documented in the code
  • this passes all the UI tests with -Zpolonius=next -- the perf is not terrible and there are a bunch of ways to improve it in the future.
  • there's a fixme left, hopefully Matthew you know a clean way to get the information it mentions.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 30, 2023
@rust-log-analyzer

This comment was marked as resolved.

@bors

This comment was marked as resolved.

@bors

This comment was marked as resolved.

@lqd
Copy link
Member Author

lqd commented Jul 27, 2023

@matthewjasper there are still things in there that I'd like to clean up, (e.g. I'm currently seeing whether some of the reachability computation can be done in liveness, and may try to make the look a bit more like the refactored CFG traversal) but I don't think they're absolutely necessary and won't change the core of the PR: you could already take a look whether you approve of the direction. It'd be greatly appreciated 🙏

Copy link
Contributor

@matthewjasper matthewjasper left a comment

Choose a reason for hiding this comment

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

Overall this approach seems fine as a first step.

It would be nice to have this "rebased" on the changes in #111759 to make determining the differences easier.

@lqd
Copy link
Member Author

lqd commented Jul 30, 2023

Thanks for taking a look.

It would be nice to have this "rebased" on the changes in #111759 to make determining the differences easier.

Sure, I'll try to tackle that soon.

It'll still have to be somewhat different, compared to diffing over https://github.com/lqd/rust/blob/eaddc3707520988f8bc2d267cb192d2f0c63ee80/compiler/rustc_borrowck/src/dataflow.rs#L155-L231 prior to the refactor and where it's easier to see that basically only the if !self.regioncx.region_contains(borrow_region, location) has changed -- as #111759 and its followup make more use of regions as sets of points during the CFG walk.

@bors

This comment was marked as resolved.

@Dylan-DPC Dylan-DPC 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-review Status: Awaiting review from the assignee but also interested parties. labels Aug 18, 2023
@bors

This comment was marked as resolved.

@lqd
Copy link
Member Author

lqd commented Oct 5, 2023

let's see the hit liveness takes to do additional checks on whether polonius is enabled

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

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

bors commented Oct 5, 2023

⌛ Trying commit 51ed991 with merge 263b07f...

bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 5, 2023
Compute NLL loan scopes using the polonius model

Draft PR to guide discussion for this monday's types team meeting, where the plan is to read this and review as a group.

For a *location-insensitive* analysis (that is, without expressiveness improvements for users yet), this PR implements loans going out of scope using reachability and liveness, rather than checking if the issuing region's values contain a given CFG point. This is equivalent to NLL scopes and computes the same data.

There are a few fixmes left, and I'll still work on them before the meeting.

A couple of notes:
- I started prototyping this a while ago so it follows the structure of the _previous_ NLL `OutOfScopePrecomputer`, before the couple recent refactors. They probably could/should look the same instead.
- there are some assumptions about placeholders, free regions, and member constraints that I think hold, and they're documented in the code
- this passes all the UI tests with `-Zpolonius=next` -- though the additional work done can be felt on the huge numeric/float tests, but the perf is [not terrible](rust-lang#112432 (comment)) and there are a bunch of ways to improve it in the future.

(cc `@matthewjasper` since you asked to be pinged about it)

r? `@ghost`
@bors
Copy link
Contributor

bors commented Oct 5, 2023

☀️ Try build successful - checks-actions
Build commit: 263b07f (263b07f838cae7fed15b3cb6147c2e0b0b1b44ec)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (263b07f): comparison URL.

Overall result: ❌ regressions - 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-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.

mean range count
Regressions ❌
(primary)
0.8% [0.7%, 0.9%] 4
Regressions ❌
(secondary)
0.7% [0.7%, 0.8%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.8% [0.7%, 0.9%] 4

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 621.055s -> 621.438s (0.06%)
Artifact size: 271.92 MiB -> 271.98 MiB (0.02%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Oct 5, 2023
@lqd
Copy link
Member Author

lqd commented Oct 5, 2023

This also should partly be noise: cachegrind only shows a 0.1% diff on helloworld. And the noise bumps shown below from the last few days, are to similar icounts within 0.03% of this run.

image

Similar noise on these benchmarks, with the same magnitude, is also currently present in other PRs, e.g. here.

That seems acceptable at least to start an initial review.

@rustbot ready

@lqd lqd marked this pull request as ready for review October 5, 2023 16:39
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 5, 2023
Copy link
Member

@jackh726 jackh726 left a comment

Choose a reason for hiding this comment

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

I don't think there's anything here that would cause me not to feel comfortable r+ing, but some thoughts nonetheless :)

compiler/rustc_borrowck/src/dataflow.rs Show resolved Hide resolved
compiler/rustc_borrowck/src/dataflow.rs Show resolved Hide resolved
compiler/rustc_borrowck/src/dataflow.rs Show resolved Hide resolved
Comment on lines +381 to +385
// FIXME: if the issuing region `i` can reach a live region `r` at point `p`, and `r` is
// live at point `q`, then it's guaranteed that `i` would reach `r` at point `q`.
// Reachability is location-insensitive, and we could take advantage of that, by jumping
// to a further point than just the next statement: we can jump to the furthest point
// within the block where `r` is live.
Copy link
Member

Choose a reason for hiding this comment

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

Could certainly do a binary search here - but I'm not sure the complexity would be helpful. What could be interesting is going from end to start (depends how often we expect loans to be live at the end of a block versus dying within (and where)

@jackh726
Copy link
Member

@bors r+

I think we can get this into tree. It's still behind a flag, so not worried.

@bors
Copy link
Contributor

bors commented Oct 11, 2023

📌 Commit 3dcff00 has been approved by jackh726

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 Oct 11, 2023
@matthiaskrgr
Copy link
Member

@bors p=6 moving over my rollup

@bors
Copy link
Contributor

bors commented Oct 11, 2023

⌛ Testing commit 3dcff00 with merge c1691db...

@bors
Copy link
Contributor

bors commented Oct 11, 2023

☀️ Test successful - checks-actions
Approved by: jackh726
Pushing c1691db to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 11, 2023
@bors bors merged commit c1691db into rust-lang:master Oct 11, 2023
11 checks passed
@rustbot rustbot added this to the 1.75.0 milestone Oct 11, 2023
@lqd lqd deleted the polonius-scopes branch October 11, 2023 20:11
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c1691db): comparison URL.

Overall result: ✅ 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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.2%] 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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.7% [-2.8%, -2.7%] 2
All ❌✅ (primary) - - 0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 628.128s -> 628.448s (0.05%)
Artifact size: 271.28 MiB -> 271.30 MiB (0.01%)

@rustbot rustbot removed the perf-regression Performance regression. label Oct 11, 2023
bors-ferrocene bot added a commit to ferrocene/ferrocene that referenced this pull request Oct 12, 2023
48: Pull upstream master 2023 10 12 r=tshepang a=Dajamante

* rust-lang/rust#113487
* rust-lang/rust#116506
* rust-lang/rust#116448
* rust-lang/rust#116640
  * rust-lang/rust#116627
  * rust-lang/rust#116597
  * rust-lang/rust#116436
  * rust-lang/rust#116315
  * rust-lang/rust#116219
* rust-lang/rust#113218
* rust-lang/rust#115937
* rust-lang/rust#116014
* rust-lang/rust#116623
* rust-lang/rust#112818
* rust-lang/rust#115948
* rust-lang/rust#116622
* rust-lang/rust#116621
  * rust-lang/rust#116612
  * rust-lang/rust#116611
  * rust-lang/rust#116530
  * rust-lang/rust#95967
* rust-lang/rust#116578
* rust-lang/rust#113915
* rust-lang/rust#116605
  * rust-lang/rust#116574
  * rust-lang/rust#116560
  * rust-lang/rust#116559
  * rust-lang/rust#116503
  * rust-lang/rust#116444
  * rust-lang/rust#116250
  * rust-lang/rust#109422
* rust-lang/rust#116598
  * rust-lang/rust#116596
  * rust-lang/rust#116595
  * rust-lang/rust#116589
  * rust-lang/rust#116586
* rust-lang/rust#116551
* rust-lang/rust#116409
* rust-lang/rust#116548
* rust-lang/rust#116366
* rust-lang/rust#109882
* rust-lang/rust#116497
* rust-lang/rust#116532
* rust-lang/rust#116569
  * rust-lang/rust#116561
  * rust-lang/rust#116556
  * rust-lang/rust#116549
  * rust-lang/rust#116543
  * rust-lang/rust#116537
  * rust-lang/rust#115882
* rust-lang/rust#116142
* rust-lang/rust#115238
* rust-lang/rust#116533
* rust-lang/rust#116096
* rust-lang/rust#116468
* rust-lang/rust#116515
* rust-lang/rust#116454
* rust-lang/rust#116183
* rust-lang/rust#116514
* rust-lang/rust#116509
* rust-lang/rust#116487
* rust-lang/rust#116486
* rust-lang/rust#116450
* rust-lang/rust#114623
* rust-lang/rust#116416
* rust-lang/rust#116437
* rust-lang/rust#100806
* rust-lang/rust#116330
* rust-lang/rust#116310
* rust-lang/rust#115583
* rust-lang/rust#116457
* rust-lang/rust#116508
* rust-lang/rust#109214
* rust-lang/rust#116318
* rust-lang/rust#116501
  * rust-lang/rust#116500
  * rust-lang/rust#116458
  * rust-lang/rust#116400
  * rust-lang/rust#116277
* rust-lang/rust#114709
* rust-lang/rust#116492
  * rust-lang/rust#116484
  * rust-lang/rust#116481
  * rust-lang/rust#116474
  * rust-lang/rust#116466
  * rust-lang/rust#116423
  * rust-lang/rust#116297
  * rust-lang/rust#114564
* rust-lang/rust#114811
* rust-lang/rust#116489
* rust-lang/rust#115304

Co-authored-by: Peter Hall <[email protected]>
Co-authored-by: Emanuele Vannacci <[email protected]>
Co-authored-by: Neven Villani <[email protected]>
Co-authored-by: Alex Macleod <[email protected]>
Co-authored-by: Tamir Duberstein <[email protected]>
Co-authored-by: Eduardo Sánchez Muñoz <[email protected]>
Co-authored-by: koka <[email protected]>
Co-authored-by: bors <[email protected]>
Co-authored-by: Philipp Krones <[email protected]>
Co-authored-by: Camille GILLOT <[email protected]>
Co-authored-by: Esteban Küber <[email protected]>
Co-authored-by: Ralf Jung <[email protected]>
bors-ferrocene bot added a commit to ferrocene/ferrocene that referenced this pull request Oct 13, 2023
48: Pull upstream master 2023 10 12 r=tshepang a=Dajamante

* rust-lang/rust#113487
* rust-lang/rust#116506
* rust-lang/rust#116448
* rust-lang/rust#116640
  * rust-lang/rust#116627
  * rust-lang/rust#116597
  * rust-lang/rust#116436
  * rust-lang/rust#116315
  * rust-lang/rust#116219
* rust-lang/rust#113218
* rust-lang/rust#115937
* rust-lang/rust#116014
* rust-lang/rust#116623
* rust-lang/rust#112818
* rust-lang/rust#115948
* rust-lang/rust#116622
* rust-lang/rust#116621
  * rust-lang/rust#116612
  * rust-lang/rust#116611
  * rust-lang/rust#116530
  * rust-lang/rust#95967
* rust-lang/rust#116578
* rust-lang/rust#113915
* rust-lang/rust#116605
  * rust-lang/rust#116574
  * rust-lang/rust#116560
  * rust-lang/rust#116559
  * rust-lang/rust#116503
  * rust-lang/rust#116444
  * rust-lang/rust#116250
  * rust-lang/rust#109422
* rust-lang/rust#116598
  * rust-lang/rust#116596
  * rust-lang/rust#116595
  * rust-lang/rust#116589
  * rust-lang/rust#116586
* rust-lang/rust#116551
* rust-lang/rust#116409
* rust-lang/rust#116548
* rust-lang/rust#116366
* rust-lang/rust#109882
* rust-lang/rust#116497
* rust-lang/rust#116532
* rust-lang/rust#116569
  * rust-lang/rust#116561
  * rust-lang/rust#116556
  * rust-lang/rust#116549
  * rust-lang/rust#116543
  * rust-lang/rust#116537
  * rust-lang/rust#115882
* rust-lang/rust#116142
* rust-lang/rust#115238
* rust-lang/rust#116533
* rust-lang/rust#116096
* rust-lang/rust#116468
* rust-lang/rust#116515
* rust-lang/rust#116454
* rust-lang/rust#116183
* rust-lang/rust#116514
* rust-lang/rust#116509
* rust-lang/rust#116487
* rust-lang/rust#116486
* rust-lang/rust#116450
* rust-lang/rust#114623
* rust-lang/rust#116416
* rust-lang/rust#116437
* rust-lang/rust#100806
* rust-lang/rust#116330
* rust-lang/rust#116310
* rust-lang/rust#115583
* rust-lang/rust#116457
* rust-lang/rust#116508
* rust-lang/rust#109214
* rust-lang/rust#116318
* rust-lang/rust#116501
  * rust-lang/rust#116500
  * rust-lang/rust#116458
  * rust-lang/rust#116400
  * rust-lang/rust#116277
* rust-lang/rust#114709
* rust-lang/rust#116492
  * rust-lang/rust#116484
  * rust-lang/rust#116481
  * rust-lang/rust#116474
  * rust-lang/rust#116466
  * rust-lang/rust#116423
  * rust-lang/rust#116297
  * rust-lang/rust#114564
* rust-lang/rust#114811
* rust-lang/rust#116489
* rust-lang/rust#115304

Co-authored-by: Emanuele Vannacci <[email protected]>
Co-authored-by: Neven Villani <[email protected]>
Co-authored-by: Alex Macleod <[email protected]>
Co-authored-by: Tamir Duberstein <[email protected]>
Co-authored-by: Eduardo Sánchez Muñoz <[email protected]>
Co-authored-by: koka <[email protected]>
Co-authored-by: bors <[email protected]>
Co-authored-by: Philipp Krones <[email protected]>
Co-authored-by: Camille GILLOT <[email protected]>
Co-authored-by: Esteban Küber <[email protected]>
Co-authored-by: Ralf Jung <[email protected]>
Co-authored-by: ShE3py <[email protected]>
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. 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.

9 participants