Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disable serialisation tests when miri is active #977

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}