diff --git a/hugr/src/hugr/serialize/test.rs b/hugr/src/hugr/serialize/test.rs index 630dc352e..069740459 100644 --- a/hugr/src/hugr/serialize/test.rs +++ b/hugr/src/hugr/serialize/test.rs @@ -180,8 +180,6 @@ pub fn check_hugr_roundtrip(hugr: &Hugr, check_schema: bool) -> Hugr { new_hugr } -// for now this is only used in property testing, so otherwise configured out to -// avoid unused warnings. fn check_testing_roundtrip(t: impl Into) { let before = Versioned::new(t.into()); let after_strict = ser_roundtrip_validate(&before, Some(&TESTING_SCHEMA_STRICT)); diff --git a/hugr/src/ops/custom.rs b/hugr/src/ops/custom.rs index 9ca0223ed..31248385f 100644 --- a/hugr/src/ops/custom.rs +++ b/hugr/src/ops/custom.rs @@ -1,8 +1,12 @@ //! Extensible operations. -use smol_str::SmolStr; use std::sync::Arc; use thiserror::Error; +#[cfg(test)] +use { + crate::proptest::{any_nonempty_smolstr, any_nonempty_string}, + ::proptest_derive::Arbitrary, +}; use crate::extension::{ConstFoldResult, ExtensionId, ExtensionRegistry, OpDef, SignatureError}; use crate::hugr::hugrmut::sealed::HugrMutInternals; @@ -268,12 +272,12 @@ impl DataflowOpTrait for ExtensionOp { /// An opaquely-serialized op that refers to an as-yet-unresolved [`OpDef`] #[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] -#[cfg_attr(test, derive(proptest_derive::Arbitrary))] +#[cfg_attr(test, derive(Arbitrary))] pub struct OpaqueOp { extension: ExtensionId, - #[cfg_attr(test, proptest(strategy = "crate::proptest::any_nonempty_smolstr()"))] - op_name: SmolStr, - #[cfg_attr(test, proptest(strategy = "crate::proptest::any_nonempty_string()"))] + #[cfg_attr(test, proptest(strategy = "any_nonempty_smolstr()"))] + op_name: OpName, + #[cfg_attr(test, proptest(strategy = "any_nonempty_string()"))] description: String, // cache in advance so description() can return &str args: Vec, signature: FunctionType, diff --git a/hugr/src/ops/dataflow.rs b/hugr/src/ops/dataflow.rs index eacf664c3..54202ffc0 100644 --- a/hugr/src/ops/dataflow.rs +++ b/hugr/src/ops/dataflow.rs @@ -7,6 +7,9 @@ use crate::ops::StaticTag; use crate::types::{EdgeKind, FunctionType, PolyFuncType, Type, TypeArg, TypeRow}; use crate::IncomingPort; +#[cfg(test)] +use ::proptest_derive::Arbitrary; + pub(crate) trait DataflowOpTrait { const TAG: OpTag; fn description(&self) -> &str; @@ -51,7 +54,7 @@ pub trait IOTrait { /// An input node. /// The outputs of this node are the inputs to the function. #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] -#[cfg_attr(test, derive(proptest_derive::Arbitrary))] +#[cfg_attr(test, derive(Arbitrary))] pub struct Input { /// Input value types pub types: TypeRow, @@ -69,7 +72,7 @@ impl IOTrait for Input { /// An output node. The inputs are the outputs of the function. #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] -#[cfg_attr(test, derive(proptest_derive::Arbitrary))] +#[cfg_attr(test, derive(Arbitrary))] pub struct Output { /// Output value types pub types: TypeRow, @@ -153,7 +156,7 @@ impl StaticTag for T { /// The port immediately following those those is connected to the def/declare /// block with a [`EdgeKind::Function`] edge. #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] -#[cfg_attr(test, derive(proptest_derive::Arbitrary))] +#[cfg_attr(test, derive(Arbitrary))] pub struct Call { /// Signature of function being called func_sig: PolyFuncType, @@ -247,7 +250,7 @@ impl Call { /// Call a function indirectly. Like call, but the function input is a value /// (runtime, not static) dataflow edge, and thus does not need any type-args. #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] -#[cfg_attr(test, derive(proptest_derive::Arbitrary))] +#[cfg_attr(test, derive(Arbitrary))] pub struct CallIndirect { /// Signature of function being called pub signature: FunctionType, @@ -272,7 +275,7 @@ impl DataflowOpTrait for CallIndirect { /// Load a static constant in to the local dataflow graph. #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] -#[cfg_attr(test, derive(proptest_derive::Arbitrary))] +#[cfg_attr(test, derive(Arbitrary))] pub struct LoadConstant { /// Constant type pub datatype: Type, @@ -323,7 +326,7 @@ impl LoadConstant { /// Load a static function in to the local dataflow graph. #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] -#[cfg_attr(test, derive(proptest_derive::Arbitrary))] +#[cfg_attr(test, derive(Arbitrary))] pub struct LoadFunction { /// Signature of the function func_sig: PolyFuncType, @@ -410,7 +413,7 @@ pub trait DataflowParent { /// A simply nested dataflow graph. #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] -#[cfg_attr(test, derive(proptest_derive::Arbitrary))] +#[cfg_attr(test, derive(Arbitrary))] pub struct DFG { /// Signature of DFG node pub signature: FunctionType, diff --git a/hugr/src/ops/module.rs b/hugr/src/ops/module.rs index 1e5450fa8..40c189b68 100644 --- a/hugr/src/ops/module.rs +++ b/hugr/src/ops/module.rs @@ -1,6 +1,11 @@ //! Module-level operations use smol_str::SmolStr; +#[cfg(test)] +use { + crate::proptest::{any_nonempty_smolstr, any_nonempty_string}, + ::proptest_derive::Arbitrary, +}; use crate::types::{EdgeKind, FunctionType, PolyFuncType}; use crate::types::{Type, TypeBound}; @@ -11,7 +16,7 @@ use super::{impl_op_name, OpTag, OpTrait}; /// The root of a module, parent of all other `OpType`s. #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] -#[cfg_attr(test, derive(proptest_derive::Arbitrary))] +#[cfg_attr(test, derive(Arbitrary))] pub struct Module; impl_op_name!(Module); @@ -34,10 +39,10 @@ impl OpTrait for Module { /// /// Children nodes are the body of the definition. #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] -#[cfg_attr(test, derive(proptest_derive::Arbitrary))] +#[cfg_attr(test, derive(Arbitrary))] pub struct FuncDefn { /// Name of function - #[cfg_attr(test, proptest(strategy = "crate::proptest::any_nonempty_string()"))] + #[cfg_attr(test, proptest(strategy = "any_nonempty_string()"))] pub name: String, /// Signature of the function pub signature: PolyFuncType, @@ -70,10 +75,10 @@ impl OpTrait for FuncDefn { /// External function declaration, linked at runtime. #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] -#[cfg_attr(test, derive(proptest_derive::Arbitrary))] +#[cfg_attr(test, derive(Arbitrary))] pub struct FuncDecl { /// Name of function - #[cfg_attr(test, proptest(strategy = "crate::proptest::any_nonempty_string()"))] + #[cfg_attr(test, proptest(strategy = "any_nonempty_string()"))] pub name: String, /// Signature of the function pub signature: PolyFuncType, @@ -100,10 +105,10 @@ impl OpTrait for FuncDecl { /// A type alias definition, used only for debug/metadata. #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] -#[cfg_attr(test, derive(proptest_derive::Arbitrary))] +#[cfg_attr(test, derive(Arbitrary))] pub struct AliasDefn { /// Alias name - #[cfg_attr(test, proptest(strategy = "crate::proptest::any_nonempty_smolstr()"))] + #[cfg_attr(test, proptest(strategy = "any_nonempty_smolstr()"))] pub name: SmolStr, /// Aliased type pub definition: Type, @@ -127,7 +132,7 @@ impl OpTrait for AliasDefn { #[cfg_attr(test, derive(proptest_derive::Arbitrary))] pub struct AliasDecl { /// Alias name - #[cfg_attr(test, proptest(strategy = "crate::proptest::any_nonempty_smolstr()"))] + #[cfg_attr(test, proptest(strategy = "any_nonempty_smolstr()"))] pub name: SmolStr, /// Flag to signify type is classical pub bound: TypeBound, diff --git a/hugr/src/types.rs b/hugr/src/types.rs index 298a5229a..147ad4b4c 100644 --- a/hugr/src/types.rs +++ b/hugr/src/types.rs @@ -23,7 +23,7 @@ use itertools::FoldWhile::{Continue, Done}; use itertools::{repeat_n, Itertools}; use serde::{Deserialize, Serialize}; #[cfg(test)] -use {crate::proptest::RecursionDepth, ::proptest::prelude::*}; +use {crate::proptest::RecursionDepth, ::proptest::prelude::*, proptest_derive::Arbitrary}; use crate::extension::{ExtensionRegistry, SignatureError}; use crate::ops::AliasDecl; @@ -72,7 +72,7 @@ impl EdgeKind { #[derive( Copy, Default, Clone, PartialEq, Eq, Hash, Debug, derive_more::Display, Serialize, Deserialize, )] -#[cfg_attr(test, derive(proptest_derive::Arbitrary))] +#[cfg_attr(test, derive(Arbitrary))] /// Bounds on the valid operations on a type in a HUGR program. pub enum TypeBound { /// The equality operation is valid on this type. @@ -197,11 +197,7 @@ impl From for Type { } #[derive(Clone, PartialEq, Debug, Eq, derive_more::Display)] -#[cfg_attr( - test, - derive(proptest_derive::Arbitrary), - proptest(params = "RecursionDepth") -)] +#[cfg_attr(test, derive(Arbitrary), proptest(params = "RecursionDepth"))] /// Core types pub enum TypeEnum { // TODO optimise with Box ? diff --git a/hugr/src/types/poly_func.rs b/hugr/src/types/poly_func.rs index 45444adf1..fc579e9d5 100644 --- a/hugr/src/types/poly_func.rs +++ b/hugr/src/types/poly_func.rs @@ -6,6 +6,7 @@ use itertools::Itertools; use { crate::proptest::RecursionDepth, ::proptest::{collection::vec, prelude::*}, + proptest_derive::Arbitrary, }; use super::type_param::{check_type_args, TypeArg, TypeParam}; @@ -20,11 +21,7 @@ use super::{FunctionType, Substitution}; #[derive( Clone, PartialEq, Debug, Default, Eq, derive_more::Display, serde::Serialize, serde::Deserialize, )] -#[cfg_attr( - test, - derive(proptest_derive::Arbitrary), - proptest(params = "RecursionDepth") -)] +#[cfg_attr(test, derive(Arbitrary), proptest(params = "RecursionDepth"))] #[display( fmt = "forall {}. {}", "params.iter().map(ToString::to_string).join(\" \")", diff --git a/hugr/src/types/signature.rs b/hugr/src/types/signature.rs index df51bb183..41bc7b58c 100644 --- a/hugr/src/types/signature.rs +++ b/hugr/src/types/signature.rs @@ -11,14 +11,10 @@ use crate::extension::{ExtensionRegistry, ExtensionSet, SignatureError}; use crate::{Direction, IncomingPort, OutgoingPort, Port}; #[cfg(test)] -use {crate::proptest::RecursionDepth, ::proptest::prelude::*}; +use {crate::proptest::RecursionDepth, ::proptest::prelude::*, proptest_derive::Arbitrary}; #[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] -#[cfg_attr( - test, - derive(proptest_derive::Arbitrary), - proptest(params = "RecursionDepth") -)] +#[cfg_attr(test, derive(Arbitrary), proptest(params = "RecursionDepth"))] /// Describes the edges required to/from a node, and thus, also the type of a [Graph]. /// This includes both the concept of "signature" in the spec, /// and also the target (value) of a call (static). diff --git a/hugr/src/types/type_param.rs b/hugr/src/types/type_param.rs index 9db33bc0f..1c4efc617 100644 --- a/hugr/src/types/type_param.rs +++ b/hugr/src/types/type_param.rs @@ -5,6 +5,8 @@ //! [`TypeDef`]: crate::extension::TypeDef use itertools::Itertools; +#[cfg(test)] +use proptest_derive::Arbitrary; use std::num::NonZeroU64; use thiserror::Error; @@ -20,7 +22,7 @@ use super::{check_typevar_decl, CustomType, Substitution, Type, TypeBound}; Clone, Debug, PartialEq, Eq, derive_more::Display, serde::Deserialize, serde::Serialize, )] #[display(fmt = "{}", "_0.map(|i|i.to_string()).unwrap_or(\"-\".to_string())")] -#[cfg_attr(test, derive(proptest_derive::Arbitrary))] +#[cfg_attr(test, derive(Arbitrary))] pub struct UpperBound(Option); impl UpperBound { fn valid_value(&self, val: u64) -> bool { @@ -439,8 +441,8 @@ mod test { type Parameters = RecursionDepth; type Strategy = BoxedStrategy; fn arbitrary_with(depth: Self::Parameters) -> Self::Strategy { - use proptest::collection::vec; - use proptest::strategy::Union; + use prop::collection::vec; + use prop::strategy::Union; let mut strat = Union::new([ Just(Self::Extensions).boxed(), any::().prop_map(|b| Self::Type { b }).boxed(), @@ -470,8 +472,8 @@ mod test { type Parameters = RecursionDepth; type Strategy = BoxedStrategy; fn arbitrary_with(depth: Self::Parameters) -> Self::Strategy { - use proptest::collection::vec; - use proptest::strategy::Union; + use prop::collection::vec; + use prop::strategy::Union; let mut strat = Union::new([ any::().prop_map(|n| Self::BoundedNat { n }).boxed(), any::() diff --git a/justfile b/justfile index 67946f884..f11bee80d 100644 --- a/justfile +++ b/justfile @@ -10,11 +10,11 @@ setup: # Run the pre-commit checks. check: - poetry run pre-commit run --all-files + HUGR_TEST_SCHEMA=1 poetry run pre-commit run --all-files # Run all the tests. test language="[rust|python]" : (_run_lang language \ - "HUGR_TEST_SCHEMA=\"1\" cargo test --features extension_inference" \ + "HUGR_TEST_SCHEMA=1 cargo test --all-features" \ "poetry run pytest" )