From 5dc2214884483496ef8cf4a8fa7f1be189669974 Mon Sep 17 00:00:00 2001 From: ouz-a Date: Thu, 21 Sep 2023 12:12:06 +0300 Subject: [PATCH] add stable for RegionKind --- compiler/rustc_smir/src/rustc_smir/mod.rs | 37 ++++++++++++++++------- compiler/stable_mir/src/ty.rs | 2 +- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index 890faa4538e..73a4798527d 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -10,7 +10,8 @@ use crate::rustc_internal::{self, opaque}; use crate::stable_mir::mir::{CopyNonOverlapping, UserTypeProjection, VariantIdx}; use crate::stable_mir::ty::{ - EarlyBoundRegion, FloatTy, GenericParamDef, IntTy, Movability, RigidTy, Span, TyKind, UintTy, + BoundRegion, EarlyBoundRegion, FloatTy, FreeRegion, GenericParamDef, IntTy, Movability, Region, + RigidTy, Span, TyKind, UintTy, }; use crate::stable_mir::{self, CompilerError, Context}; use rustc_hir as hir; @@ -1505,9 +1506,8 @@ impl<'tcx> Stable<'tcx> for ty::ImplPolarity { impl<'tcx> Stable<'tcx> for ty::Region<'tcx> { type T = stable_mir::ty::Region; - fn stable(&self, _: &mut Tables<'tcx>) -> Self::T { - // FIXME: add a real implementation of stable regions - opaque(self) + fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T { + Region { kind: self.kind().stable(tables) } } } @@ -1515,19 +1515,34 @@ impl<'tcx> Stable<'tcx> for ty::RegionKind<'tcx> { type T = stable_mir::ty::RegionKind; fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T { + use crate::stable_mir::ty::RegionKind; match self { ty::ReEarlyBound(early_reg) => RegionKind::ReEarlyBound(EarlyBoundRegion { def_id: tables.region_def(early_reg.def_id), index: early_reg.index, name: early_reg.name.to_string(), }), - ty::ReLateBound(_, _) => todo!(), - ty::ReFree(_) => todo!(), - ty::ReStatic => todo!(), - ty::ReVar(_) => todo!(), - ty::RePlaceholder(_) => todo!(), - ty::ReErased => todo!(), - ty::ReError(_) => todo!(), + ty::ReLateBound(db_index, bound_reg) => RegionKind::ReLateBound( + db_index.as_u32(), + BoundRegion { var: bound_reg.var.as_u32(), kind: bound_reg.kind.stable(tables) }, + ), + ty::ReFree(free_reg) => RegionKind::ReFree(FreeRegion { + scope: tables.region_def(free_reg.scope), + bound_region: free_reg.bound_region.stable(tables), + }), + ty::ReStatic => RegionKind::ReStatic, + ty::ReVar(vid_reg) => RegionKind::ReVar(vid_reg.as_u32()), + ty::RePlaceholder(place_holder) => { + RegionKind::RePlaceholder(stable_mir::ty::Placeholder { + universe: place_holder.universe.as_u32(), + bound: BoundRegion { + var: place_holder.bound.var.as_u32(), + kind: place_holder.bound.kind.stable(tables), + }, + }) + } + ty::ReErased => RegionKind::ReErased, + ty::ReError(_) => RegionKind::ReError(()), } } } diff --git a/compiler/stable_mir/src/ty.rs b/compiler/stable_mir/src/ty.rs index f6f433c2bad..a47621337f0 100644 --- a/compiler/stable_mir/src/ty.rs +++ b/compiler/stable_mir/src/ty.rs @@ -35,7 +35,7 @@ pub struct Const { type Ident = Opaque; pub(crate) struct Region { - kind: RegionKind, + pub kind: RegionKind, } pub enum RegionKind {