Skip to content

Commit 98179ad

Browse files
committed
Auto merge of #113943 - ericmarkmartin:smir-ty-alias, r=spastorino
Add Alias to smir r? Spastorino
2 parents 1d56e3a + 7ac0ef9 commit 98179ad

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

compiler/rustc_smir/src/rustc_internal/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ pub fn generator_def(did: DefId) -> stable_mir::ty::GeneratorDef {
4747
with_tables(|t| t.generator_def(did))
4848
}
4949

50+
pub fn alias_def(did: DefId) -> stable_mir::ty::AliasDef {
51+
with_tables(|t| t.alias_def(did))
52+
}
53+
5054
pub fn param_def(did: DefId) -> stable_mir::ty::ParamDef {
5155
with_tables(|t| t.param_def(did))
5256
}
@@ -84,6 +88,10 @@ impl<'tcx> Tables<'tcx> {
8488
stable_mir::ty::GeneratorDef(self.create_def_id(did))
8589
}
8690

91+
pub fn alias_def(&mut self, did: DefId) -> stable_mir::ty::AliasDef {
92+
stable_mir::ty::AliasDef(self.create_def_id(did))
93+
}
94+
8795
pub fn param_def(&mut self, did: DefId) -> stable_mir::ty::ParamDef {
8896
stable_mir::ty::ParamDef(self.create_def_id(did))
8997
}

compiler/rustc_smir/src/rustc_smir/mod.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,27 @@ impl<'tcx> Stable<'tcx> for mir::CastKind {
237237
}
238238
}
239239

240+
impl<'tcx> Stable<'tcx> for ty::AliasKind {
241+
type T = stable_mir::ty::AliasKind;
242+
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
243+
use ty::AliasKind::*;
244+
match self {
245+
Projection => stable_mir::ty::AliasKind::Projection,
246+
Inherent => stable_mir::ty::AliasKind::Inherent,
247+
Opaque => stable_mir::ty::AliasKind::Opaque,
248+
Weak => stable_mir::ty::AliasKind::Weak,
249+
}
250+
}
251+
}
252+
253+
impl<'tcx> Stable<'tcx> for ty::AliasTy<'tcx> {
254+
type T = stable_mir::ty::AliasTy;
255+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
256+
let ty::AliasTy { args, def_id, .. } = self;
257+
stable_mir::ty::AliasTy { def_id: tables.alias_def(*def_id), args: args.stable(tables) }
258+
}
259+
}
260+
240261
impl<'tcx> Stable<'tcx> for ty::adjustment::PointerCoercion {
241262
type T = stable_mir::mir::PointerCoercion;
242263
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
@@ -667,7 +688,9 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> {
667688
ty::Tuple(fields) => TyKind::RigidTy(RigidTy::Tuple(
668689
fields.iter().map(|ty| tables.intern_ty(ty)).collect(),
669690
)),
670-
ty::Alias(_, _) => todo!(),
691+
ty::Alias(alias_kind, alias_ty) => {
692+
TyKind::Alias(alias_kind.stable(tables), alias_ty.stable(tables))
693+
}
671694
ty::Param(_) => todo!(),
672695
ty::Bound(_, _) => todo!(),
673696
ty::Placeholder(..)

compiler/rustc_smir/src/stable_mir/ty.rs

+18
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Span = Opaque;
1717
#[derive(Clone, Debug)]
1818
pub enum TyKind {
1919
RigidTy(RigidTy),
20+
Alias(AliasKind, AliasTy),
2021
}
2122

2223
#[derive(Clone, Debug)]
@@ -94,6 +95,9 @@ pub struct BrNamedDef(pub(crate) DefId);
9495
#[derive(Clone, PartialEq, Eq, Debug)]
9596
pub struct AdtDef(pub(crate) DefId);
9697

98+
#[derive(Clone, PartialEq, Eq, Debug)]
99+
pub struct AliasDef(pub(crate) DefId);
100+
97101
#[derive(Clone, Debug)]
98102
pub struct GenericArgs(pub Vec<GenericArgKind>);
99103

@@ -104,6 +108,20 @@ pub enum GenericArgKind {
104108
Const(Const),
105109
}
106110

111+
#[derive(Clone, Debug)]
112+
pub enum AliasKind {
113+
Projection,
114+
Inherent,
115+
Opaque,
116+
Weak,
117+
}
118+
119+
#[derive(Clone, Debug)]
120+
pub struct AliasTy {
121+
pub def_id: AliasDef,
122+
pub args: GenericArgs,
123+
}
124+
107125
pub type PolyFnSig = Binder<FnSig>;
108126

109127
#[derive(Clone, Debug)]

compiler/rustc_type_ir/src/sty.rs

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub enum AliasKind {
3939
/// A projection `<Type as Trait>::AssocType`.
4040
/// Can get normalized away if monomorphic enough.
4141
Projection,
42+
/// An associated type in an inherent `impl`
4243
Inherent,
4344
/// An opaque type (usually from `impl Trait` in type aliases or function return types)
4445
/// Can only be normalized away in RevealAll mode

0 commit comments

Comments
 (0)