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

Implement selection via new trait solver #112869

Merged
merged 2 commits into from Jul 3, 2023

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Jun 21, 2023

Implements selection via the new solver by calling into assemble_and_evaluate_candidates, doing a very light-weight "winnow" to choose one candidate over the others, and then re-confirming that candidate outside of the EvalCtxt in order to compute the information necessary for the ImplSource.

This selection routine is best effort -- if it receives an ambiguous response from the EvalCtxt, then it may return ambiguity if the work to re-confirm the goal is not "easy" -- right now, that means everything except for object and impl goals. Since we don't want to reimplement all of the work of the compute_builtin_* methods in the solver internals, we bail out if we encounter ambiguity more often than the old solver. This should only barely affect method selection and not codegen. It can be made more precise later if needed.

r? @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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative labels Jun 21, 2023
@bors
Copy link
Contributor

bors commented Jun 27, 2023

☔ The latest upstream changes (presumably #112938) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me after nits and updating description

@rust-log-analyzer

This comment has been minimized.

@BoxyUwU
Copy link
Member

BoxyUwU commented Jun 30, 2023

Are we intending on having a flag for only enabling the new solver for selection?

@compiler-errors
Copy link
Member Author

compiler-errors commented Jun 30, 2023

No, the intention is just for this PR (and the deep normalization PR that lcnr has open) to remove the remaining entrypoints into old solver code when the new solver is enabled, since right now we still call into old solver logic during codegen and manual calls to SelectionContext::select (which ideally we'd remove12).

Footnotes

  1. https://github.com/rust-lang/rust/blob/97279e91d8d3973da9c1fc606a2b773213ed54e5/compiler/rustc_hir_typeck/src/method/probe.rs#L1447

  2. https://github.com/rust-lang/rust/blob/97279e91d8d3973da9c1fc606a2b773213ed54e5/compiler/rustc_hir_typeck/src/coercion.rs#L659C11-L659C11

@BoxyUwU
Copy link
Member

BoxyUwU commented Jun 30, 2023

So this select stuff ideally only exists for codegen to figure out impls?

@compiler-errors
Copy link
Member Author

compiler-errors commented Jun 30, 2023

Yes, that's the primary usecase, but we also use selection during the method probe and coercion logic I linked in the footnotes in my comment above (edited to include those).

(Also in other things like const checking, but that's broken in the new solver anyways so shrug)

bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 3, 2023
implement deep normalization via the new solver

together with rust-lang#112869 this should remove all uses of the old solver with `-Ztrait-solver=next`.

see https://hackmd.io/V0qsUB_fTxexfQO_pcOcrg for a description of this PR. Will move that doc to the `rustc-dev-guide` after merging this.

r? `@compiler-errors`
@compiler-errors compiler-errors marked this pull request as ready for review July 3, 2023 15:07
@rustbot
Copy link
Collaborator

rustbot commented Jul 3, 2023

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

@rust-log-analyzer

This comment has been minimized.

@lcnr
Copy link
Contributor

lcnr commented Jul 3, 2023

@bors r+ rollup (affects only new solver)

@bors
Copy link
Contributor

bors commented Jul 3, 2023

📌 Commit f3f8793 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 Jul 3, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 3, 2023
…llaumeGomez

Rollup of 3 pull requests

Successful merges:

 - rust-lang#112869 (Implement selection via new trait solver)
 - rust-lang#113285 ([rustdoc] Fix display of long inline cfg labels)
 - rust-lang#113286 (Don't perform selection if inherent associated types are not enabled)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 4668d3e into rust-lang:master Jul 3, 2023
11 checks passed
@rustbot rustbot added this to the 1.72.0 milestone Jul 3, 2023
@lcnr lcnr mentioned this pull request Jul 4, 2023
57 tasks
@compiler-errors compiler-errors deleted the sketchy-new-select branch August 11, 2023 20:19
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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants