Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Commit 902040e

Browse files
authored
derive traits instead of implementing them (#1403)
1 parent e319bee commit 902040e

File tree

1 file changed

+4
-84
lines changed

1 file changed

+4
-84
lines changed

bus-mapping/src/circuit_input_builder/execution.rs

Lines changed: 4 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
//! Execution step related module.
22
3-
use std::{
4-
marker::PhantomData,
5-
ops::{Add, Mul, Neg},
6-
};
3+
use std::ops::{Add, Mul, Neg};
74

85
use crate::{
96
circuit_input_builder::CallContext,
@@ -27,6 +24,7 @@ use halo2_proofs::{
2724
},
2825
plonk::Expression,
2926
};
27+
use strum_macros::EnumIter;
3028

3129
/// An execution step of the EVM.
3230
#[derive(Clone, Debug)]
@@ -206,14 +204,15 @@ impl ExecState {
206204
}
207205

208206
/// Defines the various source/destination types for a copy event.
209-
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
207+
#[derive(Clone, Copy, Debug, PartialEq, Eq, EnumIter, Default)]
210208
pub enum CopyDataType {
211209
/// When we need to pad the Copy rows of the circuit up to a certain maximum
212210
/// with rows that are not "useful".
213211
Padding,
214212
/// When the source for the copy event is the bytecode table.
215213
Bytecode,
216214
/// When the source/destination for the copy event is memory.
215+
#[default]
217216
Memory,
218217
/// When the source for the copy event is tx's calldata.
219218
TxCalldata,
@@ -235,79 +234,6 @@ impl CopyDataType {
235234
/// How many bits are necessary to represent a copy data type.
236235
pub const N_BITS: usize = 3usize;
237236
}
238-
const NUM_COPY_DATA_TYPES: usize = 8usize;
239-
pub struct CopyDataTypeIter {
240-
idx: usize,
241-
back_idx: usize,
242-
marker: PhantomData<()>,
243-
}
244-
impl CopyDataTypeIter {
245-
fn get(&self, idx: usize) -> Option<CopyDataType> {
246-
match idx {
247-
0usize => Some(CopyDataType::Padding),
248-
1usize => Some(CopyDataType::Bytecode),
249-
2usize => Some(CopyDataType::Memory),
250-
3usize => Some(CopyDataType::TxCalldata),
251-
4usize => Some(CopyDataType::TxLog),
252-
5usize => Some(CopyDataType::RlcAcc),
253-
6usize => Some(CopyDataType::AccessListAddresses),
254-
7usize => Some(CopyDataType::AccessListStorageKeys),
255-
_ => None,
256-
}
257-
}
258-
}
259-
impl strum::IntoEnumIterator for CopyDataType {
260-
type Iterator = CopyDataTypeIter;
261-
fn iter() -> CopyDataTypeIter {
262-
CopyDataTypeIter {
263-
idx: 0,
264-
back_idx: 0,
265-
marker: PhantomData,
266-
}
267-
}
268-
}
269-
impl Iterator for CopyDataTypeIter {
270-
type Item = CopyDataType;
271-
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
272-
#[allow(clippy::iter_nth_zero)]
273-
self.nth(0)
274-
}
275-
fn size_hint(&self) -> (usize, Option<usize>) {
276-
let t = if self.idx + self.back_idx >= NUM_COPY_DATA_TYPES {
277-
0
278-
} else {
279-
NUM_COPY_DATA_TYPES - self.idx - self.back_idx
280-
};
281-
(t, Some(t))
282-
}
283-
fn nth(&mut self, n: usize) -> Option<<Self as Iterator>::Item> {
284-
let idx = self.idx + n + 1;
285-
if idx + self.back_idx > NUM_COPY_DATA_TYPES {
286-
self.idx = NUM_COPY_DATA_TYPES;
287-
None
288-
} else {
289-
self.idx = idx;
290-
self.get(idx - 1)
291-
}
292-
}
293-
}
294-
impl ExactSizeIterator for CopyDataTypeIter {
295-
fn len(&self) -> usize {
296-
self.size_hint().0
297-
}
298-
}
299-
impl DoubleEndedIterator for CopyDataTypeIter {
300-
fn next_back(&mut self) -> Option<<Self as Iterator>::Item> {
301-
let back_idx = self.back_idx + 1;
302-
if self.idx + back_idx > NUM_COPY_DATA_TYPES {
303-
self.back_idx = NUM_COPY_DATA_TYPES;
304-
None
305-
} else {
306-
self.back_idx = back_idx;
307-
self.get(NUM_COPY_DATA_TYPES - self.back_idx)
308-
}
309-
}
310-
}
311237

312238
impl From<CopyDataType> for usize {
313239
fn from(t: CopyDataType) -> Self {
@@ -339,12 +265,6 @@ impl From<&CopyDataType> for u64 {
339265
}
340266
}
341267

342-
impl Default for CopyDataType {
343-
fn default() -> Self {
344-
Self::Memory
345-
}
346-
}
347-
348268
impl_expr!(CopyDataType, u64::from);
349269

350270
/// Defines a single copy step in a copy event. This type is unified over the

0 commit comments

Comments
 (0)