Skip to content

Commit

Permalink
Fix clippy warnings across pyrometer (#81)
Browse files Browse the repository at this point in the history
* fix: use correct vars for sub gte

* clippy

* more clippy

* lints

* remove nulls
  • Loading branch information
plotchy authored Jun 28, 2024
1 parent 05e381b commit ed8044b
Show file tree
Hide file tree
Showing 35 changed files with 103 additions and 130 deletions.
40 changes: 18 additions & 22 deletions crates/analyzers/src/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,29 +86,25 @@ impl OrderedAnalysis {
set.insert(init.into());
analyses.insert(source, set);
}
ba.bound_changes
.iter()
.enumerate()
.for_each(|(_i, bound_change)| {
let (parts, unsat) =
range_parts(analyzer, arena, &ba.report_config, &bound_change.1);
let item = StrippedAnalysisItem {
init: false,
name: ba.var_display_name.clone(),
loc: LocSpan(bound_change.0 .1),
order: (bound_change.0.end() - bound_change.0.start()) as i32, //i as i32,
// storage: ba.storage.clone(),
ctx: ba.ctx,
ctx_conditionals: ba.conditionals(analyzer, arena),
parts,
unsat,
};
ba.bound_changes.iter().for_each(|bound_change| {
let (parts, unsat) = range_parts(analyzer, arena, &ba.report_config, &bound_change.1);
let item = StrippedAnalysisItem {
init: false,
name: ba.var_display_name.clone(),
loc: LocSpan(bound_change.0 .1),
order: (bound_change.0.end() - bound_change.0.start()) as i32, //i as i32,
// storage: ba.storage.clone(),
ctx: ba.ctx,
ctx_conditionals: ba.conditionals(analyzer, arena),
parts,
unsat,
};

let entry = analyses
.entry(*LocSpan(bound_change.0 .1).source())
.or_default();
entry.insert(item);
});
let entry = analyses
.entry(*LocSpan(bound_change.0 .1).source())
.or_default();
entry.insert(item);
});
Self { analyses }
}

Expand Down
3 changes: 1 addition & 2 deletions crates/analyzers/src/var_analyzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ impl VarBoundAnalysis {
.collect::<BTreeMap<_, _>>();
// create the bound strings
deps.iter()
.enumerate()
.filter_map(|(_i, (_name, cvar))| {
.filter_map(|(_name, cvar)| {
let range = cvar.ref_range(analyzer).unwrap()?;
let parts = range_parts(analyzer, arena, &self.report_config, &range).0;
Some((cvar.display_name(analyzer).unwrap(), parts))
Expand Down
3 changes: 1 addition & 2 deletions crates/analyzers/src/var_analyzer/report_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ impl ReportDisplay for VarBoundAnalysis {
labels.extend(
self.bound_changes
.iter()
.enumerate()
.map(|(_i, bound_change)| {
.map(|bound_change| {
let (parts, unsat) =
range_parts(analyzer, arena, &self.report_config, &bound_change.1);
AnalysisItem {
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use shared::{GraphDot, USE_DEBUG_SITE};
use ariadne::sources;
use clap::{ArgAction, Parser, ValueHint};

use tracing::{debug, error, info, trace, warn};
use tracing::{error, trace};
use tracing_subscriber::{prelude::*, Registry};

use std::{
Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/context/versioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ impl ContextNode {
Some(CallFork::Call(call)) => format!("call {{ {} }}", call.path(analyzer)),
None => unreachable!(),
};
Err(GraphError::ChildRedefinition(panic!(
Err(GraphError::ChildRedefinition(format!(
"This is a bug. Tried to redefine a child context, parent:\n{}, current child:\n{},\nnew child: Fork({}, {})",
self.path(analyzer),
child_str,
Expand Down Expand Up @@ -388,7 +388,7 @@ impl ContextNode {
None => unreachable!(),
};
tracing::trace!("Error setting child as a call");
Err(GraphError::ChildRedefinition(panic!(
Err(GraphError::ChildRedefinition(format!(
"This is a bug. Tried to redefine a child context, parent: {}, current child: {}, new child: {}",
self.path(analyzer),
child_str,
Expand Down
9 changes: 1 addition & 8 deletions crates/graph/src/range/elem/elem_enum/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl RangeArenaLike<Elem<Concrete>> for RangeArena<Elem<Concrete>> {
}
_ => format!("{elem}"),
}
};
}

format!("{i}: {}", fmt(elem, analyzer))
})
Expand Down Expand Up @@ -125,13 +125,6 @@ impl RangeArenaLike<Elem<Concrete>> for RangeArena<Elem<Concrete>> {
self.map.insert(Elem::Null, 0);
}

let nulls = self.ranges.iter().fold(0, |mut acc, e| {
if matches!(e, Elem::Null) {
acc += 1;
}
acc
});

// println!(
// "{}\nhad cycle:\n{:?}",
// self.debug_str(analyzer),
Expand Down
9 changes: 3 additions & 6 deletions crates/graph/src/range/elem/elem_enum/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,14 @@ impl Elem<Concrete> {
Elem::Reference(reference) => {
format!("Ref-CVar{}", reference.idx.index())
}
Elem::ConcreteDyn(range_dyn) => {
Elem::ConcreteDyn(_range_dyn) => {
format!("concdyn-{}", self)
}
Elem::Concrete(range_concrete) => {
Elem::Concrete(_range_concrete) => {
format!("conc-{}", self)
}
Elem::Expr(range_expr) => {
Elem::Expr(_range_expr) => {
// Unbox and check the lhs and rhs to see if they are arena indices
let lhs_str = range_expr.lhs.arena_graph_node_label();
let rhs_str = range_expr.rhs.arena_graph_node_label();
let op = range_expr.op.clone();
format!("expr-{}", &self)
}
Elem::Arena(arena_idx) => {
Expand Down
1 change: 1 addition & 0 deletions crates/graph/src/range/elem/expr/simplify/ords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct Ords {
pub x_ord_one: Option<std::cmp::Ordering>,
}

#[allow(dead_code)]
impl Ords {
pub fn new(
x: &Elem<Concrete>,
Expand Down
2 changes: 1 addition & 1 deletion crates/graph/src/range/elem/expr/simplify/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub fn sub_ord_rules(
let rhs = x_lte_z && y_gt_zero;
let false_cond = lhs || rhs;

if x_lte_z && y_gte_zero {
if x_gte_z && y_lte_zero {
Some(Elem::from(true))
} else if false_cond {
Some(Elem::from(false))
Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/range/elem/map_or_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ impl RangeElem<Concrete> for RangeDyn<Concrete> {
.map(|(k, (v, op))| {
let mut new_k = k.clone();
let mut new_v = v.clone();
new_k.arenaize(analyzer, arena);
new_v.arenaize(analyzer, arena);
let _ = new_k.arenaize(analyzer, arena);
let _ = new_v.arenaize(analyzer, arena);
(new_k, (new_v, *op))
})
.collect();
Expand Down
2 changes: 1 addition & 1 deletion crates/graph/src/range/exec/math_ops/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub fn exec_sub(
rhs_max: &Elem<Concrete>,
maximize: bool,
wrapping: bool,
analyzer: &impl GraphBackend,
_analyzer: &impl GraphBackend,
arena: &mut RangeArena<Elem<Concrete>>,
) -> Option<Elem<Concrete>> {
// quick check if rhs is const and zero, if so return min or max
Expand Down
5 changes: 1 addition & 4 deletions crates/graph/src/solvers/dl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,7 @@ impl DLSolver {
})
.collect::<Option<BTreeMap<SolverAtom, Vec<Vec<SolverAtom>>>>>();
// println!("normalized map: {res:#?}");
match res {
Some(t) => t,
None => Default::default(),
}
res.unwrap_or_default()
}

pub fn dl_solvable_constraints(&self) -> Vec<Vec<Vec<SolverAtom>>> {
Expand Down
3 changes: 1 addition & 2 deletions crates/pyrometer/src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ use graph::elem::Elem;
use graph::{nodes::*, ContextEdge, Edge, Node, VarType};
use reqwest::Client;
use serde::{Deserialize, Serialize};
use shared::GraphDot;
use shared::{AnalyzerLike, GraphLike, JoinStats, NodeIdx, Search};
use shared::{RangeArena, USE_DEBUG_SITE};
use solc_expressions::{ExprErr, FnCallBuilder, IntoExprErr, StatementParser};
use tokio::runtime::Runtime;
use tracing::{debug, error, info, trace, warn};
use tracing::{error, trace, warn};

use ahash::AHashMap;
use ariadne::{Cache, Color, Config, Fmt, Label, Report, ReportKind, Source, Span};
Expand Down
60 changes: 26 additions & 34 deletions crates/pyrometer/src/graph_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl TryFrom<&RangeArena<Elem<Concrete>>> for Elems {
let mut inner = Vec::new();
for elem in &arena.ranges {
// Get the map value
if let Some(map_value) = arena.map.get(&elem).copied() {
if let Some(map_value) = arena.map.get(elem).copied() {
// println!("Adding idx {} to elems {}", map_value, elem);
inner.push((map_value, elem.clone()));
} else {
Expand Down Expand Up @@ -287,11 +287,10 @@ impl Elems {
existing_node_idx
} else {
// make a new ContextVar Node for the Arena graph
let new_node_idx = graph.add_node(ArenaNode::CVAR(format!(
"{}",
dep_elem.as_dot_str(graph_backend, arena)
)));
dependency_map.insert(dep_elem.clone(), new_node_idx);
let new_node_idx = graph.add_node(ArenaNode::CVAR(
dep_elem.as_dot_str(graph_backend, arena).to_string(),
));
dependency_map.insert(dep_elem, new_node_idx);
new_node_idx
};
// add an edge from the node to its dependency node
Expand All @@ -302,13 +301,13 @@ impl Elems {
}
Elem::ConcreteDyn(_range_dyn) => {
let node_str = elem.arena_graph_node_label();
let node_idx = graph.add_node(ArenaNode::ELEM(node_str));
node_idx

graph.add_node(ArenaNode::ELEM(node_str))
}
Elem::Concrete(_range_concrete) => {
let node_str = elem.arena_graph_node_label();
let node_idx = graph.add_node(ArenaNode::ELEM(node_str));
node_idx

graph.add_node(ArenaNode::ELEM(node_str))
}
Elem::Expr(range_expr) => {
let node_str = elem.arena_graph_node_label();
Expand All @@ -326,17 +325,16 @@ impl Elems {
.collect::<Vec<_>>();
context_var_nodes.iter().for_each(|dep_elem| {
let dep_node_idx = if let Some(&existing_node_idx) =
dependency_map.get(&dep_elem)
dependency_map.get(dep_elem)
{
// don't make a new ContextVar node, just use the existing one
existing_node_idx
} else {
// make a new ContextVar Node for the Arena graph
let new_node_idx = graph.add_node(ArenaNode::CVAR(format!(
"{}",
dep_elem.as_dot_str(graph_backend, arena)
)));
dependency_map.insert(dep_elem.clone(), new_node_idx);
let new_node_idx = graph.add_node(ArenaNode::CVAR(
dep_elem.as_dot_str(graph_backend, arena).to_string(),
));
dependency_map.insert(*dep_elem, new_node_idx);
new_node_idx
};
// use `update_edge` to avoid adding duplicate edges
Expand All @@ -360,17 +358,16 @@ impl Elems {
.collect::<Vec<_>>();
context_var_nodes.iter().for_each(|dep_elem| {
let dep_node_idx = if let Some(&existing_node_idx) =
dependency_map.get(&dep_elem)
dependency_map.get(dep_elem)
{
// don't make a new ContextVar node, just use the existing one
existing_node_idx
} else {
// make a new ContextVar Node for the Arena graph
let new_node_idx = graph.add_node(ArenaNode::CVAR(format!(
"{}",
dep_elem.as_dot_str(graph_backend, arena)
)));
dependency_map.insert(dep_elem.clone(), new_node_idx);
let new_node_idx = graph.add_node(ArenaNode::CVAR(
dep_elem.as_dot_str(graph_backend, arena).to_string(),
));
dependency_map.insert(*dep_elem, new_node_idx);
new_node_idx
};
// use `update_edge` to avoid adding duplicate edges
Expand Down Expand Up @@ -402,9 +399,9 @@ impl Elems {
);
}
Elem::Null => {
let node_str = format!("null");
let node_idx = graph.add_node(ArenaNode::ELEM(node_str));
node_idx
let node_str = "null".to_string();

graph.add_node(ArenaNode::ELEM(node_str))
}
};

Expand Down Expand Up @@ -514,20 +511,16 @@ flowchart TB

let nodes_str = graph
.node_indices()
.map(|idx| {
let node_str = arena_mermaid_node(graph, "\t", idx, true, true, None);
node_str
})
.map(|idx| arena_mermaid_node(graph, "\t", idx, true, true, None))
.collect::<Vec<_>>()
.join("\n");

let edges_str = graph
.edge_indices()
.enumerate()
.map(|(_i, edge)| {
.map(|edge| {
let (from, to) = graph.edge_endpoints(edge).unwrap();
let edge_label = format!("{}", graph[edge]);
if edge_label == "" {
if edge_label.is_empty() {
// don't do a label
format!(" {} --> {}", from.index(), to.index(),)
} else {
Expand All @@ -549,8 +542,7 @@ flowchart TB
// Make an invisible node that holds all our edge information for coloring later on frontend
let data_str = graph
.edge_indices()
.enumerate()
.map(|(_i, edge)| {
.map(|edge| {
let (from, to) = graph.edge_endpoints(edge).unwrap();
format!("LS-{}_LE-{}_{}", from.index(), to.index(), &graph[edge])
})
Expand Down
2 changes: 1 addition & 1 deletion crates/solc-expressions/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub trait Array: AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + Sized {
ctx: ContextNode,
) -> Result<(), ExprErr> {
self.parse_ctx_expr(arena, ty_expr, ctx)?;
self.apply_to_edges(ctx, ty_expr.loc(), arena, &|analyzer, arena, ctx, loc| {
self.apply_to_edges(ctx, ty_expr.loc(), arena, &|analyzer, _arena, ctx, loc| {
if let Some(ret) = ctx.pop_expr_latest(loc, analyzer).into_expr_err(loc)? {
if matches!(ret, ExprRet::CtxKilled(_)) {
ctx.push_expr(ret, analyzer).into_expr_err(loc)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/solc-expressions/src/bin_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ pub trait BinOp: AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + Sized {
fn checked_require_mod_div(
&mut self,
arena: &mut RangeArena<Elem<Concrete>>,
lhs: ContextVarNode,
_lhs: ContextVarNode,
rhs: ContextVarNode,
loc: Loc,
ctx: ContextNode,
Expand Down
2 changes: 1 addition & 1 deletion crates/solc-expressions/src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub trait Cmp: AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + Sized {
RangeOp::Not,
Elem::Null,
));
elem.arenaize(self, arena);
let _ = elem.arenaize(self, arena);
let mut range = SolcRange::new(elem.clone(), elem, vec![]);

range.cache_eval(self, arena).into_expr_err(loc)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/solc-expressions/src/context_builder/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ pub trait ExpressionParser:
}

self.parse_ctx_expr(arena, expr, ctx)?;
self.apply_to_edges(ctx, *loc, arena, &|analyzer, arena, ctx, loc| {
self.apply_to_edges(ctx, *loc, arena, &|analyzer, _arena, ctx, loc| {
tracing::trace!("Delete variable pop");
let Some(ret) = ctx.pop_expr_latest(loc, analyzer).into_expr_err(loc)? else {
return Err(ExprErr::NoRhs(
Expand Down
Loading

0 comments on commit ed8044b

Please sign in to comment.