From da47d7657933d988ee84e5d166f6e0c842b1362b Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Mon, 7 Apr 2025 09:43:19 -0300 Subject: [PATCH 1/2] fix: correct proptest Arbitrary for NumericType --- Cargo.lock | 1 - compiler/noirc_evaluator/Cargo.toml | 1 - compiler/noirc_evaluator/src/ssa/ir/types.rs | 27 +++++++++++++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e95f7831278..73be34e3ff3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3568,7 +3568,6 @@ dependencies = [ "num-traits", "petgraph", "proptest", - "proptest-derive", "rayon", "serde", "serde_json", diff --git a/compiler/noirc_evaluator/Cargo.toml b/compiler/noirc_evaluator/Cargo.toml index 0f558ce8b40..0e11175d0f7 100644 --- a/compiler/noirc_evaluator/Cargo.toml +++ b/compiler/noirc_evaluator/Cargo.toml @@ -35,7 +35,6 @@ petgraph.workspace = true [dev-dependencies] proptest.workspace = true -proptest-derive.workspace = true similar-asserts.workspace = true tracing-test = "0.2.5" num-traits.workspace = true diff --git a/compiler/noirc_evaluator/src/ssa/ir/types.rs b/compiler/noirc_evaluator/src/ssa/ir/types.rs index ed9451f78fc..f6ac5aa5c3e 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/types.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/types.rs @@ -15,7 +15,6 @@ use crate::ssa::ssa_gen::SSA_WORD_SIZE; /// Fields do not have a notion of ordering, so this distinction /// is reasonable. #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Serialize, Deserialize)] -#[cfg_attr(test, derive(proptest_derive::Arbitrary))] pub enum NumericType { Signed { bit_size: u32 }, Unsigned { bit_size: u32 }, @@ -101,6 +100,32 @@ impl NumericType { } } +#[cfg(test)] +mod props { + use proptest::{ + prelude::{Arbitrary, BoxedStrategy, Just, Strategy as _}, + prop_oneof, + }; + + use super::NumericType; + + impl Arbitrary for NumericType { + type Parameters = (); + type Strategy = BoxedStrategy; + + fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { + let signed = prop_oneof!(Just(8), Just(16), Just(32), Just(64)); + let unsigned = prop_oneof!(Just(8), Just(16), Just(32), Just(64), Just(128)); + prop_oneof![ + signed.prop_map(|bit_size| NumericType::Signed { bit_size }), + unsigned.prop_map(|bit_size| NumericType::Unsigned { bit_size }), + Just(NumericType::NativeField), + ] + .boxed() + } + } +} + /// All types representable in the IR. #[derive(Clone, Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Serialize, Deserialize)] pub(crate) enum Type { From b6669b8c800c061227106393ac80b4004967b045 Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Mon, 7 Apr 2025 14:33:57 -0300 Subject: [PATCH 2/2] Add u1 --- compiler/noirc_evaluator/src/ssa/ir/types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/noirc_evaluator/src/ssa/ir/types.rs b/compiler/noirc_evaluator/src/ssa/ir/types.rs index f6ac5aa5c3e..ee1a9d36205 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/types.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/types.rs @@ -115,7 +115,7 @@ mod props { fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { let signed = prop_oneof!(Just(8), Just(16), Just(32), Just(64)); - let unsigned = prop_oneof!(Just(8), Just(16), Just(32), Just(64), Just(128)); + let unsigned = prop_oneof!(Just(1), Just(8), Just(16), Just(32), Just(64), Just(128)); prop_oneof![ signed.prop_map(|bit_size| NumericType::Signed { bit_size }), unsigned.prop_map(|bit_size| NumericType::Unsigned { bit_size }),