From 513afb4a5ed5106e7c056df03d0c0a14658542a4 Mon Sep 17 00:00:00 2001 From: Craig Roy Date: Tue, 22 Aug 2023 16:33:15 +0100 Subject: [PATCH 1/3] [tests] Add failing test of get_io --- src/hugr.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/hugr.rs b/src/hugr.rs index b4178100a..a9e81e008 100644 --- a/src/hugr.rs +++ b/src/hugr.rs @@ -361,4 +361,14 @@ mod test { trait Test: Send + Sync {} impl Test for Hugr {} } + + #[test] + fn io_node() { + use crate::builder::test::simple_dfg_hugr; + use crate::hugr::views::HugrView; + use cool_asserts::assert_matches; + + let hugr = simple_dfg_hugr(); + assert_matches!((&hugr).get_io(hugr.root()), Some(_)); + } } From 76144c1b2f6bfc18d52a84ba453f1aa498f81f31 Mon Sep 17 00:00:00 2001 From: Craig Roy Date: Tue, 22 Aug 2023 16:50:00 +0100 Subject: [PATCH 2/3] [fix] Fix get_io logic --- src/hugr/views.rs | 2 +- src/ops/tag.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hugr/views.rs b/src/hugr/views.rs index 69b6545f4..275a1aabb 100644 --- a/src/hugr/views.rs +++ b/src/hugr/views.rs @@ -314,7 +314,7 @@ where #[inline] fn get_io(&self, node: Node) -> Option<[Node; 2]> { let op = self.get_nodetype(node); - if op.tag().is_superset(OpTag::DataflowParent) { + if OpTag::DataflowParent.is_superset(op.tag()) { self.children(node).take(2).collect_vec().try_into().ok() } else { None diff --git a/src/ops/tag.rs b/src/ops/tag.rs index dcd3f39af..e45014977 100644 --- a/src/ops/tag.rs +++ b/src/ops/tag.rs @@ -68,7 +68,7 @@ pub enum OpTag { } impl OpTag { - /// Returns true if the tag is more general than the given tag. + /// Returns true if this tag is more general than `other`. #[inline] pub const fn is_superset(self, other: OpTag) -> bool { // We cannot call iter().any() or even do for loops in const fn yet. From 80dcb008152fde0f2a414ba284ac983c01935e79 Mon Sep 17 00:00:00 2001 From: Craig Roy Date: Tue, 22 Aug 2023 16:54:48 +0100 Subject: [PATCH 3/3] [tests] Update failing tests --- src/builder/dataflow.rs | 10 ++-------- src/hugr.rs | 2 +- src/hugr/validate.rs | 2 +- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/builder/dataflow.rs b/src/builder/dataflow.rs index dd658af6c..4c371865f 100644 --- a/src/builder/dataflow.rs +++ b/src/builder/dataflow.rs @@ -429,18 +429,13 @@ pub(crate) mod test { #[test] fn lift_node() -> Result<(), BuildError> { - let mut module_builder = ModuleBuilder::new(); - let ab_extensions = ExtensionSet::from_iter(["A".into(), "B".into()]); let c_extensions = ExtensionSet::singleton(&"C".into()); let abc_extensions = ab_extensions.clone().union(&c_extensions); let parent_sig = FunctionType::new(type_row![BIT], type_row![BIT]).with_extension_delta(&abc_extensions); - let mut parent = module_builder.define_function( - "parent", - parent_sig.with_input_extensions(ExtensionSet::new()), - )?; + let mut parent = DFGBuilder::new(parent_sig)?; let add_c_sig = FunctionType::new(type_row![BIT], type_row![BIT]) .with_extension_delta(&c_extensions) @@ -498,8 +493,7 @@ pub(crate) mod test { let add_c = add_c.finish_with_outputs(wires)?; let [w] = add_c.outputs_arr(); - parent.finish_with_outputs([w])?; - module_builder.finish_hugr()?; + parent.finish_hugr_with_outputs([w])?; Ok(()) } diff --git a/src/hugr.rs b/src/hugr.rs index a9e81e008..88e2c161c 100644 --- a/src/hugr.rs +++ b/src/hugr.rs @@ -369,6 +369,6 @@ mod test { use cool_asserts::assert_matches; let hugr = simple_dfg_hugr(); - assert_matches!((&hugr).get_io(hugr.root()), Some(_)); + assert_matches!(hugr.get_io(hugr.root()), Some(_)); } } diff --git a/src/hugr/validate.rs b/src/hugr/validate.rs index 3fa741784..5e5ed98b1 100644 --- a/src/hugr/validate.rs +++ b/src/hugr/validate.rs @@ -1211,7 +1211,7 @@ mod test { assert_matches!( handle, Err(ValidationError::ExtensionError( - ExtensionError::TgtExceedsSrcExtensions { .. } + ExtensionError::ParentIOExtensionMismatch { .. } )) ); Ok(())