From fed72e06644db562c043f2f9cec99f2b2d9cba9d Mon Sep 17 00:00:00 2001 From: ouz-a Date: Thu, 28 Sep 2023 12:47:21 +0300 Subject: [PATCH] add visitor for Region --- compiler/stable_mir/src/visitor.rs | 37 ++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/compiler/stable_mir/src/visitor.rs b/compiler/stable_mir/src/visitor.rs index 8d5a25008d7..a26a1d8cfb9 100644 --- a/compiler/stable_mir/src/visitor.rs +++ b/compiler/stable_mir/src/visitor.rs @@ -1,6 +1,9 @@ use std::ops::ControlFlow; -use crate::Opaque; +use crate::{ + ty::{BoundRegion, BoundRegionKind}, + Opaque, +}; use super::ty::{ Allocation, Binder, Const, ConstDef, ExistentialPredicate, FnSig, GenericArgKind, GenericArgs, @@ -15,6 +18,9 @@ pub trait Visitor: Sized { fn visit_const(&mut self, c: &Const) -> ControlFlow { c.super_visit(self) } + fn visit_reg(&mut self, reg: &Region) -> ControlFlow { + reg.super_visit(self) + } } pub trait Visitable { @@ -102,11 +108,38 @@ impl Visitable for GenericArgs { } impl Visitable for Region { - fn super_visit(&self, _visitor: &mut V) -> ControlFlow { + fn visit(&self, visitor: &mut V) -> ControlFlow { + visitor.visit_reg(self) + } + + fn super_visit(&self, visitor: &mut V) -> ControlFlow { + match self.kind.clone() { + crate::ty::RegionKind::ReEarlyBound(_) => {} + crate::ty::RegionKind::ReLateBound(_, bound_reg) => bound_reg.visit(visitor)?, + crate::ty::RegionKind::ReStatic => {} + crate::ty::RegionKind::RePlaceholder(bound_reg) => bound_reg.bound.visit(visitor)?, + crate::ty::RegionKind::ReErased => {} + } ControlFlow::Continue(()) } } +impl Visitable for BoundRegion { + fn super_visit(&self, visitor: &mut V) -> ControlFlow { + self.kind.visit(visitor) + } +} + +impl Visitable for BoundRegionKind { + fn super_visit(&self, _visitor: &mut V) -> ControlFlow { + match self { + BoundRegionKind::BrAnon => ControlFlow::Continue(()), + BoundRegionKind::BrNamed(_, _) => ControlFlow::Continue(()), + BoundRegionKind::BrEnv => ControlFlow::Continue(()), + } + } +} + impl Visitable for GenericArgKind { fn super_visit(&self, visitor: &mut V) -> ControlFlow { match self {