Skip to content

Move fulfillment into rustc_next_trait_solver - #160485

Open
amirHdev wants to merge 1 commit into
rust-lang:mainfrom
amirHdev:move-fulfill-next-solver
Open

Move fulfillment into rustc_next_trait_solver#160485
amirHdev wants to merge 1 commit into
rust-lang:mainfrom
amirHdev:move-fulfill-next-solver

Conversation

@amirHdev

@amirHdev amirHdev commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

It moves the rustc fulfillment implementation into the shared crate
migrating rust-analyzer to the shared implementation will require the updated shared crates to be published and may need frontend specific adjustments
Part of #159654

@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 Aug 4, 2026
@rust-log-analyzer

This comment has been minimized.

@amirHdev
amirHdev force-pushed the move-fulfill-next-solver branch 2 times, most recently from 499da05 to 247c257 Compare August 4, 2026 09:12
@amirHdev
amirHdev marked this pull request as ready for review August 4, 2026 10:41
@rustbot

rustbot commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to the core trait solver

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

@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 Aug 4, 2026
@rustbot

rustbot commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

r? @ShoyuVanilla

rustbot has assigned @ShoyuVanilla.
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 75 candidates
  • Random selection from 21 candidates

@amirHdev

amirHdev commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

r? lcnr

@rustbot rustbot assigned lcnr and unassigned ShoyuVanilla Aug 4, 2026
use super::delegate::SolverDelegate;
use crate::traits::{FulfillmentError, ScrubbedTraitError};

#[path = "fulfill/derive_errors.rs"]

@Jamesbarford Jamesbarford Aug 4, 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 do we need this?

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.

I renamed the wrapper file. needed because the rustc-specific wrapper module was named rustc_fulfill while its file was still solve/fulfill.rs

mod fulfill;
pub mod inspect;
mod normalize;
#[path = "solve/fulfill.rs"]

@Jamesbarford Jamesbarford Aug 4, 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.

Not sure I quite understand this

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.

this was selecting file while exposing it locally as rustc_fulfill which wrapper renamed now

Comment thread compiler/rustc_type_ir/src/solve/fulfill.rs Outdated
}
}

fn into_rustc_solver_error<'tcx>(

@Jamesbarford Jamesbarford Aug 4, 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.

Could this be a 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.

that is cleaner , I did

Overflow(O),
}

type PendingObligations<I, O> = ThinVec<(O, Option<GoalStalledOn<I>>)>;

@Jamesbarford Jamesbarford Aug 4, 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.

Firstly I'm not overly familiar with this area of codebase, however, if I am not mistaken it looks like the type is PredicateObligation<'tcx>? Or an Obligation do we have something that O needs to implement or be constrained by? This applies to all instances of O, not exclusively this type definition.

View changes since the review

@amirHdev amirHdev Aug 4, 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.

As shared engine only require the <I> while PredicateObligation<'tcx> not required.
I moved that bound onto FulfillmentCtxt<I, O> itself instead

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 think you cut yourself off mid-sentence?

@amirHdev amirHdev Aug 4, 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.

Sorry for the unclear wording :)
for rustc O is PredicateObligation<'tcx> but the shared engine only requires O: FulfillmentObligation<I> which moved that bound onto FulfillmentCtxt<I, O> itself now and it applies to every instance of the context.

@amirHdev
amirHdev requested a review from Jamesbarford August 4, 2026 17:00

@khyperia khyperia 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.

A few nits! Sadly I don't feel comfortable/confident to r+ this myself but figured I'd still comment a bit on this since folks asked me to~

My main thought is checking if someone from rust-analyzer has seen/glanced over this, and/or if you've attempted to migrate rust-analyzer to it to validate the approach works (even if that's not posted yet, due to how rust-analyzer consumes crates.io rather than in-tree).

One nit: Could you squash and/or generally clean the commits up a bit before merging? Not super important I think, idk.

View changes since this review

Comment thread compiler/rustc_trait_selection/src/solve/fulfill.rs
@amirHdev
amirHdev force-pushed the move-fulfill-next-solver branch from cc83dbe to 9c18ee3 Compare August 5, 2026 16:34
Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
@amirHdev
amirHdev force-pushed the move-fulfill-next-solver branch from 9c18ee3 to 9222b8b Compare August 5, 2026 16:58
@amirHdev

amirHdev commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

My main thought is checking if someone from rust-analyzer has seen/glanced over this, and/or if you've attempted to migrate rust-analyzer to it to validate the approach works (even if that's not posted yet, due to how rust-analyzer consumes crates.io rather than in-tree).

Thanks for taking a look!
I tested the migration using the exact rust-analyzer version that uses ra-ap 0.165.0.
the migration initially exposed a difference in overflow handling.
rustc checks for overflow after a goal makes progress while rust-analyzer checks before evaluating an obligation that has already reached the recursion limit. I made this an explicit frontend policy so both can preserve their existing behavior. migrated hir-ty passes all targets's tests by that. ( this seemed like the safest option to me but I’m happy to change it if there’s a better approach 🙂 )
I haven’t had someone from rust-analyzer review it yet but I have the migration patch and validation logs ready if they would be useful

Thanks again for the feedback

@amirHdev
amirHdev requested a review from khyperia August 5, 2026 17:15
@ChayimFriedman2

Copy link
Copy Markdown
Contributor

rustc checks for overflow after a goal makes progress while rust-analyzer checks before evaluating an obligation that has already reached the recursion limit. I made this an explicit frontend policy so both can preserve their existing behavior. migrated hir-ty passes all targets's tests by that.

Any deviation from rustc in r-a in things like that are a bug (that might have occurred from previous rustc versions). You do not need to allow both behaviors.

@ChayimFriedman2 ChayimFriedman2 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.

This seems fine to me r-a wise. Our current implementation is a bit different but that is due to old rustc versions we copied from and optimizations we applied that are probably no longer applicable (and if they are, we should apply them to rustc as well).

View changes since this review

@rust-bors

rust-bors Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

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

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.

8 participants