From 723f197d0e954a72de2eb355a62b9f6a484356f9 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Thu, 20 Apr 2023 08:36:54 +0200 Subject: [PATCH] Cleanup --- plonky2/src/gates/gate.rs | 3 ++- plonky2/src/iop/generator.rs | 29 ++++++----------------------- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/plonky2/src/gates/gate.rs b/plonky2/src/gates/gate.rs index 9821106c..43c1179a 100644 --- a/plonky2/src/gates/gate.rs +++ b/plonky2/src/gates/gate.rs @@ -198,6 +198,7 @@ pub trait Gate, const D: usize>: 'static + Send + S } } +/// A wrapper trait over a `Gate`, to allow for gate serialization. pub trait AnyGate, const D: usize>: Gate { fn as_any(&self) -> &dyn Any; } @@ -208,7 +209,7 @@ impl, F: RichField + Extendable, const D: usize> AnyGate } } -/// A wrapper around an `Rc` which implements `PartialEq`, `Eq` and `Hash` based on gate IDs. +/// A wrapper around an `Arc` which implements `PartialEq`, `Eq` and `Hash` based on gate IDs. #[derive(Clone)] pub struct GateRef, const D: usize>(pub(crate) Arc>); diff --git a/plonky2/src/iop/generator.rs b/plonky2/src/iop/generator.rs index 165b5ada..16a23e26 100644 --- a/plonky2/src/iop/generator.rs +++ b/plonky2/src/iop/generator.rs @@ -1,6 +1,5 @@ use alloc::vec; use alloc::vec::Vec; -use core::any::Any; use core::fmt::Debug; use core::marker::PhantomData; @@ -118,33 +117,19 @@ pub trait WitnessGenerator: 'static + Send + Sync + Debug { Self: Sized; } -pub trait AnyWitnessGenerator: WitnessGenerator { - fn as_any(&self) -> &dyn Any; -} - -impl, F: Field> AnyWitnessGenerator for T { - fn as_any(&self) -> &dyn Any { - self - } -} - -/// A wrapper around an `Box`. -pub struct WitnessGeneratorRef(pub Box>); +/// A wrapper around an `Box` which implements `PartialEq` +/// and `Eq` based on generator IDs. +pub struct WitnessGeneratorRef(pub Box>); impl WitnessGeneratorRef { - pub fn new>(generator: G) -> WitnessGeneratorRef { + pub fn new>(generator: G) -> WitnessGeneratorRef { WitnessGeneratorRef(Box::new(generator)) } } impl PartialEq for WitnessGeneratorRef { fn eq(&self, other: &Self) -> bool { - let mut buf1 = Vec::new(); - let mut buf2 = Vec::new(); - self.0.serialize(&mut buf1).unwrap(); - other.0.serialize(&mut buf2).unwrap(); - - buf1 == buf2 + self.0.id() == other.0.id() } } @@ -152,9 +137,7 @@ impl Eq for WitnessGeneratorRef {} impl Debug for WitnessGeneratorRef { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut buf = Vec::new(); - self.0.serialize(&mut buf).unwrap(); - write!(f, "{:?}", buf) + write!(f, "{}", self.0.id()) } }