-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Resolver: introduce a conditionally mutable Resolver for (non-)speculative resolution. #144912
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
4d8cc9f
to
3ab8e2f
Compare
This comment has been minimized.
This comment has been minimized.
Looks good to me at high level. Although I expected to use impl Resolver {
fn method(self: SmartResolver) { ... }
} instead of impl SmartResolver {
fn method(&mut self) { ... }
} (It would also allow to avoid moving code and make the diff readable.) |
I though arbitrary self types were not allowed? Only std smartpointers and Pin. |
There's |
The current scheme of constructing I think the fn smart(&mut self) -> SmartResolver {
if self.speculative { SmartResolver::Speculative(self) } else { SmartResolver::Finalize(self) }
} And then every resolver method taking Of course there may be some temporary escape hatch until |
I very much agree.
Currently, mutating this flag shouldn't be a problem, since |
Also, this seems a bit extreme, I'm sure not every &mut self should be a SmartResolver. |
How are you going to guaranteed that this |
Good point, didn't think of it like that. It is going to take some time. |
So we'd only call self.res_mut().some_field = some_value; |
Hmm, but on the other hand if I guess it's not necessary to convert everything then, just convert enough functions directly or called by |
I converted some more to use a SmartResolver and I also checked every call for mutable resolver usages in Still wrapped @rustbot ready |
It's used relatively often so let's make it short.
Alternatively:
Could also be @rustbot author |
Reminder, once the PR becomes ready for a review, use |
Also need to update the PR title and description. |
I like the Edit: same convention as |
@rustbot ready |
^^^ |
SmartResolver
for speculative and finalize resolutions.
✌️ @LorrensP-2158466, you can now approve this pull request! If @petrochenkov told you to " |
e34dfc0
to
487e5ce
Compare
…=petrochenkov Resolver: introduce a conditionally mutable Resolver for (non-)speculative resolution. This pr introduces a `CmResolver`, a wrapper around the main resolver which gives out mutable access given a condition. `CmResolver` only allows mutation when we’re not in speculative import resolution. This ensures we can’t accidentally mutate the resolver during this process, which is important as we move towards a batched resolution algorithm. This also changes functions that are used during speculative import resolution to take a `CmResolver` instead of a `&mut Resolver`. Also introduces a new kind of "smart pointer" which has the behaviour described above: ```rust /// A wrapper around a mutable reference that conditionally allows mutable access. pub(crate) struct RefOrMut<'a, T> { p: &'a mut T, mutable: bool, } type CmResolver<'r, 'ra, 'tcx> = RefOrMut<'r, Resolver<'ra, 'tcx>>; ``` r? petrochenkov
Rollup of 19 pull requests Successful merges: - #144400 (`tests/ui/issues/`: The Issues Strike Back [3/N]) - #144764 ([codegen] assume the tag, not the relative discriminant) - #144807 (Streamline config in bootstrap) - #144899 (Print CGU reuse statistics in `-Zprint-mono-items`) - #144909 (Add new `test::print_merged_doctests_times` used by rustdoc to display more detailed time information) - #144912 (Resolver: introduce a conditionally mutable Resolver for (non-)speculative resolution.) - #144914 (Add support for `ty::Instance` path shortening in diagnostics) - #144931 ([win][arm64ec] Fix msvc-wholearchive for Arm64EC) - #144999 (coverage: Remove all unstable support for MC/DC instrumentation) - #145009 (A couple small changes for rust-analyzer next-solver work) - #145030 (GVN: Do not flatten derefs with ProjectionElem::Index. ) - #145042 (stdarch subtree update) - #145047 (move `type_check` out of `compute_regions`) - #145051 (Prevent name collisions with internal implementation details) - #145053 (Add a lot of NLL `known-bug` tests) - #145055 (Move metadata symbol export from exported_non_generic_symbols to exported_symbols) - #145057 (Clean up some resolved test regressions of const trait removals in std) - #145068 (Readd myself to review queue) - #145070 (Add minimal `armv7a-vex-v5` tier three target) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #144912 - LorrensP-2158466:smart-resolver, r=petrochenkov Resolver: introduce a conditionally mutable Resolver for (non-)speculative resolution. This pr introduces a `CmResolver`, a wrapper around the main resolver which gives out mutable access given a condition. `CmResolver` only allows mutation when we’re not in speculative import resolution. This ensures we can’t accidentally mutate the resolver during this process, which is important as we move towards a batched resolution algorithm. This also changes functions that are used during speculative import resolution to take a `CmResolver` instead of a `&mut Resolver`. Also introduces a new kind of "smart pointer" which has the behaviour described above: ```rust /// A wrapper around a mutable reference that conditionally allows mutable access. pub(crate) struct RefOrMut<'a, T> { p: &'a mut T, mutable: bool, } type CmResolver<'r, 'ra, 'tcx> = RefOrMut<'r, Resolver<'ra, 'tcx>>; ``` r? petrochenkov
Rollup of 19 pull requests Successful merges: - rust-lang/rust#144400 (`tests/ui/issues/`: The Issues Strike Back [3/N]) - rust-lang/rust#144764 ([codegen] assume the tag, not the relative discriminant) - rust-lang/rust#144807 (Streamline config in bootstrap) - rust-lang/rust#144899 (Print CGU reuse statistics in `-Zprint-mono-items`) - rust-lang/rust#144909 (Add new `test::print_merged_doctests_times` used by rustdoc to display more detailed time information) - rust-lang/rust#144912 (Resolver: introduce a conditionally mutable Resolver for (non-)speculative resolution.) - rust-lang/rust#144914 (Add support for `ty::Instance` path shortening in diagnostics) - rust-lang/rust#144931 ([win][arm64ec] Fix msvc-wholearchive for Arm64EC) - rust-lang/rust#144999 (coverage: Remove all unstable support for MC/DC instrumentation) - rust-lang/rust#145009 (A couple small changes for rust-analyzer next-solver work) - rust-lang/rust#145030 (GVN: Do not flatten derefs with ProjectionElem::Index. ) - rust-lang/rust#145042 (stdarch subtree update) - rust-lang/rust#145047 (move `type_check` out of `compute_regions`) - rust-lang/rust#145051 (Prevent name collisions with internal implementation details) - rust-lang/rust#145053 (Add a lot of NLL `known-bug` tests) - rust-lang/rust#145055 (Move metadata symbol export from exported_non_generic_symbols to exported_symbols) - rust-lang/rust#145057 (Clean up some resolved test regressions of const trait removals in std) - rust-lang/rust#145068 (Readd myself to review queue) - rust-lang/rust#145070 (Add minimal `armv7a-vex-v5` tier three target) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 19 pull requests Successful merges: - rust-lang/rust#144400 (`tests/ui/issues/`: The Issues Strike Back [3/N]) - rust-lang/rust#144764 ([codegen] assume the tag, not the relative discriminant) - rust-lang/rust#144807 (Streamline config in bootstrap) - rust-lang/rust#144899 (Print CGU reuse statistics in `-Zprint-mono-items`) - rust-lang/rust#144909 (Add new `test::print_merged_doctests_times` used by rustdoc to display more detailed time information) - rust-lang/rust#144912 (Resolver: introduce a conditionally mutable Resolver for (non-)speculative resolution.) - rust-lang/rust#144914 (Add support for `ty::Instance` path shortening in diagnostics) - rust-lang/rust#144931 ([win][arm64ec] Fix msvc-wholearchive for Arm64EC) - rust-lang/rust#144999 (coverage: Remove all unstable support for MC/DC instrumentation) - rust-lang/rust#145009 (A couple small changes for rust-analyzer next-solver work) - rust-lang/rust#145030 (GVN: Do not flatten derefs with ProjectionElem::Index. ) - rust-lang/rust#145042 (stdarch subtree update) - rust-lang/rust#145047 (move `type_check` out of `compute_regions`) - rust-lang/rust#145051 (Prevent name collisions with internal implementation details) - rust-lang/rust#145053 (Add a lot of NLL `known-bug` tests) - rust-lang/rust#145055 (Move metadata symbol export from exported_non_generic_symbols to exported_symbols) - rust-lang/rust#145057 (Clean up some resolved test regressions of const trait removals in std) - rust-lang/rust#145068 (Readd myself to review queue) - rust-lang/rust#145070 (Add minimal `armv7a-vex-v5` tier three target) r? `@ghost` `@rustbot` modify labels: rollup
This pr introduces a
CmResolver
, a wrapper around the main resolver which gives out mutable access given a condition.CmResolver
only allows mutation when we’re not in speculative import resolution. This ensures we can’t accidentally mutate the resolver during this process, which is important as we move towards a batched resolution algorithm.This also changes functions that are used during speculative import resolution to take a
CmResolver
instead of a&mut Resolver
.Also introduces a new kind of "smart pointer" which has the behaviour described above:
r? petrochenkov