Skip to content

Commit

Permalink
remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
brockelmore committed Jul 18, 2024
1 parent bcfcb6b commit 2daf5c3
Show file tree
Hide file tree
Showing 52 changed files with 223 additions and 3,269 deletions.
18 changes: 0 additions & 18 deletions crates/graph/src/nodes/context/var/ranging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,6 @@ impl ContextVarNode {
self.underlying(analyzer)?.ty.ref_range(analyzer)
}

pub fn last_range_op(
&self,
analyzer: &impl GraphBackend,
arena: &mut RangeArena<Elem<Concrete>>,
) -> Result<Option<RangeOp>, GraphError> {
if let Some(r) = self.ref_range(analyzer)? {
let min_op = r.range_min().last_range_op(analyzer, arena)?;
let max_op = r.range_max().last_range_op(analyzer, arena)?;
if min_op == max_op {
Ok(min_op)
} else {
Ok(None)
}
} else {
Ok(None)
}
}

pub fn range_min(
&self,
analyzer: &impl GraphBackend,
Expand Down
9 changes: 2 additions & 7 deletions crates/graph/src/nodes/yul_func.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
use crate::{
nodes::{Concrete, ContractNode},
range::elem::Elem,
AnalyzerBackend, AsDotStr, Edge, GraphBackend, Node, VarType,
};
use crate::{nodes::Concrete, range::elem::Elem, AsDotStr, GraphBackend, Node};

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

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

#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub struct YulFunctionNode(pub usize);
Expand Down
9 changes: 1 addition & 8 deletions crates/graph/src/range/elem/concrete.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
nodes::{Concrete, ContextVarNode},
range::elem::{Elem, RangeArenaLike, RangeElem, RangeOp},
range::elem::{Elem, RangeArenaLike, RangeElem},
GraphBackend,
};

Expand Down Expand Up @@ -84,13 +84,6 @@ impl RangeConcrete<Concrete> {

impl RangeElem<Concrete> for RangeConcrete<Concrete> {
type GraphError = GraphError;
fn last_range_op(
&self,
analyzer: &impl GraphBackend,
arena: &mut RangeArena<Elem<Concrete>>,
) -> Result<Option<RangeOp>, GraphError> {
Ok(None)
}
fn arenaize(
&mut self,
analyzer: &mut impl GraphBackend,
Expand Down
22 changes: 1 addition & 21 deletions crates/graph/src/range/elem/elem_enum/range_elem.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::elem::{MinMaxed, RangeArenaLike};
use crate::{
nodes::{Concrete, ContextVarNode},
range::elem::{collapse, Elem, MaybeCollapsed, RangeElem, RangeOp},
range::elem::{collapse, Elem, MaybeCollapsed, RangeElem},
GraphBackend,
};

Expand All @@ -10,26 +10,6 @@ use shared::{GraphError, NodeIdx, RangeArena};
impl RangeElem<Concrete> for Elem<Concrete> {
type GraphError = GraphError;

fn last_range_op(
&self,
analyzer: &impl GraphBackend,
arena: &mut RangeArena<Elem<Concrete>>,
) -> Result<Option<RangeOp>, GraphError> {
match self {
Self::Reference(d) => d.last_range_op(analyzer, arena),
Self::Concrete(c) => c.last_range_op(analyzer, arena),
Self::Expr(expr) => expr.last_range_op(analyzer, arena),
Self::ConcreteDyn(d) => d.last_range_op(analyzer, arena),
Self::Null => Ok(None),
Self::Arena(_) => {
let (de, idx) = self.dearenaize(arena);
let res = de.last_range_op(analyzer, arena)?;
self.rearenaize(de, idx, arena);
Ok(res)
}
}
}

fn arenaize(
&mut self,
analyzer: &mut impl GraphBackend,
Expand Down
8 changes: 1 addition & 7 deletions crates/graph/src/range/elem/elem_trait.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{elem::RangeOp, nodes::ContextVarNode, range::elem::Elem, GraphBackend};
use crate::{nodes::ContextVarNode, range::elem::Elem, GraphBackend};

use shared::{GraphError, NodeIdx, RangeArena};
use std::hash::Hash;
Expand Down Expand Up @@ -123,10 +123,4 @@ pub trait RangeElem<T: Ord + Hash>: Hash {
analyzer: &mut impl GraphBackend,
arena: &mut RangeArena<Elem<T>>,
) -> Result<(), GraphError>;

fn last_range_op(
&self,
analyzer: &impl GraphBackend,
arena: &mut RangeArena<Elem<T>>,
) -> Result<Option<RangeOp>, GraphError>;
}
8 changes: 0 additions & 8 deletions crates/graph/src/range/elem/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,6 @@ impl<T: Ord> RangeExpr<T> {
impl RangeElem<Concrete> for RangeExpr<Concrete> {
type GraphError = GraphError;

fn last_range_op(
&self,
analyzer: &impl GraphBackend,
arena: &mut RangeArena<Elem<Concrete>>,
) -> Result<Option<RangeOp>, GraphError> {
Ok(Some(self.op))
}

// #[tracing::instrument(level = "trace", skip_all)]
fn arenaize(
&mut self,
Expand Down
10 changes: 1 addition & 9 deletions crates/graph/src/range/elem/map_or_array.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
nodes::{Builtin, Concrete, ContextVarNode},
range::{
elem::{Elem, MinMaxed, RangeConcrete, RangeElem, RangeOp},
elem::{Elem, MinMaxed, RangeConcrete, RangeElem},
exec_traits::{RangeCast, RangeMemLen},
},
GraphBackend,
Expand Down Expand Up @@ -274,14 +274,6 @@ impl RangeDyn<Concrete> {
impl RangeElem<Concrete> for RangeDyn<Concrete> {
type GraphError = GraphError;

fn last_range_op(
&self,
analyzer: &impl GraphBackend,
arena: &mut RangeArena<Elem<Concrete>>,
) -> Result<Option<RangeOp>, GraphError> {
Ok(None)
}

fn arenaize(
&mut self,
analyzer: &mut impl GraphBackend,
Expand Down
10 changes: 1 addition & 9 deletions crates/graph/src/range/elem/reference.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
nodes::{Concrete, ContextVarNode},
range::{
elem::{Elem, MinMaxed, RangeArenaLike, RangeConcrete, RangeElem, RangeOp},
elem::{Elem, MinMaxed, RangeArenaLike, RangeConcrete, RangeElem},
Range,
},
GraphBackend, TypeNode, VarType,
Expand Down Expand Up @@ -56,14 +56,6 @@ impl<T> Reference<T> {
impl RangeElem<Concrete> for Reference<Concrete> {
type GraphError = GraphError;

fn last_range_op(
&self,
analyzer: &impl GraphBackend,
arena: &mut RangeArena<Elem<Concrete>>,
) -> Result<Option<RangeOp>, GraphError> {
ContextVarNode::from(self.idx).last_range_op(analyzer, arena)
}

fn arenaize(
&mut self,
analyzer: &mut impl GraphBackend,
Expand Down
5 changes: 2 additions & 3 deletions crates/graph/src/range/exec/mem_ops/mem_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ pub fn exec_get_index(
}
Elem::ConcreteDyn(d) => {
d.val.iter().for_each(|(k, (v, _op))| {
match k.overlaps(rhs, true, analyzer, arena) {
Ok(Some(true)) => candidates.push(v.clone()),
_ => {}
if let Ok(Some(true)) = k.overlaps(rhs, true, analyzer, arena) {
candidates.push(v.clone())
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions crates/pyrometer/src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use reqwest::Client;
use serde::{Deserialize, Serialize};
use shared::{AnalyzerLike, ApplyStats, GraphLike, NodeIdx, Search};
use shared::{ExprErr, ExprFlag, FlatExpr, IntoExprErr, RangeArena, USE_DEBUG_SITE};
use solc_expressions::{Flatten, StatementParser};
use solc_expressions::Flatten;
use tokio::runtime::Runtime;
use tracing::{error, trace, warn};

Expand Down Expand Up @@ -152,7 +152,7 @@ pub struct Analyzer {
pub current_asm_block: usize,
}

impl<'a> Default for Analyzer {
impl Default for Analyzer {
fn default() -> Self {
let mut a = Self {
root: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion crates/pyrometer/src/analyzer_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl AnalyzerLike for Analyzer {

Some(reconstruction_edge)
}
e => None,
_e => None,
}
}
_ => None,
Expand Down
73 changes: 2 additions & 71 deletions crates/solc-expressions/src/array.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{require::Require, variable::Variable, ContextBuilder, ExpressionParser, ListAccess};
use crate::{require::Require, variable::Variable, ListAccess};

use graph::{
elem::{Elem, RangeDyn, RangeOp},
Expand All @@ -7,39 +7,12 @@ use graph::{
};
use shared::{ExprErr, IntoExprErr, RangeArena};

use solang_parser::{
helpers::CodeLocation,
pt::{Expression, Loc},
};
use solang_parser::pt::{Expression, Loc};

impl<T> Array for T where T: AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + Sized {}
/// Handles arrays
pub trait Array: AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + Sized {
/// Gets the array type
#[tracing::instrument(level = "trace", skip_all)]
fn array_ty(
&mut self,
arena: &mut RangeArena<Elem<Concrete>>,
ty_expr: &Expression,
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| {
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)?;
return Ok(());
}
analyzer.match_ty(ctx, ty_expr.loc(), ret)
} else {
Err(ExprErr::NoLhs(
loc,
"No array specified for getting array type".to_string(),
))
}
})
}

fn match_ty(&mut self, ctx: ContextNode, loc: Loc, ret: ExprRet) -> Result<(), ExprErr> {
match ret {
ExprRet::Single(inner_ty) | ExprRet::SingleLiteral(inner_ty) => {
Expand Down Expand Up @@ -75,48 +48,6 @@ pub trait Array: AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + Sized {
}

/// Indexes into an array
#[tracing::instrument(level = "trace", skip_all)]
fn index_into_array(
&mut self,
arena: &mut RangeArena<Elem<Concrete>>,
loc: Loc,
ty_expr: &Expression,
index_expr: &Expression,
ctx: ContextNode,
) -> Result<(), ExprErr> {
tracing::trace!("Indexing into array");
self.parse_ctx_expr(arena, index_expr, ctx)?;
self.apply_to_edges(ctx, loc, arena, &|analyzer, arena, ctx, loc| {
let Some(index_tys) = ctx.pop_expr_latest(loc, analyzer).into_expr_err(loc)? else {
return Err(ExprErr::NoRhs(
loc,
"Could not find the index variable".to_string(),
));
};
if matches!(index_tys, ExprRet::CtxKilled(_)) {
ctx.push_expr(index_tys, analyzer).into_expr_err(loc)?;
return Ok(());
}
analyzer.parse_ctx_expr(arena, ty_expr, ctx)?;
analyzer.apply_to_edges(ctx, loc, arena, &|analyzer, arena, ctx, loc| {
let Some(inner_tys) = ctx.pop_expr_latest(loc, analyzer).into_expr_err(loc)? else {
return Err(ExprErr::NoLhs(loc, "Could not find the array".to_string()));
};
if matches!(inner_tys, ExprRet::CtxKilled(_)) {
ctx.push_expr(inner_tys, analyzer).into_expr_err(loc)?;
return Ok(());
}
analyzer.index_into_array_inner(
arena,
ctx,
inner_tys.flatten(),
index_tys.clone().flatten(),
loc,
)
})
})
}

#[tracing::instrument(level = "trace", skip_all)]
fn index_into_array_inner(
&mut self,
Expand Down
51 changes: 1 addition & 50 deletions crates/solc-expressions/src/assign.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{array::Array, variable::Variable, ContextBuilder, ExpressionParser, ListAccess};
use crate::variable::Variable;

use graph::{
elem::{Elem, RangeElem},
Expand All @@ -12,55 +12,6 @@ use solang_parser::pt::{Expression, Loc};
impl<T> Assign for T where T: AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + Sized {}
/// Handles assignments
pub trait Assign: AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + Sized {
#[tracing::instrument(level = "trace", skip_all)]
/// Parse an assignment expression
fn assign_exprs(
&mut self,
arena: &mut RangeArena<Elem<Concrete>>,
loc: Loc,
lhs_expr: &Expression,
rhs_expr: &Expression,
ctx: ContextNode,
) -> Result<(), ExprErr> {
self.parse_ctx_expr(arena, lhs_expr, ctx)?;
self.apply_to_edges(ctx, loc, arena, &|analyzer, arena, ctx, loc| {
let Some(lhs_paths) = ctx.pop_expr_latest(loc, analyzer).into_expr_err(loc)? else {
return Err(ExprErr::NoLhs(
loc,
"Assign operation had no left hand side".to_string(),
));
};

if matches!(lhs_paths, ExprRet::CtxKilled(_)) {
ctx.push_expr(lhs_paths, analyzer).into_expr_err(loc)?;
return Ok(());
}

ctx.push_expr(lhs_paths, analyzer).into_expr_err(loc)?;
analyzer.parse_ctx_expr(arena, rhs_expr, ctx)?;
analyzer.apply_to_edges(ctx, loc, arena, &|analyzer, arena, ctx, loc| {
let Some(rhs_paths) = ctx.pop_expr_latest(loc, analyzer).into_expr_err(loc)? else {
return Err(ExprErr::NoRhs(
loc,
"Assign operation had no right hand side".to_string(),
));
};
let lhs_paths = ctx
.pop_expr_latest(loc, analyzer)
.into_expr_err(loc)?
.unwrap()
.flatten();

if matches!(rhs_paths, ExprRet::CtxKilled(_)) {
ctx.push_expr(rhs_paths, analyzer).into_expr_err(loc)?;
return Ok(());
}
analyzer.match_assign_sides(arena, ctx, loc, &lhs_paths, &rhs_paths)?;
Ok(())
})
})
}

/// Match on the [`ExprRet`]s of an assignment expression
fn match_assign_sides(
&mut self,
Expand Down
Loading

0 comments on commit 2daf5c3

Please sign in to comment.