Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
brockelmore committed Mar 18, 2024
1 parent b703c00 commit 7e404bc
Show file tree
Hide file tree
Showing 56 changed files with 702 additions and 644 deletions.
24 changes: 11 additions & 13 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use graph::elem::RangeElem;
use analyzers::{FunctionVarsBoundAnalyzer, ReportConfig, ReportDisplay};
use graph::{
nodes::{ContractNode, FunctionNode},
Expand All @@ -12,7 +11,7 @@ use shared::Search;
use ariadne::sources;
use clap::{ArgAction, Parser, ValueHint};

use tracing_subscriber::{Registry, prelude::*};
use tracing_subscriber::{prelude::*, Registry};

use std::{
collections::{BTreeMap, HashMap},
Expand Down Expand Up @@ -111,19 +110,18 @@ pub fn subscriber() {
}

pub fn tree_subscriber() {
let subscriber = Registry::default().with(
tracing_tree::HierarchicalLayer::default()
.with_indent_lines(true)
.with_indent_amount(2)
.with_thread_names(true)
// .with_thread_ids(true)
// .with_verbose_exit(true)
// .with_verbose_entry(true)
// .with_targets(true)
)
let subscriber = Registry::default()
.with(
tracing_tree::HierarchicalLayer::default()
.with_indent_lines(true)
.with_indent_amount(2)
.with_thread_names(true), // .with_thread_ids(true)
// .with_verbose_exit(true)
// .with_verbose_entry(true)
// .with_targets(true)
)
.with(tracing_subscriber::filter::EnvFilter::from_default_env());
tracing::subscriber::set_global_default(subscriber).unwrap();

}

fn main() {
Expand Down
11 changes: 4 additions & 7 deletions crates/graph/src/nodes/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,15 @@ impl BuiltInNode {
}

/// Gets the maximum size version of this builtin, i.e. uint16 -> uint256
pub fn max_size(
&self,
analyzer: &mut (impl GraphBackend + AnalyzerBackend),
) -> Result<Self, GraphError> {
pub fn max_size(&self, analyzer: &mut impl AnalyzerBackend) -> Result<Self, GraphError> {
let m = self.underlying(analyzer)?.max_size();
Ok(analyzer.builtin_or_add(m).into())
}

/// Gets the underlying type of the dynamic builtin backing it. i.e. uint256[] -> uint256
pub fn dynamic_underlying_ty(
&self,
analyzer: &mut (impl GraphBackend + AnalyzerBackend),
analyzer: &mut impl AnalyzerBackend,
) -> Result<VarType, GraphError> {
match self.underlying(analyzer)? {
Builtin::Array(v_ty) | Builtin::SizedArray(_, v_ty) => {
Expand Down Expand Up @@ -172,7 +169,7 @@ impl Builtin {
/// `mapping (uint => MyType)`, we may not have parsed `MyType`, so we now try to resolve it
pub fn unresolved_as_resolved(
&self,
analyzer: &mut (impl GraphBackend + AnalyzerBackend),
analyzer: &mut impl AnalyzerBackend,
) -> Result<Self, GraphError> {
match self {
Builtin::Array(n) => Ok(Builtin::Array(n.unresolved_as_resolved(analyzer)?)),
Expand Down Expand Up @@ -253,7 +250,7 @@ impl Builtin {
/// Try to convert from a [`Type`] to a Builtin
pub fn try_from_ty(
ty: Type,
analyzer: &mut (impl GraphBackend + AnalyzerBackend<Expr = Expression>),
analyzer: &mut impl AnalyzerBackend<Expr = Expression>,
) -> Option<Builtin> {
use Type::*;
match ty {
Expand Down
7 changes: 2 additions & 5 deletions crates/graph/src/nodes/concrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,15 @@ impl ConcreteNode {
}

/// Creates a version of this concrete that is max size
pub fn max_size(
&self,
analyzer: &mut (impl GraphBackend + AnalyzerBackend),
) -> Result<Self, GraphError> {
pub fn max_size(&self, analyzer: &mut impl AnalyzerBackend) -> Result<Self, GraphError> {
let c = self.underlying(analyzer)?.max_size();
Ok(analyzer.add_node(Node::Concrete(c)).into())
}

/// Gets the internal type of the dynamic that backs this. Panics if this is not a dynamic concrete
pub fn dynamic_underlying_ty(
&self,
analyzer: &mut (impl GraphBackend + AnalyzerBackend),
analyzer: &mut impl AnalyzerBackend,
) -> Result<VarType, GraphError> {
let builtin = self.underlying(analyzer)?.dynamic_underlying_ty().unwrap();
let bn = analyzer.builtin_or_add(builtin);
Expand Down
14 changes: 4 additions & 10 deletions crates/graph/src/nodes/context/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ impl ContextNode {
}

/// Gets the total context width
pub fn total_width(
&self,
analyzer: &mut (impl GraphBackend + AnalyzerBackend),
) -> Result<usize, GraphError> {
pub fn total_width(&self, analyzer: &mut impl AnalyzerBackend) -> Result<usize, GraphError> {
self.first_ancestor(analyzer)?
.number_of_live_edges(analyzer)
}
Expand All @@ -48,7 +45,7 @@ impl ContextNode {
/// Gets a mutable reference to the underlying context in the graph
pub fn underlying_mut<'a>(
&self,
analyzer: &'a mut (impl GraphBackend<Node = Node> + AnalyzerBackend),
analyzer: &'a mut impl AnalyzerBackend<Node = Node>,
) -> Result<&'a mut Context, GraphError> {
match analyzer.node_mut(*self) {
Node::Context(c) => Ok(c),
Expand Down Expand Up @@ -92,18 +89,15 @@ impl ContextNode {
&self,
ret_stmt_loc: Loc,
ret: ContextVarNode,
analyzer: &mut (impl GraphBackend + AnalyzerBackend),
analyzer: &mut impl AnalyzerBackend,
) -> Result<(), GraphError> {
self.underlying_mut(analyzer)?.ret.push((ret_stmt_loc, ret));
self.propogate_end(analyzer)?;
Ok(())
}

/// Propogate that this context has ended up the context graph
pub fn propogate_end(
&self,
analyzer: &mut (impl GraphBackend + AnalyzerBackend),
) -> Result<(), GraphError> {
pub fn propogate_end(&self, analyzer: &mut impl AnalyzerBackend) -> Result<(), GraphError> {
let underlying = &mut self.underlying_mut(analyzer)?;
let curr_live = underlying.number_of_live_edges;
underlying.number_of_live_edges = 0;
Expand Down
16 changes: 8 additions & 8 deletions crates/graph/src/nodes/context/querying.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl ContextNode {
/// Gets the associated contract for the function for the context
pub fn associated_contract(
&self,
analyzer: &mut (impl GraphBackend + AnalyzerBackend),
analyzer: &mut impl AnalyzerBackend,
) -> Result<ContractNode, GraphError> {
Ok(self
.associated_fn(analyzer)?
Expand All @@ -23,7 +23,7 @@ impl ContextNode {
/// Tries to get the associated function for the context
pub fn maybe_associated_contract(
&self,
analyzer: &mut (impl GraphBackend + AnalyzerBackend),
analyzer: &mut impl AnalyzerBackend,
) -> Result<Option<ContractNode>, GraphError> {
Ok(self
.associated_fn(analyzer)?
Expand All @@ -33,7 +33,7 @@ impl ContextNode {
/// Tries to get the associated source for the context
pub fn maybe_associated_source(
&self,
analyzer: &mut (impl GraphBackend + AnalyzerBackend),
analyzer: &mut impl AnalyzerBackend,
) -> Option<SourceUnitNode> {
let context = self.underlying(analyzer).unwrap();
if let Some(src) = context.cache.associated_source {
Expand All @@ -54,7 +54,7 @@ impl ContextNode {
/// Tries to get the associated source unit part for the context
pub fn associated_source_unit_part(
&self,
analyzer: &mut (impl GraphBackend + AnalyzerBackend),
analyzer: &mut impl AnalyzerBackend,
) -> Result<SourceUnitPartNode, GraphError> {
if let Some(sup) = self
.associated_fn(analyzer)?
Expand All @@ -71,7 +71,7 @@ impl ContextNode {
/// Gets visible functions
pub fn visible_modifiers(
&self,
analyzer: &mut (impl GraphBackend<Edge = Edge> + AnalyzerBackend),
analyzer: &mut impl AnalyzerBackend<Edge = Edge>,
) -> Result<Vec<FunctionNode>, GraphError> {
// TODO: filter privates
let Some(source) = self.maybe_associated_source(analyzer) else {
Expand Down Expand Up @@ -142,7 +142,7 @@ impl ContextNode {
/// Gets visible functions
pub fn visible_funcs(
&self,
analyzer: &mut (impl GraphBackend<Edge = Edge> + AnalyzerBackend),
analyzer: &mut impl AnalyzerBackend<Edge = Edge>,
) -> Result<Vec<FunctionNode>, GraphError> {
// TODO: filter privates
if let Some(vis) = &self.underlying(analyzer)?.cache.visible_funcs {
Expand Down Expand Up @@ -188,7 +188,7 @@ impl ContextNode {
/// Gets all visible functions
pub fn source_funcs(
&self,
analyzer: &mut (impl GraphBackend<Edge = Edge> + AnalyzerBackend),
analyzer: &mut impl AnalyzerBackend<Edge = Edge>,
) -> Vec<FunctionNode> {
// TODO: filter privates
let Some(source) = self.maybe_associated_source(analyzer) else {
Expand All @@ -211,7 +211,7 @@ impl ContextNode {
/// Gets all visible structs
pub fn visible_structs(
&self,
analyzer: &mut (impl GraphBackend<Edge = Edge> + AnalyzerBackend),
analyzer: &mut impl AnalyzerBackend<Edge = Edge>,
) -> Result<Vec<StructNode>, GraphError> {
// TODO: filter privates
if let Some(vis) = &self.underlying(analyzer)?.cache.visible_structs {
Expand Down
14 changes: 10 additions & 4 deletions crates/graph/src/nodes/context/solving.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::FlattenedRange;
use crate::elem::Elem;
use crate::FlattenedRange;
use crate::SolcRange;
use crate::{
as_dot_str,
Expand Down Expand Up @@ -30,7 +30,10 @@ impl ContextNode {
}

/// Get the dependencies as normalized solver atoms
pub fn dep_atoms(&self, analyzer: &mut impl GraphBackend) -> Result<Vec<SolverAtom>, GraphError> {
pub fn dep_atoms(
&self,
analyzer: &mut impl GraphBackend,
) -> Result<Vec<SolverAtom>, GraphError> {
let deps: Vec<_> = self.ctx_deps(analyzer)?;
let mut ranges = BTreeMap::default();
deps.iter().try_for_each(|dep| {
Expand Down Expand Up @@ -78,7 +81,7 @@ impl ContextNode {
pub fn add_ctx_dep(
&self,
dep: ContextVarNode,
analyzer: &mut (impl GraphBackend + AnalyzerBackend),
analyzer: &mut impl AnalyzerBackend,
) -> Result<(), GraphError> {
tracing::trace!(
"Adding ctx dependency: {}, is_controllable: {}",
Expand All @@ -91,7 +94,10 @@ impl ContextNode {
// dep.cache_flattened_range(analyzer)?;
let mut range = dep.range(analyzer)?.unwrap();
let r = range.flattened_range(analyzer)?.into_owned();
tracing::trace!("flattened: {}", <FlattenedRange as Into<SolcRange>>::into(r.clone()).as_dot_str(analyzer));
tracing::trace!(
"flattened: {}",
<FlattenedRange as Into<SolcRange>>::into(r.clone()).as_dot_str(analyzer)
);
// add the atomic constraint
if let Some(atom) = Elem::Arena(r.min).atomize(analyzer) {
let mut solver = std::mem::take(&mut self.underlying_mut(analyzer)?.dl_solver);
Expand Down
12 changes: 3 additions & 9 deletions crates/graph/src/nodes/context/typing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl ContextNode {
pub fn is_fn_ext(
&self,
fn_node: FunctionNode,
analyzer: &mut (impl GraphBackend + AnalyzerBackend),
analyzer: &mut impl AnalyzerBackend,
) -> Result<bool, GraphError> {
match fn_node.maybe_associated_contract(analyzer) {
None => Ok(false),
Expand Down Expand Up @@ -75,19 +75,13 @@ impl ContextNode {
}

/// Sets the context to use unchecked math
pub fn set_unchecked(
&self,
analyzer: &mut (impl GraphBackend + AnalyzerBackend),
) -> Result<(), GraphError> {
pub fn set_unchecked(&self, analyzer: &mut impl AnalyzerBackend) -> Result<(), GraphError> {
self.underlying_mut(analyzer)?.unchecked = true;
Ok(())
}

/// Sets the context to use checked math
pub fn unset_unchecked(
&self,
analyzer: &mut (impl GraphBackend + AnalyzerBackend),
) -> Result<(), GraphError> {
pub fn unset_unchecked(&self, analyzer: &mut impl AnalyzerBackend) -> Result<(), GraphError> {
self.underlying_mut(analyzer)?.unchecked = false;
Ok(())
}
Expand Down
14 changes: 7 additions & 7 deletions crates/graph/src/nodes/context/var/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ impl ContextVarNode {
Ok(self.underlying(analyzer)?.tmp_of())
}

pub fn struct_to_fields(&self, analyzer: &impl GraphBackend) -> Result<Vec<ContextVarNode>, GraphError> {
pub fn struct_to_fields(
&self,
analyzer: &impl GraphBackend,
) -> Result<Vec<ContextVarNode>, GraphError> {
if self.ref_range(analyzer)?.is_none() {
let fields = analyzer
.graph()
Expand Down Expand Up @@ -309,10 +312,7 @@ impl ContextVarNode {
.collect()
}

pub fn set_dependent_on(
&self,
analyzer: &mut impl GraphBackend,
) -> Result<(), GraphError> {
pub fn set_dependent_on(&self, analyzer: &mut impl GraphBackend) -> Result<(), GraphError> {
let mut return_self = false;
let mut first_iter = true;
let mut stack = vec![*self];
Expand All @@ -335,7 +335,7 @@ impl ContextVarNode {

if first_iter {
first_iter = false;
return_self = true;
return_self = true;
}
}

Expand Down Expand Up @@ -372,7 +372,7 @@ impl ContextVarNode {

if first_iter {
first_iter = false;
return_self = true;
return_self = true;
}
}

Expand Down
Loading

0 comments on commit 7e404bc

Please sign in to comment.