From 58885713bc20ca3674e49cf16821ea6341a19e90 Mon Sep 17 00:00:00 2001 From: Douglas Wilson Date: Fri, 26 Apr 2024 13:20:12 +0100 Subject: [PATCH] fix: disable serialisation tests when miri is active We move the `serialize_types_roundtrip` test to put it under the new cfg flag --- hugr/src/hugr/serialize.rs | 23 ++++++++++++++++++++--- hugr/src/hugr/validate.rs | 3 +-- hugr/src/types/serialize.rs | 28 ---------------------------- 3 files changed, 21 insertions(+), 33 deletions(-) diff --git a/hugr/src/hugr/serialize.rs b/hugr/src/hugr/serialize.rs index ccfa5b6f3..4e92be610 100644 --- a/hugr/src/hugr/serialize.rs +++ b/hugr/src/hugr/serialize.rs @@ -260,8 +260,7 @@ impl TryFrom for Hugr { } } -#[cfg(test)] -#[cfg_attr(miri, ignore = "miri does not support 'life before main'")] +#[cfg(all(test, not(miri)))] // Miri doesn't run the extension registration required by `typetag` for // registering `CustomConst`s. https://github.com/rust-lang/miri/issues/450 pub mod test { @@ -271,7 +270,7 @@ pub mod test { test::closed_dfg_root_hugr, Container, DFGBuilder, Dataflow, DataflowHugr, DataflowSubContainer, HugrBuilder, ModuleBuilder, }; - use crate::extension::prelude::BOOL_T; + use crate::extension::prelude::{BOOL_T, USIZE_T}; use crate::extension::simple_op::MakeRegisteredOp; use crate::extension::{EMPTY_REG, PRELUDE_REGISTRY}; use crate::hugr::hugrmut::sealed::HugrMutInternals; @@ -562,4 +561,22 @@ pub mod test { Ok(()) } + + #[test] + fn serialize_types_roundtrip() { + let g: Type = Type::new_function(FunctionType::new_endo(vec![])); + + assert_eq!(ser_roundtrip(&g), g); + + // A Simple tuple + let t = Type::new_tuple(vec![USIZE_T, g]); + assert_eq!(ser_roundtrip(&t), t); + + // A Classic sum + let t = Type::new_sum([type_row![USIZE_T], type_row![FLOAT64_TYPE]]); + assert_eq!(ser_roundtrip(&t), t); + + let t = Type::new_unit_sum(4); + assert_eq!(ser_roundtrip(&t), t); + } } diff --git a/hugr/src/hugr/validate.rs b/hugr/src/hugr/validate.rs index 2ee170596..6b19636fb 100644 --- a/hugr/src/hugr/validate.rs +++ b/hugr/src/hugr/validate.rs @@ -104,8 +104,7 @@ impl<'a, 'b> ValidationContext<'a, 'b> { // TODO: We should also verify that the serialized hugr matches the // in-tree schema. For now, our serialized hugr does not match the // schema. When this is fixed we should pass true below. - #[cfg(test)] - #[cfg_attr(miri, ignore = "miri does not support 'life before main'")] + #[cfg(all(test, not(miri)))] crate::hugr::serialize::test::check_hugr_roundtrip(self.hugr, false); Ok(()) diff --git a/hugr/src/types/serialize.rs b/hugr/src/types/serialize.rs index 1e80cce65..e848a9d41 100644 --- a/hugr/src/types/serialize.rs +++ b/hugr/src/types/serialize.rs @@ -54,31 +54,3 @@ impl From for Type { } } } - -#[cfg(test)] -mod test { - use crate::extension::prelude::USIZE_T; - use crate::hugr::serialize::test::ser_roundtrip; - use crate::std_extensions::arithmetic::float_types::FLOAT64_TYPE; - use crate::type_row; - use crate::types::FunctionType; - use crate::types::Type; - - #[test] - fn serialize_types_roundtrip() { - let g: Type = Type::new_function(FunctionType::new_endo(vec![])); - - assert_eq!(ser_roundtrip(&g), g); - - // A Simple tuple - let t = Type::new_tuple(vec![USIZE_T, g]); - assert_eq!(ser_roundtrip(&t), t); - - // A Classic sum - let t = Type::new_sum([type_row![USIZE_T], type_row![FLOAT64_TYPE]]); - assert_eq!(ser_roundtrip(&t), t); - - let t = Type::new_unit_sum(4); - assert_eq!(ser_roundtrip(&t), t); - } -}