From 24a730e81cc2d9b93a6b9679ac7ab07126c7136d Mon Sep 17 00:00:00 2001 From: Agustin Borgna Date: Fri, 14 Jun 2024 13:33:25 +0100 Subject: [PATCH 1/4] chore: Skip unsupported test in miri --- hugr-cli/tests/cli.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hugr-cli/tests/cli.rs b/hugr-cli/tests/cli.rs index beb1e19f2..1cd8b5438 100644 --- a/hugr-cli/tests/cli.rs +++ b/hugr-cli/tests/cli.rs @@ -1,3 +1,9 @@ +//! Tests for the CLI +//! +//! Miri is globally disabled for these tests because they mostly involve +//! calling the CLI binary, which Miri doesn't support. +#![cfg(all(test, not(miri)))] + use assert_cmd::Command; use assert_fs::{fixture::FileWriteStr, NamedTempFile}; use hugr_cli::VALID_PRINT; From fc020002207a84f51a8fafd889623222b007750d Mon Sep 17 00:00:00 2001 From: Agustin Borgna Date: Fri, 14 Jun 2024 14:43:23 +0100 Subject: [PATCH 2/4] Always implement arbitrary for CustomSerialized --- hugr-core/src/ops/constant/custom.rs | 75 ++++++++++++++-------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/hugr-core/src/ops/constant/custom.rs b/hugr-core/src/ops/constant/custom.rs index eb46a2bb7..e3df87b45 100644 --- a/hugr-core/src/ops/constant/custom.rs +++ b/hugr-core/src/ops/constant/custom.rs @@ -476,44 +476,45 @@ mod test { serde_yaml::from_value(serde_yaml::to_value(&ev).unwrap()).unwrap() ); } +} - mod proptest { - use ::proptest::prelude::*; - - use crate::{ - extension::ExtensionSet, - ops::constant::CustomSerialized, - proptest::{any_serde_yaml_value, any_string}, - types::Type, - }; - - impl Arbitrary for CustomSerialized { - type Parameters = (); - type Strategy = BoxedStrategy; - fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { - let typ = any::(); - let extensions = any::(); - // here we manually construct a serialized `dyn CustomConst`. - // The "c" and "v" come from the `typetag::serde` annotation on - // `trait CustomConst`. - // TODO This is not ideal, if we were to accidentally - // generate a valid tag(e.g. "ConstInt") then things will - // go wrong: the serde::Deserialize impl for that type will - // interpret "v" and fail. - let value = (any_serde_yaml_value(), any_string()).prop_map(|(content, tag)| { - [("c".into(), tag.into()), ("v".into(), content)] - .into_iter() - .collect::() - .into() - }); - (typ, value, extensions) - .prop_map(|(typ, value, extensions)| CustomSerialized { - typ, - value, - extensions, - }) - .boxed() - } +#[cfg(test)] +mod proptest { + use ::proptest::prelude::*; + + use crate::{ + extension::ExtensionSet, + ops::constant::CustomSerialized, + proptest::{any_serde_yaml_value, any_string}, + types::Type, + }; + + impl Arbitrary for CustomSerialized { + type Parameters = (); + type Strategy = BoxedStrategy; + fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { + let typ = any::(); + let extensions = any::(); + // here we manually construct a serialized `dyn CustomConst`. + // The "c" and "v" come from the `typetag::serde` annotation on + // `trait CustomConst`. + // TODO This is not ideal, if we were to accidentally + // generate a valid tag(e.g. "ConstInt") then things will + // go wrong: the serde::Deserialize impl for that type will + // interpret "v" and fail. + let value = (any_serde_yaml_value(), any_string()).prop_map(|(content, tag)| { + [("c".into(), tag.into()), ("v".into(), content)] + .into_iter() + .collect::() + .into() + }); + (typ, value, extensions) + .prop_map(|(typ, value, extensions)| CustomSerialized { + typ, + value, + extensions, + }) + .boxed() } } } From 8ad32d8c5c6c54b5e8a33ac79953f666d5ac267c Mon Sep 17 00:00:00 2001 From: Agustin Borgna Date: Fri, 14 Jun 2024 14:44:10 +0100 Subject: [PATCH 3/4] Add justfile `miri` command --- justfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/justfile b/justfile index f11bee80d..7f0d752eb 100644 --- a/justfile +++ b/justfile @@ -42,6 +42,10 @@ coverage language="[rust|python]": (_run_lang language \ "poetry run pytest --cov=./ --cov-report=html" ) +# Run undsoundness checks using miri +miri: + PROPTEST_DISABLE_FAILURE_PERSISTENCE=true MIRIFLAGS='-Zmiri-env-forward=PROPTEST_DISABLE_FAILURE_PERSISTENCE' cargo +nightly miri test + # Load a shell with all the dependencies installed shell: poetry shell From 51b90fca4f156983b631a29634019eff77111d0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Borgna?= <121866228+aborgna-q@users.noreply.github.com> Date: Mon, 17 Jun 2024 09:04:28 +0100 Subject: [PATCH 4/4] Update justfile Co-authored-by: doug-q <141026920+doug-q@users.noreply.github.com> --- justfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/justfile b/justfile index 7f0d752eb..f7f52f2f0 100644 --- a/justfile +++ b/justfile @@ -42,7 +42,7 @@ coverage language="[rust|python]": (_run_lang language \ "poetry run pytest --cov=./ --cov-report=html" ) -# Run undsoundness checks using miri +# Run unsoundness checks using miri miri: PROPTEST_DISABLE_FAILURE_PERSISTENCE=true MIRIFLAGS='-Zmiri-env-forward=PROPTEST_DISABLE_FAILURE_PERSISTENCE' cargo +nightly miri test