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

cleanup candidate_should_be_dropped_in_favor_of #124592

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

lcnr
Copy link
Contributor

@lcnr lcnr commented May 1, 2024

and make sure it's actually a partial ordering :< the previous ordering was:

  • non-global where-bounds are preferred over impls
  • impls are preferred over global where-bound
  • non-global where-bounds and global where-bounds are considered equal

The new solver currently does not implement the lowered priority of global ParamEnv candidates, so the divergence between it and the old solver in the added tests will be resolved in favor of the old solver behavior after this PR.

r? @compiler-errors

@lcnr lcnr added needs-fcp This change is insta-stable, so needs a completed FCP to proceed. T-types Relevant to the types team, which will review and decide on the PR/issue. labels May 1, 2024
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 1, 2024
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels May 1, 2024
@lcnr lcnr removed the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label May 1, 2024
@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label May 1, 2024
@lcnr

This comment was marked as outdated.

@lcnr
Copy link
Contributor Author

lcnr commented May 1, 2024

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request May 1, 2024
cleaning `candidate_should_be_dropped_in_favor_of`

and make sure it's actually a partial ordering :<

- non-global where-bounds are preferred over impls
- impls are preferred over global where-bound
- non-global where-bounds and global where-bounds are considered equal

The new solver currently does not implement thelowered priority of global `ParamEnv` candidates, so the divergence between it and the old solver in the added tests will be resolved in favor of the old solver behavior after this PR.

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

bors commented May 1, 2024

⌛ Trying commit a0359c8 with merge 2466b92...

@lcnr lcnr removed the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label May 1, 2024
@lcnr lcnr changed the title cleaning candidate_should_be_dropped_in_favor_of cleanup candidate_should_be_dropped_in_favor_of May 1, 2024
@bors
Copy link
Contributor

bors commented May 1, 2024

☀️ Try build successful - checks-actions
Build commit: 2466b92 (2466b92ed5feb282a98bb984f45d1e6d39f8c1aa)

@compiler-errors
Copy link
Member

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-124592 created and queued.
🤖 Automatically detected try build 2466b92
🔍 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 May 1, 2024
@craterbot
Copy link
Collaborator

🚧 Experiment pr-124592 is now running

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

@craterbot
Copy link
Collaborator

🎉 Experiment pr-124592 is completed!
📊 51 regressed and 4 fixed (444840 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 removed the S-waiting-on-crater Status: Waiting on a crater run to be completed. label May 6, 2024
@craterbot craterbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 6, 2024
@fmease
Copy link
Member

fmease commented May 10, 2024

📊 51 regressed and 4 fixed (444840 total)

Minimizations:

  1. tc-collection
    • Minimized (playground)
    • Error message of MIN differs slightly cmp'ed to ORIG but that's not substantial
      • We still have a u64 / T mismatch
  2. Andlon/ice_testcase
    • Already tracked in tests/ui/associated-item/issue-105449.rs
  3. droundy/sad-monte-carlo
  4. imgui
  5. 47 “unknown” build failures
    • TODO(fmease)

@fmease
Copy link
Member

fmease commented May 17, 2024

@lcnr, I just went through the crater reports of all 47 “unknown” regressions. Some of them were spurious (no space left on device), all of the the remaining ones are type mismatches of the expected kind as well as secondary regressions only (except for redst4r/bustools_cli-rs / bustools_cli-0.2.1) with the primary regression being imgui in most cases and tc-collection otherwise (downstream crates are owned by the same person (monorepo) in the latter case).

As discussed, this is ready for an FCP. I will open “incoming breakage” PRs for the relevant crates if/once this PR gets accepted.

@lcnr
Copy link
Contributor Author

lcnr commented May 18, 2024

This PR changes the rule to candidate winnowing during selection. We prefer candidates over others, both to guide inference and to avoid ambiguity in case there are multipe applicable candidates.

The current preference rules aren't a proper order, making candidate selection order-dependent. The issue arrises for "global ParamEnv candidates": where-bounds which are not higher-ranked and do not mention any generic parameters.

This current preference rules are as follows

non-global ParamEnv > impl
impl > global ParamEnv
global ParamEnv == non-global ParamEnv

I propose to change these rules to a proper ordering:

non-global ParamEnv > impl > global ParamEnv

This avoids order-dependence and is easier to support in the next-generation trait solver. The current behavior is also unintuitive.


This change adds additional incomplete inference guidance in cases with

  • at least one applicable global ParamEnv candidate
  • exactly one applicable non-global ParamEnv candidate
  • less than 2 or 3 (depending of the order of where-clauses) impl candidates

With this setup, we previously did not use the impls to drop the global ParamEnv candidate as the impls were first dropped via the non-global candidate.

If there were more than 2 or 3 impl candidates, we ended dropping the global ParamEnv candidates via an impl candidate before all impls were dropped due to the non-global ParamEnv candidate. This subtle behavior is caused by using swap_remove when dropping impl candidates:

let should_drop_i = (0..candidates.len()).filter(|&j| i != j).any(|j| {
self.candidate_should_be_dropped_in_favor_of(
&candidates[i],
&candidates[j],
has_non_region_infer,
) == DropVictim::Yes
});
if should_drop_i {
debug!(candidate = ?candidates[i], "Dropping candidate #{}/{}", i, candidates.len());
candidates.swap_remove(i);
} else {

This causes the following patterns to change behavior

while keeping the behavior of the patterns in

The new solver currently does not implement the lowered priority of global ParamEnv candidates, so the divergence between it and the old solver in the added tests will be resolved in favor of the old solver behavior after this PR.

There are multiple existing crates which break due to inference changes, see #124592 (comment). All breakage should be fixable by adding explicit type annotations and we intend to open PRs doing so once this is in FCP. Thank you @fmease for minimizing them.

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented May 18, 2024

Team member @lcnr has proposed to merge this. The next step is review by the rest of the tagged team members:

Concerns:

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels May 18, 2024
@BoxyUwU
Copy link
Member

BoxyUwU commented May 22, 2024

is imgui not a relatively significant crate to be breaking? I would expect that to be being used by a lot of projects 🤔

@lcnr
Copy link
Contributor Author

lcnr commented May 22, 2024

I still think we should go ahead with it. The fix to it will be local. I don't mind if we have to keep this regression on nightly for 1 or 2 versions

@lcnr
Copy link
Contributor Author

lcnr commented Jun 14, 2024

I still think we should go ahead with it. The fix to it will be local. I don't mind if we have to keep this regression on nightly for 1 or 2 versions

@rfcbot concern could we instead prioritize trivial where-bounds over impls without preventing impls in normalization somehow?

@nikomatsakis
Copy link
Contributor

As I've said a few times, I hope that in the new solver we can convert this to more of a "guidance" setup, but regardless we will need some kind of ordering to give that guidance, and in that vein...

@rfcbot reviewed

...I think this ordering makes intuitive sense. It would be good to work with the regressions (especially imgui) to ensure they update their where-clauses up front, if that is needed, and/or issue point releases.

@compiler-errors compiler-errors added S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 9, 2024
@Dylan-DPC Dylan-DPC added the S-waiting-on-concerns Status: Awaiting concerns to be addressed by the author label Oct 24, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 7, 2024
rework winnowing to sensibly handle global where-bounds

this is somewhat weird, but it at least allows us to mirror this behavior in the new solver:
- trivial builtin-impls
- non-global where-bounds, bailing with ambiguity if at least one global where-bound exists
- object ☠️ + alias-bound candidates
- merge candidates ignoring global where-bounds

This is a different approach from rust-lang#124592 which maintains the "if there are global where-bounds, don't guide type inference using non-global where-bounds" behavior, hopefully avoiding the breakage and means we use guidance from non-global where-bounds in fewer, instead of in more cases.

r? `@compiler-errors`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. S-waiting-on-concerns Status: Awaiting concerns to be addressed by the author S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.