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

Properly consider binder vars in HasTypeFlagsVisitor #115834

Merged
merged 1 commit into from Sep 14, 2023

Conversation

compiler-errors
Copy link
Member

Given a PolyTraitRef like for<'a> Ty: Trait (where neither Ty nor Trait mention 'a), we do not return true for .has_type_flags(TypeFlags::HAS_LATE_BOUND), even though binders are supposed to act as if they have late-bound vars even if they don't mention them in their bound value: 31ae3b2. This is because we use HasTypeFlagsVisitor, which only computes the type flags for Ty, Const and Region and Predicates, and we consequently skip any binders (and setting flags for their vars) that are not contained in one of these types.

This ends up causing a problem, because when we call TyCtxt::erase_regions (which both erases regions and anonymizes bound vars), we will skip such a PolyTraitRef, not anonymizing it, and therefore not making it structurally equal to other binders. This breaks vtable computations.

This PR computes the flags for all binders we enter in HasTypeFlagsVisitor if we're looking for TypeFlags::HAS_LATE_BOUND (or TypeFlags::HAS_{RE,TY,CT}_LATE_BOUND).

Fixes #115807

@rustbot
Copy link
Collaborator

rustbot commented Sep 14, 2023

r? @jackh726

(rustbot has picked a reviewer for you, use r? to override)

@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. labels Sep 14, 2023
@jackh726
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Sep 14, 2023

📌 Commit 7ae301e has been approved by jackh726

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 Sep 14, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 14, 2023
…iaskrgr

Rollup of 4 pull requests

Successful merges:

 - rust-lang#115772 (Improve Span in smir)
 - rust-lang#115832 (Fix the error message for `#![feature(no_coverage)]`)
 - rust-lang#115834 (Properly consider binder vars in `HasTypeFlagsVisitor`)
 - rust-lang#115844 (Paper over an accidental regression)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 5737082 into rust-lang:master Sep 14, 2023
11 checks passed
@bors
Copy link
Contributor

bors commented Sep 14, 2023

⌛ Testing commit 7ae301e with merge ccf817b...

@rustbot rustbot added this to the 1.74.0 milestone Sep 14, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Sep 14, 2023
Rollup merge of rust-lang#115834 - compiler-errors:binder-vars, r=jackh726

Properly consider binder vars in `HasTypeFlagsVisitor`

Given a PolyTraitRef like `for<'a> Ty: Trait` (where neither `Ty` nor `Trait` mention `'a`), we do *not* return true for `.has_type_flags(TypeFlags::HAS_LATE_BOUND)`, even though binders are supposed to act as if they have late-bound vars even if they don't mention them in their bound value: 31ae3b2. This is because we use `HasTypeFlagsVisitor`, which only computes the type flags for `Ty`, `Const` and `Region` and `Predicates`, and we consequently skip any binders (and setting flags for their vars) that are not contained in one of these types.

This ends up causing a problem, because when we call `TyCtxt::erase_regions` (which both erases regions *and* anonymizes bound vars), we will skip such a PolyTraitRef, not anonymizing it, and therefore not making it structurally equal to other binders. This breaks vtable computations.

This PR computes the flags for all binders we enter in `HasTypeFlagsVisitor` if we're looking for `TypeFlags::HAS_LATE_BOUND` (or `TypeFlags::HAS_{RE,TY,CT}_LATE_BOUND`).

Fixes rust-lang#115807
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 4, 2023
…try>

Make sure that predicates with unmentioned bound vars are still considered global in the old solver

In the old solver, we consider predicates with late-bound vars to not be "global":
https://github.com/rust-lang/rust/blob/9c8a2694fadf3900c4d7880f6357cee60e9aa39b/compiler/rustc_trait_selection/src/traits/select/mod.rs#L1840-L1844

The implementation of `has_late_bound_vars` was modified in rust-lang#115834 so that we'd properly anonymize binders that had late-bound vars but didn't reference them. This fixed an ICE.

However, this also led to a behavioral change in rust-lang#117056 (comment) for a couple of crates, which now consider `for<'a> GL33: Shader` (note the binder var that is *not* used in the predicate) to not be "global". This forces associated types to not be normalizable due to the old trait solver being dumb.

This PR distinguishes types which *reference* late-bound vars and binders which *have* late-bound vars. The latter is represented with the new type flag `TypeFlags::HAS_BINDER_VARS`, which is used when we only care about knowing whether binders have vars in their bound var list (even if they're not used, like for binder anonymization).

This should fix (after beta backport) the `luminance-gl` and `luminance-webgl` crates in rust-lang#117056.

r? types
**(priority is kinda high on a review here given beta becomes stable on November 16.)**
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 4, 2023
…try>

Make sure that predicates with unmentioned bound vars are still considered global in the old solver

In the old solver, we consider predicates with late-bound vars to not be "global":
https://github.com/rust-lang/rust/blob/9c8a2694fadf3900c4d7880f6357cee60e9aa39b/compiler/rustc_trait_selection/src/traits/select/mod.rs#L1840-L1844

The implementation of `has_late_bound_vars` was modified in rust-lang#115834 so that we'd properly anonymize binders that had late-bound vars but didn't reference them. This fixed an ICE.

However, this also led to a behavioral change in rust-lang#117056 (comment) for a couple of crates, which now consider `for<'a> GL33: Shader` (note the binder var that is *not* used in the predicate) to not be "global". This forces associated types to not be normalizable due to the old trait solver being dumb.

This PR distinguishes types which *reference* late-bound vars and binders which *have* late-bound vars. The latter is represented with the new type flag `TypeFlags::HAS_BINDER_VARS`, which is used when we only care about knowing whether binders have vars in their bound var list (even if they're not used, like for binder anonymization).

This should fix (after beta backport) the `luminance-gl` and `luminance-webgl` crates in rust-lang#117056.

r? types
**(priority is kinda high on a review here given beta becomes stable on November 16.)**
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 5, 2023
…ackh726

Make sure that predicates with unmentioned bound vars are still considered global in the old solver

In the old solver, we consider predicates with late-bound vars to not be "global":
https://github.com/rust-lang/rust/blob/9c8a2694fadf3900c4d7880f6357cee60e9aa39b/compiler/rustc_trait_selection/src/traits/select/mod.rs#L1840-L1844

The implementation of `has_late_bound_vars` was modified in rust-lang#115834 so that we'd properly anonymize binders that had late-bound vars but didn't reference them. This fixed an ICE.

However, this also led to a behavioral change in rust-lang#117056 (comment) for a couple of crates, which now consider `for<'a> GL33: Shader` (note the binder var that is *not* used in the predicate) to not be "global". This forces associated types to not be normalizable due to the old trait solver being dumb.

This PR distinguishes types which *reference* late-bound vars and binders which *have* late-bound vars. The latter is represented with the new type flag `TypeFlags::HAS_BINDER_VARS`, which is used when we only care about knowing whether binders have vars in their bound var list (even if they're not used, like for binder anonymization).

This should fix (after beta backport) the `luminance-gl` and `luminance-webgl` crates in rust-lang#117056.

r? types
**(priority is kinda high on a review here given beta becomes stable on November 16.)**
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compiler error involving HRTBs
4 participants