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 for Unsize for better coercion behavior #113353

Merged
merged 2 commits into from
Jul 13, 2023

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Jul 5, 2023

In order for much of coercion to succeed, we need to be able to deal with partial ambiguity of Unsize traits during selection. However, I pessimistically implemented selection in the new trait solver to just bail out with ambiguity if it was a built-in impl:

| (Certainty::Maybe(_), _) => Ok(None),

This implements a proper "rematch" procedure for dealing with built-in Unsize goals, so that even if the goal is ambiguous, we are able to get nested obligations which are used in the coercion selection-like loop:

Ok(Some(impl_source)) => queue.extend(impl_source.nested_obligations()),

Second commit just moves a resolve_vars_if_possible call to fix a bug where we weren't detecting a trait upcasting to occur.

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 (-Znext-solver) labels Jul 5, 2023
@rustbot
Copy link
Collaborator

rustbot commented Jul 5, 2023

Some changes occurred to the core trait solver

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

@compiler-errors compiler-errors changed the title Implement selection for unsize for better coercion behavior Implement selection for Unsize for better coercion behavior Jul 5, 2023
@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 Jul 5, 2023
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

ty::TraitRef::new(tcx, goal.predicate.def_id(), [*a_last_ty, *b_last_ty]),
));
}
_ => return Ok(None),
Copy link
Contributor

Choose a reason for hiding this comment

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

please ICE here to detect mismatches

Copy link
Member Author

Choose a reason for hiding this comment

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

We cannot ICE here because this goal is selected during coercion, so we legitimately may see, e.g. [T; N]: Unsize<_> during selection.

One more point towards having a typeck and codegen mode for selection...

Copy link
Member Author

Choose a reason for hiding this comment

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

Left a fixme anyways.

@bors
Copy link
Contributor

bors commented Jul 7, 2023

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

@compiler-errors
Copy link
Member Author

You said r=me after nits, which I think I have addressed.

@bors r=lcnr rollup (new solver)

@bors
Copy link
Contributor

bors commented Jul 12, 2023

📌 Commit a071044 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 12, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 12, 2023
Implement selection for `Unsize` for better coercion behavior

In order for much of coercion to succeed, we need to be able to deal with partial ambiguity of `Unsize` traits during selection. However, I pessimistically implemented selection in the new trait solver to just bail out with ambiguity if it was a built-in impl:
https://github.com/rust-lang/rust/blob/9227ff28aff55b252314076fcf21c9a66f10ac1e/compiler/rustc_trait_selection/src/solve/eval_ctxt/select.rs#L126

This implements a proper "rematch" procedure for dealing with built-in `Unsize` goals, so that even if the goal is ambiguous, we are able to get nested obligations which are used in the coercion selection-like loop:
https://github.com/rust-lang/rust/blob/9227ff28aff55b252314076fcf21c9a66f10ac1e/compiler/rustc_hir_typeck/src/coercion.rs#L702

Second commit just moves a `resolve_vars_if_possible` call to fix a bug where we weren't detecting a trait upcasting to occur.

r? `@lcnr`
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 13, 2023
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#113353 (Implement selection for `Unsize` for better coercion behavior)
 - rust-lang#113553 (Make Placeholder, GeneratorWitness*, Infer and Error unreachable on SMIR rustc_ty_to_ty)
 - rust-lang#113598 (Update cargo)
 - rust-lang#113603 (Test simd-wide-sum for codegen error)
 - rust-lang#113613 (Allow to have `-` in rustdoc-json test file name)
 - rust-lang#113615 (llvm-wrapper: adapt for LLVM API change)
 - rust-lang#113616 (Fix bootstrap.py uname error)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 893a5d2 into rust-lang:master Jul 13, 2023
@rustbot rustbot added this to the 1.73.0 milestone Jul 13, 2023
@compiler-errors compiler-errors deleted the select-better 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
A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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 (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants