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

Add all RPITITs when augmenting param-env with GAT bounds in check_type_bounds #117131

Merged
merged 2 commits into from
Nov 3, 2023

Conversation

compiler-errors
Copy link
Member

When checking that associated type definitions actually satisfy their associated type bounds in check_type_bounds, we construct a "normalize_param_env" which adds a projection predicate that allows us to assume that we can project the GAT to the definition we're checking. For example, in:

type Foo {
  type Bar: Display = i32;
}

We would add <Self as Foo>::Bar = i32 as a projection predicate when checking that i32: Display holds.

That normalize_param_env was, for some reason, only being used to normalize the predicate before it was registered. This is sketchy, because a nested obligation may require the GAT bound to hold, and also the projection cache is broken and doesn't differentiate projection cache keys that differ by param-envs 😿.

This normalize_param_env is also not sufficient when we have nested RPITITs and default trait methods, since we need to be able to assume we can normalize both the RPITIT and all of its child RPITITs to sufficiently prove all of its bounds. This is the cause of #117104, which only starts to fail for RPITITs that are nested 3 and above due to the projection-cache bug above.1

First fix

Use the normalize_param_env everywhere in check_type_bounds. This is reflected in a test I've constructed that fixes a GAT-only failure.

Second fix

For RPITITs, install projection predicates for each RPITIT in the same function in check_type_bounds. This fixes #117104.

not sure who to request, so...
r? @lcnr hehe feel free to reassign :3

Footnotes

  1. The projection cache bug specifically occurs because we try normalizing the assumed_wf_types with the non-normalization param-env. This causes us to insert a projection cache entry that keeps the outermost RPITIT rigid, and it trivially satisifes all its own bounds. Super sketchy!2

  2. I haven't actually gone and fixed the projection cache bug because it's only marginally related, but I could, and it should no longer be triggered here.

@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 Oct 24, 2023
@rust-log-analyzer

This comment has been minimized.

@rust-cloud-vms rust-cloud-vms bot force-pushed the projection-oops branch 2 times, most recently from ca6f45c to bfd836b Compare October 25, 2023 02:30
@axos88
Copy link

axos88 commented Oct 27, 2023

Is there a (relatively) easy way to build a compiler from this PR before it gets merged? This bug is blocking me.

@lcnr
Copy link
Contributor

lcnr commented Nov 2, 2023

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Nov 2, 2023

📌 Commit bfd836b 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 Nov 2, 2023
@lcnr
Copy link
Contributor

lcnr commented Nov 2, 2023

@bors rollup=never

@bors
Copy link
Contributor

bors commented Nov 2, 2023

⌛ Testing commit bfd836b with merge 5626f49...

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 2, 2023
Add all RPITITs when augmenting param-env with GAT bounds in `check_type_bounds`

When checking that associated type definitions actually satisfy their associated type bounds in `check_type_bounds`, we construct a "`normalize_param_env`" which adds a projection predicate that allows us to assume that we can project the GAT to the definition we're checking. For example, in:

```rust
type Foo {
  type Bar: Display = i32;
}
```

We would add `<Self as Foo>::Bar = i32` as a projection predicate when checking that `i32: Display` holds.

That `normalize_param_env` was, for some reason, only being used to normalize the predicate before it was registered. This is sketchy, because a nested obligation may require the GAT bound to hold, and also the projection cache is broken and doesn't differentiate projection cache keys that differ by param-envs 😿.

This `normalize_param_env` is also not sufficient when we have nested RPITITs and default trait methods, since we need to be able to assume we can normalize both the RPITIT and all of its child RPITITs to sufficiently prove all of its bounds. This is the cause of rust-lang#117104, which only starts to fail for RPITITs that are nested 3 and above due to the projection-cache bug above.[^1]

## First fix

Use the `normalize_param_env` everywhere in `check_type_bounds`. This is reflected in a test I've constructed that fixes a GAT-only failure.

## Second fix

For RPITITs, install projection predicates for each RPITIT in the same function in `check_type_bounds`. This fixes rust-lang#117104.

not sure who to request, so...
r? `@lcnr` hehe feel free to reassign :3

[^1]: The projection cache bug specifically occurs because we try normalizing the `assumed_wf_types` with the non-normalization param-env. This causes us to insert a projection cache entry that keeps the outermost RPITIT rigid, and it trivially satisifes all its own bounds. Super sketchy![^2]

[^2]: I haven't actually gone and fixed the projection cache bug because it's only marginally related, but I could, and it should no longer be triggered here.
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Nov 2, 2023

💔 Test failed - checks-actions

@bors bors 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 2, 2023
@compiler-errors
Copy link
Member Author

@bors r=lcnr

@bors
Copy link
Contributor

bors commented Nov 2, 2023

📌 Commit dd571e4 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 Nov 2, 2023
@bors
Copy link
Contributor

bors commented Nov 3, 2023

⌛ Testing commit dd571e4 with merge 2520ca8...

@bors
Copy link
Contributor

bors commented Nov 3, 2023

☀️ Test successful - checks-actions
Approved by: lcnr
Pushing 2520ca8 to master...

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

Finished benchmarking commit (2520ca8): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
32.3% [0.3%, 99.8%] 19
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.4% [-1.7%, -1.0%] 6
All ❌✅ (primary) 32.3% [0.3%, 99.8%] 19

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)
16.1% [8.0%, 24.4%] 13
Regressions ❌
(secondary)
1.7% [0.8%, 2.6%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 16.1% [8.0%, 24.4%] 13

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)
46.4% [7.5%, 105.5%] 13
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 46.4% [7.5%, 105.5%] 13

Binary size

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

Bootstrap: 635.107s -> 636.745s (0.26%)
Artifact size: 304.48 MiB -> 304.48 MiB (-0.00%)

@rustbot rustbot added the perf-regression Performance regression. label Nov 3, 2023
bors-ferrocene bot added a commit to ferrocene/ferrocene that referenced this pull request Nov 3, 2023
82: Automated pull from upstream `master` r=tshepang a=github-actions[bot]


This PR pulls the following changes from the upstream repository:

* rust-lang/rust#117313
* rust-lang/rust#117131
* rust-lang/rust#117134
* rust-lang/rust#117471
* rust-lang/rust#117521
* rust-lang/rust#117513
  * rust-lang/rust#117512
  * rust-lang/rust#117509
  * rust-lang/rust#117495
  * rust-lang/rust#117394
* rust-lang/rust#117466
* rust-lang/rust#117204
* rust-lang/rust#117386
* rust-lang/rust#117506



Co-authored-by: Nicholas Nethercote <n.nethercote@gmail.com>
Co-authored-by: roblabla <unfiltered@roblab.la>
Co-authored-by: Michael Goulet <michael@errs.io>
Co-authored-by: massivebird <gdrakemail@gmail.com>
Co-authored-by: bors <bors@rust-lang.org>
Co-authored-by: Zalathar <Zalathar@users.noreply.github.com>
Co-authored-by: lcnr <rust@lcnr.de>
Co-authored-by: Joshua Liebow-Feeser <joshlf@users.noreply.github.com>
Co-authored-by: Matthias Krüger <matthias.krueger@famsik.de>
@lcnr
Copy link
Contributor

lcnr commented Nov 3, 2023

alright... that's bad 😅 how tf does eval_to_allocation_raw take that much longer because of this PR 😅 I think we should either solve these regressions or revert before the beta cutoff

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 7, 2023
Only instantiate binder during dyn's built-in trait candidate probe once

See UI test for demonstration of the issue.

This was "caused" by rust-lang#117131, but only because we're using the `normalize_param_env` (which has been augmented with a projection clause used to normalize GATs) which features non-lifetime bound vars in it.

Fixes rust-lang#117602 technically, though that's also fixed by rust-lang#117542.

r? types
@pnkfelix
Copy link
Member

pnkfelix commented Nov 7, 2023

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. 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.

nested impl Trait in trait with default definition does not compile
8 participants