Skip to content

Commit 6650024

Browse files
Fix the missing parallel feature flag for ark-serialize, take #2 (arkworks-rs#835)
* revert a9b2dea * fix the missing feature flag * add the rayon dependency --------- Co-authored-by: weikengchen <[email protected]>
1 parent 065cd24 commit 6650024

File tree

11 files changed

+43
-51
lines changed

11 files changed

+43
-51
lines changed

bench-templates/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ paste.workspace = true
2828

2929
[features]
3030
asm = [ "ark-ff/asm" ]
31-
parallel = [ "ark-std/parallel", "ark-ff/parallel", "ark-ec/parallel", ]
31+
parallel = [ "ark-std/parallel", "ark-ff/parallel", "ark-ec/parallel", "ark-serialize/parallel" ]

ec/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ hex.workspace = true
4141
[features]
4242
default = []
4343
std = [ "ark-std/std", "ark-ff/std", "ark-serialize/std" ]
44-
parallel = [ "std", "rayon", "ark-std/parallel" ]
44+
parallel = [ "std", "rayon", "ark-std/parallel", "ark-serialize/parallel" ]

ec/src/models/short_weierstrass/group.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,9 @@ impl<P: SWCurveConfig> Valid for Projective<P> {
604604
self.into_affine().check()
605605
}
606606

607-
fn batch_check<'a>(batch: impl Iterator<Item = &'a Self>) -> Result<(), SerializationError>
607+
fn batch_check<'a>(
608+
batch: impl Iterator<Item = &'a Self> + Send,
609+
) -> Result<(), SerializationError>
608610
where
609611
Self: 'a,
610612
{

ec/src/models/twisted_edwards/group.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,9 @@ impl<P: TECurveConfig> Valid for Projective<P> {
457457
self.into_affine().check()
458458
}
459459

460-
fn batch_check<'a>(batch: impl Iterator<Item = &'a Self>) -> Result<(), SerializationError>
460+
fn batch_check<'a>(
461+
batch: impl Iterator<Item = &'a Self> + Send,
462+
) -> Result<(), SerializationError>
461463
where
462464
Self: 'a,
463465
{

ff/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ hex.workspace = true
4444
[features]
4545
default = []
4646
std = [ "ark-std/std", "ark-serialize/std", "itertools/use_std" ]
47-
parallel = [ "std", "rayon", "ark-std/parallel" ]
47+
parallel = [ "std", "rayon", "ark-std/parallel", "ark-serialize/parallel" ]
4848
asm = []

poly/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ criterion = "0.5.1"
3030

3131
[features]
3232
default = []
33-
std = [ "ark-std/std", "ark-ff/std" ]
34-
parallel = [ "std", "ark-ff/parallel", "rayon", "ark-std/parallel" ]
33+
std = [ "ark-std/std", "ark-ff/std", "ark-serialize/std" ]
34+
parallel = [ "std", "ark-ff/parallel", "rayon", "ark-std/parallel", "ark-serialize/parallel" ]
3535

3636

3737
[[bench]]

serialize-derive/src/deserialize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn impl_valid(ast: &syn::DeriveInput) -> TokenStream {
7878
Ok(())
7979
}
8080
#[allow(unused_mut, unused_variables)]
81-
fn batch_check<'a>(batch: impl Iterator<Item = &'a Self> ) -> Result<(), ark_serialize::SerializationError>
81+
fn batch_check<'a>(batch: impl Iterator<Item = &'a Self> + Send) -> Result<(), ark_serialize::SerializationError>
8282
where
8383
Self: 'a
8484
{

serialize/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ark-serialize-derive = { workspace = true, optional = true }
2020
ark-std.workspace = true
2121
digest.workspace = true
2222
num-bigint.workspace = true
23+
rayon = { workspace = true, optional = true }
2324

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

3132
[features]
3233
default = []
33-
std = [ "ark-std/std", ]
34+
parallel = [ "rayon" ]
35+
std = [ "ark-std/std" ]
3436
derive = [ "ark-serialize-derive" ]

serialize/src/impls.rs

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ impl<T: Valid> Valid for Option<T> {
227227
}
228228

229229
#[inline]
230-
fn batch_check<'a>(batch: impl Iterator<Item = &'a Self>) -> Result<(), SerializationError>
230+
fn batch_check<'a>(
231+
batch: impl Iterator<Item = &'a Self> + Send,
232+
) -> Result<(), SerializationError>
231233
where
232234
Self: 'a,
233235
{
@@ -304,34 +306,6 @@ impl<T: CanonicalSerialize + ToOwned> CanonicalSerialize for Rc<T> {
304306
}
305307
}
306308

307-
impl<T: Valid + Sync> Valid for Rc<T> {
308-
#[inline]
309-
fn check(&self) -> Result<(), SerializationError> {
310-
self.as_ref().check()
311-
}
312-
313-
#[inline]
314-
fn batch_check<'a>(batch: impl Iterator<Item = &'a Self>) -> Result<(), SerializationError>
315-
where
316-
Self: 'a,
317-
{
318-
T::batch_check(batch.map(|v| v.as_ref()))
319-
}
320-
}
321-
322-
impl<T: CanonicalDeserialize + Sync> CanonicalDeserialize for Rc<T> {
323-
#[inline]
324-
fn deserialize_with_mode<R: Read>(
325-
reader: R,
326-
compress: Compress,
327-
validate: Validate,
328-
) -> Result<Self, SerializationError> {
329-
Ok(Rc::new(T::deserialize_with_mode(
330-
reader, compress, validate,
331-
)?))
332-
}
333-
}
334-
335309
#[cfg(target_has_atomic = "ptr")]
336310
impl<T: CanonicalSerialize + ToOwned> CanonicalSerialize for ark_std::sync::Arc<T> {
337311
#[inline]
@@ -358,7 +332,9 @@ impl<T: Valid + Sync + Send> Valid for ark_std::sync::Arc<T> {
358332

359333
#[inline]
360334

361-
fn batch_check<'a>(batch: impl Iterator<Item = &'a Self>) -> Result<(), SerializationError>
335+
fn batch_check<'a>(
336+
batch: impl Iterator<Item = &'a Self> + Send,
337+
) -> Result<(), SerializationError>
362338
where
363339
Self: 'a,
364340
{
@@ -410,7 +386,9 @@ where
410386

411387
#[inline]
412388

413-
fn batch_check<'a>(batch: impl Iterator<Item = &'a Self>) -> Result<(), SerializationError>
389+
fn batch_check<'a>(
390+
batch: impl Iterator<Item = &'a Self> + Send,
391+
) -> Result<(), SerializationError>
414392
where
415393
Self: 'a,
416394
{
@@ -463,7 +441,9 @@ impl<T: CanonicalDeserialize, const N: usize> Valid for [T; N] {
463441
}
464442

465443
#[inline]
466-
fn batch_check<'a>(batch: impl Iterator<Item = &'a Self>) -> Result<(), SerializationError>
444+
fn batch_check<'a>(
445+
batch: impl Iterator<Item = &'a Self> + Send,
446+
) -> Result<(), SerializationError>
467447
where
468448
Self: 'a,
469449
{
@@ -511,7 +491,9 @@ impl<T: Valid> Valid for Vec<T> {
511491
}
512492

513493
#[inline]
514-
fn batch_check<'a>(batch: impl Iterator<Item = &'a Self>) -> Result<(), SerializationError>
494+
fn batch_check<'a>(
495+
batch: impl Iterator<Item = &'a Self> + Send,
496+
) -> Result<(), SerializationError>
515497
where
516498
Self: 'a,
517499
{
@@ -605,7 +587,9 @@ impl<T: Valid> Valid for VecDeque<T> {
605587
}
606588

607589
#[inline]
608-
fn batch_check<'a>(batch: impl Iterator<Item = &'a Self>) -> Result<(), SerializationError>
590+
fn batch_check<'a>(
591+
batch: impl Iterator<Item = &'a Self> + Send,
592+
) -> Result<(), SerializationError>
609593
where
610594
Self: 'a,
611595
{
@@ -664,7 +648,9 @@ impl<T: Valid> Valid for LinkedList<T> {
664648
}
665649

666650
#[inline]
667-
fn batch_check<'a>(batch: impl Iterator<Item = &'a Self>) -> Result<(), SerializationError>
651+
fn batch_check<'a>(
652+
batch: impl Iterator<Item = &'a Self> + Send,
653+
) -> Result<(), SerializationError>
668654
where
669655
Self: 'a,
670656
{
@@ -918,7 +904,9 @@ impl<V: Valid> Valid for BTreeSet<V> {
918904
}
919905

920906
#[inline]
921-
fn batch_check<'a>(batch: impl Iterator<Item = &'a Self>) -> Result<(), SerializationError>
907+
fn batch_check<'a>(
908+
batch: impl Iterator<Item = &'a Self> + Send,
909+
) -> Result<(), SerializationError>
922910
where
923911
Self: 'a,
924912
{

serialize/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ pub enum Validate {
6262
No,
6363
}
6464

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

68-
fn batch_check<'a>(batch: impl Iterator<Item = &'a Self>) -> Result<(), SerializationError>
68+
fn batch_check<'a>(
69+
batch: impl Iterator<Item = &'a Self> + Send,
70+
) -> Result<(), SerializationError>
6971
where
7072
Self: 'a,
7173
{

0 commit comments

Comments
 (0)