Skip to content

Remove ResultsVisitable - #132134

Merged
bors merged 2 commits into
rust-lang:masterfrom
nnethercote:rm-ResultsVisitable
Nov 17, 2024
Merged

Remove ResultsVisitable#132134
bors merged 2 commits into
rust-lang:masterfrom
nnethercote:rm-ResultsVisitable

Conversation

@nnethercote

@nnethercotennethercote commented Oct 25, 2024

Copy link
Copy Markdown
Contributor

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

r? @cjgillot.

@rustbotrustbot 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

bors commented Oct 30, 2024

Copy link
Copy Markdown
Collaborator

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

@nnethercote
nnethercoteforce-pushed the rm-ResultsVisitable branch 2 times, most recently from b6f5887 to ad84311CompareOctober 31, 2024 09:31
@nnethercote
nnethercote marked this pull request as ready for review October 31, 2024 09:31
@rustbot

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@bors

bors commented Nov 4, 2024

Copy link
Copy Markdown
Collaborator

☔ 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
Copy Markdown
ContributorAuthor

I rebased.

@nnethercote

Copy link
Copy Markdown
ContributorAuthor

@cjgillot: two week review ping!

@cjgillot

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Nov 16, 2024

Copy link
Copy Markdown
Collaborator

📌 Commit c904c6a has been approved by cjgillot

It is now in the queue for this repository.

@borsbors 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:masterNov 17, 2024
@rustbotrustbot 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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant 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

@nnethercote@bors@rustbot@cjgillot