Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions compiler/rustc_middle/src/ty/context/impl_interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_hir::def::{CtorKind, CtorOf, DefKind};
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::lang_items::LangItem;
use rustc_span::{DUMMY_SP, Span, Symbol};
use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverLangItem, SolverTraitLangItem};
use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverProjectionLangItem, SolverTraitLangItem};
use rustc_type_ir::{CollectAndApply, Interner, TypeFoldable, Unnormalized, search_graph};

use crate::dep_graph::{DepKind, DepNodeIndex};
Expand Down Expand Up @@ -39,6 +39,20 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
type AdtId = DefId;
type ImplId = DefId;
type UnevaluatedConstId = DefId;
type TraitAssocTyId = DefId;
type TraitAssocConstId = DefId;
type TraitAssocTermId = DefId;
type OpaqueTyId = DefId;
type LocalOpaqueTyId = LocalDefId;
type FreeTyAliasId = DefId;
type FreeConstAliasId = DefId;
type FreeTermAliasId = DefId;
type ImplOrTraitAssocTyId = DefId;
type ImplOrTraitAssocConstId = DefId;
type ImplOrTraitAssocTermId = DefId;
type InherentAssocTyId = DefId;
type InherentAssocConstId = DefId;
type InherentAssocTermId = DefId;
type Span = Span;

type GenericArgs = ty::GenericArgsRef<'tcx>;
Expand Down Expand Up @@ -288,7 +302,15 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
self.mk_type_list_from_iter(args)
}

fn parent(self, def_id: DefId) -> DefId {
fn projection_parent(self, def_id: Self::TraitAssocTermId) -> Self::TraitId {
self.parent(def_id)
}

fn impl_or_trait_assoc_term_parent(self, def_id: Self::ImplOrTraitAssocTyId) -> DefId {
self.parent(def_id)
}

fn inherent_alias_term_parent(self, def_id: Self::InherentAssocTermId) -> Self::ImplId {
self.parent(def_id)
}

Expand Down Expand Up @@ -446,7 +468,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
!self.codegen_fn_attrs(def_id).target_features.is_empty()
}

fn require_lang_item(self, lang_item: SolverLangItem) -> DefId {
fn require_projection_lang_item(self, lang_item: SolverProjectionLangItem) -> DefId {
self.require_lang_item(solver_lang_item_to_lang_item(lang_item), DUMMY_SP)
}

Expand All @@ -458,7 +480,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
self.require_lang_item(solver_adt_lang_item_to_lang_item(lang_item), DUMMY_SP)
}

fn is_lang_item(self, def_id: DefId, lang_item: SolverLangItem) -> bool {
fn is_projection_lang_item(self, def_id: DefId, lang_item: SolverProjectionLangItem) -> bool {
self.is_lang_item(def_id, solver_lang_item_to_lang_item(lang_item))
}

Expand All @@ -478,7 +500,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
self.is_sizedness_trait(def_id)
}

fn as_lang_item(self, def_id: DefId) -> Option<SolverLangItem> {
fn as_projection_lang_item(self, def_id: DefId) -> Option<SolverProjectionLangItem> {
lang_item_to_solver_lang_item(self.lang_items().from_def_id(def_id)?)
}

Expand Down Expand Up @@ -757,7 +779,7 @@ macro_rules! bidirectional_lang_item_map {
}

bidirectional_lang_item_map! {
SolverLangItem, fn lang_item_to_solver_lang_item, fn solver_lang_item_to_lang_item;
SolverProjectionLangItem, fn lang_item_to_solver_lang_item, fn solver_lang_item_to_lang_item;

// tidy-alphabetical-start
AsyncFnKindUpvars,
Expand All @@ -766,7 +788,6 @@ bidirectional_lang_item_map! {
CallRefFuture,
CoroutineReturn,
CoroutineYield,
DynMetadata,
FieldBase,
FieldType,
FutureOutput,
Expand All @@ -778,6 +799,7 @@ bidirectional_lang_item_map! {
SolverAdtLangItem, fn lang_item_to_solver_adt_lang_item, fn solver_adt_lang_item_to_lang_item;

// tidy-alphabetical-start
DynMetadata,
Option,
Poll,
// tidy-alphabetical-end
Expand All @@ -791,7 +813,6 @@ bidirectional_lang_item_map! {
AsyncFnKindHelper,
AsyncFnMut,
AsyncFnOnce,
AsyncFnOnceOutput,
AsyncIterator,
BikeshedGuaranteedNoDrop,
Clone,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_next_trait_solver/src/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {

fn add_item_bounds_for_hidden_type(
&self,
def_id: <Self::Interner as Interner>::DefId,
def_id: <Self::Interner as Interner>::OpaqueTyId,
args: <Self::Interner as Interner>::GenericArgs,
param_env: <Self::Interner as Interner>::ParamEnv,
hidden_ty: <Self::Interner as Interner>::Ty,
Expand All @@ -79,7 +79,7 @@ pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
fn fetch_eligible_assoc_item(
&self,
goal_trait_ref: ty::TraitRef<Self::Interner>,
trait_assoc_def_id: <Self::Interner as Interner>::DefId,
trait_assoc_def_id: <Self::Interner as Interner>::TraitAssocTermId,
impl_def_id: <Self::Interner as Interner>::ImplId,
) -> FetchEligibleAssocItemResponse<Self::Interner>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use derive_where::derive_where;
use rustc_type_ir::data_structures::HashMap;
use rustc_type_ir::inherent::*;
use rustc_type_ir::lang_items::{SolverLangItem, SolverTraitLangItem};
use rustc_type_ir::lang_items::{SolverProjectionLangItem, SolverTraitLangItem};
use rustc_type_ir::solve::SizedTraitKind;
use rustc_type_ir::solve::inspect::ProbeKind;
use rustc_type_ir::{
Expand Down Expand Up @@ -106,7 +106,9 @@ where
// We can resolve the `impl Trait` to its concrete type,
// which enforces a DAG between the functions requiring
// the auto trait bounds in question.
Ok(ty::Binder::dummy(vec![cx.type_of(def_id).instantiate(cx, args).skip_norm_wip()]))
Ok(ty::Binder::dummy(vec![
cx.type_of(def_id.into()).instantiate(cx, args).skip_norm_wip(),
]))
}
}
}
Expand Down Expand Up @@ -541,7 +543,8 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I:
);
}

let future_output_def_id = cx.require_lang_item(SolverLangItem::FutureOutput);
let future_output_def_id =
cx.require_projection_lang_item(SolverProjectionLangItem::FutureOutput);
let future_output_ty = Ty::new_projection(cx, future_output_def_id, [sig.output()]);
Ok((
bound_sig.rebind(AsyncCallableRelevantTypes {
Expand Down Expand Up @@ -596,7 +599,8 @@ fn fn_item_to_async_callable<I: Interner>(
let nested = vec![
bound_sig.rebind(ty::TraitRef::new(cx, future_trait_def_id, [sig.output()])).upcast(cx),
];
let future_output_def_id = cx.require_lang_item(SolverLangItem::FutureOutput);
let future_output_def_id =
cx.require_projection_lang_item(SolverProjectionLangItem::FutureOutput);
let future_output_ty = Ty::new_projection(cx, future_output_def_id, [sig.output()]);
Ok((
bound_sig.rebind(AsyncCallableRelevantTypes {
Expand Down Expand Up @@ -642,7 +646,8 @@ fn coroutine_closure_to_ambiguous_coroutine<I: Interner>(
args: ty::CoroutineClosureArgs<I>,
sig: ty::CoroutineClosureSignature<I>,
) -> I::Ty {
let upvars_projection_def_id = cx.require_lang_item(SolverLangItem::AsyncFnKindUpvars);
let upvars_projection_def_id =
cx.require_projection_lang_item(SolverProjectionLangItem::AsyncFnKindUpvars);
let tupled_upvars_ty = Ty::new_projection(
cx,
upvars_projection_def_id,
Expand Down Expand Up @@ -920,7 +925,10 @@ where
// show up in the bounds, but just ones that come from substituting
// `Self` with the dyn type.
let proj = proj.with_self_ty(cx, trait_ref.self_ty());
replace_projection_with.entry(proj.def_id()).or_default().push(bound.rebind(proj));
replace_projection_with
.entry(proj.def_id().into())
.or_default()
.push(bound.rebind(proj));
}
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ where
original_typing_mode: TypingMode<I>,
parent_opaque_types: &[(OpaqueTypeKey<I>, I::Ty)],
) -> RerunDecision {
let parent_opaque_defids = parent_opaque_types.iter().map(|(key, _)| key.def_id);
let parent_opaque_defids = parent_opaque_types.iter().map(|(key, _)| key.def_id.into());
let opaque_in_storage = |opaques: I::LocalDefIds, defids: SmallCopyList<_>| {
if defids.as_ref().is_empty() {
RerunDecision::No
Expand Down Expand Up @@ -1357,7 +1357,7 @@ where
pub(super) fn fetch_eligible_assoc_item(
&self,
goal_trait_ref: ty::TraitRef<I>,
trait_assoc_def_id: I::DefId,
trait_assoc_def_id: I::TraitAssocTermId,
impl_def_id: I::ImplId,
) -> FetchEligibleAssocItemResponse<I> {
self.delegate.fetch_eligible_assoc_item(goal_trait_ref, trait_assoc_def_id, impl_def_id)
Expand All @@ -1374,7 +1374,7 @@ where

pub(super) fn add_item_bounds_for_hidden_type(
&mut self,
opaque_def_id: I::DefId,
opaque_def_id: I::OpaqueTyId,
opaque_args: I::GenericArgs,
param_env: I::ParamEnv,
hidden_ty: I::Ty,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_next_trait_solver/src/solve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ where
}
}

fn opaque_type_is_rigid(&self, def_id: I::DefId) -> bool {
fn opaque_type_is_rigid(&self, def_id: I::OpaqueTyId) -> bool {
match self
.typing_mode()
// Caller should handle erased mode
Expand All @@ -370,7 +370,7 @@ where
TypingMode::Analysis { defining_opaque_types_and_generators: non_rigid_opaques }
| TypingMode::Borrowck { defining_opaque_types: non_rigid_opaques }
| TypingMode::PostBorrowckAnalysis { defined_opaque_types: non_rigid_opaques } => {
!def_id.as_local().is_some_and(|def_id| non_rigid_opaques.contains(&def_id))
!def_id.as_local().is_some_and(|def_id| non_rigid_opaques.contains(&def_id.into()))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ where
pub(super) fn normalize_anon_const(
&mut self,
goal: Goal<I, ty::NormalizesTo<I>>,
def_id: I::UnevaluatedConstId,
Copy link
Copy Markdown
Contributor

@lcnr lcnr May 5, 2026

Choose a reason for hiding this comment

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

hmm, passing the DefId in separately feels redundant 🤔

could you do

pub struct NormalizesTo<I, K = AliasTermKind<I>> {
    pub alias: AliasTerm<I, K>,
    pub term: Term<'tcx>,
}

oh actually, that's just a very big change xd

we should have a single

struct Alias<I: Interner, K> {
    kind: K,
    args: I::GenericArgs,
}

this is not something we should do in this PR but as a separate cleanup. so this is fine for now

View changes since the review

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.

opened #156181 for this

) -> QueryResult<I> {
let uv = goal.predicate.alias.expect_ct(self.cx());
self.evaluate_const_and_instantiate_normalizes_to_term(goal, uv)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ where

let actual = match free_alias.kind(cx) {
ty::AliasTermKind::FreeTy { def_id } => {
cx.type_of(def_id).instantiate(cx, free_alias.args).skip_norm_wip().into()
}
ty::AliasTermKind::FreeConst { def_id } if cx.is_type_const(def_id) => {
cx.const_of_item(def_id).instantiate(cx, free_alias.args).skip_norm_wip().into()
cx.type_of(def_id.into()).instantiate(cx, free_alias.args).skip_norm_wip().into()
}
ty::AliasTermKind::FreeConst { def_id } if cx.is_type_const(def_id.into()) => cx
.const_of_item(def_id.into())
.instantiate(cx, free_alias.args)
.skip_norm_wip()
.into(),
ty::AliasTermKind::FreeConst { .. } => {
return self.evaluate_const_and_instantiate_normalizes_to_term(
goal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ where
pub(super) fn normalize_inherent_associated_term(
&mut self,
goal: Goal<I, ty::NormalizesTo<I>>,
def_id: I::InherentAssocTermId,
) -> QueryResult<I> {
let cx = self.cx();
let inherent = goal.predicate.alias;

let impl_def_id = cx.parent(inherent.def_id());
let impl_args = self.fresh_args_for_item(impl_def_id);
let impl_def_id = cx.inherent_alias_term_parent(def_id);
let impl_args = self.fresh_args_for_item(impl_def_id.into());

// Equate impl header and add impl where clauses
self.eq(
goal.param_env,
inherent.self_ty(),
cx.type_of(impl_def_id).instantiate(cx, impl_args).skip_norm_wip(),
cx.type_of(impl_def_id.into()).instantiate(cx, impl_args).skip_norm_wip(),
)?;

// Equate IAT with the RHS of the project goal
Expand All @@ -46,19 +47,21 @@ where
// to be very careful when changing the impl where-clauses to be productive.
self.add_goals(
GoalSource::Misc,
cx.predicates_of(inherent.def_id())
cx.predicates_of(def_id.into())
.iter_instantiated(cx, inherent_args)
.map(Unnormalized::skip_norm_wip)
.map(|pred| goal.with(cx, pred)),
);

let normalized = match inherent.kind(cx) {
ty::AliasTermKind::InherentTy { def_id } => {
cx.type_of(def_id).instantiate(cx, inherent_args).skip_norm_wip().into()
}
ty::AliasTermKind::InherentConst { def_id } if cx.is_type_const(def_id) => {
cx.const_of_item(def_id).instantiate(cx, inherent_args).skip_norm_wip().into()
cx.type_of(def_id.into()).instantiate(cx, inherent_args).skip_norm_wip().into()
}
ty::AliasTermKind::InherentConst { def_id } if cx.is_type_const(def_id.into()) => cx
.const_of_item(def_id.into())
.instantiate(cx, inherent_args)
.skip_norm_wip()
.into(),
ty::AliasTermKind::InherentConst { .. } => {
// FIXME(gca): This is dead code at the moment. It should eventually call
// self.evaluate_const like projected consts do in consider_impl_candidate in
Expand Down
Loading
Loading