move implied bounds computation out of borrowck - #160491
Conversation
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
move implied bounds computation out of borrowck
48a8766 to
5c0c099
Compare
6eb8247 to
1dd6c27
Compare
|
@bors cancel @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
|
❗ There is currently no auto build in progress on this PR. Hint: There is a pending try build on this PR. Maybe you meant to cancel it? You can do that using |
This comment has been minimized.
This comment has been minimized.
move implied bounds computation out of borrowck
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
move implied bounds computation out of borrowck
This comment has been minimized.
This comment has been minimized.
70041ae to
9151a02
Compare
|
@craterbot check |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
Finished benchmarking commit (615014f): comparison URL. Overall result: ❌✅ regressions and improvements - please read:Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never rustc-perf Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 1.3%, secondary -0.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -0.1%, secondary -0.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 489.838s -> 489.061s (-0.16%) |
9151a02 to
73c2b60
Compare
This comment has been minimized.
This comment has been minimized.
73c2b60 to
4dd4689
Compare
cleanup borrowck, improve c-variadic handling The first commits of rust-lang#160491. Hopefully all of them make sense. It feels intuitive to me that the `c-variadic` region should be just another late-bound region and tracking region correctly for rust-lang#160491 is otherwise a mess. r? types
cleanup borrowck, improve c-variadic handling The first commits of rust-lang#160491. Hopefully all of them make sense. It feels intuitive to me that the `c-variadic` region should be just another late-bound region and tracking region correctly for rust-lang#160491 is otherwise a mess. r? types
cleanup borrowck, improve c-variadic handling The first commits of rust-lang#160491. Hopefully all of them make sense. It feels intuitive to me that the `c-variadic` region should be just another late-bound region and tracking region correctly for rust-lang#160491 is otherwise a mess. r? types
cleanup borrowck, improve c-variadic handling The first commits of rust-lang#160491. Hopefully all of them make sense. It feels intuitive to me that the `c-variadic` region should be just another late-bound region and tracking region correctly for rust-lang#160491 is otherwise a mess. r? types
| constraints.push(c); | ||
| } | ||
| } | ||
| Err::<_, ErrorGuaranteed>(_) => {} |
There was a problem hiding this comment.
why can we ignore errors here?
| // However, for nested bodies, we always check that they are well-formed in their | ||
| // parent body, so for these we do want to define opaque types. Not doing so can result | ||
| // in incorrect errors when normalizing implied bounds. |
There was a problem hiding this comment.
Nested bodies are exempted because
- To have implied bounds from hidden types, they need to have opaques in their signatures.
- If they have opaques in the signatures, the call to them would add wf obligations for normalized inputs and output thus those implied bounds are still checked in the parent.
Is my understanding correct? 🤔
| let var_values = implied_bounds_query_var_values(tcx, &inputs_and_output, |r| match r.kind() { | ||
| ty::RePlaceholder(_) => true, | ||
| ty::ReEarlyParam(_) | ||
| | ty::ReLateParam(_) | ||
| | ty::ReBound(..) | ||
| | ty::ReStatic | ||
| | ty::ReError(_) => false, | ||
| ty::ReVar(..) | ty::ReErased => unreachable!(), | ||
| }); | ||
| let input_values = CanonicalVarValues { var_values: tcx.mk_args(&var_values) }; |
There was a problem hiding this comment.
Confused here 🤔
Placeholders are from erased regions and closure ty has erased regions in signature and upvars.
So these var_values are corresponding to local universals while we compute the original vars from external universals in compute_implied_bounds. Why so?
| use crate::traits::query::NoSolution; | ||
| use crate::traits::{ObligationCtxt, wf}; | ||
|
|
||
| impl<'tcx> super::QueryTypeOp<'tcx> for ImpliedOutlivesBounds<'tcx> { |
There was a problem hiding this comment.
ImpliedOutlivesBounds is no longer a type op. Maybe we can cleanup the file path later?
| } | ||
| } | ||
|
|
||
| pub fn query_compute_implied_outlives_bounds<'tcx>( |
There was a problem hiding this comment.
Why don't we worry about the same implied bounds problem in wfcheck? Because mir borrowck would run first if opaques are involved? 🤔
cleanup borrowck, improve c-variadic handling The first commits of rust-lang#160491. Hopefully all of them make sense. It feels intuitive to me that the `c-variadic` region should be just another late-bound region and tracking region correctly for rust-lang#160491 is otherwise a mess. r? types
cleanup borrowck, improve c-variadic handling The first commits of rust-lang#160491. Hopefully all of them make sense. It feels intuitive to me that the `c-variadic` region should be just another late-bound region and tracking region correctly for rust-lang#160491 is otherwise a mess. r? types
cleanup borrowck, improve c-variadic handling The first commits of rust-lang#160491. Hopefully all of them make sense. It feels intuitive to me that the `c-variadic` region should be just another late-bound region and tracking region correctly for rust-lang#160491 is otherwise a mess. r? types
cleanup borrowck, improve c-variadic handling The first commits of rust-lang#160491. Hopefully all of them make sense. It feels intuitive to me that the `c-variadic` region should be just another late-bound region and tracking region correctly for rust-lang#160491 is otherwise a mess. r? types
|
☔ The latest upstream changes (presumably #160725) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
Rollup merge of #160504 - lcnr:borrowck-cleanup, r=oli-obk cleanup borrowck, improve c-variadic handling The first commits of #160491. Hopefully all of them make sense. It feels intuitive to me that the `c-variadic` region should be just another late-bound region and tracking region correctly for #160491 is otherwise a mess. r? types
cleanup borrowck, improve c-variadic handling The first commits of rust-lang/rust#160491. Hopefully all of them make sense. It feels intuitive to me that the `c-variadic` region should be just another late-bound region and tracking region correctly for rust-lang/rust#160491 is otherwise a mess. r? types
View all comments
First 3 commits don't change behavior and I moved them into #160504.
@tiif did the initial implementation work in #152051. This ended up being more involved than I originally expected, so I ended up finishing this PR after spending a few days on it myself.
Computing implied bounds now happens in a new query
mir_borrowck_implied_outlives_boundswhich does two things differently from MIR borrowck:Using param and placeholder regions instead of NLL vars
This fixes #106569. We previously computed the implied bounds using
ty::ReVareven for universal variables, which meant that resolving them can drop constraints in borrowck.As explained in #106569 (comment)
Computing implied bounds now uses universal variables instead of
ReVar, fixing this issue.Do not reveal the hidden type of opaques for typeck roots
This fixes rust-lang/trait-system-refactor-initiative#159 with the new trait solver.
Computing the implied bounds for
boompreviously revealed the hidden type ofimpl Extend<'a, 'b>giving us a'a: 'bimplied bound. Callingboomcannot reveal the opaque type as it's outside of the defining scope, so the caller never has to prove that outlives requirement.We do still reveal opaque types when computing the implied bounds for nested bodies! This is subtle and I nearly missed this. For nested bodies, they are only ever used inside of their parent function, which is able to define the same opaque types. We never check that e.g. a closure is well-formed outside of the parent body.
This means trying to compute implied bounds for closures without defining opaque types can result in incorrect errors, see tests/ui/traits/next-solver/opaques/implied-bounds-opaque-hidden-in-closure-sig.rs:
Implementation details and nuances
var_valuesReturning implied bounds and canonicalization. Figuring out how to do so was quite challenging. The main question is how to link regions from the query to the correct regions in MIR borrowck. The way to do so is via
var_values.As we're using old style canonicalizing we keep early and late bound parameters around, so these don't have to be part of the
var_values. We do need to link regions from the closure signature in the query to the regions in the signature used in MIR borrowck. We do this by going over the signature and collecting all regions we find in thevar_values. The query uses placeholders for these while MIR borrowck uses external NLL vars for them.Normalizing the signature and unconstrained region vars
Normalizing a function signature can result in unconstrained existential regions due to #136547. Types involving these regions can be relevant for implied bounds. Using such type outlives bounds relies on structural equality. If we separately normalize the signature two times, once in borrowck and once in the implied bounds query, we get different unconstrained region vars, breaking the
gluon_salsatest.To avoid this,
mir_borrowck_implied_outlives_boundsnormalizes the signature without revealing opaque types and returns its result to MIR borrowck. MIR borrowck now renormalizes this signature to also correctly normalize opaque types.The bevy implied bounds hack
This PR keeps the current behavior of #119956 while somewhat changing the actual implementation.
We continue to consider constraints from computing implied bounds as implied bounds only for arguments whose type mentions
bevy_ecs::ParamSet.