Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Region for smir #116024

Merged
merged 13 commits into from
Sep 29, 2023
Prev Previous commit
Next Next commit
simplify fold
  • Loading branch information
ouz-a committed Sep 28, 2023
commit 8c41cd0d78caed65ebd2f057d5209fc564f9cc10
37 changes: 3 additions & 34 deletions compiler/stable_mir/src/fold.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use std::ops::ControlFlow;

use crate::{
ty::{self, BoundRegion, BoundRegionKind},
Opaque,
};
use crate::Opaque;

use super::ty::{
Allocation, Binder, Const, ConstDef, ConstantKind, ExistentialPredicate, FnSig, GenericArgKind,
Expand Down Expand Up @@ -116,36 +113,8 @@ impl Foldable for Region {
fn fold<V: Folder>(&self, folder: &mut V) -> ControlFlow<V::Break, Self> {
folder.fold_reg(self)
}
fn super_fold<V: Folder>(&self, folder: &mut V) -> ControlFlow<V::Break, Self> {
let mut kind = self.kind.clone();
match &mut kind {
crate::ty::RegionKind::ReEarlyBound(_) => {}
crate::ty::RegionKind::ReLateBound(_, bound_reg) => {
*bound_reg = bound_reg.fold(folder)?
}
crate::ty::RegionKind::ReStatic => {}
crate::ty::RegionKind::RePlaceholder(bound_reg) => {
bound_reg.bound = bound_reg.bound.fold(folder)?
}
crate::ty::RegionKind::ReErased => {}
}
ControlFlow::Continue(ty::Region { kind: kind }.into())
}
}

impl Foldable for BoundRegion {
fn super_fold<V: Folder>(&self, folder: &mut V) -> ControlFlow<V::Break, Self> {
ControlFlow::Continue(BoundRegion { var: self.var, kind: self.kind.fold(folder)? })
}
}

impl Foldable for BoundRegionKind {
fn super_fold<V: Folder>(&self, _folder: &mut V) -> ControlFlow<V::Break, Self> {
match self {
BoundRegionKind::BrAnon => ControlFlow::Continue(self.clone()),
BoundRegionKind::BrNamed(_, _) => ControlFlow::Continue(self.clone()),
BoundRegionKind::BrEnv => ControlFlow::Continue(self.clone()),
}
fn super_fold<V: Folder>(&self, _: &mut V) -> ControlFlow<V::Break, Self> {
ControlFlow::Continue(self.clone())
}
}

Expand Down