From c3332262fa0bdbb5ef14a110e162e1a9a69630ad Mon Sep 17 00:00:00 2001 From: Michal Piotrowski Date: Mon, 14 Oct 2024 15:37:59 +0200 Subject: [PATCH 1/3] Fix match_same_arms in stable_mir --- compiler/stable_mir/src/mir/pretty.rs | 12 ++++----- compiler/stable_mir/src/mir/visit.rs | 38 +++++++++++---------------- compiler/stable_mir/src/visitor.rs | 18 ++++++------- 3 files changed, 30 insertions(+), 38 deletions(-) diff --git a/compiler/stable_mir/src/mir/pretty.rs b/compiler/stable_mir/src/mir/pretty.rs index 74081af1d86d0..16a22f84a6290 100644 --- a/compiler/stable_mir/src/mir/pretty.rs +++ b/compiler/stable_mir/src/mir/pretty.rs @@ -189,7 +189,10 @@ fn pretty_terminator_head(writer: &mut W, terminator: &TerminatorKind) fn pretty_successor_labels(terminator: &TerminatorKind) -> Vec { use self::TerminatorKind::*; match terminator { - Resume | Abort | Return | Unreachable => vec![], + Call { target: None, unwind: UnwindAction::Cleanup(_), .. } + | InlineAsm { destination: None, .. } => vec!["unwind".into()], + Resume | Abort | Return | Unreachable + | Call { target: None, unwind: _, .. } => vec![], Goto { .. } => vec!["".to_string()], SwitchInt { targets, .. } => targets .branches() @@ -197,19 +200,16 @@ fn pretty_successor_labels(terminator: &TerminatorKind) -> Vec { .chain(iter::once("otherwise".into())) .collect(), Drop { unwind: UnwindAction::Cleanup(_), .. } => vec!["return".into(), "unwind".into()], - Drop { unwind: _, .. } => vec!["return".into()], Call { target: Some(_), unwind: UnwindAction::Cleanup(_), .. } => { vec!["return".into(), "unwind".into()] } - Call { target: Some(_), unwind: _, .. } => vec!["return".into()], - Call { target: None, unwind: UnwindAction::Cleanup(_), .. } => vec!["unwind".into()], - Call { target: None, unwind: _, .. } => vec![], + Drop { unwind: _, .. } + | Call { target: Some(_), unwind: _, .. } => vec!["return".into()], Assert { unwind: UnwindAction::Cleanup(_), .. } => { vec!["success".into(), "unwind".into()] } Assert { unwind: _, .. } => vec!["success".into()], InlineAsm { destination: Some(_), .. } => vec!["goto".into(), "unwind".into()], - InlineAsm { destination: None, .. } => vec!["unwind".into()], } } diff --git a/compiler/stable_mir/src/mir/visit.rs b/compiler/stable_mir/src/mir/visit.rs index e2d1ff7fdd3a4..cfc36d27e986a 100644 --- a/compiler/stable_mir/src/mir/visit.rs +++ b/compiler/stable_mir/src/mir/visit.rs @@ -194,27 +194,19 @@ pub trait MirVisitor { self.visit_place(place, PlaceContext::MUTATING, location); self.visit_rvalue(rvalue, location); } - StatementKind::FakeRead(_, place) => { + StatementKind::FakeRead(_, place) + | StatementKind::PlaceMention(place) => { self.visit_place(place, PlaceContext::NON_MUTATING, location); } - StatementKind::SetDiscriminant { place, .. } => { + StatementKind::SetDiscriminant { place, .. } + | StatementKind::Deinit(place) + | StatementKind::Retag(_, place) => { self.visit_place(place, PlaceContext::MUTATING, location); } - StatementKind::Deinit(place) => { - self.visit_place(place, PlaceContext::MUTATING, location); - } - StatementKind::StorageLive(local) => { + StatementKind::StorageLive(local) + | StatementKind::StorageDead(local) => { self.visit_local(local, PlaceContext::NON_USE, location); } - StatementKind::StorageDead(local) => { - self.visit_local(local, PlaceContext::NON_USE, location); - } - StatementKind::Retag(_, place) => { - self.visit_place(place, PlaceContext::MUTATING, location); - } - StatementKind::PlaceMention(place) => { - self.visit_place(place, PlaceContext::NON_MUTATING, location); - } StatementKind::AscribeUserType { place, projections, variance: _ } => { self.visit_place(place, PlaceContext::NON_USE, location); self.visit_user_type_projection(projections); @@ -234,8 +226,8 @@ pub trait MirVisitor { self.visit_operand(count, location); } }, - StatementKind::ConstEvalCounter => {} - StatementKind::Nop => {} + StatementKind::ConstEvalCounter + | StatementKind::Nop => {} } } @@ -304,14 +296,14 @@ pub trait MirVisitor { location: Location, ) { match elem { - ProjectionElem::Deref => {} + ProjectionElem::Downcast(_idx) => {} + ProjectionElem::ConstantIndex { offset: _, min_length: _, from_end: _ } + | ProjectionElem::Deref + | ProjectionElem::Subslice { from: _, to: _, from_end: _ } => {} ProjectionElem::Field(_idx, ty) => self.visit_ty(ty, location), ProjectionElem::Index(local) => self.visit_local(local, ptx, location), - ProjectionElem::ConstantIndex { offset: _, min_length: _, from_end: _ } => {} - ProjectionElem::Subslice { from: _, to: _, from_end: _ } => {} - ProjectionElem::Downcast(_idx) => {} - ProjectionElem::OpaqueCast(ty) => self.visit_ty(ty, location), - ProjectionElem::Subtype(ty) => self.visit_ty(ty, location), + ProjectionElem::OpaqueCast(ty) + | ProjectionElem::Subtype(ty) => self.visit_ty(ty, location), } } diff --git a/compiler/stable_mir/src/visitor.rs b/compiler/stable_mir/src/visitor.rs index 3c769b2d37cfc..4e9abac097c89 100644 --- a/compiler/stable_mir/src/visitor.rs +++ b/compiler/stable_mir/src/visitor.rs @@ -35,8 +35,8 @@ impl Visitable for Ty { match self.kind() { super::ty::TyKind::RigidTy(ty) => ty.visit(visitor)?, super::ty::TyKind::Alias(_, alias) => alias.args.visit(visitor)?, - super::ty::TyKind::Param(_) => {} - super::ty::TyKind::Bound(_, _) => {} + super::ty::TyKind::Param(_) + | super::ty::TyKind::Bound(_, _) => {} } ControlFlow::Continue(()) } @@ -48,8 +48,8 @@ impl Visitable for TyConst { } fn super_visit(&self, visitor: &mut V) -> ControlFlow { match &self.kind { - crate::ty::TyConstKind::Param(_) => {} - crate::ty::TyConstKind::Bound(_, _) => {} + crate::ty::TyConstKind::Param(_) + | crate::ty::TyConstKind::Bound(_, _) => {} crate::ty::TyConstKind::Unevaluated(_, args) => args.visit(visitor)?, crate::ty::TyConstKind::Value(ty, alloc) => { alloc.visit(visitor)?; @@ -166,17 +166,17 @@ impl Visitable for RigidTy { reg.visit(visitor); ty.visit(visitor) } - RigidTy::FnDef(_, args) => args.visit(visitor), + RigidTy::Adt(_, args) + | RigidTy::Closure(_, args) + | RigidTy::Coroutine(_, args, _) + | RigidTy::CoroutineWitness(_, args) + | RigidTy::FnDef(_, args) => args.visit(visitor), RigidTy::FnPtr(sig) => sig.visit(visitor), - RigidTy::Closure(_, args) => args.visit(visitor), - RigidTy::Coroutine(_, args, _) => args.visit(visitor), - RigidTy::CoroutineWitness(_, args) => args.visit(visitor), RigidTy::Dynamic(pred, r, _) => { pred.visit(visitor)?; r.visit(visitor) } RigidTy::Tuple(fields) => fields.visit(visitor), - RigidTy::Adt(_, args) => args.visit(visitor), } } } From ce4f7b5c0487db27ca1dcf56e94788dbd3105090 Mon Sep 17 00:00:00 2001 From: Michal Piotrowski Date: Mon, 14 Oct 2024 17:20:53 +0200 Subject: [PATCH 2/3] Fix match_same_arms in stable_mir - rustfmt --- compiler/stable_mir/src/mir/pretty.rs | 8 +++----- compiler/stable_mir/src/mir/visit.rs | 14 ++++++-------- compiler/stable_mir/src/visitor.rs | 8 +++----- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/compiler/stable_mir/src/mir/pretty.rs b/compiler/stable_mir/src/mir/pretty.rs index 16a22f84a6290..8a6237319a871 100644 --- a/compiler/stable_mir/src/mir/pretty.rs +++ b/compiler/stable_mir/src/mir/pretty.rs @@ -7,7 +7,7 @@ use fmt::{Display, Formatter}; use super::{AssertMessage, BinOp, BorrowKind, FakeBorrowKind, TerminatorKind}; use crate::mir::{Operand, Place, Rvalue, StatementKind, UnwindAction, VarDebugInfoContents}; use crate::ty::{IndexedVal, MirConst, Ty, TyConst}; -use crate::{Body, Mutability, with}; +use crate::{with, Body, Mutability}; impl Display for Ty { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { @@ -191,8 +191,7 @@ fn pretty_successor_labels(terminator: &TerminatorKind) -> Vec { match terminator { Call { target: None, unwind: UnwindAction::Cleanup(_), .. } | InlineAsm { destination: None, .. } => vec!["unwind".into()], - Resume | Abort | Return | Unreachable - | Call { target: None, unwind: _, .. } => vec![], + Resume | Abort | Return | Unreachable | Call { target: None, unwind: _, .. } => vec![], Goto { .. } => vec!["".to_string()], SwitchInt { targets, .. } => targets .branches() @@ -203,8 +202,7 @@ fn pretty_successor_labels(terminator: &TerminatorKind) -> Vec { Call { target: Some(_), unwind: UnwindAction::Cleanup(_), .. } => { vec!["return".into(), "unwind".into()] } - Drop { unwind: _, .. } - | Call { target: Some(_), unwind: _, .. } => vec!["return".into()], + Drop { unwind: _, .. } | Call { target: Some(_), unwind: _, .. } => vec!["return".into()], Assert { unwind: UnwindAction::Cleanup(_), .. } => { vec!["success".into(), "unwind".into()] } diff --git a/compiler/stable_mir/src/mir/visit.rs b/compiler/stable_mir/src/mir/visit.rs index cfc36d27e986a..08fcfa01a06c1 100644 --- a/compiler/stable_mir/src/mir/visit.rs +++ b/compiler/stable_mir/src/mir/visit.rs @@ -194,8 +194,7 @@ pub trait MirVisitor { self.visit_place(place, PlaceContext::MUTATING, location); self.visit_rvalue(rvalue, location); } - StatementKind::FakeRead(_, place) - | StatementKind::PlaceMention(place) => { + StatementKind::FakeRead(_, place) | StatementKind::PlaceMention(place) => { self.visit_place(place, PlaceContext::NON_MUTATING, location); } StatementKind::SetDiscriminant { place, .. } @@ -203,8 +202,7 @@ pub trait MirVisitor { | StatementKind::Retag(_, place) => { self.visit_place(place, PlaceContext::MUTATING, location); } - StatementKind::StorageLive(local) - | StatementKind::StorageDead(local) => { + StatementKind::StorageLive(local) | StatementKind::StorageDead(local) => { self.visit_local(local, PlaceContext::NON_USE, location); } StatementKind::AscribeUserType { place, projections, variance: _ } => { @@ -226,8 +224,7 @@ pub trait MirVisitor { self.visit_operand(count, location); } }, - StatementKind::ConstEvalCounter - | StatementKind::Nop => {} + StatementKind::ConstEvalCounter | StatementKind::Nop => {} } } @@ -302,8 +299,9 @@ pub trait MirVisitor { | ProjectionElem::Subslice { from: _, to: _, from_end: _ } => {} ProjectionElem::Field(_idx, ty) => self.visit_ty(ty, location), ProjectionElem::Index(local) => self.visit_local(local, ptx, location), - ProjectionElem::OpaqueCast(ty) - | ProjectionElem::Subtype(ty) => self.visit_ty(ty, location), + ProjectionElem::OpaqueCast(ty) | ProjectionElem::Subtype(ty) => { + self.visit_ty(ty, location) + } } } diff --git a/compiler/stable_mir/src/visitor.rs b/compiler/stable_mir/src/visitor.rs index 4e9abac097c89..53132f9ef1b05 100644 --- a/compiler/stable_mir/src/visitor.rs +++ b/compiler/stable_mir/src/visitor.rs @@ -4,8 +4,8 @@ use super::ty::{ Allocation, Binder, ConstDef, ExistentialPredicate, FnSig, GenericArgKind, GenericArgs, MirConst, Promoted, Region, RigidTy, TermKind, Ty, UnevaluatedConst, }; -use crate::Opaque; use crate::ty::TyConst; +use crate::Opaque; pub trait Visitor: Sized { type Break; @@ -35,8 +35,7 @@ impl Visitable for Ty { match self.kind() { super::ty::TyKind::RigidTy(ty) => ty.visit(visitor)?, super::ty::TyKind::Alias(_, alias) => alias.args.visit(visitor)?, - super::ty::TyKind::Param(_) - | super::ty::TyKind::Bound(_, _) => {} + super::ty::TyKind::Param(_) | super::ty::TyKind::Bound(_, _) => {} } ControlFlow::Continue(()) } @@ -48,8 +47,7 @@ impl Visitable for TyConst { } fn super_visit(&self, visitor: &mut V) -> ControlFlow { match &self.kind { - crate::ty::TyConstKind::Param(_) - | crate::ty::TyConstKind::Bound(_, _) => {} + crate::ty::TyConstKind::Param(_) | crate::ty::TyConstKind::Bound(_, _) => {} crate::ty::TyConstKind::Unevaluated(_, args) => args.visit(visitor)?, crate::ty::TyConstKind::Value(ty, alloc) => { alloc.visit(visitor)?; From 817c67a0b96996c385441484b17107cadd476f73 Mon Sep 17 00:00:00 2001 From: Michal Piotrowski Date: Mon, 14 Oct 2024 17:42:55 +0200 Subject: [PATCH 3/3] Fix match_same_arms in stable_mir - ./x.py fmt --- compiler/stable_mir/src/mir/pretty.rs | 2 +- compiler/stable_mir/src/visitor.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/stable_mir/src/mir/pretty.rs b/compiler/stable_mir/src/mir/pretty.rs index 8a6237319a871..d71d96804f3ea 100644 --- a/compiler/stable_mir/src/mir/pretty.rs +++ b/compiler/stable_mir/src/mir/pretty.rs @@ -7,7 +7,7 @@ use fmt::{Display, Formatter}; use super::{AssertMessage, BinOp, BorrowKind, FakeBorrowKind, TerminatorKind}; use crate::mir::{Operand, Place, Rvalue, StatementKind, UnwindAction, VarDebugInfoContents}; use crate::ty::{IndexedVal, MirConst, Ty, TyConst}; -use crate::{with, Body, Mutability}; +use crate::{Body, Mutability, with}; impl Display for Ty { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { diff --git a/compiler/stable_mir/src/visitor.rs b/compiler/stable_mir/src/visitor.rs index 53132f9ef1b05..48260285408c7 100644 --- a/compiler/stable_mir/src/visitor.rs +++ b/compiler/stable_mir/src/visitor.rs @@ -4,8 +4,8 @@ use super::ty::{ Allocation, Binder, ConstDef, ExistentialPredicate, FnSig, GenericArgKind, GenericArgs, MirConst, Promoted, Region, RigidTy, TermKind, Ty, UnevaluatedConst, }; -use crate::ty::TyConst; use crate::Opaque; +use crate::ty::TyConst; pub trait Visitor: Sized { type Break;