Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the missing parallel feature flag for ark-serialize, take #2 #835

Merged
merged 3 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
revert a9b2dea
  • Loading branch information
mmagician committed Jun 19, 2024
commit de7fc41723eca3097810293404007b6592c60fa6
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 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
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