Rollup merge of #146111 - ChayimFriedman2:more-ns-specific-defid, r=lcnr

Migrate more things in the new solver to specific `DefId`s

Continuation of https://github.com/rust-lang/rust/pull/145377. I migrated the rest of the types, except aliases.

Aliases are problematic because opaques and associated types share the same type in the new solver. `@jackh726,` `@lcnr,` `@ShoyuVanilla` I'd like to hear ideas here. Anyway, even if we do nothing with them we already got a substantial improvement.

r? types
This commit is contained in:
Matthias Krüger
2025-09-08 16:34:55 +02:00
committed by GitHub
17 changed files with 154 additions and 80 deletions

View File

@@ -435,7 +435,21 @@ where
}
}
ty::Error(_) => ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty)),
ty::Closure(did, ..) | ty::CoroutineClosure(did, ..) | ty::Coroutine(did, ..) => {
ty::Closure(did, ..) => {
if self.def_id_is_local(did) {
ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty))
} else {
self.found_non_local_ty(ty)
}
}
ty::CoroutineClosure(did, ..) => {
if self.def_id_is_local(did) {
ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty))
} else {
self.found_non_local_ty(ty)
}
}
ty::Coroutine(did, ..) => {
if self.def_id_is_local(did) {
ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty))
} else {

View File

@@ -76,7 +76,7 @@ pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
&self,
goal_trait_ref: ty::TraitRef<Self::Interner>,
trait_assoc_def_id: <Self::Interner as Interner>::DefId,
impl_def_id: <Self::Interner as Interner>::DefId,
impl_def_id: <Self::Interner as Interner>::ImplId,
) -> Result<
Option<<Self::Interner as Interner>::DefId>,
<Self::Interner as Interner>::ErrorGuaranteed,

View File

@@ -186,7 +186,7 @@ where
fn consider_impl_candidate(
ecx: &mut EvalCtxt<'_, D>,
goal: Goal<I, Self>,
impl_def_id: I::DefId,
impl_def_id: I::ImplId,
) -> Result<Candidate<I>, NoSolution>;
/// If the predicate contained an error, we want to avoid emitting unnecessary trait

View File

@@ -605,7 +605,7 @@ fn coroutine_closure_to_certain_coroutine<I: Interner>(
cx: I,
goal_kind: ty::ClosureKind,
goal_region: I::Region,
def_id: I::DefId,
def_id: I::CoroutineClosureId,
args: ty::CoroutineClosureArgs<I>,
sig: ty::CoroutineClosureSignature<I>,
) -> I::Ty {
@@ -629,7 +629,7 @@ fn coroutine_closure_to_ambiguous_coroutine<I: Interner>(
cx: I,
goal_kind: ty::ClosureKind,
goal_region: I::Region,
def_id: I::DefId,
def_id: I::CoroutineClosureId,
args: ty::CoroutineClosureArgs<I>,
sig: ty::CoroutineClosureSignature<I>,
) -> I::Ty {
@@ -664,7 +664,7 @@ fn coroutine_closure_to_ambiguous_coroutine<I: Interner>(
pub(in crate::solve) fn extract_fn_def_from_const_callable<I: Interner>(
cx: I,
self_ty: I::Ty,
) -> Result<(ty::Binder<I, (I::FnInputTys, I::Ty)>, I::DefId, I::GenericArgs), NoSolution> {
) -> Result<(ty::Binder<I, (I::FnInputTys, I::Ty)>, I::FunctionId, I::GenericArgs), NoSolution> {
match self_ty.kind() {
ty::FnDef(def_id, args) => {
let sig = cx.fn_sig(def_id);

View File

@@ -123,7 +123,7 @@ where
fn consider_impl_candidate(
ecx: &mut EvalCtxt<'_, D>,
goal: Goal<I, Self>,
impl_def_id: I::DefId,
impl_def_id: I::ImplId,
) -> Result<Candidate<I>, NoSolution> {
let cx = ecx.cx();
@@ -152,20 +152,20 @@ where
}
ecx.probe_trait_candidate(CandidateSource::Impl(impl_def_id)).enter(|ecx| {
let impl_args = ecx.fresh_args_for_item(impl_def_id);
let impl_args = ecx.fresh_args_for_item(impl_def_id.into());
ecx.record_impl_args(impl_args);
let impl_trait_ref = impl_trait_ref.instantiate(cx, impl_args);
ecx.eq(goal.param_env, goal.predicate.trait_ref, impl_trait_ref)?;
let where_clause_bounds = cx
.predicates_of(impl_def_id)
.predicates_of(impl_def_id.into())
.iter_instantiated(cx, impl_args)
.map(|pred| goal.with(cx, pred));
ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds);
// For this impl to be `const`, we need to check its `[const]` bounds too.
let const_conditions = cx
.const_conditions(impl_def_id)
.const_conditions(impl_def_id.into())
.iter_instantiated(cx, impl_args)
.map(|bound_trait_ref| {
goal.with(
@@ -240,7 +240,7 @@ where
ty::TraitRef::new(cx, cx.require_trait_lang_item(SolverTraitLangItem::Sized), [output])
});
let requirements = cx
.const_conditions(def_id)
.const_conditions(def_id.into())
.iter_instantiated(cx, args)
.map(|trait_ref| {
(

View File

@@ -1092,7 +1092,7 @@ where
&self,
goal_trait_ref: ty::TraitRef<I>,
trait_assoc_def_id: I::DefId,
impl_def_id: I::DefId,
impl_def_id: I::ImplId,
) -> Result<Option<I::DefId>, I::ErrorGuaranteed> {
self.delegate.fetch_eligible_assoc_item(goal_trait_ref, trait_assoc_def_id, impl_def_id)
}

View File

@@ -5,7 +5,7 @@ mod opaque_types;
use rustc_type_ir::fast_reject::DeepRejectCtxt;
use rustc_type_ir::inherent::*;
use rustc_type_ir::lang_items::{SolverLangItem, SolverTraitLangItem};
use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverLangItem, SolverTraitLangItem};
use rustc_type_ir::solve::SizedTraitKind;
use rustc_type_ir::{self as ty, Interner, NormalizesTo, PredicateKind, Upcast as _};
use tracing::instrument;
@@ -193,7 +193,7 @@ where
fn consider_impl_candidate(
ecx: &mut EvalCtxt<'_, D>,
goal: Goal<I, NormalizesTo<I>>,
impl_def_id: I::DefId,
impl_def_id: I::ImplId,
) -> Result<Candidate<I>, NoSolution> {
let cx = ecx.cx();
@@ -217,13 +217,13 @@ where
};
ecx.probe_trait_candidate(CandidateSource::Impl(impl_def_id)).enter(|ecx| {
let impl_args = ecx.fresh_args_for_item(impl_def_id);
let impl_args = ecx.fresh_args_for_item(impl_def_id.into());
let impl_trait_ref = impl_trait_ref.instantiate(cx, impl_args);
ecx.eq(goal.param_env, goal_trait_ref, impl_trait_ref)?;
let where_clause_bounds = cx
.predicates_of(impl_def_id)
.predicates_of(impl_def_id.into())
.iter_instantiated(cx, impl_args)
.map(|pred| goal.with(cx, pred));
ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds);
@@ -824,10 +824,10 @@ where
// coroutine yield ty `Poll<Option<I>>`.
let wrapped_expected_ty = Ty::new_adt(
cx,
cx.adt_def(cx.require_lang_item(SolverLangItem::Poll)),
cx.adt_def(cx.require_adt_lang_item(SolverAdtLangItem::Poll)),
cx.mk_args(&[Ty::new_adt(
cx,
cx.adt_def(cx.require_lang_item(SolverLangItem::Option)),
cx.adt_def(cx.require_adt_lang_item(SolverAdtLangItem::Option)),
cx.mk_args(&[expected_ty.into()]),
)
.into()]),
@@ -979,7 +979,7 @@ where
fn translate_args(
&mut self,
goal: Goal<I, ty::NormalizesTo<I>>,
impl_def_id: I::DefId,
impl_def_id: I::ImplId,
impl_args: I::GenericArgs,
impl_trait_ref: rustc_type_ir::TraitRef<I>,
target_container_def_id: I::DefId,
@@ -988,14 +988,15 @@ where
Ok(if target_container_def_id == impl_trait_ref.def_id.into() {
// Default value from the trait definition. No need to rebase.
goal.predicate.alias.args
} else if target_container_def_id == impl_def_id {
} else if target_container_def_id == impl_def_id.into() {
// Same impl, no need to fully translate, just a rebase from
// the trait is sufficient.
goal.predicate.alias.args.rebase_onto(cx, impl_trait_ref.def_id.into(), impl_args)
} else {
let target_args = self.fresh_args_for_item(target_container_def_id);
let target_trait_ref =
cx.impl_trait_ref(target_container_def_id).instantiate(cx, target_args);
let target_trait_ref = cx
.impl_trait_ref(target_container_def_id.try_into().unwrap())
.instantiate(cx, target_args);
// Relate source impl to target impl by equating trait refs.
self.eq(goal.param_env, impl_trait_ref, target_trait_ref)?;
// Also add predicates since they may be needed to constrain the

View File

@@ -54,7 +54,7 @@ where
fn consider_impl_candidate(
ecx: &mut EvalCtxt<'_, D>,
goal: Goal<I, TraitPredicate<I>>,
impl_def_id: I::DefId,
impl_def_id: I::ImplId,
) -> Result<Candidate<I>, NoSolution> {
let cx = ecx.cx();
@@ -91,13 +91,13 @@ where
};
ecx.probe_trait_candidate(CandidateSource::Impl(impl_def_id)).enter(|ecx| {
let impl_args = ecx.fresh_args_for_item(impl_def_id);
let impl_args = ecx.fresh_args_for_item(impl_def_id.into());
ecx.record_impl_args(impl_args);
let impl_trait_ref = impl_trait_ref.instantiate(cx, impl_args);
ecx.eq(goal.param_env, goal.predicate.trait_ref, impl_trait_ref)?;
let where_clause_bounds = cx
.predicates_of(impl_def_id)
.predicates_of(impl_def_id.into())
.iter_instantiated(cx, impl_args)
.map(|pred| goal.with(cx, pred));
ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds);