Return constants and sqrt impls separately for individual rendering
This commit is contained in:
@@ -52,14 +52,17 @@ pub fn prime_field(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
|||||||
|
|
||||||
let mut gen = proc_macro2::TokenStream::new();
|
let mut gen = proc_macro2::TokenStream::new();
|
||||||
|
|
||||||
gen.extend(prime_field_repr_impl(&repr_ident, limbs));
|
let (constants_impl, sqrt_impl) = prime_field_constants_and_sqrt(
|
||||||
gen.extend(prime_field_constants_and_sqrt(
|
|
||||||
&ast.ident,
|
&ast.ident,
|
||||||
&repr_ident,
|
&repr_ident,
|
||||||
modulus,
|
modulus,
|
||||||
limbs,
|
limbs,
|
||||||
generator,
|
generator,
|
||||||
));
|
);
|
||||||
|
|
||||||
|
gen.extend(prime_field_repr_impl(&repr_ident, limbs));
|
||||||
|
gen.extend(constants_impl);
|
||||||
|
gen.extend(sqrt_impl);
|
||||||
gen.extend(prime_field_impl(&ast.ident, &repr_ident, limbs));
|
gen.extend(prime_field_impl(&ast.ident, &repr_ident, limbs));
|
||||||
|
|
||||||
// Return the generated impl
|
// Return the generated impl
|
||||||
@@ -398,7 +401,7 @@ fn prime_field_constants_and_sqrt(
|
|||||||
modulus: BigUint,
|
modulus: BigUint,
|
||||||
limbs: usize,
|
limbs: usize,
|
||||||
generator: BigUint,
|
generator: BigUint,
|
||||||
) -> proc_macro2::TokenStream {
|
) -> (proc_macro2::TokenStream, proc_macro2::TokenStream) {
|
||||||
let modulus_num_bits = biguint_num_bits(modulus.clone());
|
let modulus_num_bits = biguint_num_bits(modulus.clone());
|
||||||
|
|
||||||
// The number of bits we should "shave" from a randomly sampled reputation, i.e.,
|
// The number of bits we should "shave" from a randomly sampled reputation, i.e.,
|
||||||
@@ -540,7 +543,7 @@ fn prime_field_constants_and_sqrt(
|
|||||||
}
|
}
|
||||||
inv = inv.wrapping_neg();
|
inv = inv.wrapping_neg();
|
||||||
|
|
||||||
quote! {
|
(quote! {
|
||||||
/// This is the modulus m of the prime field
|
/// This is the modulus m of the prime field
|
||||||
const MODULUS: #repr = #repr([#(#modulus,)*]);
|
const MODULUS: #repr = #repr([#(#modulus,)*]);
|
||||||
|
|
||||||
@@ -569,9 +572,7 @@ fn prime_field_constants_and_sqrt(
|
|||||||
|
|
||||||
/// 2^s root of unity computed by GENERATOR^t
|
/// 2^s root of unity computed by GENERATOR^t
|
||||||
const ROOT_OF_UNITY: #repr = #repr(#root_of_unity);
|
const ROOT_OF_UNITY: #repr = #repr(#root_of_unity);
|
||||||
|
}, sqrt_impl)
|
||||||
#sqrt_impl
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Implement PrimeField for the derived type.
|
/// Implement PrimeField for the derived type.
|
||||||
|
|||||||
Reference in New Issue
Block a user