Skip to content

Commit

Permalink
add stable for RegionKind
Browse files Browse the repository at this point in the history
  • Loading branch information
ouz-a committed Sep 21, 2023
1 parent e534b64 commit 1e2bde6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
37 changes: 26 additions & 11 deletions compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1508,29 +1509,43 @@ 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) }
}
}

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(()),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_smir/src/stable_mir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct Const {

type Ident = Opaque;
pub(crate) struct Region {
kind: RegionKind,
pub kind: RegionKind,
}

pub enum RegionKind {
Expand Down

0 comments on commit 1e2bde6

Please sign in to comment.