diff --git a/crates/graph/src/nodes/context/var/ranging.rs b/crates/graph/src/nodes/context/var/ranging.rs index 16ba76d5..7012111f 100644 --- a/crates/graph/src/nodes/context/var/ranging.rs +++ b/crates/graph/src/nodes/context/var/ranging.rs @@ -1,4 +1,3 @@ -use std::collections::BTreeSet; use crate::{ nodes::{Concrete, ContextNode, ContextVarNode}, range::{range_string::ToRangeString, Range}, diff --git a/crates/graph/src/range/elem/concrete.rs b/crates/graph/src/range/elem/concrete.rs index d264ee6a..da84e397 100644 --- a/crates/graph/src/range/elem/concrete.rs +++ b/crates/graph/src/range/elem/concrete.rs @@ -32,10 +32,14 @@ impl RangeElem for RangeConcrete { // Elem::Concrete(self.clone()) // } - fn has_cycle(&self, seen: &mut Vec, analyzer: &impl GraphBackend) -> Result { + fn has_cycle( + &self, + _seen: &mut Vec, + _analyzer: &impl GraphBackend, + ) -> Result { Ok(false) } - + fn flatten( &self, _maximize: bool, @@ -158,5 +162,10 @@ impl RangeElem for RangeConcrete { Ok(false) } - fn recursive_dependent_on(&self, _: &impl GraphBackend) -> Result, GraphError> { Ok(vec![]) } + fn recursive_dependent_on( + &self, + _: &impl GraphBackend, + ) -> Result, GraphError> { + Ok(vec![]) + } } diff --git a/crates/graph/src/range/elem/elem_enum.rs b/crates/graph/src/range/elem/elem_enum.rs index 9bf8cdf2..39315503 100644 --- a/crates/graph/src/range/elem/elem_enum.rs +++ b/crates/graph/src/range/elem/elem_enum.rs @@ -411,7 +411,10 @@ impl RangeElem for Elem { } } - fn recursive_dependent_on(&self, analyzer: &impl GraphBackend) -> Result, GraphError> { + fn recursive_dependent_on( + &self, + analyzer: &impl GraphBackend, + ) -> Result, GraphError> { match self { Self::Reference(d) => d.recursive_dependent_on(analyzer), Self::Concrete(_) => Ok(vec![]), @@ -421,7 +424,11 @@ impl RangeElem for Elem { } } - fn has_cycle(&self, seen: &mut Vec, analyzer: &impl GraphBackend) -> Result { + fn has_cycle( + &self, + seen: &mut Vec, + analyzer: &impl GraphBackend, + ) -> Result { match self { Self::Reference(d) => d.has_cycle(seen, analyzer), Self::Concrete(_) => Ok(false), diff --git a/crates/graph/src/range/elem/elem_trait.rs b/crates/graph/src/range/elem/elem_trait.rs index c01eaffc..8231d603 100644 --- a/crates/graph/src/range/elem/elem_trait.rs +++ b/crates/graph/src/range/elem/elem_trait.rs @@ -53,9 +53,16 @@ pub trait RangeElem { /// and returns it in a vector. fn dependent_on(&self) -> Vec; - fn recursive_dependent_on(&self, analyzer: &impl GraphBackend) -> Result, Self::GraphError>; + fn recursive_dependent_on( + &self, + analyzer: &impl GraphBackend, + ) -> Result, Self::GraphError>; - fn has_cycle(&self, seen: &mut Vec, analyzer: &impl GraphBackend) -> Result; + fn has_cycle( + &self, + seen: &mut Vec, + analyzer: &impl GraphBackend, + ) -> Result; /// Traverses the range expression and updates stale pointers from older versions /// of a variable to a newer version. /// diff --git a/crates/graph/src/range/elem/expr.rs b/crates/graph/src/range/elem/expr.rs index 40e3030d..2193ceb5 100644 --- a/crates/graph/src/range/elem/expr.rs +++ b/crates/graph/src/range/elem/expr.rs @@ -117,13 +117,20 @@ impl RangeElem for RangeExpr { deps } - fn recursive_dependent_on(&self, analyzer: &impl GraphBackend) -> Result, GraphError> { + fn recursive_dependent_on( + &self, + analyzer: &impl GraphBackend, + ) -> Result, GraphError> { let mut deps = self.lhs.recursive_dependent_on(analyzer)?; deps.extend(self.rhs.recursive_dependent_on(analyzer)?); Ok(deps) } - fn has_cycle(&self, seen: &mut Vec, analyzer: &impl GraphBackend) -> Result { + fn has_cycle( + &self, + seen: &mut Vec, + analyzer: &impl GraphBackend, + ) -> Result { let lhs_has_cycle = self.lhs.has_cycle(seen, analyzer)?; let rhs_has_cycle = self.rhs.has_cycle(seen, analyzer)?; Ok(lhs_has_cycle || rhs_has_cycle) diff --git a/crates/graph/src/range/elem/map_or_array.rs b/crates/graph/src/range/elem/map_or_array.rs index 96996ad3..4dcc397d 100644 --- a/crates/graph/src/range/elem/map_or_array.rs +++ b/crates/graph/src/range/elem/map_or_array.rs @@ -59,7 +59,10 @@ impl RangeElem for RangeDyn { deps } - fn recursive_dependent_on(&self, analyzer: &impl GraphBackend) -> Result, GraphError> { + fn recursive_dependent_on( + &self, + analyzer: &impl GraphBackend, + ) -> Result, GraphError> { let mut deps: Vec = self.len.recursive_dependent_on(analyzer)?; deps.extend( self.val @@ -68,7 +71,7 @@ impl RangeElem for RangeDyn { .collect::>, _>>()? .iter() .flatten() - .collect::>() + .collect::>(), ); deps.extend( self.val @@ -77,20 +80,22 @@ impl RangeElem for RangeDyn { .collect::>, _>>()? .iter() .flatten() - .collect::>() + .collect::>(), ); Ok(deps) } - fn has_cycle(&self, seen: &mut Vec, analyzer: &impl GraphBackend) -> Result { + fn has_cycle( + &self, + seen: &mut Vec, + analyzer: &impl GraphBackend, + ) -> Result { let mut has_cycle = false; has_cycle = has_cycle || self.len.has_cycle(seen, analyzer)?; - self.val - .iter() - .try_for_each(|(_, val)| { - has_cycle = has_cycle || val.has_cycle(seen, analyzer)?; - Ok(()) - })?; + self.val.iter().try_for_each(|(_, val)| { + has_cycle = has_cycle || val.has_cycle(seen, analyzer)?; + Ok(()) + })?; Ok(has_cycle) } diff --git a/crates/graph/src/range/elem/reference.rs b/crates/graph/src/range/elem/reference.rs index beb15b7c..0b9fd386 100644 --- a/crates/graph/src/range/elem/reference.rs +++ b/crates/graph/src/range/elem/reference.rs @@ -52,14 +52,21 @@ impl RangeElem for Reference { fn dependent_on(&self) -> Vec { vec![self.idx.into()] } - - fn recursive_dependent_on(&self, analyzer: &impl GraphBackend) -> Result, GraphError> { + + fn recursive_dependent_on( + &self, + analyzer: &impl GraphBackend, + ) -> Result, GraphError> { let mut deps = ContextVarNode(self.idx.index()).dependent_on(analyzer, true)?; deps.push(ContextVarNode(self.idx.index())); Ok(deps) } - fn has_cycle(&self, seen: &mut Vec, analyzer: &impl GraphBackend) -> Result { + fn has_cycle( + &self, + seen: &mut Vec, + analyzer: &impl GraphBackend, + ) -> Result { let cvar = ContextVarNode::from(self.idx); let mut has_cycle = false; if seen.contains(&cvar) { diff --git a/crates/graph/src/range/solc_range.rs b/crates/graph/src/range/solc_range.rs index a981154f..52bd46b5 100644 --- a/crates/graph/src/range/solc_range.rs +++ b/crates/graph/src/range/solc_range.rs @@ -67,7 +67,10 @@ impl SolcRange { deps.into_iter().map(ContextVarNode::from).collect() } - pub fn recursive_dependent_on(&self, analyzer: &impl GraphBackend,) -> Result, GraphError> { + pub fn recursive_dependent_on( + &self, + analyzer: &impl GraphBackend, + ) -> Result, GraphError> { let mut deps = self.range_min().recursive_dependent_on(analyzer)?; deps.extend(self.range_max().recursive_dependent_on(analyzer)?); deps.dedup(); diff --git a/crates/solc-expressions/src/bin_op.rs b/crates/solc-expressions/src/bin_op.rs index c3bba13a..712cfe7b 100644 --- a/crates/solc-expressions/src/bin_op.rs +++ b/crates/solc-expressions/src/bin_op.rs @@ -158,7 +158,8 @@ pub trait BinOp: AnalyzerBackend + Sized { let new_lhs = if assign { let new = self.advance_var_in_ctx_forcible(lhs_cvar, loc, ctx, true)?; - new.underlying_mut(self).into_expr_err(loc)?.tmp_of = Some(TmpConstruction::new(lhs_cvar, op, Some(rhs_cvar))); + new.underlying_mut(self).into_expr_err(loc)?.tmp_of = + Some(TmpConstruction::new(lhs_cvar, op, Some(rhs_cvar))); new } else { let mut new_lhs_underlying = ContextVar { @@ -666,7 +667,10 @@ pub trait BinOp: AnalyzerBackend + Sized { .latest_version(self) .set_range_min(self, expr.clone()) .into_expr_err(loc)?; - new_lhs.latest_version(self).set_range_max(self, expr).into_expr_err(loc)?; + new_lhs + .latest_version(self) + .set_range_max(self, expr) + .into_expr_err(loc)?; // last ditch effort to prevent exponentiation from having a minimum of 1 instead of 0. // if the lhs is 0 check if the rhs is also 0, otherwise set minimum to 0. diff --git a/crates/solc-expressions/src/require.rs b/crates/solc-expressions/src/require.rs index 0f3ff47b..d27908ef 100644 --- a/crates/solc-expressions/src/require.rs +++ b/crates/solc-expressions/src/require.rs @@ -942,7 +942,6 @@ pub trait Require: AnalyzerBackend + Variable + BinOp + Sized { ctx.add_ctx_dep(cvar, self).into_expr_err(loc)?; } - tracing::trace!( "{} is tmp: {}", new_lhs.display_name(self).unwrap(), @@ -1309,8 +1308,6 @@ pub trait Require: AnalyzerBackend + Variable + BinOp + Sized { let rhs_elem = Elem::from(new_rhs.latest_version(self)); let lhs_elem = Elem::from(new_lhs.latest_version(self)); - - // if lhs.max is < rhs.min, we can't make this true let max = lhs_range.evaled_range_max(self).into_expr_err(loc)?; let min = rhs_elem.minimize(self).into_expr_err(loc)?; @@ -1318,8 +1315,16 @@ pub trait Require: AnalyzerBackend + Variable + BinOp + Sized { return Ok(true); } - let new_min = Elem::Expr(RangeExpr::new(new_lhs.latest_version(self).into(), RangeOp::Max, rhs_elem)); - let new_max = Elem::Expr(RangeExpr::new(new_rhs.latest_version(self).into(), RangeOp::Min, lhs_elem)); + let new_min = Elem::Expr(RangeExpr::new( + new_lhs.latest_version(self).into(), + RangeOp::Max, + rhs_elem, + )); + let new_max = Elem::Expr(RangeExpr::new( + new_rhs.latest_version(self).into(), + RangeOp::Min, + lhs_elem, + )); let new_new_lhs = self.advance_var_in_curr_ctx(new_lhs, loc)?; let new_new_rhs = self.advance_var_in_curr_ctx(new_rhs, loc)?;