diff options
| author | Eric Mark Martin <ericmarkmartin@gmail.com> | 2023-07-17 20:46:33 -0400 |
|---|---|---|
| committer | Eric Mark Martin <ericmarkmartin@gmail.com> | 2023-07-22 15:38:41 -0400 |
| commit | aa33e8945c37a7a2ae59bba880bffa516bf408b6 (patch) | |
| tree | 3858b35530a9e05d43b8e6fca311902627973b36 /compiler | |
| parent | a5e2eca40ec17f17b6641bcc7c069380ac395acf (diff) | |
| download | rust-aa33e8945c37a7a2ae59bba880bffa516bf408b6.tar.gz rust-aa33e8945c37a7a2ae59bba880bffa516bf408b6.zip | |
add Alias for smir
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_smir/src/rustc_internal/mod.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_smir/src/rustc_smir/mod.rs | 25 | ||||
| -rw-r--r-- | compiler/rustc_smir/src/stable_mir/ty.rs | 18 |
3 files changed, 50 insertions, 1 deletions
diff --git a/compiler/rustc_smir/src/rustc_internal/mod.rs b/compiler/rustc_smir/src/rustc_internal/mod.rs index a918bc981c0..e0cf698acd7 100644 --- a/compiler/rustc_smir/src/rustc_internal/mod.rs +++ b/compiler/rustc_smir/src/rustc_internal/mod.rs @@ -47,6 +47,10 @@ pub fn generator_def(did: DefId) -> stable_mir::ty::GeneratorDef { with_tables(|t| t.generator_def(did)) } +pub fn alias_def(did: DefId) -> stable_mir::ty::AliasDef { + with_tables(|t| t.alias_def(did)) +} + pub fn param_def(did: DefId) -> stable_mir::ty::ParamDef { with_tables(|t| t.param_def(did)) } @@ -84,6 +88,10 @@ impl<'tcx> Tables<'tcx> { stable_mir::ty::GeneratorDef(self.create_def_id(did)) } + pub fn alias_def(&mut self, did: DefId) -> stable_mir::ty::AliasDef { + stable_mir::ty::AliasDef(self.create_def_id(did)) + } + pub fn param_def(&mut self, did: DefId) -> stable_mir::ty::ParamDef { stable_mir::ty::ParamDef(self.create_def_id(did)) } diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index c9da752ab77..97bde5c3c19 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -237,6 +237,27 @@ impl<'tcx> Stable<'tcx> for mir::CastKind { } } +impl<'tcx> Stable<'tcx> for ty::AliasKind { + type T = stable_mir::ty::AliasKind; + fn stable(&self, _: &mut Tables<'tcx>) -> Self::T { + use ty::AliasKind::*; + match self { + Projection => stable_mir::ty::AliasKind::Projection, + Inherent => stable_mir::ty::AliasKind::Inherent, + Opaque => stable_mir::ty::AliasKind::Opaque, + Weak => stable_mir::ty::AliasKind::Weak, + } + } +} + +impl<'tcx> Stable<'tcx> for ty::AliasTy<'tcx> { + type T = stable_mir::ty::AliasTy; + fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T { + let ty::AliasTy { args, def_id, .. } = self; + stable_mir::ty::AliasTy { def_id: tables.alias_def(*def_id), args: args.stable(tables) } + } +} + impl<'tcx> Stable<'tcx> for ty::adjustment::PointerCoercion { type T = stable_mir::mir::PointerCoercion; fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T { @@ -667,7 +688,9 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> { ty::Tuple(fields) => TyKind::RigidTy(RigidTy::Tuple( fields.iter().map(|ty| tables.intern_ty(ty)).collect(), )), - ty::Alias(_, _) => todo!(), + ty::Alias(alias_kind, alias_ty) => { + TyKind::Alias(alias_kind.stable(tables), alias_ty.stable(tables)) + } ty::Param(_) => todo!(), ty::Bound(_, _) => todo!(), ty::Placeholder(..) diff --git a/compiler/rustc_smir/src/stable_mir/ty.rs b/compiler/rustc_smir/src/stable_mir/ty.rs index 2b762eab5ef..885beeda78c 100644 --- a/compiler/rustc_smir/src/stable_mir/ty.rs +++ b/compiler/rustc_smir/src/stable_mir/ty.rs @@ -17,6 +17,7 @@ type Span = Opaque; #[derive(Clone, Debug)] pub enum TyKind { RigidTy(RigidTy), + Alias(AliasKind, AliasTy), } #[derive(Clone, Debug)] @@ -94,6 +95,9 @@ pub struct BrNamedDef(pub(crate) DefId); #[derive(Clone, PartialEq, Eq, Debug)] pub struct AdtDef(pub(crate) DefId); +#[derive(Clone, PartialEq, Eq, Debug)] +pub struct AliasDef(pub(crate) DefId); + #[derive(Clone, Debug)] pub struct GenericArgs(pub Vec<GenericArgKind>); @@ -104,6 +108,20 @@ pub enum GenericArgKind { Const(Const), } +#[derive(Clone, Debug)] +pub enum AliasKind { + Projection, + Inherent, + Opaque, + Weak, +} + +#[derive(Clone, Debug)] +pub struct AliasTy { + pub def_id: AliasDef, + pub args: GenericArgs, +} + pub type PolyFnSig = Binder<FnSig>; #[derive(Clone, Debug)] |
