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

don't uniquify regions when canonicalizing #110180

Merged
merged 3 commits into from
Apr 14, 2023
Merged

Conversation

lcnr
Copy link
Contributor

@lcnr lcnr commented Apr 11, 2023

uniquifying causes a bunch of issues, most notably it causes AliasEq(<?x as Trait<'a>>::Assoc, <?x as Trait<'a>>::Assoc) to result in ambiguity because both normalizes-to paths result in ambiguity and substs equate should trivially succeed but doesn't because we uniquified 'a to two different regions.

I originally added uniquification to make it easier to deal with requirement 6 from the dev-guide: https://rustc-dev-guide.rust-lang.org/solve/trait-solving.html#requirements

6. Trait solving must be (free) lifetime agnostic

Trait solving during codegen should have the same result as during typeck. As we erase
all free regions during codegen we must not rely on them during typeck. A noteworthy example
is special behavior for 'static.

cc rust-lang/rustc-dev-guide#1671

Relying on regions being identical may cause ICE during MIR typeck, but even without this PR we can end up relying on that as type inference vars can resolve to types which contain an identical region. Let's land this and deal with any ICE that crop up as we go. Will look at this issue again before stabilization.

r? @compiler-errors

this test was added for rust 0.4 and doesn't test anything specific.
The repro originally relied on extern functions which are now just
ordinary methods. It's also a run pass test even though `main` has
been commented out.
@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 Apr 11, 2023
@rustbot
Copy link
Collaborator

rustbot commented Apr 11, 2023

Some changes occurred to the core trait solver

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

@lcnr
Copy link
Contributor Author

lcnr commented Apr 13, 2023

@rustbot ready

@compiler-errors
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Apr 13, 2023

📌 Commit 43e6f99 has been approved by compiler-errors

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 Apr 13, 2023
@compiler-errors
Copy link
Member

Whoops, I forgot that we had discussed that I should add a test to show that not uniquifying regions actually fixed the HIR issue I was seeing (and tried to fix in #109617). Pushed that test on top of the stack.

@bors r+

@bors
Copy link
Contributor

bors commented Apr 14, 2023

📌 Commit c68c6c3 has been approved by compiler-errors

It is now in the queue for this repository.

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Apr 14, 2023
don't uniquify regions when canonicalizing

uniquifying causes a bunch of issues, most notably it causes `AliasEq(<?x as Trait<'a>>::Assoc, <?x as Trait<'a>>::Assoc)` to result in ambiguity because both `normalizes-to` paths result in ambiguity and substs equate should trivially succeed but doesn't because we uniquified `'a` to two different regions.

I originally added uniquification to make it easier to deal with requirement 6 from the dev-guide: https://rustc-dev-guide.rust-lang.org/solve/trait-solving.html#requirements

> ### 6. Trait solving must be (free) lifetime agnostic
>
> Trait solving during codegen should have the same result as during typeck. As we erase
> all free regions during codegen we must not rely on them during typeck. A noteworthy example
> is special behavior for `'static`.

cc rust-lang/rustc-dev-guide#1671

Relying on regions being identical may cause ICE during MIR typeck, but even without this PR we can end up relying on that as type inference vars can resolve to types which contain an identical region. Let's land this and deal with any ICE that crop up as we go. Will look at this issue again before stabilization.

r? `@compiler-errors`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 14, 2023
don't uniquify regions when canonicalizing

uniquifying causes a bunch of issues, most notably it causes `AliasEq(<?x as Trait<'a>>::Assoc, <?x as Trait<'a>>::Assoc)` to result in ambiguity because both `normalizes-to` paths result in ambiguity and substs equate should trivially succeed but doesn't because we uniquified `'a` to two different regions.

I originally added uniquification to make it easier to deal with requirement 6 from the dev-guide: https://rustc-dev-guide.rust-lang.org/solve/trait-solving.html#requirements

> ### 6. Trait solving must be (free) lifetime agnostic
>
> Trait solving during codegen should have the same result as during typeck. As we erase
> all free regions during codegen we must not rely on them during typeck. A noteworthy example
> is special behavior for `'static`.

cc rust-lang/rustc-dev-guide#1671

Relying on regions being identical may cause ICE during MIR typeck, but even without this PR we can end up relying on that as type inference vars can resolve to types which contain an identical region. Let's land this and deal with any ICE that crop up as we go. Will look at this issue again before stabilization.

r? ``@compiler-errors``
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 14, 2023
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#109225 (Clarify that RUST_MIN_STACK may be internally cached)
 - rust-lang#109800 (Improve safe transmute error reporting)
 - rust-lang#110158 (Remove obsolete test case)
 - rust-lang#110180 (don't uniquify regions when canonicalizing)
 - rust-lang#110207 (Assemble `Unpin` candidates specially for generators in new solver)
 - rust-lang#110276 (Remove all but one of the spans in `BoundRegionKind::BrAnon`)
 - rust-lang#110279 (rustdoc: Correctly handle built-in compiler proc-macros as proc-macro and not macro)
 - rust-lang#110298 (Cover edge cases for {f32, f64}.hypot() docs)
 - rust-lang#110299 (Switch to `EarlyBinder` for `impl_subject` query)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 44db7c3 into rust-lang:master Apr 14, 2023
@rustbot rustbot added this to the 1.70.0 milestone Apr 14, 2023
@lcnr lcnr deleted the canonicalize branch April 14, 2023 12:08
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 27, 2023
…lcnr

Restore region uniquification in the new solver 🎉

All of the bugs that were "due" to uniquification have been settled via other means (e.g. bidirectional alias-relate, param-env incompleteness, etc).

Firstly, revert the functional changes in rust-lang#110180. 😸

Secondly, we need to ignore regions when considering if a goal has changed (the "has_changed" boolean returned from `evaluate_goal`) -- otherwise, because we're doing region uniquification, we may perpetually consider a goal to be changed. See the UI test I committed for an explanation.
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