Skip to content
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

Opportunistically resolve regions in new solver #112443

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Jun 9, 2023

Use opportunistic_resolve_var during canonicalization to collapse some regions.

We have to start using CanonicalVarValues::is_identity_modulo_regions. We also have to modify that function to consider responses like ['static, ^0, '^1, ^2] to be an "identity" response, since because we opportunistically resolve regions, there's no longer a 1:1 mapping between canonical var values and bound var indices in the response...

There's one nasty side-effect -- one test (tests/ui/dyn-star/param-env-infer.rs) starts to ICE because the certainty goes from Yes to Maybe(Overflow)... Not exactly sure why, though? Putting this up for discussion/investigation.

r? @lcnr

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative labels Jun 9, 2023
@rustbot
Copy link
Collaborator

rustbot commented Jun 9, 2023

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

}
ty::GenericArgKind::Const(ct) => {
matches!(ct.kind(), ty::ConstKind::Bound(ty::INNERMOST, bc) if bc.as_usize() == bv)
let mut var = ty::BoundVar::from_u32(0);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This essentially just checks that the type and const vars are monotonically increasing, ignoring regions (which may have been resolved to a concrete region or a different region var).

// incremental

//[next] compile-flags: -Ztrait-solver=next
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ends up ICEing like:

https://gist.github.com/compiler-errors/2660fdd9902ec2686f6288b697953294

Not sure why it's overflowing now, though. I'll look into it tomorrow.

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the ICE is interesting 🤷

r=me after nit whether or not you fix the ICE

Copy link
Member

@aliemjay aliemjay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think region resolution should be limited to the query response. Resolving regions in the input side is bad for caching especially because we no longer "uniquify" input regions. It would also allow for trait selection bugs to easily rely on two input regions being equal.

@rust-cloud-vms rust-cloud-vms bot force-pushed the next-solver-opportunistically-resolve-regions branch from 5d0b44b to 01377e8 Compare June 13, 2023 22:11
@compiler-errors
Copy link
Member Author

Only opportunistically resolving regions on response (instead of on input), per @aliemjay's suggestion, actually also fixes that ICE. And I gave is_identity_modulo_regions a simpler implementation.

Think this PR is ready now.

@lcnr
Copy link
Contributor

lcnr commented Jun 15, 2023

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jun 15, 2023

📌 Commit 01377e8 has been approved by lcnr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 15, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 16, 2023
…unistically-resolve-regions, r=lcnr

Opportunistically resolve regions in new solver

Use `opportunistic_resolve_var` during canonicalization to collapse some regions.

We have to start using `CanonicalVarValues::is_identity_modulo_regions`. We also have to modify that function to consider responses like `['static, ^0, '^1, ^2]` to be an "identity" response, since because we opportunistically resolve regions, there's no longer a 1:1 mapping between canonical var values and bound var indices in the response...

There's one nasty side-effect -- one test (`tests/ui/dyn-star/param-env-infer.rs`) starts to ICE because the certainty goes from `Yes` to `Maybe(Overflow)`... Not exactly sure why, though? Putting this up for discussion/investigation.

r? `@lcnr`
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jun 16, 2023
…unistically-resolve-regions, r=lcnr

Opportunistically resolve regions in new solver

Use `opportunistic_resolve_var` during canonicalization to collapse some regions.

We have to start using `CanonicalVarValues::is_identity_modulo_regions`. We also have to modify that function to consider responses like `['static, ^0, '^1, ^2]` to be an "identity" response, since because we opportunistically resolve regions, there's no longer a 1:1 mapping between canonical var values and bound var indices in the response...

There's one nasty side-effect -- one test (`tests/ui/dyn-star/param-env-infer.rs`) starts to ICE because the certainty goes from `Yes` to `Maybe(Overflow)`... Not exactly sure why, though? Putting this up for discussion/investigation.

r? ``@lcnr``
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 16, 2023
Rollup of 7 pull requests

Successful merges:

 - rust-lang#112163 (fix: inline `predicate_may_hold_fatal` and remove expect call in it)
 - rust-lang#112399 (Instantiate closure synthetic substs in root universe)
 - rust-lang#112443 (Opportunistically resolve regions in new solver)
 - rust-lang#112535 (reorder attributes to make miri-test-libstd work again)
 - rust-lang#112579 (Fix building libstd documentation on FreeBSD.)
 - rust-lang#112639 (Fix `dead_code_cgu` computation)
 - rust-lang#112642 (Handle interpolated literal errors)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 64f6c00 into rust-lang:master Jun 16, 2023
11 checks passed
@rustbot rustbot added this to the 1.72.0 milestone Jun 16, 2023
@compiler-errors compiler-errors deleted the next-solver-opportunistically-resolve-regions branch August 11, 2023 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants