Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
brockelmore committed Dec 8, 2023
1 parent 3d1b17a commit 5252d8c
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 54 deletions.
6 changes: 3 additions & 3 deletions crates/analyzers/src/var_analyzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use graph::{
nodes::{ContextNode, ContextVarNode, KilledKind},
AnalyzerBackend, GraphBackend, Range, SolcRange,
};
use shared::{StorageLocation, Search};
use shared::{Search, StorageLocation};

use std::collections::BTreeSet;

Expand Down Expand Up @@ -98,7 +98,7 @@ impl VarBoundAnalysis {
order: -1,
name: self.var_display_name.clone(),
loc: self.var_def.0.clone(),
storage: self.storage.clone(),
storage: self.storage,
ctx: self.ctx,
ctx_conditionals: self.conditionals(analyzer),
parts,
Expand Down Expand Up @@ -215,7 +215,7 @@ pub trait VarBoundAnalyzer: Search + AnalyzerBackend + Sized {
),
bound_changes: vec![],
report_config,
storage: curr.underlying(self).unwrap().storage.clone(),
storage: curr.underlying(self).unwrap().storage,
ctx_killed: ctx
.killed_loc(self)
.unwrap()
Expand Down
2 changes: 1 addition & 1 deletion crates/analyzers/src/var_analyzer/report_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl ReportDisplay for VarBoundAnalysis {
name: self.var_display_name.clone(),
loc: bound_change.0.clone(),
order: i as i32,
storage: self.storage.clone(),
storage: self.storage,
ctx: self.ctx,
ctx_conditionals: self.conditionals(analyzer),
parts,
Expand Down
7 changes: 5 additions & 2 deletions crates/graph/src/nodes/context/var/typing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
AnalyzerBackend, ContextEdge, Edge, GraphBackend, GraphError, Node, VarType,
};

use shared::{StorageLocation, Search};
use shared::{Search, StorageLocation};

use petgraph::Direction;
use solang_parser::pt::Loc;
Expand Down Expand Up @@ -86,7 +86,10 @@ impl ContextVarNode {
}

pub fn is_controllable(&self, analyzer: &impl GraphBackend) -> Result<bool, GraphError> {
if self.is_storage_or_calldata_input(analyzer)? || self.is_msg(analyzer)? || self.is_block(analyzer)? {
if self.is_storage_or_calldata_input(analyzer)?
|| self.is_msg(analyzer)?
|| self.is_block(analyzer)?
{
Ok(true)
} else if let Some(tmp) = self.tmp_of(analyzer)? {
let rhs_controllable = if let Some(rhs) = tmp.rhs {
Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/context/var/underlying.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
};

use crate::range::elem::*;
use shared::{StorageLocation, NodeIdx};
use shared::{NodeIdx, StorageLocation};

use solang_parser::pt::Loc;

Expand Down Expand Up @@ -479,7 +479,7 @@ impl ContextVar {
display_name: parent_var.name.clone()
+ "."
+ &field.name.expect("Field had no name").name,
storage: parent_var.storage.clone(),
storage: parent_var.storage,
is_tmp: false,
tmp_of: None,
is_symbolic: true,
Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/func_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ impl FunctionParam {
loc: param.loc,
ty: analyzer.parse_expr(&param.ty, None),
order,
storage: if let Some(s) = param.storage { Some(s.into()) } else { None },
storage: param.storage.map(|s| s.into()),
name: param.name,
}
}
Expand Down Expand Up @@ -875,7 +875,7 @@ impl FunctionReturn {
FunctionReturn {
loc: param.loc,
ty: analyzer.parse_expr(&param.ty, None),
storage: if let Some(s) = param.storage { Some(s.into()) } else { None },
storage: param.storage.map(|s| s.into()),
name: param.name,
}
}
Expand Down
29 changes: 20 additions & 9 deletions crates/graph/src/range/elem/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,13 @@ fn collapse(l: Elem<Concrete>, op: RangeOp, r: Elem<Concrete>) -> MaybeCollapsed
(RangeOp::Sub(false), RangeOp::Min) => {
// min{x - y, z}
// if x <= z, then x - y will be the minimum if y >= 0
if matches!(x.range_ord(&z), Some(std::cmp::Ordering::Equal) | Some(std::cmp::Ordering::Less))
&& matches!(y.range_ord(&zero), Some(std::cmp::Ordering::Equal) | Some(std::cmp::Ordering::Greater)) {
if matches!(
x.range_ord(&z),
Some(std::cmp::Ordering::Equal) | Some(std::cmp::Ordering::Less)
) && matches!(
y.range_ord(&zero),
Some(std::cmp::Ordering::Equal) | Some(std::cmp::Ordering::Greater)
) {
MaybeCollapsed::Collapsed(l)
} else {
MaybeCollapsed::Not(l, r)
Expand All @@ -234,13 +239,19 @@ fn collapse(l: Elem<Concrete>, op: RangeOp, r: Elem<Concrete>) -> MaybeCollapsed
// max{x + y, z}
// if x >= z, then x + y will be the maximum if y >= 0
// or if y >= z, then x + y will be the maximum if x >= 0
if (
matches!(x.range_ord(&z), Some(std::cmp::Ordering::Equal) | Some(std::cmp::Ordering::Greater))
&& matches!(y.range_ord(&zero), Some(std::cmp::Ordering::Equal) | Some(std::cmp::Ordering::Greater))
) || (
matches!(y.range_ord(&z), Some(std::cmp::Ordering::Equal) | Some(std::cmp::Ordering::Greater))
&& matches!(x.range_ord(&zero), Some(std::cmp::Ordering::Equal) | Some(std::cmp::Ordering::Greater))
) {
if (matches!(
x.range_ord(&z),
Some(std::cmp::Ordering::Equal) | Some(std::cmp::Ordering::Greater)
) && matches!(
y.range_ord(&zero),
Some(std::cmp::Ordering::Equal) | Some(std::cmp::Ordering::Greater)
)) || (matches!(
y.range_ord(&z),
Some(std::cmp::Ordering::Equal) | Some(std::cmp::Ordering::Greater)
) && matches!(
x.range_ord(&zero),
Some(std::cmp::Ordering::Equal) | Some(std::cmp::Ordering::Greater)
)) {
MaybeCollapsed::Collapsed(l)
} else {
MaybeCollapsed::Not(l, r)
Expand Down
51 changes: 22 additions & 29 deletions crates/shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,33 @@ pub use analyzer_like::*;
pub use graph_like::*;
pub use search::*;


#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
pub enum StorageLocation {
Memory(solang_parser::pt::Loc),
Storage(solang_parser::pt::Loc),
Calldata(solang_parser::pt::Loc),
Block(solang_parser::pt::Loc),
Msg(solang_parser::pt::Loc),
Memory(solang_parser::pt::Loc),
Storage(solang_parser::pt::Loc),
Calldata(solang_parser::pt::Loc),
Block(solang_parser::pt::Loc),
Msg(solang_parser::pt::Loc),
}

impl std::fmt::Display for StorageLocation {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Memory(_) => write!(f, "memory"),
Self::Storage(_) => write!(f, "storage"),
Self::Calldata(_) => write!(f, "calldata"),
Self::Block(_) => write!(f, "block"),
Self::Msg(_) => write!(f, "msg"),
}
}
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Memory(_) => write!(f, "memory"),
Self::Storage(_) => write!(f, "storage"),
Self::Calldata(_) => write!(f, "calldata"),
Self::Block(_) => write!(f, "block"),
Self::Msg(_) => write!(f, "msg"),
}
}
}

impl From<solang_parser::pt::StorageLocation> for StorageLocation {
fn from(sl: solang_parser::pt::StorageLocation) -> Self {
match sl {
solang_parser::pt::StorageLocation::Memory(m) =>{
StorageLocation::Memory(m)
}
solang_parser::pt::StorageLocation::Storage(m) =>{
StorageLocation::Storage(m)
}
solang_parser::pt::StorageLocation::Calldata(m) =>{
StorageLocation::Calldata(m)
}
}
}
}
fn from(sl: solang_parser::pt::StorageLocation) -> Self {
match sl {
solang_parser::pt::StorageLocation::Memory(m) => StorageLocation::Memory(m),
solang_parser::pt::StorageLocation::Storage(m) => StorageLocation::Storage(m),
solang_parser::pt::StorageLocation::Calldata(m) => StorageLocation::Calldata(m),
}
}
}
2 changes: 1 addition & 1 deletion crates/solc-expressions/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub trait Array: AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + Sized {
parent.display_name(self).into_expr_err(loc)?,
index.display_name(self).into_expr_err(loc)?
),
storage: parent.storage(self).into_expr_err(loc)?.clone(),
storage: *parent.storage(self).into_expr_err(loc)?,
is_tmp: false,
tmp_of: None,
is_symbolic: true,
Expand Down
4 changes: 2 additions & 2 deletions crates/solc-expressions/src/context_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ pub trait ContextBuilder:
loc: Some(loc),
name: name.to_string(),
display_name: name.to_string(),
storage: if let Some(s) = &var_decl.storage { Some(s.clone().into()) } else { None },
storage: var_decl.storage.as_ref().map(|s| s.clone().into()),
is_tmp: false,
is_symbolic: true,
tmp_of: None,
Expand All @@ -642,7 +642,7 @@ pub trait ContextBuilder:
loc: Some(loc),
name: name.to_string(),
display_name: name.to_string(),
storage: if let Some(s) = &var_decl.storage { Some(s.clone().into()) } else { None },
storage: var_decl.storage.as_ref().map(|s| s.clone().into()),
is_tmp: false,
is_symbolic: true,
tmp_of: None,
Expand Down
1 change: 0 additions & 1 deletion crates/solc-expressions/src/env.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use crate::{func_call::FuncCaller, ExprErr, IntoExprErr};

use graph::{
Expand Down
2 changes: 1 addition & 1 deletion crates/solc-expressions/src/func_call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use graph::{
},
AnalyzerBackend, ContextEdge, Edge, GraphBackend, Node, Range, VarType,
};
use shared::{StorageLocation, NodeIdx};
use shared::{NodeIdx, StorageLocation};

use solang_parser::helpers::CodeLocation;
use solang_parser::pt::{Expression, Loc, NamedArgument};
Expand Down
2 changes: 1 addition & 1 deletion crates/solc-expressions/src/member_access/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ pub trait MemberAccess: AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> +
loc,
parent_name,
parent_display_name,
parent_stor.clone(),
*parent_stor,
&parent_ty,
ContextVarNode::from(*idx),
)
Expand Down

0 comments on commit 5252d8c

Please sign in to comment.