Skip to content

move Predicate and Clause into rustc_type_ir - #163985

Open
amirHdev wants to merge 12 commits into
rust-lang:mainfrom
amirHdev:uplift-predicate-clause
Open

amirHdev wants to merge 12 commits into
rust-lang:mainfrom
amirHdev:uplift-predicate-clause

Conversation

@amirHdev

@amirHdev amirHdev commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

moves Predicate and Clause into rustc_type_ir removing the need for their associated types and inherent traits

most of the changes are moving existing implementations and making them generic over the interner

a few things worth explaining:

  • PredicateProxy stays because folding and visiting still use it for both predicates and clauses
  • PredicateEncoder and the extension to InternerDecoder preserve the existing shorthand encoding
  • diagnostic formatting still goes through rustc_middle to retain the existing short_string behavior
  • some outlives clauses are constructed explicitly because the generic UpcastFrom impls would overlap

split out BoundVarIndexShifter into #164040

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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 Oct 8, 2026
@rust-log-analyzer

This comment has been minimized.

@amirHdev
amirHdev force-pushed the uplift-predicate-clause branch from 5696dd7 to 3365481 Compare October 8, 2026 15:38
}
}

impl<I: Interner> PredicateProxy<I> for Predicate<I> {

@lcnr lcnr Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what's that trait?

View changes since the review

@amirHdev amirHdev Oct 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it's an existing trait for handling predicates and clauses during folding and visiting
but we may no longer need it 👍🏻

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

PredicateProxy is still used by folding and visiting to avoid depending on the concrete predicate representation

I removed the redundant inherent::Predicate trait but kept PredicateProxy since those hooks still need it

needs_triple::<T>();
}

fn main() {}

@lcnr lcnr Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

? 🤔 why added in this PR

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed
moved to #164040

}
}

impl<'a, 'tcx> rustc_middle::ty::PredicateDecoder<TyCtxt<'tcx>>

@lcnr lcnr Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why does this have to be a separate trait?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it's the existing InternerDecoder
I just extended it to preserve rustc's shorthand decoding

@lcnr lcnr left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if there are parts you can uplift individually, can you split this into multiple PRs, e.g. the BoundVarIndexShifter

also, please explain in the PR description the changes and traits you needed to do the uplifting, skimming over the PR, it does otherwise look good.

I do weakly dislike the uses of crate:: in rustc_type_ir, could you use explicit use statements instead.

Also, I think there should be some Predicate trait in inherent you should remove

View changes since this review

@rust-log-analyzer

This comment has been minimized.

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Oct 13, 2026
…ifter, r=lcnr

move `BoundVarReplacer` into rustc_type_ir

move `BoundVarReplacer` into `rustc_type_ir` and use it from `TyCtxt::shift_bound_var_indices`

this is split out of rust-lang#163985
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Oct 13, 2026
…ifter, r=lcnr

move `BoundVarReplacer` into rustc_type_ir

move `BoundVarReplacer` into `rustc_type_ir` and use it from `TyCtxt::shift_bound_var_indices`

this is split out of rust-lang#163985
rust-bors Bot pushed a commit that referenced this pull request Oct 14, 2026
Rollup merge of #164040 - amirHdev:uplift-bound-var-index-shifter, r=lcnr

move `BoundVarReplacer` into rustc_type_ir

move `BoundVarReplacer` into `rustc_type_ir` and use it from `TyCtxt::shift_bound_var_indices`

this is split out of #163985
@rust-bors

This comment has been minimized.

@amirHdev
amirHdev force-pushed the uplift-predicate-clause branch 3 times, most recently from d26083a to 992c0c7 Compare October 14, 2026 10:28
@amirHdev
amirHdev marked this pull request as ready for review October 14, 2026 10:44
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 14, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 14, 2026
@rustbot

rustbot commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

r? @folkertdev

rustbot has assigned @folkertdev.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler, types
  • compiler, types expanded to 77 candidates
  • Random selection from 18 candidates

@amirHdev

Copy link
Copy Markdown
Contributor Author

r? lcnr

@rustbot rustbot assigned lcnr and unassigned folkertdev Oct 14, 2026
@amirHdev
amirHdev requested a review from lcnr October 19, 2026 18:03
@rust-bors

This comment has been minimized.

Comment thread compiler/rustc_middle/src/ty/context.rs Outdated
#[inline(never)]
fn intern_predicate(&self, kind: Binder<'tcx, PredicateKind<'tcx>>) -> Predicate<'tcx> {
Predicate(Interned::new_unchecked(
rustc_type_ir::predicates::Predicate(Interned::new_unchecked(

@lcnr lcnr Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

use ty::Predicate or sth instead

View changes since the review

pub struct Predicate<'tcx>(
pub(super) Interned<'tcx, WithCachedTypeInfo<ty::Binder<'tcx, PredicateKind<'tcx>>>>,
);
/// An interned statement the trait solver can prove.

@lcnr lcnr Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i'd keep it consistent with the other type aliases and not have any comments

View changes since the review

Comment on lines +52 to +53
// Preserve rustc's existing diagnostic formatting while the concrete
// predicate wrappers are being migrated into rustc_type_ir.

@lcnr lcnr Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

confusing comment once this PR is merged

View changes since the review

.into_iter()
.chain(requirements.into_iter().map(|clause| Goal::new(cx, param_env, clause)))
.chain(
requirements.into_iter().map(|clause| Goal::new(cx, param_env, clause.as_predicate())),

@lcnr lcnr Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

let cx = self.cx();
let clauses = reqs
.into_iter()
.filter_map(|goal| goal.predicate.as_clause().map(|clause| clause.kind().upcast(cx)));

@lcnr lcnr Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmm, that feels off. why is this change required?

View changes since the review

@lcnr lcnr left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you summarize all the changes necessary to uplift Predicate and Clause in the PR description and why you're doing them. Some of them feel unnecessary and even undesirable

View changes since this review

@lcnr

lcnr commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

@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 Nov 24, 2026
@rustbot

rustbot commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@amirHdev
amirHdev force-pushed the uplift-predicate-clause branch from 992c0c7 to 8e923fc Compare November 25, 2026 12:33
@rustbot

This comment has been minimized.

Signed-off-by: Amirhossein Akhlaghpour <[email protected]>
Signed-off-by: Amirhossein Akhlaghpour <[email protected]>
Signed-off-by: Amirhossein Akhlaghpour <[email protected]>
Signed-off-by: Amirhossein Akhlaghpour <[email protected]>
@amirHdev
amirHdev force-pushed the uplift-predicate-clause branch from 8e923fc to dbbb13b Compare November 25, 2026 12:54
@rustbot

rustbot commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@amirHdev

Copy link
Copy Markdown
Contributor Author

@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 Nov 25, 2026
@amirHdev
amirHdev requested a review from lcnr November 25, 2026 12:57

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants