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 ResultsVisitable #132134

Merged
merged 2 commits into from
Nov 17, 2024
Merged

Remove ResultsVisitable #132134

merged 2 commits into from
Nov 17, 2024

Conversation

nnethercote
Copy link
Contributor

@nnethercote nnethercote commented Oct 25, 2024

ResultsVisitable has annoyed me for a while. This PR removes it. Details in the individual commits.

r? @cjgillot.

@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 Oct 25, 2024
@bors
Copy link
Contributor

bors commented Oct 30, 2024

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

@nnethercote nnethercote force-pushed the rm-ResultsVisitable branch 2 times, most recently from b6f5887 to ad84311 Compare October 31, 2024 09:31
@nnethercote nnethercote marked this pull request as ready for review October 31, 2024 09:31
@rustbot
Copy link
Collaborator

rustbot commented Oct 31, 2024

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@bors
Copy link
Contributor

bors commented Nov 4, 2024

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

The results of most analyses end up in a `Results<'tcx, A>`, where `A`
is the analysis. It's then possible to traverse the results via a
`ResultsVisitor`, which relies on the `ResultsVisitable` trait. (That
trait ends up using the same `apply_*` methods that were used when
computing the analysis, albeit indirectly.)

This pattern of "compute analysis results, then visit them" is common.
But there is one exception. For borrow checking we compute three
separate analyses (`Borrows`, `MaybeUninitializedPlaces`, and
`EverInitializedPlaces`), combine them into a single `BorrowckResults`,
and then do a single visit of that `BorrowckResults` with
`MirBorrowckResults`. `BorrowckResults` is just different enough from
`Results` that it requires the existence of `ResultsVisitable`, which
abstracts over the traversal differences between `Results` and
`BorrowckResults`.

This commit changes things by introducing `Borrowck` and bundling the
three borrowck analysis results into a standard `Results<Borrowck>`
instead of the exceptional `BorrowckResults`. Once that's done, the
results can be visited like any other analysis results.
`BorrowckResults` is removed, as is `impl ResultsVisitable for
BorrowckResults`. (It's instructive to see how similar the added `impl
Analysis for Borrowck` is to the removed `impl ResultsVisitable for
BorrowckResults`. They're both doing exactly the same things.)

Overall this increases the number of lines of code and might not seem
like a win. But it enables the removal of `ResultsVisitable` in the next
commit, which results in many simplifications.
Now that `Results` is the only impl of `ResultsVisitable`, the trait can
be removed. This simplifies things by removining unnecessary layers of
indirection and abstraction.

- `ResultsVisitor` is simpler.
  - Its type parameter changes from `R` (an analysis result) to the
    simpler `A` (an analysis).
  - It no longer needs the `Domain` associated type, because it can use
    `A::Domain`.
  - Occurrences of `R` become `Results<'tcx, A>`, because there is now
    only one kind of analysis results.

- `save_as_intervals` also changes type parameter from `R` to `A`.

- The `results.reconstruct_*` method calls are replaced with
  `results.analysis.apply_*` method calls, which are equivalent.

- `Direction::visit_results_in_block` is simpler, with a single generic
  param (`A`) instead of two (`D` and `R`/`F`, with a bound connecting
  them). Likewise for `visit_results`.

- The `ResultsVisitor` impls for `MirBorrowCtxt` and
  `StorageConflictVisitor` are now specific about the type of the
  analysis results they work with. They both used to have a type param
  `R` but they weren't genuinely generic. In both cases there was only a
  single results type that made sense to instantiate them with.
@nnethercote
Copy link
Contributor Author

I rebased.

@nnethercote
Copy link
Contributor Author

@cjgillot: two week review ping!

@cjgillot
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Nov 16, 2024

📌 Commit c904c6a has been approved by cjgillot

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 Nov 16, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 16, 2024
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#131717 (Stabilize `const_atomic_from_ptr`)
 - rust-lang#132134 (Remove `ResultsVisitable`)
 - rust-lang#132449 (mark is_val_statically_known intrinsic as stably const-callable)
 - rust-lang#132569 (rustdoc search: allow queries to end in an empty path segment)
 - rust-lang#132787 (Unify FnKind between AST visitors and make WalkItemKind more straight forward)
 - rust-lang#132832 (Deny capturing late-bound ty/const params in nested opaques)
 - rust-lang#133097 (Opt out TaKO8Ki from review rotation for now)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 17, 2024
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#131717 (Stabilize `const_atomic_from_ptr`)
 - rust-lang#132134 (Remove `ResultsVisitable`)
 - rust-lang#132449 (mark is_val_statically_known intrinsic as stably const-callable)
 - rust-lang#132569 (rustdoc search: allow queries to end in an empty path segment)
 - rust-lang#132787 (Unify FnKind between AST visitors and make WalkItemKind more straight forward)
 - rust-lang#132832 (Deny capturing late-bound ty/const params in nested opaques)
 - rust-lang#133097 (Opt out TaKO8Ki from review rotation for now)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 5c81dbf into rust-lang:master Nov 17, 2024
6 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Nov 17, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 17, 2024
Rollup merge of rust-lang#132134 - nnethercote:rm-ResultsVisitable, r=cjgillot

Remove `ResultsVisitable`

`ResultsVisitable` has annoyed me for a while. This PR removes it. Details in the individual commits.

r? `@cjgillot.`
@nnethercote nnethercote deleted the rm-ResultsVisitable branch November 19, 2024 21:37
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.

4 participants