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

Only compute specializes query if (min)specialization is enabled in the crate of the specializing impl #126139

Merged
merged 2 commits into from
Jun 11, 2024

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Jun 7, 2024

Fixes (after backport) #125197

What

#122791 makes it so that inductive cycles are no longer hard errors. That means that when we are testing, for example, whether these impls overlap:

impl PartialEq<Self> for AnyId {
    fn eq(&self, _: &Self) -> bool {
        todo!()
    }
}

impl<T: Identifier> PartialEq<T> for AnyId {
    fn eq(&self, _: &T) -> bool {
        todo!()
    }
}

...given...

pub trait Identifier: Display + 'static {}

impl<T> Identifier for T where T: PartialEq + Display + 'static {}

Then we try to see if the second impl holds given T = AnyId. That requires AnyId: Identifier, which requires that AnyId: PartialEq, which is satisfied by these two impl candidates... The PartialEq<T> impl is a cycle, and we used to winnow it when we used to treat inductive cycles as errors.

However, now that we don't winnow it, this means that we now try calling candidate_should_be_dropped_in_favor_of, which tries to check whether one of the impls specializes the other: the specializes query. In that query, we currently bail early if the impl is local.

However, in a foreign crate, we try to compute if the two impls specialize each other by doing trait solving. This may itself lead to the same situation where we call specializes, which will lead to a query cycle.

How does this fix the problem

We now record whether specialization is enabled in foreign crates, and extend this early-return behavior to foreign impls too. This means that we can only encounter these cycles if we truly have a specializing impl from a crate with specialization enabled.


r? @oli-obk or @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. labels Jun 7, 2024
@compiler-errors
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 7, 2024
@compiler-errors compiler-errors added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Jun 7, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 7, 2024
Only compute `specializes` query if (min)specialization is enabled in the crate of the specializing impl

Fixes (after backport) rust-lang#125197

### What

rust-lang#122791 makes it so that inductive cycles are no longer hard errors. That means that when we are testing, for example, whether these impls overlap:

```rust
impl PartialEq<Self> for AnyId {
    fn eq(&self, _: &Self) -> bool {
        todo!()
    }
}

impl<T: Identifier> PartialEq<T> for AnyId {
    fn eq(&self, _: &T) -> bool {
        todo!()
    }
}
```

...given...

```rust
pub trait Identifier: Display + 'static {}

impl<T> Identifier for T where T: PartialEq + Display + 'static {}
```

Then we try to see if the second impl holds given `T = AnyId`. That requires `AnyId: Identifier`, which requires that `AnyId: PartialEq`, which is satisfied by these two impl candidates... The `PartialEq<T>` impl is a cycle, and we used to winnow it when we used to treat inductive cycles as errors.

However, now that we don't winnow it, this means that we *now* try calling `candidate_should_be_dropped_in_favor_of`, which tries to check whether one of the impls specializes the other: the `specializes` query. In that query, we currently bail early if the impl is local:

However, in a foreign crate, we try to compute if the two impls specialize each other by doing trait solving. This may itself lead to the same situation where we call `specializes`, which will lead to a query cycle.

### How does this fix the problem

We now record whether specialization is enabled in foreign crates, and extend this early-return behavior to foreign impls too. This means that we can only encounter these cycles if we truly have a specializing impl from a crate with specialization enabled.

-----

r? `@oli-obk` or `@lcnr`
@bors
Copy link
Contributor

bors commented Jun 7, 2024

⌛ Trying commit 4b188d9 with merge 20182a9...

@bors
Copy link
Contributor

bors commented Jun 7, 2024

☀️ Try build successful - checks-actions
Build commit: 20182a9 (20182a9ce3a4c9bba5a4d4df53c3b8777f2006cc)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (20182a9): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

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)
- - 0
Regressions ❌
(secondary)
0.1% [0.1%, 0.1%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

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

Cycles

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

Binary size

Results (secondary 0.0%)

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
Regressions ❌
(secondary)
0.0% [0.0%, 0.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Bootstrap: missing data
Artifact size: 319.56 MiB -> 318.87 MiB (-0.21%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 7, 2024
@rust-lang rust-lang deleted a comment Jun 7, 2024
@lcnr
Copy link
Contributor

lcnr commented Jun 10, 2024

@bors r+

@bors
Copy link
Contributor

bors commented Jun 10, 2024

📌 Commit 4b188d9 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 Jun 10, 2024
@lqd
Copy link
Member

lqd commented Jun 10, 2024

As 1.79 artifacts are being prepared right now, this PR could be stable-nominated in the future. Maybe we'll just keep a look at open issues to see whether people encounter #125197 or similar in the wild. There wasn't many crater regressions (nor did it seem issues were opened about this on nightly?), and maybe a stable backport won't be needed.

@bors
Copy link
Contributor

bors commented Jun 11, 2024

⌛ Testing commit 4b188d9 with merge 336e6ab...

@bors
Copy link
Contributor

bors commented Jun 11, 2024

☀️ Test successful - checks-actions
Approved by: lcnr
Pushing 336e6ab to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 11, 2024
@bors bors merged commit 336e6ab into rust-lang:master Jun 11, 2024
7 checks passed
@rustbot rustbot added this to the 1.81.0 milestone Jun 11, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (336e6ab): 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)

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

Cycles

Results (secondary -4.8%)

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
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.8% [-6.4%, -2.2%] 6
All ❌✅ (primary) - - 0

Binary size

Results (secondary 0.0%)

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
Regressions ❌
(secondary)
0.0% [0.0%, 0.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Bootstrap: 677.913s -> 675.77s (-0.32%)
Artifact size: 320.07 MiB -> 319.45 MiB (-0.19%)

@compiler-errors compiler-errors deleted the specializes branch June 11, 2024 12:06
@apiraino
Copy link
Contributor

Beta backport accepted as per compiler team on Zulip. A backport PR will be authored by the release team at the end of the current development cycle.

@rustbot label +beta-accepted

@rustbot rustbot added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Jun 20, 2024
@apiraino
Copy link
Contributor

Also suitable for a stable backport in case a point release is planned.

@rustbot label +stable-accepted

@rustbot rustbot added the stable-accepted Accepted for backporting to the compiler in the stable channel. label Jun 20, 2024
@cuviper
Copy link
Member

cuviper commented Jun 21, 2024

Adding the nomination so it comes up in our queries.

@rustbot label +stable-nominated

@rustbot rustbot added the stable-nominated Nominated for backporting to the compiler in the stable channel. label Jun 21, 2024
@cuviper cuviper mentioned this pull request Jun 21, 2024
@cuviper cuviper modified the milestones: 1.81.0, 1.80.0 Jun 21, 2024
@cuviper cuviper removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Jun 21, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 21, 2024
[beta] backports

- Only compute `specializes` query if (min)specialization is enabled in the crate of the specializing impl rust-lang#126139
- Add pub struct with allow(dead_code) into worklist rust-lang#126315
- ci: Update centos:7 to use vault repos rust-lang#126352

r? cuviper
@cuviper
Copy link
Member

cuviper commented Aug 1, 2024

Clearing stable backport labels since we didn't ship a 1.79 point release, and this is already in current stable 1.80.0.

@rustbot label -stable-nominated -stable-accepted

@rustbot rustbot removed stable-nominated Nominated for backporting to the compiler in the stable channel. stable-accepted Accepted for backporting to the compiler in the stable channel. labels Aug 1, 2024
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-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.

9 participants