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

Uplift Relate/TypeRelation into rustc_next_trait_solver #125724

Merged
merged 3 commits into from
Jun 7, 2024

Conversation

compiler-errors
Copy link
Member

For use in the new solver. This doesn't yet uplift ObligationEmittingRelation.

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. labels May 29, 2024
@rustbot
Copy link
Collaborator

rustbot commented May 29, 2024

changes to the core type system

cc @compiler-errors, @lcnr

changes to the core type system

cc @compiler-errors, @lcnr

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@rustbot rustbot added the WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) label May 29, 2024
@compiler-errors
Copy link
Member Author

compiler-errors commented May 29, 2024

One structure question: Currently this uplifts TypeRelation and Relate into rustc_next_trait_solver. This is actually somewhat problematic, since I would eventually like to make InferCtxtLike have a eq<T: Relate<Self>>() method, but InferCtxtLike is defined in rustc_type_ir:

  • We may need to move InferCtxtLike down rustc_next_trait_solver (which affects the ability to use DebugWithInfcx)
  • Or alternatively, we need to move relations up into rustc_type_ir.

edit: I just ended up uplifting relations into rustc_type_ir. We can fix this later by moving it down if desired, it's not a lot of work.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

b_arg: I::GenericArgs,
) -> RelateResult<I, I::GenericArgs>
where
I::GenericArg: Relate<Infcx>,
Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, I think this makes it pretty obvious that Relate needs to be parameterized over Interner, not InferCtxt.

We want to be able to add the bound:

trait Interner {
    type GenericArg: ... + Relate<Self>;
                        // ++++++++++++
}

which we can't do if Relate is generic over Infcx :/

Copy link
Contributor

@lcnr lcnr May 30, 2024

Choose a reason for hiding this comment

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

trait Sup {
    type Assoc;
}
trait Trait: Sup<Assoc: Copy> {}

fn foo<T: Trait>(x: T::Assoc) -> (T::Assoc, T::Assoc) {
    (x, x)
}

tbh I am actually surpised that that works, don't fully understand why it does

Can add

trait Interner {
    type GenericArg;
}
// To allow an impl in `rustc_infer` while still having super traits
trait InternerForInfcx<Infcx: ?Sized>: Interner<GenericArg: Relate<Infcx>> {}

trait InferCtxtLike {
    type Interner: InternerForInfcx<Self>;
}


fn foo<Infcx: InferCtxtLike<Interner = I>, I: InternerForInfcx<Infcx>>() {}

:3

edit: this will make rustc a ParamEnv stress test however, because now every function with an InternerForInfcx<Infcx> bound will have a lot of caller_bounds

@compiler-errors
Copy link
Member Author

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 30, 2024
@bors
Copy link
Contributor

bors commented May 30, 2024

☔ The latest upstream changes (presumably #125671) 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.

stopped reviewing after getting to the comment in relate.rs

as a general note: would you mind moving some of the param bounds into where-bounds, I personally find multi-line generic param listings hard to read


#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext, TyEncodable, TyDecodable))]
pub enum BoundConstness {
Copy link
Contributor

Choose a reason for hiding this comment

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

idk how I feel about BoundConstness being part of const_kind, maybe move it to const_trait module or sth?

/// type).
CyclicTy(I::Ty),
CyclicConst(I::Const),
ProjectionMismatched(ExpectedFound<I::DefId>),
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
ProjectionMismatched(ExpectedFound<I::DefId>),
ProjectionMismatch(ExpectedFound<I::DefId>),

idk if you want to fix it in this PR

#[derive(TypeVisitable_Generic)]
#[rustc_pass_by_value]
pub enum TypeError<I: Interner> {
Mismatch,
Copy link
Contributor

Choose a reason for hiding this comment

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

not for this PR

Suggested change
Mismatch,
Misc,

Comment on lines +19 to +61
/// Returns a static string we can use for printouts.
fn tag(&self) -> &'static str;
Copy link
Contributor

Choose a reason for hiding this comment

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

not necessarily for this PR. Remove this and just use std::any::type_name for debug printing instead

b_arg: I::GenericArgs,
) -> RelateResult<I, I::GenericArgs>
where
I::GenericArg: Relate<Infcx>,
Copy link
Contributor

@lcnr lcnr May 30, 2024

Choose a reason for hiding this comment

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

trait Sup {
    type Assoc;
}
trait Trait: Sup<Assoc: Copy> {}

fn foo<T: Trait>(x: T::Assoc) -> (T::Assoc, T::Assoc) {
    (x, x)
}

tbh I am actually surpised that that works, don't fully understand why it does

Can add

trait Interner {
    type GenericArg;
}
// To allow an impl in `rustc_infer` while still having super traits
trait InternerForInfcx<Infcx: ?Sized>: Interner<GenericArg: Relate<Infcx>> {}

trait InferCtxtLike {
    type Interner: InternerForInfcx<Self>;
}


fn foo<Infcx: InferCtxtLike<Interner = I>, I: InternerForInfcx<Infcx>>() {}

:3

edit: this will make rustc a ParamEnv stress test however, because now every function with an InternerForInfcx<Infcx> bound will have a lot of caller_bounds

@bors
Copy link
Contributor

bors commented Jun 1, 2024

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

@rustbot
Copy link
Collaborator

rustbot commented Jun 3, 2024

Some changes occurred to the core trait solver

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

@compiler-errors
Copy link
Member Author

I think this is basically ready for another round of review

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 4, 2024
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

compiler/rustc_middle/src/ty/error.rs Outdated Show resolved Hide resolved
compiler/rustc_type_ir/src/ty_kind.rs Outdated Show resolved Hide resolved
@bors
Copy link
Contributor

bors commented Jun 4, 2024

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

@lcnr
Copy link
Contributor

lcnr commented Jun 5, 2024

going to wait on #125958 with this (if we're able to merge that today)

@compiler-errors
Copy link
Member Author

Yeah I already locally rebased it onto that PR expecting it would land first, will push the rebased one when it's done.

@bors
Copy link
Contributor

bors commented Jun 6, 2024

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

@compiler-errors
Copy link
Member Author

@bors r=lcnr

@bors
Copy link
Contributor

bors commented Jun 6, 2024

📌 Commit 91274c8 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 6, 2024
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Jun 7, 2024
Uplift `Relate`/`TypeRelation` into `rustc_next_trait_solver`

For use in the new solver. This doesn't yet uplift `ObligationEmittingRelation`.

r? lcnr
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 7, 2024
…kingjubilee

Rollup of 8 pull requests

Successful merges:

 - rust-lang#125606 (Size optimize int formatting)
 - rust-lang#125724 (Uplift `Relate`/`TypeRelation` into `rustc_next_trait_solver`)
 - rust-lang#126040 (Don't warn on fields in the `unreachable_pub` lint )
 - rust-lang#126065 (mark binding undetermined if target name exist and not obtained)
 - rust-lang#126098 (Remove `same-lib-two-locations-no-panic` run-make test)
 - rust-lang#126099 (Crate loader cleanups)
 - rust-lang#126101 (Revert "Disallow ambiguous attributes on expressions" on nightly)
 - rust-lang#126103 (Improve Docs for `hir::Impl` and `hir::ImplItem`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 7, 2024
…kingjubilee

Rollup of 7 pull requests

Successful merges:

 - rust-lang#125606 (Size optimize int formatting)
 - rust-lang#125724 (Uplift `Relate`/`TypeRelation` into `rustc_next_trait_solver`)
 - rust-lang#126040 (Don't warn on fields in the `unreachable_pub` lint )
 - rust-lang#126098 (Remove `same-lib-two-locations-no-panic` run-make test)
 - rust-lang#126099 (Crate loader cleanups)
 - rust-lang#126101 (Revert "Disallow ambiguous attributes on expressions" on nightly)
 - rust-lang#126103 (Improve Docs for `hir::Impl` and `hir::ImplItem`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 75aa9d1 into rust-lang:master Jun 7, 2024
6 checks passed
@rustbot rustbot added this to the 1.80.0 milestone Jun 7, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jun 7, 2024
Rollup merge of rust-lang#125724 - compiler-errors:uplift-relate, r=lcnr

Uplift `Relate`/`TypeRelation` into `rustc_next_trait_solver`

For use in the new solver. This doesn't yet uplift `ObligationEmittingRelation`.

r? lcnr
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 (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants