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
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
|
r? @JohnTitor rustbot has assigned @JohnTitor. Use Why was this reviewer chosen?The reviewer was selected based on:
|
d4ad7a6 to
6898626
Compare
This comment has been minimized.
This comment has been minimized.
6898626 to
760b9ae
Compare
| /// explicitly mentioned in user types. We do not encounter these in this query, | ||
| /// so we don't care about them. | ||
| /// | ||
| /// We never late bound regions from a parent while computing implied bounds for the current item. |
There was a problem hiding this comment.
| /// We never late bound regions from a parent while computing implied bounds for the current item. | |
| /// We never ??? late bound regions from a parent while computing implied bounds for the current item. |
There was a problem hiding this comment.
what do you not understand!
WE... NEVER... LATE!
760b9ae to
31fc0d7
Compare
|
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
31fc0d7 to
4c1d119
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
copied this over to #161047 with a final commit which reverts all changes for the old solver |
|
☔ The latest upstream changes (presumably #160982) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
|
🎉 Experiment
Footnotes
|
…white only next-solver: move implied bounds computation out of borrowck version of #160491 which does not enable this change for the old solver, meaning that we can merge it without a types team FCP :> r? adwinwhite
…white only next-solver: move implied bounds computation out of borrowck version of rust-lang/rust#160491 which does not enable this change for the old solver, meaning that we can merge it without a types team FCP :> r? adwinwhite
…white only next-solver: move implied bounds computation out of borrowck version of rust-lang/rust#160491 which does not enable this change for the old solver, meaning that we can merge it without a types team FCP :> r? adwinwhite
|
waddup T-types, see PR description, not rebasing as we've already merged this PR only for the new solver, so rebasing it on top of that would hide the actual impl change. See the PR description for a complete summary, the only user visible change is that implied bounds computation doesn't incorrectly drop implied bounds by equating NLL vars. Also worth it to review the actual change itself as while it doesn't matter for the current solver rn, the underlying concept is already significant and this will very much matter when stabilizing the new solver. @rfcbot fcp merge tpyes |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
@lcnr has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
View all comments
@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.