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

Make object bound candidates sound in the new trait solver #108333

Merged
merged 3 commits into from
Feb 26, 2023

Conversation

compiler-errors
Copy link
Member

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 Feb 22, 2023
@rustbot
Copy link
Collaborator

rustbot commented Feb 22, 2023

Some changes occurred to the core trait solver

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

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 comments

compiler/rustc_trait_selection/src/solve/assembly.rs Outdated Show resolved Hide resolved
.predicates,
);
for item in infcx.tcx.associated_items(trait_ref.def_id).in_definition_order() {
if item.kind == ty::AssocKind::Type {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if item.kind == ty::AssocKind::Type {
// FIXME(associated_const_equality): Also add associated consts to
// the requirements here.
if item.kind == ty::AssocKind::Type {

I think that will be necessary

Copy link
Member Author

Choose a reason for hiding this comment

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

Can assoc consts have WC?

/// impl Bar for dyn Foo<Item = Ty> {}
/// ```
///
/// However, in order to make such impls well-formed, we need to do an
Copy link
Contributor

Choose a reason for hiding this comment

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

That's the main concerning step here 🤔 because I don't have a strong understanding of why the impl with unnormalized projections is not well-formed.

It doesn't compile with either the new solver or the old one, but that doesn't feel like a good enough explanation :< can look into this a bit myself (and should have a rustc-dev-guide section about this)

Copy link
Member Author

@compiler-errors compiler-errors Feb 22, 2023

Choose a reason for hiding this comment

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

trait Trait {
    type Assoc: Bound;
}

trait Bound {}

struct Ty;

/*

impl Trait for dyn Trait<Assoc = Ty> {
    type Assoc = Ty;
}

*/

struct DynTrait;

impl Trait for DynTrait
where
    <DynTrait as Trait>::Assoc: Bound,
{
    type Assoc = Ty;
}

fn needs_trait(_: impl Trait) {}

fn main() {
    needs_trait(DynTrait);
}

So this actually isn't (technically) failing during wfcheck. On both the "classic" solver and "next" solver, this overflows in normalize_param_env_or_error in the param_env query for the impl. 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

lcnr/solver-woes#10 to track this

@bors
Copy link
Contributor

bors commented Feb 22, 2023

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

@compiler-errors
Copy link
Member Author

Addressed the comments (except for the main "is this enough for soundness" issue).

@bors r=lcnr

@bors
Copy link
Contributor

bors commented Feb 24, 2023

📌 Commit ed30eff 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 Feb 24, 2023
@compiler-errors
Copy link
Member Author

@bors rollup only new solver

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 25, 2023
…mpiler-errors

Rollup of 7 pull requests

Successful merges:

 - rust-lang#105736 (Test that the compiler/library builds with validate-mir)
 - rust-lang#107291 ([breaking change] Remove a rustdoc back compat warning)
 - rust-lang#107675 (Implement -Zlink-directives=yes/no)
 - rust-lang#107848 (Split `x setup` sub-actions to CLI arguments)
 - rust-lang#107911 (Add check for invalid #[macro_export] arguments)
 - rust-lang#108229 ([107049] Recognise top level keys in config.toml.example)
 - rust-lang#108333 (Make object bound candidates sound in the new trait solver)

Failed merges:

 - rust-lang#108337 (hir-analysis: make a helpful note)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 4723a9a into rust-lang:master Feb 26, 2023
@rustbot rustbot added this to the 1.69.0 milestone Feb 26, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 10, 2023
…lcnr

Make alias bounds sound in the new solver (take 2)

Make alias bounds sound in the new solver (in a way that does not require coinduction) by only considering them for projection types whose corresponding trait refs come from a param-env candidate.

That is, given `<T as Trait>::Assoc: Bound`, we only *really* need to consider the alias bound if `T: Trait` is satisfied via a param-env candidate. If it's instead satisfied, e.g., via an user provided impl candidate or a , then that impl should have a concrete type to which we could otherwise normalize `<T as Trait>::Assoc`, and that concrete type is then responsible to prove the `Bound` on it.

Similar consideration is given to opaque types, since we only need to consider alias bounds if we're *not* in reveal-all mode, since similarly we'd be able to reveal the opaque types and prove any bounds that way.

This does not remove that hacky "eager projection replacement" logic from object bounds, which are somewhat like alias bounds. But removing this eager normalization behavior (added in rust-lang#108333) would require full coinduction to be enabled. Compare to rust-lang#110628, which does remove this object-bound custom logic but requires coinduction to be sound.

r? `@lcnr`
@compiler-errors compiler-errors deleted the new-solver-object-sound branch August 11, 2023 20:09
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.

4 participants