Skip to content

Commit

Permalink
clippy lint fixes and silence
Browse files Browse the repository at this point in the history
  • Loading branch information
brockelmore committed Jul 10, 2024
1 parent 4c6ec8f commit 38992f8
Show file tree
Hide file tree
Showing 23 changed files with 149 additions and 224 deletions.
2 changes: 2 additions & 0 deletions crates/analyzers/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::too_many_arguments)]

pub mod bounds;

use ariadne::{Cache, Label, Report, ReportKind, Span};
Expand Down
3 changes: 3 additions & 0 deletions crates/graph/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![allow(clippy::too_many_arguments)]
#![allow(clippy::type_complexity)]

mod graph_elements;
mod range;
mod var_type;
Expand Down
2 changes: 1 addition & 1 deletion crates/graph/src/nodes/context/querying.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
AnalyzerBackend, ContextEdge, Edge, GraphBackend,
};

use shared::{GraphError, Search, NodeIdx};
use shared::{GraphError, NodeIdx, Search};
use std::collections::{BTreeMap, BTreeSet};

impl ContextNode {
Expand Down
6 changes: 2 additions & 4 deletions crates/graph/src/nodes/context/variables.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::{
nodes::{
ContextNode, ContextVarNode, EnumNode, ErrorNode, ExprRet, StructNode, TyNode, VarNode,
},
nodes::{ContextNode, ContextVarNode, ExprRet, VarNode},
AnalyzerBackend, ContextEdge, Edge, GraphBackend, Node, TypeNode,
};
use shared::GraphError;
Expand Down Expand Up @@ -43,7 +41,7 @@ impl ContextNode {
.tmp_expr
.iter()
.enumerate()
.filter(|(i, maybe_elem)| maybe_elem.is_some())
.filter(|(_i, maybe_elem)| maybe_elem.is_some())
.for_each(|(i, elem)| println!("{i}. {}", elem.clone().unwrap().debug_str(analyzer)));
Ok(())
}
Expand Down
4 changes: 3 additions & 1 deletion crates/graph/src/nodes/debug_reconstruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use crate::{
AnalyzerBackend, Edge, TypeNode,
};

use shared::GraphError;

use petgraph::{visit::EdgeRef, Direction};
use shared::GraphError;
use solang_parser::pt::Loc;
Expand Down Expand Up @@ -446,7 +448,7 @@ impl ContractNode {
let structs = self.reconstruct_structs(analyzer, contract_to_funcs)?;
let enums = self.reconstruct_enums(analyzer, contract_to_funcs)?;
let tys = self.reconstruct_tys(analyzer, contract_to_funcs)?;
let errs = self.reconstruct_errs(analyzer, contract_to_funcs)?;
let _errs = self.reconstruct_errs(analyzer, contract_to_funcs)?;
let funcs = self.reconstruct_funcs(analyzer, contract_to_funcs)?;
Ok(format!(
"{reconstructed_name} {inherited} {{\n{usings}{structs}{enums}{tys}{storage}{funcs}\n}}"
Expand Down
3 changes: 2 additions & 1 deletion crates/graph/src/nodes/err_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use crate::{
AnalyzerBackend, AsDotStr, Edge, GraphBackend, Node,
};

use shared::{NodeIdx, RangeArena, GraphError};
use shared::{GraphError, NodeIdx, RangeArena};

use petgraph::visit::EdgeRef;
use solang_parser::pt::{ErrorDefinition, ErrorParameter, Expression, Identifier, Loc};

Expand Down
1 change: 1 addition & 0 deletions crates/graph/src/range/elem/concrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ impl RangeElem<Concrete> for RangeConcrete<Concrete> {
Ok(())
}

#[allow(clippy::only_used_in_recursion)]
fn range_eq(&self, other: &Self, arena: &mut RangeArena<Elem<Concrete>>) -> bool {
match (self.val.into_u256(), other.val.into_u256()) {
(Some(self_val), Some(other_val)) => self_val == other_val,
Expand Down
3 changes: 1 addition & 2 deletions crates/graph/src/range/elem/elem_enum/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,6 @@ impl Elem<Concrete> {
pub fn arenaized_flattened(
&self,
max: bool,
analyzer: &mut impl GraphBackend,
arena: &mut RangeArena<Elem<Concrete>>,
) -> Option<Box<Elem<Concrete>>> {
if let Some(idx) = arena.idx(self) {
Expand Down Expand Up @@ -586,7 +585,7 @@ impl Elem<Concrete> {
}
c @ Elem::Concrete(_) => Some(Box::new(c.clone())),
c @ Elem::Null => Some(Box::new(c.clone())),
Elem::Arena(idx) => Elem::Arena(*idx).arenaized_flattened(max, analyzer, arena),
Elem::Arena(idx) => Elem::Arena(*idx).arenaized_flattened(max, arena),
}
} else {
None
Expand Down
12 changes: 6 additions & 6 deletions crates/graph/src/range/elem/expr/collapse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub fn collapse(

match (expr.op, op) {
(RangeOp::Sub(false), _) if ORD_OPS.contains(&op) => {
if let Some(res) = sub_ord_rules(x, y, op, &z, ords, arena) {
if let Some(res) = sub_ord_rules(x, y, op, &z, ords) {
MaybeCollapsed::Collapsed(res)
} else {
MaybeCollapsed::Not(Elem::Expr(expr), z)
Expand Down Expand Up @@ -170,14 +170,14 @@ pub fn collapse(

match (expr.op, op) {
(RangeOp::Sub(false), _) if ORD_OPS.contains(&op) => {
if let Some(res) = sub_ord_rules(x, y, op, &z, ords, arena) {
if let Some(res) = sub_ord_rules(x, y, op, &z, ords) {
MaybeCollapsed::Collapsed(res)
} else {
MaybeCollapsed::Not(Elem::Expr(expr), z)
}
}
(RangeOp::Add(false), _) if ORD_OPS.contains(&op) => {
if let Some(res) = add_ord_rules(x, y, op, &z, ords, arena) {
if let Some(res) = add_ord_rules(x, y, op, &z, ords) {
MaybeCollapsed::Collapsed(res)
} else {
MaybeCollapsed::Not(Elem::Expr(expr), z)
Expand All @@ -186,9 +186,9 @@ pub fn collapse(
(RangeOp::Eq, RangeOp::Eq) => {
// ((x == y) == z)
// can skip if x and z eq
if ords.x_eq_z() || ords.y_eq_z() {
MaybeCollapsed::Collapsed(Elem::Expr(expr))
} else if z.range_eq(&Elem::from(Concrete::from(true)), arena) {
if (ords.x_eq_z() || ords.y_eq_z())
|| z.range_eq(&Elem::from(Concrete::from(true)), arena)
{
MaybeCollapsed::Collapsed(Elem::Expr(expr))
} else {
MaybeCollapsed::Not(Elem::Expr(expr), z)
Expand Down
36 changes: 12 additions & 24 deletions crates/graph/src/range/elem/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,8 @@ impl RangeElem<Concrete> for RangeExpr<Concrete> {
) -> bool {
self.flattened_min.is_some() && self.flattened_max.is_some() || {
if let Some(idx) = self.arena_idx(arena) {
if let Some(t) = arena.ranges.get(idx) {
if let Elem::Expr(ref arenaized) = *t {
arenaized.flattened_min.is_some() && arenaized.flattened_max.is_some()
} else {
false
}
if let Some(Elem::Expr(ref arenaized)) = arena.ranges.get(idx) {
arenaized.flattened_min.is_some() && arenaized.flattened_max.is_some()
} else {
false
}
Expand All @@ -304,12 +300,8 @@ impl RangeElem<Concrete> for RangeExpr<Concrete> {
) -> (bool, bool) {
let (arena_cached_min, arena_cached_max) = {
if let Some(idx) = self.arena_idx(arena) {
if let Some(t) = arena.ranges.get(idx) {
if let Elem::Expr(ref arenaized) = *t {
(arenaized.minimized.is_some(), arenaized.maximized.is_some())
} else {
(false, false)
}
if let Some(Elem::Expr(ref arenaized)) = arena.ranges.get(idx) {
(arenaized.minimized.is_some(), arenaized.maximized.is_some())
} else {
(false, false)
}
Expand Down Expand Up @@ -528,7 +520,7 @@ impl RangeElem<Concrete> for RangeExpr<Concrete> {
) -> Result<Elem<Concrete>, GraphError> {
let Elem::Expr(this) = this else {
this.cache_flatten(analyzer, arena)?;
if let Some(t) = this.arenaized_flattened(false, analyzer, arena) {
if let Some(t) = this.arenaized_flattened(false, arena) {
return Ok(*t);
} else {
return Ok(this.clone());
Expand Down Expand Up @@ -588,7 +580,7 @@ impl RangeElem<Concrete> for RangeExpr<Concrete> {
) -> Result<Elem<Concrete>, GraphError> {
let Elem::Expr(this) = this else {
this.cache_flatten(analyzer, arena)?;
if let Some(t) = this.arenaized_flattened(true, analyzer, arena) {
if let Some(t) = this.arenaized_flattened(true, arena) {
return Ok(*t);
} else {
return Ok(this.clone());
Expand Down Expand Up @@ -643,11 +635,9 @@ impl RangeElem<Concrete> for RangeExpr<Concrete> {

if self.flattened_max.is_none() {
if let Some(idx) = self.arena_idx(arena) {
if let Some(t) = arena.ranges.get(idx) {
if let Elem::Expr(ref arenaized) = *t {
if arenaized.flattened_max.is_some() {
return Ok(());
}
if let Some(Elem::Expr(ref arenaized)) = arena.ranges.get(idx) {
if arenaized.flattened_max.is_some() {
return Ok(());
}
};
} else {
Expand All @@ -665,11 +655,9 @@ impl RangeElem<Concrete> for RangeExpr<Concrete> {

if self.flattened_min.is_none() {
if let Some(idx) = self.arena_idx(arena) {
if let Some(t) = arena.ranges.get(idx) {
if let Elem::Expr(ref arenaized) = *t {
if arenaized.flattened_min.is_some() {
return Ok(());
}
if let Some(Elem::Expr(ref arenaized)) = arena.ranges.get(idx) {
if arenaized.flattened_min.is_some() {
return Ok(());
}
};
} else {
Expand Down
7 changes: 2 additions & 5 deletions crates/graph/src/range/elem/expr/simplify/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ use crate::{
},
};

use shared::RangeArena;

pub fn add_ord_rules(
x: &Elem<Concrete>,
y: &Elem<Concrete>,
ord_op: RangeOp,
z: &Elem<Concrete>,
ords: Ords,
arena: &mut RangeArena<Elem<Concrete>>,
) -> Option<Elem<Concrete>> {
match ord_op {
RangeOp::Eq => {
Expand Down Expand Up @@ -118,7 +115,7 @@ pub fn add_ord_rules(
RangeOp::Max => {
// max{x + y, z}
// same as gt but return lhs or rhs instead
match add_ord_rules(x, y, RangeOp::Gt, z, ords, arena) {
match add_ord_rules(x, y, RangeOp::Gt, z, ords) {
Some(Elem::Concrete(RangeConcrete {
val: Concrete::Bool(b),
..
Expand All @@ -139,7 +136,7 @@ pub fn add_ord_rules(
RangeOp::Min => {
// min{x - y, z}
// same as lt but return lhs or rhs instead
match add_ord_rules(x, y, RangeOp::Lt, z, ords, arena) {
match add_ord_rules(x, y, RangeOp::Lt, z, ords) {
Some(Elem::Concrete(RangeConcrete {
val: Concrete::Bool(b),
..
Expand Down
7 changes: 2 additions & 5 deletions crates/graph/src/range/elem/expr/simplify/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ use crate::{
},
};

use shared::RangeArena;

pub fn sub_ord_rules(
x: &Elem<Concrete>,
y: &Elem<Concrete>,
ord_op: RangeOp,
z: &Elem<Concrete>,
ords: Ords,
arena: &mut RangeArena<Elem<Concrete>>,
) -> Option<Elem<Concrete>> {
match ord_op {
RangeOp::Eq => {
Expand Down Expand Up @@ -133,7 +130,7 @@ pub fn sub_ord_rules(
RangeOp::Max => {
// max{x - y, z}
// same as gt but return lhs or rhs instead
match sub_ord_rules(x, y, RangeOp::Gt, z, ords, arena) {
match sub_ord_rules(x, y, RangeOp::Gt, z, ords) {
Some(Elem::Concrete(RangeConcrete {
val: Concrete::Bool(b),
..
Expand All @@ -154,7 +151,7 @@ pub fn sub_ord_rules(
RangeOp::Min => {
// min{x - y, z}
// same as lt but return lhs or rhs instead
match sub_ord_rules(x, y, RangeOp::Lt, z, ords, arena) {
match sub_ord_rules(x, y, RangeOp::Lt, z, ords) {
Some(Elem::Concrete(RangeConcrete {
val: Concrete::Bool(b),
..
Expand Down
Loading

0 comments on commit 38992f8

Please sign in to comment.