Skip to content

Commit

Permalink
Cleanup alloc / std imports for plonky2 (0xPolygonZero#1518)
Browse files Browse the repository at this point in the history
* Cleanup alloc/std versions for plonky2

* Fix import for macro
  • Loading branch information
Nashtare authored Feb 10, 2024
1 parent 6b39fc9 commit b600142
Show file tree
Hide file tree
Showing 71 changed files with 235 additions and 152 deletions.
5 changes: 5 additions & 0 deletions plonky2/examples/bench_recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
// put it in `src/bin/`, but then we wouldn't have access to
// `[dev-dependencies]`.

#[cfg(not(feature = "std"))]
extern crate alloc;

#[cfg(not(feature = "std"))]
use alloc::sync::Arc;
use core::num::ParseIntError;
use core::ops::RangeInclusive;
use core::str::FromStr;
#[cfg(feature = "std")]
use std::sync::Arc;

use anyhow::{anyhow, Context as _, Result};
use itertools::Itertools;
Expand Down
1 change: 1 addition & 0 deletions plonky2/src/fri/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! It provides both a native implementation and an in-circuit version
//! of the FRI verifier for recursive proof composition.
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

use serde::Serialize;
Expand Down
4 changes: 2 additions & 2 deletions plonky2/src/fri/oracle.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloc::format;
use alloc::vec::Vec;
#[cfg(not(feature = "std"))]
use alloc::{format, vec::Vec};

use itertools::Itertools;
use plonky2_field::types::Field;
Expand Down
4 changes: 2 additions & 2 deletions plonky2/src/fri/proof.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloc::vec;
use alloc::vec::Vec;
#[cfg(not(feature = "std"))]
use alloc::{vec, vec::Vec};

use hashbrown::HashMap;
use itertools::izip;
Expand Down
1 change: 1 addition & 0 deletions plonky2/src/fri/prover.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

use plonky2_maybe_rayon::*;
Expand Down
4 changes: 2 additions & 2 deletions plonky2/src/fri/recursive_verifier.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloc::format;
use alloc::vec::Vec;
#[cfg(not(feature = "std"))]
use alloc::{format, vec::Vec};

use itertools::Itertools;

Expand Down
4 changes: 2 additions & 2 deletions plonky2/src/fri/reduction_strategies.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloc::vec;
use alloc::vec::Vec;
#[cfg(not(feature = "std"))]
use alloc::{vec, vec::Vec};

use log::debug;
use serde::Serialize;
Expand Down
1 change: 1 addition & 0 deletions plonky2/src/fri/structure.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Information about the structure of a FRI instance, in terms of the oracles and polynomials
//! involved, and the points they are opened at.
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use core::ops::Range;

Expand Down
1 change: 1 addition & 0 deletions plonky2/src/fri/verifier.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

use anyhow::{ensure, Result};
Expand Down
9 changes: 6 additions & 3 deletions plonky2/src/gadgets/arithmetic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use alloc::string::{String, ToString};
use alloc::vec;
use alloc::vec::Vec;
#[cfg(not(feature = "std"))]
use alloc::{
string::{String, ToString},
vec,
vec::Vec,
};
use core::borrow::Borrow;

use crate::field::extension::Extendable;
Expand Down
9 changes: 6 additions & 3 deletions plonky2/src/gadgets/arithmetic_extension.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use alloc::string::{String, ToString};
use alloc::vec;
use alloc::vec::Vec;
#[cfg(not(feature = "std"))]
use alloc::{
string::{String, ToString},
vec,
vec::Vec,
};
use core::borrow::Borrow;

use crate::field::extension::{Extendable, FieldExtension, OEF};
Expand Down
1 change: 1 addition & 0 deletions plonky2/src/gadgets/interpolation.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(not(feature = "std"))]
use alloc::vec;

use plonky2_field::extension::Extendable;
Expand Down
4 changes: 2 additions & 2 deletions plonky2/src/gadgets/lookup.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloc::borrow::ToOwned;
use alloc::vec;
#[cfg(not(feature = "std"))]
use alloc::{borrow::ToOwned, vec};

use crate::field::extension::Extendable;
use crate::gates::lookup::LookupGate;
Expand Down
1 change: 1 addition & 0 deletions plonky2/src/gadgets/polynomial.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

use crate::field::extension::Extendable;
Expand Down
1 change: 1 addition & 0 deletions plonky2/src/gadgets/random_access.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

use crate::field::extension::Extendable;
Expand Down
9 changes: 6 additions & 3 deletions plonky2/src/gadgets/range_check.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use alloc::string::{String, ToString};
use alloc::vec;
use alloc::vec::Vec;
#[cfg(not(feature = "std"))]
use alloc::{
string::{String, ToString},
vec,
vec::Vec,
};

use crate::field::extension::Extendable;
use crate::hash::hash_types::RichField;
Expand Down
5 changes: 2 additions & 3 deletions plonky2/src/gadgets/split_base.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use alloc::string::String;
use alloc::vec::Vec;
use alloc::{format, vec};
#[cfg(not(feature = "std"))]
use alloc::{format, string::String, vec, vec::Vec};
use core::borrow::Borrow;

use itertools::Itertools;
Expand Down
9 changes: 6 additions & 3 deletions plonky2/src/gadgets/split_join.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use alloc::string::{String, ToString};
use alloc::vec;
use alloc::vec::Vec;
#[cfg(not(feature = "std"))]
use alloc::{
string::{String, ToString},
vec,
vec::Vec,
};

use crate::field::extension::Extendable;
use crate::gates::base_sum::BaseSumGate;
Expand Down
9 changes: 6 additions & 3 deletions plonky2/src/gates/arithmetic_base.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use alloc::format;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
#[cfg(not(feature = "std"))]
use alloc::{
format,
string::{String, ToString},
vec::Vec,
};

use crate::field::extension::Extendable;
use crate::field::packed::PackedField;
Expand Down
9 changes: 6 additions & 3 deletions plonky2/src/gates/arithmetic_extension.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use alloc::format;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
#[cfg(not(feature = "std"))]
use alloc::{
format,
string::{String, ToString},
vec::Vec,
};
use core::ops::Range;

use crate::field::extension::{Extendable, FieldExtension};
Expand Down
5 changes: 2 additions & 3 deletions plonky2/src/gates/base_sum.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use alloc::string::String;
use alloc::vec::Vec;
use alloc::{format, vec};
#[cfg(not(feature = "std"))]
use alloc::{format, string::String, vec, vec::Vec};
use core::ops::Range;

use crate::field::extension::Extendable;
Expand Down
5 changes: 2 additions & 3 deletions plonky2/src/gates/constant.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use alloc::string::String;
use alloc::vec::Vec;
use alloc::{format, vec};
#[cfg(not(feature = "std"))]
use alloc::{format, string::String, vec, vec::Vec};

use serde::{Deserialize, Serialize};

Expand Down
10 changes: 7 additions & 3 deletions plonky2/src/gates/coset_interpolation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use alloc::{format, vec};
#[cfg(not(feature = "std"))]
use alloc::{
format,
string::{String, ToString},
vec,
vec::Vec,
};
use core::marker::PhantomData;
use core::ops::Range;

Expand Down
10 changes: 7 additions & 3 deletions plonky2/src/gates/exponentiation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use alloc::{format, vec};
#[cfg(not(feature = "std"))]
use alloc::{
format,
string::{String, ToString},
vec,
vec::Vec,
};
use core::marker::PhantomData;

use crate::field::extension::Extendable;
Expand Down
8 changes: 4 additions & 4 deletions plonky2/src/gates/gate.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use alloc::string::String;
use alloc::sync::Arc;
use alloc::vec;
use alloc::vec::Vec;
#[cfg(not(feature = "std"))]
use alloc::{string::String, sync::Arc, vec, vec::Vec};
use core::any::Any;
use core::fmt::{Debug, Error, Formatter};
use core::hash::{Hash, Hasher};
use core::ops::Range;
#[cfg(feature = "std")]
use std::sync::Arc;

use hashbrown::HashMap;
use serde::{Serialize, Serializer};
Expand Down
4 changes: 2 additions & 2 deletions plonky2/src/gates/gate_testing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloc::vec;
use alloc::vec::Vec;
#[cfg(not(feature = "std"))]
use alloc::{vec, vec::Vec};

use anyhow::{ensure, Result};

Expand Down
10 changes: 7 additions & 3 deletions plonky2/src/gates/lookup.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use alloc::{format, vec};
#[cfg(not(feature = "std"))]
use alloc::{
format,
string::{String, ToString},
vec,
vec::Vec,
};
use core::usize;

use itertools::Itertools;
Expand Down
14 changes: 10 additions & 4 deletions plonky2/src/gates/lookup_table.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
use alloc::string::{String, ToString};
use alloc::sync::Arc;
use alloc::vec::Vec;
use alloc::{format, vec};
#[cfg(not(feature = "std"))]
use alloc::{
format,
string::{String, ToString},
sync::Arc,
vec,
vec::Vec,
};
use core::usize;
#[cfg(feature = "std")]
use std::sync::Arc;

use itertools::Itertools;
use keccak_hash::keccak;
Expand Down
9 changes: 6 additions & 3 deletions plonky2/src/gates/multiplication_extension.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use alloc::format;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
#[cfg(not(feature = "std"))]
use alloc::{
format,
string::{String, ToString},
vec::Vec,
};
use core::ops::Range;

use crate::field::extension::{Extendable, FieldExtension};
Expand Down
4 changes: 2 additions & 2 deletions plonky2/src/gates/noop.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloc::string::String;
use alloc::vec::Vec;
#[cfg(not(feature = "std"))]
use alloc::{string::String, vec::Vec};

use crate::field::extension::Extendable;
use crate::gates::gate::Gate;
Expand Down
4 changes: 2 additions & 2 deletions plonky2/src/gates/packed_util.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloc::vec;
use alloc::vec::Vec;
#[cfg(not(feature = "std"))]
use alloc::{vec, vec::Vec};

use crate::field::extension::Extendable;
use crate::field::packable::Packable;
Expand Down
23 changes: 10 additions & 13 deletions plonky2/src/gates/poseidon.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use alloc::{format, vec};
#[cfg(not(feature = "std"))]
use alloc::{
format,
string::{String, ToString},
vec,
vec::Vec,
};
use core::marker::PhantomData;

use crate::field::extension::Extendable;
Expand Down Expand Up @@ -532,20 +536,13 @@ impl<F: RichField + Extendable<D> + Poseidon, const D: usize> SimpleGenerator<F,

#[cfg(test)]
mod tests {
#[cfg(not(feature = "std"))]
use alloc::{vec, vec::Vec};

use anyhow::Result;
use plonky2_field::goldilocks_field::GoldilocksField;

use crate::field::goldilocks_field::GoldilocksField;
use crate::field::types::Field;
use super::*;
use crate::gates::gate_testing::{test_eval_fns, test_low_degree};
use crate::gates::poseidon::PoseidonGate;
use crate::hash::poseidon::{Poseidon, SPONGE_WIDTH};
use crate::iop::generator::generate_partial_witness;
use crate::iop::wire::Wire;
use crate::iop::witness::{PartialWitness, Witness, WitnessWrite};
use crate::plonk::circuit_builder::CircuitBuilder;
use crate::iop::witness::PartialWitness;
use crate::plonk::circuit_data::CircuitConfig;
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};

Expand Down
10 changes: 7 additions & 3 deletions plonky2/src/gates/poseidon_mds.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use alloc::{format, vec};
#[cfg(not(feature = "std"))]
use alloc::{
format,
string::{String, ToString},
vec,
vec::Vec,
};
use core::marker::PhantomData;
use core::ops::Range;

Expand Down
4 changes: 2 additions & 2 deletions plonky2/src/gates/public_input.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloc::string::String;
use alloc::vec::Vec;
#[cfg(not(feature = "std"))]
use alloc::{string::String, vec::Vec};
use core::ops::Range;

use crate::field::extension::Extendable;
Expand Down
10 changes: 7 additions & 3 deletions plonky2/src/gates/random_access.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use alloc::{format, vec};
#[cfg(not(feature = "std"))]
use alloc::{
format,
string::{String, ToString},
vec,
vec::Vec,
};
use core::marker::PhantomData;

use itertools::Itertools;
Expand Down
Loading

0 comments on commit b600142

Please sign in to comment.