Skip to content

Commit

Permalink
Derive PartialEq, Eq for ExecutionError (#1145)
Browse files Browse the repository at this point in the history
* Derive `PartialEq, Eq` for `ExecutionError`

* clippy
  • Loading branch information
plafer authored Nov 9, 2023
1 parent 01ee16a commit ed0e870
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 28 deletions.
4 changes: 3 additions & 1 deletion assembly/src/ast/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ impl ModuleImports {
/// Look up the actual procedure name and module path associated with the given [ProcedureId],
/// if that procedure was imported and invoked in the current module.
pub fn get_procedure_info(&self, id: &ProcedureId) -> Option<(&ProcedureName, &LibraryPath)> {
self.invoked_procs.get(id).map(|(name, path)| (name, path))
self.invoked_procs
.get(id)
.map(|invoked_proc| (&invoked_proc.0, &invoked_proc.1))
}

/// Look up the procedure name associated with the given [ProcedureId],
Expand Down
2 changes: 1 addition & 1 deletion core/src/program/blocks/call_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::utils::to_hex;
/// > hash(fn_hash || padding, domain=SYSCALL_DOMAIN) # when a syscall is used
///
/// Where `fn_hash` is 4 field elements (256 bits), and `padding` is 4 ZERO elements (256 bits).
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Call {
hash: Digest,
fn_hash: Digest,
Expand Down
2 changes: 1 addition & 1 deletion core/src/program/blocks/dyn_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const DYN_CONSTANT: Digest = Digest::new([
/// affect the representation of the Dyn block. Therefore all Dyn blocks are represented by the same
/// constant (rather than by unique hashes), which is computed as an RPO hash of two empty words
/// ([ZERO, ZERO, ZERO, ZERO]) with a domain value of `DYN_DOMAIN`.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Dyn {}

impl Dyn {
Expand Down
2 changes: 1 addition & 1 deletion core/src/program/blocks/join_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use super::{fmt, hasher, Box, CodeBlock, Digest, Felt, Operation};
/// > hash(left_block_hash || right_block_hash, domain=JOIN_DOMAIN)
///
/// Where `left_block_hash` and `right_block_hash` are 4 field elements (256 bits) each.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Join {
body: Box<[CodeBlock; 2]>,
hash: Digest,
Expand Down
2 changes: 1 addition & 1 deletion core/src/program/blocks/loop_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::{fmt, hasher, Box, CodeBlock, Digest, Felt, Operation};
/// > hash(body_hash || padding, domain=LOOP_DOMAIN)
///
/// Where `body_hash` is 4 field elements (256 bits), and `padding` is 4 ZERO elements (256 bits).
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Loop {
body: Box<CodeBlock>,
hash: Digest,
Expand Down
2 changes: 1 addition & 1 deletion core/src/program/blocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub use split_block::Split;
// PROGRAM BLOCK
// ================================================================================================
/// TODO: add comments
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum CodeBlock {
Span(Span),
Join(Join),
Expand Down
2 changes: 1 addition & 1 deletion core/src/program/blocks/proxy_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::{fmt, Digest};
/// of the program secret. Fails if executed.
///
/// Hash of a proxy block is not computed but is rather defined at instantiation time.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Proxy {
hash: Digest,
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/program/blocks/span_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const MAX_OPS_PER_BATCH: usize = GROUP_SIZE * BATCH_SIZE;
///
/// Where `batches` is the concatenation of each `batch` in the span, and each batch is 8 field
/// elements (512 bits).
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Span {
op_batches: Vec<OpBatch>,
hash: Digest,
Expand Down Expand Up @@ -170,7 +170,7 @@ impl fmt::Display for Span {
///
/// An operation batch consists of up to 8 operation groups, with each group containing up to 9
/// operations or a single immediate value.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct OpBatch {
ops: Vec<Operation>,
groups: [Felt; BATCH_SIZE],
Expand Down
2 changes: 1 addition & 1 deletion core/src/program/blocks/split_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::{fmt, hasher, Box, CodeBlock, Digest, Felt, Operation};
/// > hash(true_branch_hash || false_branch_hash, domain=SPLIT_DOMAIN)
///
/// Where `true_branch_hash` and `false_branch_hash` are 4 field elements (256 bits) each.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Split {
branches: Box<[CodeBlock; 2]>,
hash: Digest,
Expand Down
10 changes: 2 additions & 8 deletions core/src/stack/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,8 @@ impl StackInputs {
where
I: IntoIterator<Item = u64>,
{
iter.into_iter()
.map(|v| {
Felt::try_from(v).map_err(|_| {
InputError::NotFieldElement(v, "the provided value isn't a valid field element")
})
})
.collect::<Result<Vec<_>, _>>()
.map(Self::new)
let values: Vec<Felt> = iter.into_iter().map(Felt::from).collect();
Ok(Self::new(values))
}

// PUBLIC ACCESSORS
Expand Down
4 changes: 2 additions & 2 deletions processor/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::error::Error;
// EXECUTION ERROR
// ================================================================================================

#[derive(Debug)]
#[derive(Debug, PartialEq, Eq)]
pub enum ExecutionError {
AdviceMapKeyNotFound(Word),
AdviceMapValueInvalidLength(Word, usize, usize),
Expand Down Expand Up @@ -169,7 +169,7 @@ impl From<Ext2InttError> for ExecutionError {
// EXT2INTT ERROR
// ================================================================================================

#[derive(Debug)]
#[derive(Debug, PartialEq, Eq)]
pub enum Ext2InttError {
DomainSizeNotPowerOf2(u64),
DomainSizeTooSmall(u64),
Expand Down
9 changes: 1 addition & 8 deletions processor/src/host/advice/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,7 @@ impl AdviceInputs {
where
I: IntoIterator<Item = u64>,
{
let stack = iter
.into_iter()
.map(|v| {
Felt::try_from(v).map_err(|_| {
InputError::NotFieldElement(v, "the provided value isn't a valid field element")
})
})
.collect::<Result<Vec<_>, _>>()?;
let stack = iter.into_iter().map(Felt::from);
self.stack.extend(stack);
Ok(self)
}
Expand Down

0 comments on commit ed0e870

Please sign in to comment.