Skip to content

Commit ce54c3a

Browse files
committed
Auto merge of #155981 - ChayimFriedman2:alias-def-id, r=<try>
Use special DefIds for aliases
2 parents 045b177 + 5e8cb76 commit ce54c3a

17 files changed

Lines changed: 295 additions & 178 deletions

File tree

compiler/rustc_middle/src/ty/context/impl_interner.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_hir::def::{CtorKind, CtorOf, DefKind};
88
use rustc_hir::def_id::{DefId, LocalDefId};
99
use rustc_hir::lang_items::LangItem;
1010
use rustc_span::{DUMMY_SP, Span, Symbol};
11-
use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverLangItem, SolverTraitLangItem};
11+
use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverProjectionLangItem, SolverTraitLangItem};
1212
use rustc_type_ir::{CollectAndApply, Interner, TypeFoldable, Unnormalized, search_graph};
1313

1414
use crate::dep_graph::{DepKind, DepNodeIndex};
@@ -39,6 +39,17 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
3939
type AdtId = DefId;
4040
type ImplId = DefId;
4141
type UnevaluatedConstId = DefId;
42+
type DefinitionAssocTyId = DefId;
43+
type DefinitionAssocConstId = DefId;
44+
type DefinitionAssocTermId = DefId;
45+
type OpaqueTyId = DefId;
46+
type LocalOpaqueTyId = LocalDefId;
47+
type FreeTyAliasId = DefId;
48+
type FreeConstAliasId = DefId;
49+
type FreeTermAliasId = DefId;
50+
type ImplOrTraitAssocTyId = DefId;
51+
type ImplOrTraitAssocConstId = DefId;
52+
type ImplOrTraitAssocTermId = DefId;
4253
type Span = Span;
4354

4455
type GenericArgs = ty::GenericArgsRef<'tcx>;
@@ -285,7 +296,11 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
285296
self.mk_type_list_from_iter(args)
286297
}
287298

288-
fn parent(self, def_id: DefId) -> DefId {
299+
fn projection_parent(self, def_id: Self::DefinitionAssocTermId) -> Self::TraitId {
300+
self.parent(def_id)
301+
}
302+
303+
fn impl_or_trait_assoc_term_parent(self, def_id: Self::ImplOrTraitAssocTyId) -> Self::ImplId {
289304
self.parent(def_id)
290305
}
291306

@@ -443,7 +458,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
443458
!self.codegen_fn_attrs(def_id).target_features.is_empty()
444459
}
445460

446-
fn require_lang_item(self, lang_item: SolverLangItem) -> DefId {
461+
fn require_projection_lang_item(self, lang_item: SolverProjectionLangItem) -> DefId {
447462
self.require_lang_item(solver_lang_item_to_lang_item(lang_item), DUMMY_SP)
448463
}
449464

@@ -455,7 +470,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
455470
self.require_lang_item(solver_adt_lang_item_to_lang_item(lang_item), DUMMY_SP)
456471
}
457472

458-
fn is_lang_item(self, def_id: DefId, lang_item: SolverLangItem) -> bool {
473+
fn is_projection_lang_item(self, def_id: DefId, lang_item: SolverProjectionLangItem) -> bool {
459474
self.is_lang_item(def_id, solver_lang_item_to_lang_item(lang_item))
460475
}
461476

@@ -475,7 +490,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
475490
self.is_sizedness_trait(def_id)
476491
}
477492

478-
fn as_lang_item(self, def_id: DefId) -> Option<SolverLangItem> {
493+
fn as_projection_lang_item(self, def_id: DefId) -> Option<SolverProjectionLangItem> {
479494
lang_item_to_solver_lang_item(self.lang_items().from_def_id(def_id)?)
480495
}
481496

@@ -754,7 +769,7 @@ macro_rules! bidirectional_lang_item_map {
754769
}
755770

756771
bidirectional_lang_item_map! {
757-
SolverLangItem, fn lang_item_to_solver_lang_item, fn solver_lang_item_to_lang_item;
772+
SolverProjectionLangItem, fn lang_item_to_solver_lang_item, fn solver_lang_item_to_lang_item;
758773

759774
// tidy-alphabetical-start
760775
AsyncFnKindUpvars,
@@ -788,7 +803,6 @@ bidirectional_lang_item_map! {
788803
AsyncFnKindHelper,
789804
AsyncFnMut,
790805
AsyncFnOnce,
791-
AsyncFnOnceOutput,
792806
AsyncIterator,
793807
BikeshedGuaranteedNoDrop,
794808
Clone,

compiler/rustc_next_trait_solver/src/delegate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
6767

6868
fn add_item_bounds_for_hidden_type(
6969
&self,
70-
def_id: <Self::Interner as Interner>::DefId,
70+
def_id: <Self::Interner as Interner>::OpaqueTyId,
7171
args: <Self::Interner as Interner>::GenericArgs,
7272
param_env: <Self::Interner as Interner>::ParamEnv,
7373
hidden_ty: <Self::Interner as Interner>::Ty,
@@ -77,10 +77,10 @@ pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
7777
fn fetch_eligible_assoc_item(
7878
&self,
7979
goal_trait_ref: ty::TraitRef<Self::Interner>,
80-
trait_assoc_def_id: <Self::Interner as Interner>::DefId,
80+
trait_assoc_def_id: <Self::Interner as Interner>::DefinitionAssocTermId,
8181
impl_def_id: <Self::Interner as Interner>::ImplId,
8282
) -> Result<
83-
Option<<Self::Interner as Interner>::DefId>,
83+
Option<<Self::Interner as Interner>::ImplOrTraitAssocTermId>,
8484
<Self::Interner as Interner>::ErrorGuaranteed,
8585
>;
8686

compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use derive_where::derive_where;
55
use rustc_type_ir::data_structures::HashMap;
66
use rustc_type_ir::inherent::*;
7-
use rustc_type_ir::lang_items::{SolverLangItem, SolverTraitLangItem};
7+
use rustc_type_ir::lang_items::{SolverProjectionLangItem, SolverTraitLangItem};
88
use rustc_type_ir::solve::SizedTraitKind;
99
use rustc_type_ir::solve::inspect::ProbeKind;
1010
use rustc_type_ir::{
@@ -106,7 +106,9 @@ where
106106
// We can resolve the `impl Trait` to its concrete type,
107107
// which enforces a DAG between the functions requiring
108108
// the auto trait bounds in question.
109-
Ok(ty::Binder::dummy(vec![cx.type_of(def_id).instantiate(cx, args).skip_norm_wip()]))
109+
Ok(ty::Binder::dummy(vec![
110+
cx.type_of(def_id.into()).instantiate(cx, args).skip_norm_wip(),
111+
]))
110112
}
111113
}
112114
}
@@ -541,7 +543,8 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I:
541543
);
542544
}
543545

544-
let future_output_def_id = cx.require_lang_item(SolverLangItem::FutureOutput);
546+
let future_output_def_id =
547+
cx.require_projection_lang_item(SolverProjectionLangItem::FutureOutput);
545548
let future_output_ty = Ty::new_projection(cx, future_output_def_id, [sig.output()]);
546549
Ok((
547550
bound_sig.rebind(AsyncCallableRelevantTypes {
@@ -596,7 +599,8 @@ fn fn_item_to_async_callable<I: Interner>(
596599
let nested = vec![
597600
bound_sig.rebind(ty::TraitRef::new(cx, future_trait_def_id, [sig.output()])).upcast(cx),
598601
];
599-
let future_output_def_id = cx.require_lang_item(SolverLangItem::FutureOutput);
602+
let future_output_def_id =
603+
cx.require_projection_lang_item(SolverProjectionLangItem::FutureOutput);
600604
let future_output_ty = Ty::new_projection(cx, future_output_def_id, [sig.output()]);
601605
Ok((
602606
bound_sig.rebind(AsyncCallableRelevantTypes {
@@ -642,7 +646,8 @@ fn coroutine_closure_to_ambiguous_coroutine<I: Interner>(
642646
args: ty::CoroutineClosureArgs<I>,
643647
sig: ty::CoroutineClosureSignature<I>,
644648
) -> I::Ty {
645-
let upvars_projection_def_id = cx.require_lang_item(SolverLangItem::AsyncFnKindUpvars);
649+
let upvars_projection_def_id =
650+
cx.require_projection_lang_item(SolverProjectionLangItem::AsyncFnKindUpvars);
646651
let tupled_upvars_ty = Ty::new_projection(
647652
cx,
648653
upvars_projection_def_id,
@@ -920,7 +925,10 @@ where
920925
// show up in the bounds, but just ones that come from substituting
921926
// `Self` with the dyn type.
922927
let proj = proj.with_self_ty(cx, trait_ref.self_ty());
923-
replace_projection_with.entry(proj.def_id()).or_default().push(bound.rebind(proj));
928+
replace_projection_with
929+
.entry(proj.def_id().into())
930+
.or_default()
931+
.push(bound.rebind(proj));
924932
}
925933
}
926934

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,9 +1152,9 @@ where
11521152
pub(super) fn fetch_eligible_assoc_item(
11531153
&self,
11541154
goal_trait_ref: ty::TraitRef<I>,
1155-
trait_assoc_def_id: I::DefId,
1155+
trait_assoc_def_id: I::DefinitionAssocTermId,
11561156
impl_def_id: I::ImplId,
1157-
) -> Result<Option<I::DefId>, I::ErrorGuaranteed> {
1157+
) -> Result<Option<I::ImplOrTraitAssocTermId>, I::ErrorGuaranteed> {
11581158
self.delegate.fetch_eligible_assoc_item(goal_trait_ref, trait_assoc_def_id, impl_def_id)
11591159
}
11601160

@@ -1169,7 +1169,7 @@ where
11691169

11701170
pub(super) fn add_item_bounds_for_hidden_type(
11711171
&mut self,
1172-
opaque_def_id: I::DefId,
1172+
opaque_def_id: I::OpaqueTyId,
11731173
opaque_args: I::GenericArgs,
11741174
param_env: I::ParamEnv,
11751175
hidden_ty: I::Ty,

compiler/rustc_next_trait_solver/src/solve/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ where
357357
}
358358
}
359359

360-
fn opaque_type_is_rigid(&self, def_id: I::DefId) -> bool {
360+
fn opaque_type_is_rigid(&self, def_id: I::OpaqueTyId) -> bool {
361361
match self.typing_mode() {
362362
// Opaques are never rigid outside of analysis mode.
363363
TypingMode::Coherence | TypingMode::PostAnalysis => false,
@@ -366,7 +366,7 @@ where
366366
TypingMode::Analysis { defining_opaque_types_and_generators: non_rigid_opaques }
367367
| TypingMode::Borrowck { defining_opaque_types: non_rigid_opaques }
368368
| TypingMode::PostBorrowckAnalysis { defined_opaque_types: non_rigid_opaques } => {
369-
!def_id.as_local().is_some_and(|def_id| non_rigid_opaques.contains(&def_id))
369+
!def_id.as_local().is_some_and(|def_id| non_rigid_opaques.contains(&def_id.into()))
370370
}
371371
}
372372
}

compiler/rustc_next_trait_solver/src/solve/normalizes_to/anon_const.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ where
1313
pub(super) fn normalize_anon_const(
1414
&mut self,
1515
goal: Goal<I, ty::NormalizesTo<I>>,
16+
def_id: I::UnevaluatedConstId,
1617
) -> QueryResult<I> {
1718
if let Some(normalized_const) = self.evaluate_const(
1819
goal.param_env,
19-
ty::UnevaluatedConst::new(
20-
goal.predicate.alias.def_id().try_into().unwrap(),
21-
goal.predicate.alias.args,
22-
),
20+
ty::UnevaluatedConst::new(def_id, goal.predicate.alias.args),
2321
) {
2422
self.instantiate_normalizes_to_term(goal, normalized_const.into());
2523
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)

compiler/rustc_next_trait_solver/src/solve/normalizes_to/inherent.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ where
1818
pub(super) fn normalize_inherent_associated_term(
1919
&mut self,
2020
goal: Goal<I, ty::NormalizesTo<I>>,
21+
def_id: I::ImplOrTraitAssocTermId,
2122
) -> QueryResult<I> {
2223
let cx = self.cx();
2324
let inherent = goal.predicate.alias;
2425

25-
let impl_def_id = cx.parent(inherent.def_id());
26+
let impl_def_id = cx.impl_or_trait_assoc_term_parent(def_id);
2627
let impl_args = self.fresh_args_for_item(impl_def_id);
2728

2829
// Equate impl header and add impl where clauses
@@ -46,19 +47,16 @@ where
4647
// to be very careful when changing the impl where-clauses to be productive.
4748
self.add_goals(
4849
GoalSource::Misc,
49-
cx.predicates_of(inherent.def_id())
50+
cx.predicates_of(def_id.into())
5051
.iter_instantiated(cx, inherent_args)
5152
.map(Unnormalized::skip_norm_wip)
5253
.map(|pred| goal.with(cx, pred)),
5354
);
5455

5556
let normalized = if inherent.kind(cx).is_type() {
56-
cx.type_of(inherent.def_id()).instantiate(cx, inherent_args).skip_norm_wip().into()
57+
cx.type_of(def_id.into()).instantiate(cx, inherent_args).skip_norm_wip().into()
5758
} else {
58-
cx.const_of_item(inherent.def_id())
59-
.instantiate(cx, inherent_args)
60-
.skip_norm_wip()
61-
.into()
59+
cx.const_of_item(def_id.into()).instantiate(cx, inherent_args).skip_norm_wip().into()
6260
};
6361
self.instantiate_normalizes_to_term(goal, normalized);
6462
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)

0 commit comments

Comments
 (0)