From 6edbd31330e153dc4f8398ae3c48428b67992d0f Mon Sep 17 00:00:00 2001 From: Grant Wuerker Date: Tue, 27 Jul 2021 13:44:13 -0600 Subject: [PATCH] cleanup --- crates/yulgen/src/mappers/functions.rs | 6 +++--- crates/yulgen/src/operations/mod.rs | 2 +- crates/yulgen/src/operations/revert.rs | 10 +++++++--- crates/yulgen/src/runtime/functions/abi.rs | 10 +++++++--- crates/yulgen/src/runtime/functions/revert.rs | 6 ++---- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/crates/yulgen/src/mappers/functions.rs b/crates/yulgen/src/mappers/functions.rs index 44c269d6be..bb4a5db9b3 100644 --- a/crates/yulgen/src/mappers/functions.rs +++ b/crates/yulgen/src/mappers/functions.rs @@ -3,10 +3,10 @@ use crate::mappers::{assignments, declarations, expressions}; use crate::names; use crate::operations::data as data_operations; use crate::operations::revert as revert_operations; -use crate::types::{AbiType, EvmSized, to_abi_types}; +use crate::types::{AbiType, EvmSized}; use crate::Context; use fe_analyzer::context::ExpressionAttributes; -use fe_analyzer::namespace::types::{FixedSize, Type}; +use fe_analyzer::namespace::types::Type; use fe_parser::ast as fe; use fe_parser::node::Node; use yultsur::*; @@ -135,7 +135,7 @@ fn revert(context: &mut Context, stmt: &Node) -> yul::Statement { revert_operations::revert( &_struct.name, &AbiType::from(_struct), - expressions::expr(context, error_expr) + expressions::expr(context, error_expr), ) } else { panic!("trying to revert with non-struct expression") diff --git a/crates/yulgen/src/operations/mod.rs b/crates/yulgen/src/operations/mod.rs index 83ef64ade4..2b80b29af2 100644 --- a/crates/yulgen/src/operations/mod.rs +++ b/crates/yulgen/src/operations/mod.rs @@ -1,5 +1,5 @@ pub mod abi; pub mod contracts; pub mod data; +pub mod revert; pub mod structs; -pub mod revert; \ No newline at end of file diff --git a/crates/yulgen/src/operations/revert.rs b/crates/yulgen/src/operations/revert.rs index 60e51aa7c4..722600cd1d 100644 --- a/crates/yulgen/src/operations/revert.rs +++ b/crates/yulgen/src/operations/revert.rs @@ -1,5 +1,5 @@ -use crate::types::AbiType; use crate::names; +use crate::types::AbiType; use yultsur::*; // this is more of an assert operation @@ -8,10 +8,14 @@ pub fn error_revert(typ: &AbiType, msg: yul::Expression) -> yul::Statement { } pub fn panic_revert(val: usize) -> yul::Statement { - revert("Panic", &AbiType::Uint { size: 32 }, literal_expression! { (val) }) + revert( + "Panic", + &AbiType::Uint { size: 32 }, + literal_expression! { (val) }, + ) } pub fn revert(name: &str, typ: &AbiType, val: yul::Expression) -> yul::Statement { let func_name = names::revert(name, typ); statement! { [func_name]([val]) } -} \ No newline at end of file +} diff --git a/crates/yulgen/src/runtime/functions/abi.rs b/crates/yulgen/src/runtime/functions/abi.rs index 9822ae2db4..a59a5c09a4 100644 --- a/crates/yulgen/src/runtime/functions/abi.rs +++ b/crates/yulgen/src/runtime/functions/abi.rs @@ -1,15 +1,20 @@ use crate::constants::PANIC_INVALID_ABI_DATA; use crate::names::abi as abi_names; use crate::operations::abi as abi_operations; -use crate::operations::revert as revert_operations; use crate::operations::abi::EncodingSize; +use crate::operations::revert as revert_operations; use crate::types::{AbiDecodeLocation, AbiType}; use crate::utils::ceil_32; use yultsur::*; /// Return all abi runtime functions pub fn all() -> Vec { - vec![unpack(), is_left_padded(), is_right_padded(), encode(vec![AbiType::Uint { size: 32 }])] + vec![ + unpack(), + is_left_padded(), + is_right_padded(), + encode(vec![AbiType::Uint { size: 32 }]), + ] } /// Creates a batch of encoding function for the given type arrays. @@ -43,7 +48,6 @@ pub fn batch_decode(data_batch: Vec<(Vec, AbiDecodeLocation)>) -> Vec = component_batch .into_iter() .map(|(typ, location)| { - let typ: AbiType = typ.into(); let top_function = decode_component(&typ, location); let inner_functions = match &typ { diff --git a/crates/yulgen/src/runtime/functions/revert.rs b/crates/yulgen/src/runtime/functions/revert.rs index d1f9d9e4f7..ea3cf82f8f 100644 --- a/crates/yulgen/src/runtime/functions/revert.rs +++ b/crates/yulgen/src/runtime/functions/revert.rs @@ -1,8 +1,6 @@ use crate::names; -use crate::names::abi as abi_names; use crate::operations::abi as abi_operations; -use crate::types::{to_abi_selector_names, AbiType, to_abi_types}; -use fe_analyzer::namespace::types::Struct; +use crate::types::{to_abi_selector_names, AbiType}; use yultsur::*; /// Generate a YUL function to revert with the `Error` signature and the @@ -26,7 +24,7 @@ pub fn revert(name: &str, typ: &AbiType) -> yul::Statement { let selector = { let selector_params = match typ.clone() { AbiType::Tuple { components } => components, - typ => vec![typ] + typ => vec![typ], }; let selector = fe_abi::utils::func_selector(name, &to_abi_selector_names(&selector_params)); literal_expression! { (selector) }