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

Fall back to bidirectional normalizes-to if no subst-relate candidate in alias-relate goal #112076

Merged
merged 2 commits into from
Jun 7, 2023

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented May 29, 2023

Sometimes we get into the case where the choice of normalizes-to branch in alias-relate are both valid, but we cannot make a choice of which one to take because they are different -- either returning equivalent but permuted region constraints, or equivalent opaque type definitions but differing modulo normalization.

In this case, we can make progress by considering a fourth candidate where we compute both normalizes-to branches together and canonicalize that as a response. This is essentially the AND intersection of both normalizes-to branches. In an ideal world, we'd be returning something more like the OR intersection of both branches, but we have no way of representing that either for regions (maybe eventually) or opaques (don't see that happening ever).

This is incomplete, so like the subst-relate fallback it's only considered outside of coherence. But it doesn't seem like a dramatic strengthening of inference or anything, and is useful for helping opaque type inference succeed when the hidden type is a projection.

Example

Consider the goal - AliasRelate(Tait, <[i32; 32] as IntoIterator>::IntoIter).

We have three ways of currently solving this goal:

  1. SubstRelate - fails because we can't directly equate the substs of different alias kinds.
  2. NormalizesToRhs - Tait normalizes-to <[i32; 32] as IntoIterator>::IntoIter
    • Ends up infering opaque definition - Tait := <[i32; 32] as IntoIterator>::IntoIter
  3. NormalizesToLhs - <[i32; 32] as IntoIterator>::IntoIter normalizes-to Tait
    • Find impl candidate, substitute the associated type - std::array::IntoIter<i32, 32>
    • Equate std::array::IntoIter<i32, 32> and Tait
      • Ends up infering opaque definition - Tait := std::array::IntoIter<i32, 32>

The problem here is that 2 and 3 are essentially both valid, since we have aliases that normalize on both sides, but due to lazy norm, they end up inferring different opaque type definitions that are only equal after normalizing them further.


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 May 29, 2023
@rustbot
Copy link
Collaborator

rustbot commented May 29, 2023

Some changes occurred to the core trait solver

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

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.

please also add TAIT eq TAIT tests

and projection eq projection, would assume that these are also possible

after that r=me (though I would wait for the first commit to land separately?)

@compiler-errors
Copy link
Member Author

Cannot for the life of me construct an example that involves projections only. I think this is a consequence of us still doing eager norm during HIR typeck in some places, and also a consequence of us not using the RHS of a projection predicate during candidate assembly.

@compiler-errors
Copy link
Member Author

Cannot for the life of me construct an example that involves projections only

Nevermind, here's a projection-relate-projection test that has to do with regions: rust-lang/trait-system-refactor-initiative#25 (comment)

Perhaps harder to construct an example that involves infer vars, but I've kinda given up on that :s

@lcnr
Copy link
Contributor

lcnr commented Jun 6, 2023

r=me after rebase

@lcnr lcnr added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 6, 2023
@compiler-errors
Copy link
Member Author

@bors r=lcnr

@bors
Copy link
Contributor

bors commented Jun 6, 2023

📌 Commit 3ea7c51 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 6, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 7, 2023
Rollup of 6 pull requests

Successful merges:

 - rust-lang#112076 (Fall back to bidirectional normalizes-to if no subst-relate candidate in alias-relate goal)
 - rust-lang#112122 (Add `-Ztrait-solver=next-coherence`)
 - rust-lang#112251 (rustdoc: convert `if let Some()` that always matches to variable)
 - rust-lang#112345 (fix(expand): prevent infinity loop in macro containing only "///")
 - rust-lang#112359 (Respect `RUST_BACKTRACE` for delayed bugs)
 - rust-lang#112382 (download-rustc: Fix `x test core` on MacOS)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit cbe429c into rust-lang:master Jun 7, 2023
@rustbot rustbot added this to the 1.72.0 milestone Jun 7, 2023
@compiler-errors compiler-errors deleted the bidirectional-alias-eq branch August 11, 2023 19:56
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.

4 participants