Skip to content

Commit

Permalink
make reg public and add visit, fold
Browse files Browse the repository at this point in the history
  • Loading branch information
ouz-a committed Sep 21, 2023
1 parent 1e2bde6 commit db3cdb6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
8 changes: 7 additions & 1 deletion compiler/rustc_smir/src/stable_mir/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::rustc_internal::Opaque;

use super::ty::{
Allocation, Binder, Const, ConstDef, ConstantKind, ExistentialPredicate, FnSig, GenericArgKind,
GenericArgs, Promoted, RigidTy, TermKind, Ty, TyKind, UnevaluatedConst,
GenericArgs, Promoted, Region, RigidTy, TermKind, Ty, TyKind, UnevaluatedConst,
};

pub trait Folder: Sized {
Expand Down Expand Up @@ -106,6 +106,12 @@ impl Foldable for GenericArgs {
}
}

impl Foldable for Region {
fn super_fold<V: Folder>(&self, _folder: &mut V) -> ControlFlow<V::Break, Self> {
ControlFlow::Continue(self.clone())
}
}

impl Foldable for GenericArgKind {
fn super_fold<V: Folder>(&self, folder: &mut V) -> ControlFlow<V::Break, Self> {
let mut this = self.clone();
Expand Down
9 changes: 8 additions & 1 deletion compiler/rustc_smir/src/stable_mir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ pub struct Const {
}

type Ident = Opaque;
pub(crate) struct Region {

#[derive(Debug, Clone)]
pub struct Region {
pub kind: RegionKind,
}

#[derive(Debug, Clone)]
pub enum RegionKind {
ReEarlyBound(EarlyBoundRegion),
ReLateBound(DebruijnIndex, BoundRegion),
Expand All @@ -51,6 +54,7 @@ pub enum RegionKind {

pub(crate) type DebruijnIndex = u32;

#[derive(Debug, Clone)]
pub struct EarlyBoundRegion {
pub def_id: RegionDef,
pub index: u32,
Expand All @@ -59,11 +63,13 @@ pub struct EarlyBoundRegion {

pub(crate) type BoundVar = u32;

#[derive(Debug, Clone)]
pub struct BoundRegion {
pub var: BoundVar,
pub kind: BoundRegionKind,
}

#[derive(Debug, Clone)]
pub struct FreeRegion {
pub scope: RegionDef,
pub bound_region: BoundRegionKind,
Expand All @@ -73,6 +79,7 @@ pub(crate) type RegionVid = u32;

pub(crate) type UniverseIndex = u32;

#[derive(Debug, Clone)]
pub struct Placeholder<T> {
pub universe: UniverseIndex,
pub bound: T,
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_smir/src/stable_mir/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::rustc_internal::Opaque;

use super::ty::{
Allocation, Binder, Const, ConstDef, ExistentialPredicate, FnSig, GenericArgKind, GenericArgs,
Promoted, RigidTy, TermKind, Ty, UnevaluatedConst,
Promoted, Region, RigidTy, TermKind, Ty, UnevaluatedConst,
};

pub trait Visitor: Sized {
Expand Down Expand Up @@ -101,6 +101,12 @@ impl Visitable for GenericArgs {
}
}

impl Visitable for Region {
fn super_visit<V: Visitor>(&self, _visitor: &mut V) -> ControlFlow<V::Break> {
ControlFlow::Continue(())
}
}

impl Visitable for GenericArgKind {
fn super_visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
match self {
Expand Down

0 comments on commit db3cdb6

Please sign in to comment.