Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
brockelmore committed Dec 10, 2023
1 parent fda559b commit 7a47c4f
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 31 deletions.
1 change: 0 additions & 1 deletion crates/graph/src/nodes/context/var/ranging.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::collections::BTreeSet;
use crate::{
nodes::{Concrete, ContextNode, ContextVarNode},
range::{range_string::ToRangeString, Range},
Expand Down
15 changes: 12 additions & 3 deletions crates/graph/src/range/elem/concrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@ impl RangeElem<Concrete> for RangeConcrete<Concrete> {
// Elem::Concrete(self.clone())
// }

fn has_cycle(&self, seen: &mut Vec<ContextVarNode>, analyzer: &impl GraphBackend) -> Result<bool, Self::GraphError> {
fn has_cycle(
&self,
_seen: &mut Vec<ContextVarNode>,
_analyzer: &impl GraphBackend,
) -> Result<bool, Self::GraphError> {
Ok(false)
}

fn flatten(
&self,
_maximize: bool,
Expand Down Expand Up @@ -158,5 +162,10 @@ impl RangeElem<Concrete> for RangeConcrete<Concrete> {
Ok(false)
}

fn recursive_dependent_on(&self, _: &impl GraphBackend) -> Result<Vec<ContextVarNode>, GraphError> { Ok(vec![]) }
fn recursive_dependent_on(
&self,
_: &impl GraphBackend,
) -> Result<Vec<ContextVarNode>, GraphError> {
Ok(vec![])
}
}
11 changes: 9 additions & 2 deletions crates/graph/src/range/elem/elem_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,10 @@ impl RangeElem<Concrete> for Elem<Concrete> {
}
}

fn recursive_dependent_on(&self, analyzer: &impl GraphBackend) -> Result<Vec<ContextVarNode>, GraphError> {
fn recursive_dependent_on(
&self,
analyzer: &impl GraphBackend,
) -> Result<Vec<ContextVarNode>, GraphError> {
match self {
Self::Reference(d) => d.recursive_dependent_on(analyzer),
Self::Concrete(_) => Ok(vec![]),
Expand All @@ -421,7 +424,11 @@ impl RangeElem<Concrete> for Elem<Concrete> {
}
}

fn has_cycle(&self, seen: &mut Vec<ContextVarNode>, analyzer: &impl GraphBackend) -> Result<bool, Self::GraphError> {
fn has_cycle(
&self,
seen: &mut Vec<ContextVarNode>,
analyzer: &impl GraphBackend,
) -> Result<bool, Self::GraphError> {
match self {
Self::Reference(d) => d.has_cycle(seen, analyzer),
Self::Concrete(_) => Ok(false),
Expand Down
11 changes: 9 additions & 2 deletions crates/graph/src/range/elem/elem_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,16 @@ pub trait RangeElem<T> {
/// and returns it in a vector.
fn dependent_on(&self) -> Vec<ContextVarNode>;

fn recursive_dependent_on(&self, analyzer: &impl GraphBackend) -> Result<Vec<ContextVarNode>, Self::GraphError>;
fn recursive_dependent_on(
&self,
analyzer: &impl GraphBackend,
) -> Result<Vec<ContextVarNode>, Self::GraphError>;

fn has_cycle(&self, seen: &mut Vec<ContextVarNode>, analyzer: &impl GraphBackend) -> Result<bool, Self::GraphError>;
fn has_cycle(
&self,
seen: &mut Vec<ContextVarNode>,
analyzer: &impl GraphBackend,
) -> Result<bool, Self::GraphError>;
/// Traverses the range expression and updates stale pointers from older versions
/// of a variable to a newer version.
///
Expand Down
11 changes: 9 additions & 2 deletions crates/graph/src/range/elem/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,20 @@ impl RangeElem<Concrete> for RangeExpr<Concrete> {
deps
}

fn recursive_dependent_on(&self, analyzer: &impl GraphBackend) -> Result<Vec<ContextVarNode>, GraphError> {
fn recursive_dependent_on(
&self,
analyzer: &impl GraphBackend,
) -> Result<Vec<ContextVarNode>, 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<ContextVarNode>, analyzer: &impl GraphBackend) -> Result<bool, GraphError> {
fn has_cycle(
&self,
seen: &mut Vec<ContextVarNode>,
analyzer: &impl GraphBackend,
) -> Result<bool, GraphError> {
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)
Expand Down
25 changes: 15 additions & 10 deletions crates/graph/src/range/elem/map_or_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ impl RangeElem<Concrete> for RangeDyn<Concrete> {
deps
}

fn recursive_dependent_on(&self, analyzer: &impl GraphBackend) -> Result<Vec<ContextVarNode>, GraphError> {
fn recursive_dependent_on(
&self,
analyzer: &impl GraphBackend,
) -> Result<Vec<ContextVarNode>, GraphError> {
let mut deps: Vec<ContextVarNode> = self.len.recursive_dependent_on(analyzer)?;
deps.extend(
self.val
Expand All @@ -68,7 +71,7 @@ impl RangeElem<Concrete> for RangeDyn<Concrete> {
.collect::<Result<Vec<Vec<_>>, _>>()?
.iter()
.flatten()
.collect::<Vec<_>>()
.collect::<Vec<_>>(),
);
deps.extend(
self.val
Expand All @@ -77,20 +80,22 @@ impl RangeElem<Concrete> for RangeDyn<Concrete> {
.collect::<Result<Vec<Vec<_>>, _>>()?
.iter()
.flatten()
.collect::<Vec<_>>()
.collect::<Vec<_>>(),
);
Ok(deps)
}

fn has_cycle(&self, seen: &mut Vec<ContextVarNode>, analyzer: &impl GraphBackend) -> Result<bool, GraphError> {
fn has_cycle(
&self,
seen: &mut Vec<ContextVarNode>,
analyzer: &impl GraphBackend,
) -> Result<bool, GraphError> {
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)
}

Expand Down
13 changes: 10 additions & 3 deletions crates/graph/src/range/elem/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,21 @@ impl RangeElem<Concrete> for Reference<Concrete> {
fn dependent_on(&self) -> Vec<ContextVarNode> {
vec![self.idx.into()]
}

fn recursive_dependent_on(&self, analyzer: &impl GraphBackend) -> Result<Vec<ContextVarNode>, GraphError> {

fn recursive_dependent_on(
&self,
analyzer: &impl GraphBackend,
) -> Result<Vec<ContextVarNode>, 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<ContextVarNode>, analyzer: &impl GraphBackend) -> Result<bool, GraphError> {
fn has_cycle(
&self,
seen: &mut Vec<ContextVarNode>,
analyzer: &impl GraphBackend,
) -> Result<bool, GraphError> {
let cvar = ContextVarNode::from(self.idx);
let mut has_cycle = false;
if seen.contains(&cvar) {
Expand Down
5 changes: 4 additions & 1 deletion crates/graph/src/range/solc_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ impl SolcRange {
deps.into_iter().map(ContextVarNode::from).collect()
}

pub fn recursive_dependent_on(&self, analyzer: &impl GraphBackend,) -> Result<Vec<ContextVarNode>, GraphError> {
pub fn recursive_dependent_on(
&self,
analyzer: &impl GraphBackend,
) -> Result<Vec<ContextVarNode>, GraphError> {
let mut deps = self.range_min().recursive_dependent_on(analyzer)?;
deps.extend(self.range_max().recursive_dependent_on(analyzer)?);
deps.dedup();
Expand Down
8 changes: 6 additions & 2 deletions crates/solc-expressions/src/bin_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ pub trait BinOp: AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + 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 {
Expand Down Expand Up @@ -666,7 +667,10 @@ pub trait BinOp: AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + 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.
Expand Down
15 changes: 10 additions & 5 deletions crates/solc-expressions/src/require.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -1309,17 +1308,23 @@ 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)?;
if let Some(Ordering::Less) = max.range_ord(&min) {
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)?;
Expand Down

0 comments on commit 7a47c4f

Please sign in to comment.