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

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

Merged
merged 1 commit into from
Nov 5, 2023

Conversation

compiler-errors
Copy link
Member

In the old solver, we consider predicates with late-bound vars to not be "global":

// Check if a bound would previously have been removed when normalizing
// the param_env so that it can be given the lowest priority. See
// #50825 for the motivation for this.
let is_global =
|cand: &ty::PolyTraitPredicate<'tcx>| cand.is_global() && !cand.has_late_bound_vars();

The implementation of has_late_bound_vars was modified in #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 #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 #117056.

r? types
(priority is kinda high on a review here given beta becomes stable on November 16.)

@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 Nov 4, 2023
@compiler-errors compiler-errors assigned jackh726 and unassigned BoxyUwU Nov 4, 2023
@compiler-errors

This comment was marked as outdated.

@compiler-errors

This comment was marked as outdated.

@bors

This comment was marked as outdated.

@bors

This comment was marked as outdated.

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.)**
@compiler-errors
Copy link
Member Author

@bors try

@bors
Copy link
Contributor

bors commented Nov 4, 2023

⌛ Trying commit 32294fc with merge 1e981f3...

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.)**
@jackh726
Copy link
Member

jackh726 commented Nov 4, 2023

r=me with or without crater (maybe we want to land and then do a crater run?)

@bors
Copy link
Contributor

bors commented Nov 4, 2023

☀️ Try build successful - checks-actions
Build commit: 1e981f3 (1e981f329e2ae73beb121ad9b30e8013bc4ead78)

@compiler-errors
Copy link
Member Author

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-117589 created and queued.
🤖 Automatically detected try build 1e981f3
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 4, 2023
@compiler-errors
Copy link
Member Author

@bors r=jackh726 rollup=never

@bors
Copy link
Contributor

bors commented Nov 4, 2023

📌 Commit 32294fc 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-crater Status: Waiting on a crater run to be completed. labels Nov 4, 2023
@craterbot
Copy link
Collaborator

🚧 Experiment pr-117589 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@bors
Copy link
Contributor

bors commented Nov 5, 2023

⌛ Testing commit 32294fc with merge f64d028...

@bors
Copy link
Contributor

bors commented Nov 5, 2023

☀️ Test successful - checks-actions
Approved by: jackh726
Pushing f64d028 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 5, 2023
@bors bors merged commit f64d028 into rust-lang:master Nov 5, 2023
11 checks passed
@rustbot rustbot added this to the 1.75.0 milestone Nov 5, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f64d028): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.4% [0.8%, 2.6%] 4
Regressions ❌
(secondary)
2.7% [2.7%, 2.7%] 1
Improvements ✅
(primary)
-0.9% [-2.3%, -0.4%] 4
Improvements ✅
(secondary)
-1.0% [-1.0%, -1.0%] 1
All ❌✅ (primary) 0.3% [-2.3%, 2.6%] 8

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.5% [0.5%, 0.6%] 2
Regressions ❌
(secondary)
0.5% [0.5%, 0.5%] 1
Improvements ✅
(primary)
-0.5% [-0.7%, -0.4%] 4
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.2% [-0.7%, 0.6%] 6

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 638.32s -> 638.639s (0.05%)
Artifact size: 304.42 MiB -> 304.53 MiB (0.04%)

bors-ferrocene bot added a commit to ferrocene/ferrocene that referenced this pull request Nov 6, 2023
84: Automated pull from upstream `master` r=Dajamante a=github-actions[bot]


This PR pulls the following changes from the upstream repository:

* rust-lang/rust#117585
* rust-lang/rust#117576
* rust-lang/rust#96979
* rust-lang/rust#117191
* rust-lang/rust#117179
* rust-lang/rust#117574
* rust-lang/rust#117537
* rust-lang/rust#117608
  * rust-lang/rust#117596
  * rust-lang/rust#117588
  * rust-lang/rust#117524
  * rust-lang/rust#116017
* rust-lang/rust#117504
* rust-lang/rust#117469
* rust-lang/rust#116218
* rust-lang/rust#117589
* rust-lang/rust#117581
* rust-lang/rust#117503
* rust-lang/rust#117590
  * rust-lang/rust#117583
  * rust-lang/rust#117570
  * rust-lang/rust#117562
  * rust-lang/rust#117534
  * rust-lang/rust#116894
  * rust-lang/rust#110340
* rust-lang/rust#113343
* rust-lang/rust#117579
* rust-lang/rust#117094
* rust-lang/rust#117566
* rust-lang/rust#117564
  * rust-lang/rust#117554
  * rust-lang/rust#117550
  * rust-lang/rust#117343
* rust-lang/rust#115274
* rust-lang/rust#117540
* rust-lang/rust#116412
* rust-lang/rust#115333
* rust-lang/rust#117507
* rust-lang/rust#117538
  * rust-lang/rust#117533
  * rust-lang/rust#117523
  * rust-lang/rust#117520
  * rust-lang/rust#117505
  * rust-lang/rust#117434
* rust-lang/rust#117535
* rust-lang/rust#117510
* rust-lang/rust#116439
* rust-lang/rust#117508



Co-authored-by: Ben Wiederhake <BenWiederhake.GitHub@gmx.de>
Co-authored-by: SabrinaJewson <sejewson@gmail.com>
Co-authored-by: J-ZhengLi <lizheng135@huawei.com>
Co-authored-by: koka <koka.code@gmail.com>
Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
Co-authored-by: Joshua Liebow-Feeser <joshlf@users.noreply.github.com>
Co-authored-by: lengyijun <sjtu5140809011@gmail.com>
Co-authored-by: Zalathar <Zalathar@users.noreply.github.com>
Co-authored-by: Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de>
Co-authored-by: Philipp Krones <hello@philkrones.com>
Co-authored-by: y21 <30553356+y21@users.noreply.github.com>
Co-authored-by: bors <bors@rust-lang.org>
Co-authored-by: bohan <bohan-zhang@foxmail.com>
@craterbot
Copy link
Collaborator

🎉 Experiment pr-117589 is completed!
📊 2 regressed and 12 fixed (385369 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the blacklist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 6, 2023
@lqd
Copy link
Member

lqd commented Nov 6, 2023

No need to re-run crater on the regressions imho, out of the two:

  • the behavior change on soa_derive-0.13.0 is probably real
  • graphql-client-302-repro however is unrelated and non-deterministic

@jackh726
Copy link
Member

jackh726 commented Nov 6, 2023

We should open a PR to soa_derive I think

(At the very least- it does seem like a bit of a rough regression)

@jackh726
Copy link
Member

jackh726 commented Nov 6, 2023

To revert to the old behavior for this, we probably need to change here:

if pred.is_global() && !pred.has_late_bound_vars() {

!pred.has_late_bound_vars probably needs to be replaced with !pred.has_type_flags(TypeFlags::HAS_BINDER_VARS | TypeFlags::HAS_LATE_BOUND)

@compiler-errors
Copy link
Member Author

compiler-errors commented Nov 6, 2023

HAS_LATE_BOUND necessarily implies HAS_BINDER_VARS, but yeah, I will prepare a PR for that soon.

@lqd
Copy link
Member

lqd commented Nov 6, 2023

Maybe even just !pred.has_type_flags(TypeFlags::HAS_BINDER_VARS) ? 🤔

In any case, to save 2 minutes for a test, here's a trivial bound that's not using the lifetime and that now trips:

struct S;

fn repro()
    where
        for<'a> S: Clone,
    {
    }

(If the above and Jack's comment sounds right, Michael, I can open a PR)

@compiler-errors
Copy link
Member Author

open a pr @lqd since I am still in bed!!

@lqd
Copy link
Member

lqd commented Nov 6, 2023

@compiler-errors working on rust while in Bed, Bath, and Beyond.

@compiler-errors
Copy link
Member Author

Oh right, this needs to be backported to fix a beta regression. This should be backported together with #117637.

@compiler-errors compiler-errors added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Nov 6, 2023
@jackh726
Copy link
Member

jackh726 commented Nov 6, 2023

Good call on the crater run here. Nice catch.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 6, 2023
…s, r=compiler-errors

Check binders with bound vars for global bounds that don't hold

This fixes `soa_derive-0.13.0` from rust-lang#117589's crater run.

r? `@compiler-errors`
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 6, 2023
Rollup merge of rust-lang#117637 - lqd:trivial-bounds-with-binder-vars, r=compiler-errors

Check binders with bound vars for global bounds that don't hold

This fixes `soa_derive-0.13.0` from rust-lang#117589's crater run.

r? `@compiler-errors`
@apiraino
Copy link
Contributor

apiraino commented Nov 9, 2023

Beta backport accepted as per compiler team on Zulip

@rustbot label +beta-accepted

@rustbot rustbot added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Nov 9, 2023
@cuviper cuviper mentioned this pull request Nov 9, 2023
@cuviper cuviper modified the milestones: 1.75.0, 1.74.0 Nov 9, 2023
@cuviper cuviper removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Nov 9, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 9, 2023
[beta] backports

- dropck_outlives check whether generator witness needs_drop rust-lang#117134
- Make sure that predicates with unmentioned bound vars are still considered global in the old solver rust-lang#117589
- Check binders with bound vars for global bounds that don't hold rust-lang#117637
- generator layout: ignore fake borrows rust-lang#117712

r? ghost
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 10, 2023
[beta] backports

- dropck_outlives check whether generator witness needs_drop rust-lang#117134
- Make sure that predicates with unmentioned bound vars are still considered global in the old solver rust-lang#117589
- Check binders with bound vars for global bounds that don't hold rust-lang#117637
- generator layout: ignore fake borrows rust-lang#117712

r? ghost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel. merged-by-bors This PR was explicitly merged by bors. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants