Skip to content

Commit

Permalink
Fix the missing parallel feature flag for ark-serialize, take #2 (a…
Browse files Browse the repository at this point in the history
…rkworks-rs#835)

* revert a9b2dea

* fix the missing feature flag

* add the rayon dependency

---------

Co-authored-by: weikengchen <w.k@berkeley.edu>
  • Loading branch information
mmagician and weikengchen authored Jun 19, 2024
1 parent 065cd24 commit 6650024
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 51 deletions.
2 changes: 1 addition & 1 deletion bench-templates/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ paste.workspace = true

[features]
asm = [ "ark-ff/asm" ]
parallel = [ "ark-std/parallel", "ark-ff/parallel", "ark-ec/parallel", ]
parallel = [ "ark-std/parallel", "ark-ff/parallel", "ark-ec/parallel", "ark-serialize/parallel" ]
2 changes: 1 addition & 1 deletion ec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ hex.workspace = true
[features]
default = []
std = [ "ark-std/std", "ark-ff/std", "ark-serialize/std" ]
parallel = [ "std", "rayon", "ark-std/parallel" ]
parallel = [ "std", "rayon", "ark-std/parallel", "ark-serialize/parallel" ]
4 changes: 3 additions & 1 deletion ec/src/models/short_weierstrass/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,9 @@ impl<P: SWCurveConfig> Valid for Projective<P> {
self.into_affine().check()
}

fn batch_check<'a>(batch: impl Iterator<Item = &'a Self>) -> Result<(), SerializationError>
fn batch_check<'a>(
batch: impl Iterator<Item = &'a Self> + Send,
) -> Result<(), SerializationError>
where
Self: 'a,
{
Expand Down
4 changes: 3 additions & 1 deletion ec/src/models/twisted_edwards/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,9 @@ impl<P: TECurveConfig> Valid for Projective<P> {
self.into_affine().check()
}

fn batch_check<'a>(batch: impl Iterator<Item = &'a Self>) -> Result<(), SerializationError>
fn batch_check<'a>(
batch: impl Iterator<Item = &'a Self> + Send,
) -> Result<(), SerializationError>
where
Self: 'a,
{
Expand Down
2 changes: 1 addition & 1 deletion ff/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ hex.workspace = true
[features]
default = []
std = [ "ark-std/std", "ark-serialize/std", "itertools/use_std" ]
parallel = [ "std", "rayon", "ark-std/parallel" ]
parallel = [ "std", "rayon", "ark-std/parallel", "ark-serialize/parallel" ]
asm = []
4 changes: 2 additions & 2 deletions poly/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ criterion = "0.5.1"

[features]
default = []
std = [ "ark-std/std", "ark-ff/std" ]
parallel = [ "std", "ark-ff/parallel", "rayon", "ark-std/parallel" ]
std = [ "ark-std/std", "ark-ff/std", "ark-serialize/std" ]
parallel = [ "std", "ark-ff/parallel", "rayon", "ark-std/parallel", "ark-serialize/parallel" ]


[[bench]]
Expand Down
2 changes: 1 addition & 1 deletion serialize-derive/src/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn impl_valid(ast: &syn::DeriveInput) -> TokenStream {
Ok(())
}
#[allow(unused_mut, unused_variables)]
fn batch_check<'a>(batch: impl Iterator<Item = &'a Self> ) -> Result<(), ark_serialize::SerializationError>
fn batch_check<'a>(batch: impl Iterator<Item = &'a Self> + Send) -> Result<(), ark_serialize::SerializationError>
where
Self: 'a
{
Expand Down
4 changes: 3 additions & 1 deletion serialize/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ark-serialize-derive = { workspace = true, optional = true }
ark-std.workspace = true
digest.workspace = true
num-bigint.workspace = true
rayon = { workspace = true, optional = true }

[dev-dependencies]
sha2.workspace = true
Expand All @@ -30,5 +31,6 @@ ark-test-curves = { workspace = true, default-features = false, features = [ "bl

[features]
default = []
std = [ "ark-std/std", ]
parallel = [ "rayon" ]
std = [ "ark-std/std" ]
derive = [ "ark-serialize-derive" ]
60 changes: 24 additions & 36 deletions serialize/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ impl<T: Valid> Valid for Option<T> {
}

#[inline]
fn batch_check<'a>(batch: impl Iterator<Item = &'a Self>) -> Result<(), SerializationError>
fn batch_check<'a>(
batch: impl Iterator<Item = &'a Self> + Send,
) -> Result<(), SerializationError>
where
Self: 'a,
{
Expand Down Expand Up @@ -304,34 +306,6 @@ impl<T: CanonicalSerialize + ToOwned> CanonicalSerialize for Rc<T> {
}
}

impl<T: Valid + Sync> Valid for Rc<T> {
#[inline]
fn check(&self) -> Result<(), SerializationError> {
self.as_ref().check()
}

#[inline]
fn batch_check<'a>(batch: impl Iterator<Item = &'a Self>) -> Result<(), SerializationError>
where
Self: 'a,
{
T::batch_check(batch.map(|v| v.as_ref()))
}
}

impl<T: CanonicalDeserialize + Sync> CanonicalDeserialize for Rc<T> {
#[inline]
fn deserialize_with_mode<R: Read>(
reader: R,
compress: Compress,
validate: Validate,
) -> Result<Self, SerializationError> {
Ok(Rc::new(T::deserialize_with_mode(
reader, compress, validate,
)?))
}
}

#[cfg(target_has_atomic = "ptr")]
impl<T: CanonicalSerialize + ToOwned> CanonicalSerialize for ark_std::sync::Arc<T> {
#[inline]
Expand All @@ -358,7 +332,9 @@ impl<T: Valid + Sync + Send> Valid for ark_std::sync::Arc<T> {

#[inline]

fn batch_check<'a>(batch: impl Iterator<Item = &'a Self>) -> Result<(), SerializationError>
fn batch_check<'a>(
batch: impl Iterator<Item = &'a Self> + Send,
) -> Result<(), SerializationError>
where
Self: 'a,
{
Expand Down Expand Up @@ -410,7 +386,9 @@ where

#[inline]

fn batch_check<'a>(batch: impl Iterator<Item = &'a Self>) -> Result<(), SerializationError>
fn batch_check<'a>(
batch: impl Iterator<Item = &'a Self> + Send,
) -> Result<(), SerializationError>
where
Self: 'a,
{
Expand Down Expand Up @@ -463,7 +441,9 @@ impl<T: CanonicalDeserialize, const N: usize> Valid for [T; N] {
}

#[inline]
fn batch_check<'a>(batch: impl Iterator<Item = &'a Self>) -> Result<(), SerializationError>
fn batch_check<'a>(
batch: impl Iterator<Item = &'a Self> + Send,
) -> Result<(), SerializationError>
where
Self: 'a,
{
Expand Down Expand Up @@ -511,7 +491,9 @@ impl<T: Valid> Valid for Vec<T> {
}

#[inline]
fn batch_check<'a>(batch: impl Iterator<Item = &'a Self>) -> Result<(), SerializationError>
fn batch_check<'a>(
batch: impl Iterator<Item = &'a Self> + Send,
) -> Result<(), SerializationError>
where
Self: 'a,
{
Expand Down Expand Up @@ -605,7 +587,9 @@ impl<T: Valid> Valid for VecDeque<T> {
}

#[inline]
fn batch_check<'a>(batch: impl Iterator<Item = &'a Self>) -> Result<(), SerializationError>
fn batch_check<'a>(
batch: impl Iterator<Item = &'a Self> + Send,
) -> Result<(), SerializationError>
where
Self: 'a,
{
Expand Down Expand Up @@ -664,7 +648,9 @@ impl<T: Valid> Valid for LinkedList<T> {
}

#[inline]
fn batch_check<'a>(batch: impl Iterator<Item = &'a Self>) -> Result<(), SerializationError>
fn batch_check<'a>(
batch: impl Iterator<Item = &'a Self> + Send,
) -> Result<(), SerializationError>
where
Self: 'a,
{
Expand Down Expand Up @@ -918,7 +904,9 @@ impl<V: Valid> Valid for BTreeSet<V> {
}

#[inline]
fn batch_check<'a>(batch: impl Iterator<Item = &'a Self>) -> Result<(), SerializationError>
fn batch_check<'a>(
batch: impl Iterator<Item = &'a Self> + Send,
) -> Result<(), SerializationError>
where
Self: 'a,
{
Expand Down
6 changes: 4 additions & 2 deletions serialize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ pub enum Validate {
No,
}

pub trait Valid: Sized {
pub trait Valid: Sized + Sync {
fn check(&self) -> Result<(), SerializationError>;

fn batch_check<'a>(batch: impl Iterator<Item = &'a Self>) -> Result<(), SerializationError>
fn batch_check<'a>(
batch: impl Iterator<Item = &'a Self> + Send,
) -> Result<(), SerializationError>
where
Self: 'a,
{
Expand Down
4 changes: 0 additions & 4 deletions serialize/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,6 @@ fn test_bool() {

#[test]
fn test_rc_arc() {
use ark_std::rc::Rc;
test_serialize(Rc::new(Dummy));
test_serialize(Rc::new(10u64));

use ark_std::sync::Arc;
test_serialize(Arc::new(Dummy));
test_serialize(Arc::new(10u64));
Expand Down

0 comments on commit 6650024

Please sign in to comment.