Skip to content

Commit

Permalink
Rollup merge of #113930 - spastorino:smir-types-6, r=oli-obk
Browse files Browse the repository at this point in the history
Add Param and Bound ty to SMIR

r? ``@oli-obk``
  • Loading branch information
matthiaskrgr committed Jul 26, 2023
2 parents 26d791b + 7af1697 commit d910e7d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
22 changes: 20 additions & 2 deletions compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,8 +825,10 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> {
ty::Alias(alias_kind, alias_ty) => {
TyKind::Alias(alias_kind.stable(tables), alias_ty.stable(tables))
}
ty::Param(_) => todo!(),
ty::Bound(_, _) => todo!(),
ty::Param(param_ty) => TyKind::Param(param_ty.stable(tables)),
ty::Bound(debruijn_idx, bound_ty) => {
TyKind::Bound(debruijn_idx.as_usize(), bound_ty.stable(tables))
}
ty::Placeholder(..)
| ty::GeneratorWitness(_)
| ty::GeneratorWitnessMIR(_, _)
Expand All @@ -837,3 +839,19 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> {
}
}
}

impl<'tcx> Stable<'tcx> for rustc_middle::ty::ParamTy {
type T = stable_mir::ty::ParamTy;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
use stable_mir::ty::ParamTy;
ParamTy { index: self.index, name: self.name.to_string() }
}
}

impl<'tcx> Stable<'tcx> for rustc_middle::ty::BoundTy {
type T = stable_mir::ty::BoundTy;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
use stable_mir::ty::BoundTy;
BoundTy { var: self.var.as_usize(), kind: self.kind.stable(tables) }
}
}
14 changes: 14 additions & 0 deletions compiler/rustc_smir/src/stable_mir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type Span = Opaque;
pub enum TyKind {
RigidTy(RigidTy),
Alias(AliasKind, AliasTy),
Param(ParamTy),
Bound(usize, BoundTy),
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -228,3 +230,15 @@ pub struct ExistentialProjection {
pub generic_args: GenericArgs,
pub term: TermKind,
}

#[derive(Clone, Debug)]
pub struct ParamTy {
pub index: u32,
pub name: String,
}

#[derive(Clone, Debug)]
pub struct BoundTy {
pub var: usize,
pub kind: BoundTyKind,
}

0 comments on commit d910e7d

Please sign in to comment.