-
Couldn't load subscription status.
- Fork 13.9k
Make Visitor::visit_body take a plain &Body
#70449
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
Conversation
Visitor::visit_body take a simple BodyVisitor::visit_body take a simple &Body
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use &body instead of *body everywhere? I think it would've already coerced except ReadOnlyBodyAndCache is itself a reference internally so it's not passed by reference.
Although, I'm surprised ReadOnlyBodyAndCache exists, wouldn't &BodyAndCache also do the same thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReadOnlyBodyAndCache can only exist if the cache has already been precomputed. That guarantee doesn't hold with &BodyAndCache. That was the only reason a separate type was used. It would have been a lot easier if I could have just used &BodyAndCache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the assert here:
rust/src/librustc/mir/cache.rs
Lines 195 to 198 in a06baa5
| assert!( | |
| cache.predecessors.is_some(), | |
| "Cannot construct ReadOnlyBodyAndCache without computed predecessors" | |
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the reason a variant with &Body and &mut Cache doesn't work is that there were some places that required such a struct to be Copy, which doesn't hold with the &mut. Though I can't remember which trait was causing that issue.
|
cc @oli-obk |
src/librustc/mir/visit.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you're having the read-only case not require the cache? I actually hadn't even considered that when I first wrote this. That should actually make this a lot easier to use!
|
r? @oli-obk |
|
r=me after a rebase |
d52b4ac to
fc480d1
Compare
fc480d1 to
538cdef
Compare
Visitor::visit_body take a simple &BodyVisitor::visit_body take a plain &Body
|
@bors r=oli-obk |
|
📌 Commit 538cdef has been approved by |
|
☀️ Test successful - checks-azure |
|
📣 Toolstate changed by #70449! Tested on commit 0afdf43. 💔 clippy-driver on windows: test-pass → build-fail (cc @mcarton @oli-obk @Manishearth @flip1995 @yaahc @phansch @llogiq). |
Tested on commit rust-lang/rust@0afdf43. Direct link to PR: <rust-lang/rust#70449> 💔 clippy-driver on windows: test-pass → build-fail (cc @mcarton @oli-obk @Manishearth @flip1995 @yaahc @phansch @llogiq). 💔 clippy-driver on linux: test-pass → build-fail (cc @mcarton @oli-obk @Manishearth @flip1995 @yaahc @phansch @llogiq).
Rustup to rust-lang/rust#70449 cc rust-lang/rust#70449 changelog: none
Changes: ```` rustup rust-lang#70536 Rustup to rust-lang#70449 readme: move "how to run single lint" instructions to "Allowing/denying lints" section. git attribute macros not allowed in submodules Deprecate REPLACE_CONSTS lint Bump itertools ```` Fixes rust-lang#70554
submodules: update clippy from 70b93aa to e170c84 Changes: ```` rustup rust-lang#70536 Rustup to rust-lang#70449 readme: move "how to run single lint" instructions to "Allowing/denying lints" section. git attribute macros not allowed in submodules Deprecate REPLACE_CONSTS lint Bump itertools ```` Fixes rust-lang#70554
Changes: ```` rustup rust-lang/rust#70536 Rustup to rust-lang/rust#70449 readme: move "how to run single lint" instructions to "Allowing/denying lints" section. git attribute macros not allowed in submodules Deprecate REPLACE_CONSTS lint Bump itertools ```` Fixes #70554
ReadOnlyBodyAndCachehas replaced&Bodyin many parts of the code base that don't care about basic block predecessors. This includes the MIRVisitortrait, which I suspect resulted in many unnecessary changes in #64736. This reverts part of that PR to reduce the number of places where we need to pass aReadOnlyBodyAndCache.In the long term, we should either give
ReadOnlyBodyAndCachemore ergonomic name and replace all uses of&mir::Bodywith it at the cost of carrying an extra pointer everywhere, or use it only in places that actually need access to the predecessor cache. Perhaps there is an even nicer alternative.r? @Nashenas88