Skip to content

Commit

Permalink
fix: disable serialisation tests when miri is active (#977)
Browse files Browse the repository at this point in the history
We move the `serialize_types_roundtrip` test to put it under the new cfg
flag
  • Loading branch information
doug-q authored Apr 26, 2024
1 parent ef5485a commit c352abf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 33 deletions.
23 changes: 20 additions & 3 deletions hugr/src/hugr/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ impl TryFrom<SerHugrV1> 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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
3 changes: 1 addition & 2 deletions hugr/src/hugr/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
28 changes: 0 additions & 28 deletions hugr/src/types/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,3 @@ impl From<SerSimpleType> 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);
}
}

0 comments on commit c352abf

Please sign in to comment.