From 648cf070ebcb52a42fb2e10febace4e8027557c7 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 21 Jul 2023 14:18:32 -0300 Subject: [PATCH 1/2] Add Param ty to SMIR --- compiler/rustc_smir/src/rustc_smir/mod.rs | 10 +++++++++- compiler/rustc_smir/src/stable_mir/ty.rs | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index 044e2f8f325..0e7673d25fb 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -825,7 +825,7 @@ fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T { ty::Alias(alias_kind, alias_ty) => { TyKind::Alias(alias_kind.stable(tables), alias_ty.stable(tables)) } - ty::Param(_) => todo!(), + ty::Param(param_ty) => TyKind::Param(param_ty.stable(tables)), ty::Bound(_, _) => todo!(), ty::Placeholder(..) | ty::GeneratorWitness(_) @@ -837,3 +837,11 @@ fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T { } } } + +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() } + } +} diff --git a/compiler/rustc_smir/src/stable_mir/ty.rs b/compiler/rustc_smir/src/stable_mir/ty.rs index 7b4747a7fe2..62dd02c1808 100644 --- a/compiler/rustc_smir/src/stable_mir/ty.rs +++ b/compiler/rustc_smir/src/stable_mir/ty.rs @@ -18,6 +18,7 @@ pub fn kind(&self) -> TyKind { pub enum TyKind { RigidTy(RigidTy), Alias(AliasKind, AliasTy), + Param(ParamTy), } #[derive(Clone, Debug)] @@ -228,3 +229,9 @@ pub struct ExistentialProjection { pub generic_args: GenericArgs, pub term: TermKind, } + +#[derive(Clone, Debug)] +pub struct ParamTy { + pub index: u32, + pub name: String, +} From 7af1697138de14dbfebe75d37d83d035c29a2bf8 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 21 Jul 2023 14:52:45 -0300 Subject: [PATCH 2/2] Add Bound ty to SMIR --- compiler/rustc_smir/src/rustc_smir/mod.rs | 12 +++++++++++- compiler/rustc_smir/src/stable_mir/ty.rs | 7 +++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index 0e7673d25fb..cefcab1e18f 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -826,7 +826,9 @@ fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T { TyKind::Alias(alias_kind.stable(tables), alias_ty.stable(tables)) } ty::Param(param_ty) => TyKind::Param(param_ty.stable(tables)), - ty::Bound(_, _) => todo!(), + ty::Bound(debruijn_idx, bound_ty) => { + TyKind::Bound(debruijn_idx.as_usize(), bound_ty.stable(tables)) + } ty::Placeholder(..) | ty::GeneratorWitness(_) | ty::GeneratorWitnessMIR(_, _) @@ -845,3 +847,11 @@ fn stable(&self, _: &mut Tables<'tcx>) -> Self::T { 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) } + } +} diff --git a/compiler/rustc_smir/src/stable_mir/ty.rs b/compiler/rustc_smir/src/stable_mir/ty.rs index 62dd02c1808..7a72afd666c 100644 --- a/compiler/rustc_smir/src/stable_mir/ty.rs +++ b/compiler/rustc_smir/src/stable_mir/ty.rs @@ -19,6 +19,7 @@ pub enum TyKind { RigidTy(RigidTy), Alias(AliasKind, AliasTy), Param(ParamTy), + Bound(usize, BoundTy), } #[derive(Clone, Debug)] @@ -235,3 +236,9 @@ pub struct ParamTy { pub index: u32, pub name: String, } + +#[derive(Clone, Debug)] +pub struct BoundTy { + pub var: usize, + pub kind: BoundTyKind, +}