Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pop unneeded ExprRets #92

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/graph/src/nodes/context/typing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ impl ContextNode {
.underlying(analyzer)?
.inherits
.iter()
.filter_map(|i| i.as_ref())
.any(|inherited| *inherited == fn_ctrt))
} else {
Ok(false)
Expand Down
36 changes: 23 additions & 13 deletions crates/graph/src/nodes/contract_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl ContractNode {
self.underlying_mut(analyzer)
.unwrap()
.inherits
.push(ContractNode::from(*found));
.push(Some(ContractNode::from(*found)));
analyzer.add_edge(*found, *self, Edge::InheritedContract);
});
self.order_inherits(analyzer);
Expand All @@ -119,17 +119,25 @@ impl ContractNode {
let inherits = self.underlying(analyzer).unwrap().inherits.clone();

let mut tmp_inherits = vec![];
tmp_inherits.resize(inherits.len(), ContractNode::from(NodeIdx::from(0)));
tmp_inherits.resize(inherits.len(), None);
inherits.into_iter().for_each(|inherited| {
let i_name = inherited.name(analyzer).unwrap();
let position = raw_inherits.iter().position(|raw| &i_name == raw).unwrap();
tmp_inherits[position] = inherited;
if let Some(inherited) = inherited {
let i_name = inherited.name(analyzer).unwrap();
let position = raw_inherits.iter().position(|raw| &i_name == raw).unwrap();
tmp_inherits[position] = Some(inherited);
}
});
self.underlying_mut(analyzer).unwrap().inherits = tmp_inherits;
}

pub fn direct_inherited_contracts(&self, analyzer: &impl GraphBackend) -> Vec<ContractNode> {
self.underlying(analyzer).unwrap().inherits.clone()
self.underlying(analyzer)
.unwrap()
.inherits
.iter()
.filter_map(|i| i.as_ref())
.cloned()
.collect()
}

pub fn all_inherited_contracts(&self, analyzer: &impl GraphBackend) -> Vec<ContractNode> {
Expand Down Expand Up @@ -384,7 +392,7 @@ pub struct Contract {
/// Raw inherited strings, ordered by least base to most base
pub raw_inherits: Vec<String>,
/// A list of contracts that this contract inherits (TODO: inheritance linearization)
pub inherits: Vec<ContractNode>,
pub inherits: Vec<Option<ContractNode>>,
/// Cached linearized functions
pub cached_functions: Option<BTreeMap<String, FunctionNode>>,
}
Expand Down Expand Up @@ -416,7 +424,7 @@ impl Contract {
{
let name = ContractNode::from(contract).name(analyzer).unwrap();
if &name == inherited_name {
inherits.push(ContractNode::from(contract));
inherits.push(Some(ContractNode::from(contract)));
found = true;
break;
}
Expand All @@ -430,7 +438,7 @@ impl Contract {
{
let name = ContractNode::from(contract).name(analyzer).unwrap();
if &name == inherited_name {
inherits.push(ContractNode::from(contract));
inherits.push(Some(ContractNode::from(contract)));
found = true;
break;
}
Expand Down Expand Up @@ -462,11 +470,13 @@ impl Contract {
let inherits = self.inherits.clone();

let mut tmp_inherits = vec![];
tmp_inherits.resize(inherits.len(), ContractNode::from(NodeIdx::from(0)));
tmp_inherits.resize(raw_inherits.len(), None);
inherits.into_iter().for_each(|inherited| {
let i_name = inherited.name(analyzer).unwrap();
let position = raw_inherits.iter().position(|raw| &i_name == raw).unwrap();
tmp_inherits[position] = inherited;
if let Some(inherited) = inherited {
let i_name = inherited.name(analyzer).unwrap();
let position = raw_inherits.iter().position(|raw| &i_name == raw).unwrap();
tmp_inherits[position] = Some(inherited);
}
});
self.inherits = tmp_inherits;
}
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 @@ -1049,8 +1049,8 @@ impl Analyzer {
node.into()
};

inherits.iter().for_each(|contract_node| {
self.add_edge(*contract_node, con_node, Edge::InheritedContract);
inherits.into_iter().flatten().for_each(|contract_node| {
self.add_edge(contract_node, con_node, Edge::InheritedContract);
});

let mut usings = vec![];
Expand Down
2 changes: 2 additions & 0 deletions crates/shared/src/flattened.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub enum FlatExpr {
},

Todo(Loc, &'static str),
Pop,

Emit(Loc),
TestCommand(Loc, &'static str),
Expand Down Expand Up @@ -399,6 +400,7 @@ impl FlatExpr {
| ArrayLiteral(loc, ..) => Some(*loc),

FunctionCallName(..)
| Pop
| YulExpr(FlatYulExpr::YulStartBlock(_))
| YulExpr(FlatYulExpr::YulEndBlock(_)) => None,
}
Expand Down
9 changes: 9 additions & 0 deletions crates/solc-expressions/src/context_builder/flattened.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,9 @@ pub trait Flatten:
});
let cmp = self.expr_stack_mut().pop().unwrap();
self.traverse_requirement(cmp, *loc);
if input_exprs.len() > 1 {
self.push_expr(FlatExpr::Pop);
}
}
_ => {
// func(inputs)
Expand Down Expand Up @@ -1146,6 +1149,12 @@ pub trait Flatten:
// Semi useless
Super(..) => unreachable!(),
Parameter(_, _, _) => Ok(()),
Pop => {
let _ = ctx
.pop_n_latest_exprs(1, Loc::Implicit, self)
.into_expr_err(Loc::Implicit)?;
Ok(())
}
Emit(loc) => {
let _ = ctx.pop_n_latest_exprs(1, loc, self).into_expr_err(loc)?;
Ok(())
Expand Down
Loading