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
|
r? @JohnTitor rustbot has assigned @JohnTitor. Use Why was this reviewer chosen?The reviewer was selected based on:
|
4b5fc7f to
70041ae
Compare
| //@ [wfcheck] check-pass | ||
| //@ [borrowck_current] check-fail | ||
| //@ [borrowck_current] known-bug: #106569 | ||
| //@ [borrowck_next] compile-flags: -Znext-solver |
There was a problem hiding this comment.
Don't we want to keep this?
There was a problem hiding this comment.
what do you mean? we are keeping this test. The only thing that changed is that this test now passes with all revisions
woops. jup jup
you're totally right 🤣 thank you
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%) |
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.