diff --git a/src/builder/cfg.rs b/src/builder/cfg.rs index 153d367f0..18855abd0 100644 --- a/src/builder/cfg.rs +++ b/src/builder/cfg.rs @@ -73,7 +73,7 @@ impl HugrBuilder for CFGBuilder { mut self, extension_registry: &ExtensionRegistry, ) -> Result { - self.base.infer_and_validate(extension_registry)?; + self.base.update_validate(extension_registry)?; Ok(self.base) } } diff --git a/src/builder/conditional.rs b/src/builder/conditional.rs index b42167ff9..54076b3ce 100644 --- a/src/builder/conditional.rs +++ b/src/builder/conditional.rs @@ -150,7 +150,7 @@ impl HugrBuilder for ConditionalBuilder { mut self, extension_registry: &ExtensionRegistry, ) -> Result { - self.base.infer_and_validate(extension_registry)?; + self.base.update_validate(extension_registry)?; Ok(self.base) } } diff --git a/src/builder/dataflow.rs b/src/builder/dataflow.rs index 07c1e2f97..9088b3c5c 100644 --- a/src/builder/dataflow.rs +++ b/src/builder/dataflow.rs @@ -90,7 +90,7 @@ impl HugrBuilder for DFGBuilder { mut self, extension_registry: &ExtensionRegistry, ) -> Result { - self.base.infer_and_validate(extension_registry)?; + self.base.update_validate(extension_registry)?; Ok(self.base) } } diff --git a/src/builder/module.rs b/src/builder/module.rs index 2df7a1241..83b08a32c 100644 --- a/src/builder/module.rs +++ b/src/builder/module.rs @@ -60,7 +60,7 @@ impl HugrBuilder for ModuleBuilder { mut self, extension_registry: &ExtensionRegistry, ) -> Result { - self.0.infer_and_validate(extension_registry)?; + self.0.update_validate(extension_registry)?; Ok(self.0) } } diff --git a/src/extension/infer.rs b/src/extension/infer.rs index f1a08cff3..a1df4d4a1 100644 --- a/src/extension/infer.rs +++ b/src/extension/infer.rs @@ -867,7 +867,7 @@ mod test { // nodes and their parents and `report_mismatch` isn't yet smart enough // to handle that. assert_matches!( - hugr.infer_and_validate(&PRELUDE_REGISTRY), + hugr.update_validate(&PRELUDE_REGISTRY), Err(ValidationError::CantInfer(_)) ); Ok(()) @@ -1155,7 +1155,7 @@ mod test { for (src, tgt) in nodes.into_iter().tuple_windows() { hugr.connect(src, 0, tgt, 0)?; } - hugr.infer_and_validate(&PRELUDE_REGISTRY)?; + hugr.update_validate(&PRELUDE_REGISTRY)?; Ok(()) } @@ -1421,7 +1421,7 @@ mod test { hugr.connect(bb1, 0, bb2, 0)?; hugr.connect(bb2, 0, exit, 0)?; - hugr.infer_and_validate(&PRELUDE_REGISTRY)?; + hugr.update_validate(&PRELUDE_REGISTRY)?; Ok(()) } @@ -1520,7 +1520,7 @@ mod test { for (bb0, bb1, bb2) in variants.into_iter() { let mut hugr = make_looping_cfg(bb0, bb1, bb2)?; - hugr.infer_and_validate(&PRELUDE_REGISTRY)?; + hugr.update_validate(&PRELUDE_REGISTRY)?; } Ok(()) } @@ -1573,7 +1573,7 @@ mod test { hugr.connect(bb, 0, bb, 0)?; hugr.connect(bb, 0, exit, 0)?; - hugr.infer_and_validate(&PRELUDE_REGISTRY)?; + hugr.update_validate(&PRELUDE_REGISTRY)?; Ok(()) } diff --git a/src/hugr.rs b/src/hugr.rs index 6f9bb4b27..ec5926fb9 100644 --- a/src/hugr.rs +++ b/src/hugr.rs @@ -29,6 +29,7 @@ pub use self::views::{HugrView, RootTagged}; use crate::extension::{ infer_extensions, ExtensionRegistry, ExtensionSet, ExtensionSolution, InferExtensionError, }; +use crate::ops::custom::resolve_extension_ops; use crate::ops::{OpTag, OpTrait, OpType, DEFAULT_OPTYPE}; use crate::types::{FunctionType, Signature}; @@ -230,11 +231,12 @@ pub type Direction = portgraph::Direction; /// Public API for HUGRs. impl Hugr { - /// Run resource inference and pass the closure into validation - pub fn infer_and_validate( + /// Resolve extension ops, infer extensions used, and pass the closure into validation + pub fn update_validate( &mut self, extension_registry: &ExtensionRegistry, ) -> Result<(), ValidationError> { + resolve_extension_ops(self, extension_registry)?; let closure = self.infer_extensions()?; self.validate_with_extension_closure(closure, extension_registry)?; Ok(()) diff --git a/src/hugr/rewrite/insert_identity.rs b/src/hugr/rewrite/insert_identity.rs index 28f1c6529..cf4e12a70 100644 --- a/src/hugr/rewrite/insert_identity.rs +++ b/src/hugr/rewrite/insert_identity.rs @@ -146,7 +146,7 @@ mod tests { assert_eq!(noop, LeafOp::Noop { ty: QB_T }); - h.infer_and_validate(&PRELUDE_REGISTRY).unwrap(); + h.update_validate(&PRELUDE_REGISTRY).unwrap(); } #[test] diff --git a/src/hugr/rewrite/outline_cfg.rs b/src/hugr/rewrite/outline_cfg.rs index c01f28c18..691fb8a40 100644 --- a/src/hugr/rewrite/outline_cfg.rs +++ b/src/hugr/rewrite/outline_cfg.rs @@ -301,7 +301,7 @@ mod test { #[test] fn test_outline_cfg() { let (mut h, head, tail) = build_conditional_in_loop_cfg(false).unwrap(); - h.infer_and_validate(&PRELUDE_REGISTRY).unwrap(); + h.update_validate(&PRELUDE_REGISTRY).unwrap(); do_outline_cfg_test(&mut h, head, tail, 1); h.validate(&PRELUDE_REGISTRY).unwrap(); } diff --git a/src/hugr/rewrite/simple_replace.rs b/src/hugr/rewrite/simple_replace.rs index 9a8393ace..53e3f68a7 100644 --- a/src/hugr/rewrite/simple_replace.rs +++ b/src/hugr/rewrite/simple_replace.rs @@ -416,7 +416,7 @@ pub(in crate::hugr::rewrite) mod test { // ├───┤├───┤┌─┴─┐ // ┤ H ├┤ H ├┤ X ├ // └───┘└───┘└───┘ - assert_eq!(h.infer_and_validate(&PRELUDE_REGISTRY), Ok(())); + assert_eq!(h.update_validate(&PRELUDE_REGISTRY), Ok(())); } #[rstest] @@ -488,7 +488,7 @@ pub(in crate::hugr::rewrite) mod test { // ├───┤├───┤┌───┐ // ┤ H ├┤ H ├┤ H ├ // └───┘└───┘└───┘ - assert_eq!(h.infer_and_validate(&PRELUDE_REGISTRY), Ok(())); + assert_eq!(h.update_validate(&PRELUDE_REGISTRY), Ok(())); } #[test] diff --git a/src/hugr/serialize.rs b/src/hugr/serialize.rs index 89b2da36f..2fdc2fb36 100644 --- a/src/hugr/serialize.rs +++ b/src/hugr/serialize.rs @@ -470,7 +470,7 @@ pub mod test { hugr.connect(new_in, 0, out, 0).unwrap(); hugr.move_before_sibling(new_in, old_in).unwrap(); hugr.remove_node(old_in).unwrap(); - hugr.infer_and_validate(&PRELUDE_REGISTRY).unwrap(); + hugr.update_validate(&PRELUDE_REGISTRY).unwrap(); let ser = serde_json::to_vec(&hugr).unwrap(); let new_hugr: Hugr = serde_json::from_slice(&ser).unwrap(); diff --git a/src/hugr/validate.rs b/src/hugr/validate.rs index c16cae8e1..3338c081a 100644 --- a/src/hugr/validate.rs +++ b/src/hugr/validate.rs @@ -1113,20 +1113,20 @@ mod test { h.connect(sub_dfg, 0, output, 0)?; assert_matches!( - h.infer_and_validate(&EMPTY_REG), + h.update_validate(&EMPTY_REG), Err(ValidationError::UnconnectedPort { .. }) ); h.connect(input, 1, sub_op, 1)?; assert_matches!( - h.infer_and_validate(&EMPTY_REG), + h.update_validate(&EMPTY_REG), Err(ValidationError::InterGraphEdgeError( InterGraphEdgeError::MissingOrderEdge { .. } )) ); //Order edge. This will need metadata indicating its purpose. h.add_other_edge(input, sub_dfg)?; - h.infer_and_validate(&EMPTY_REG).unwrap(); + h.update_validate(&EMPTY_REG).unwrap(); Ok(()) } @@ -1143,7 +1143,7 @@ mod test { h.connect(input, 0, and, 0)?; h.connect(and, 0, output, 0)?; assert_eq!( - h.infer_and_validate(&EMPTY_REG), + h.update_validate(&EMPTY_REG), Err(ValidationError::UnconnectedPort { node: and, port: Port::new_incoming(1), @@ -1161,7 +1161,7 @@ mod test { h.connect(cst, 0, lcst, 0)?; h.connect(lcst, 0, and, 1)?; // There is no edge from Input to LoadConstant, but that's OK: - h.infer_and_validate(&EMPTY_REG).unwrap(); + h.update_validate(&EMPTY_REG).unwrap(); Ok(()) } diff --git a/src/hugr/views/sibling.rs b/src/hugr/views/sibling.rs index 4829a2418..4311afb2d 100644 --- a/src/hugr/views/sibling.rs +++ b/src/hugr/views/sibling.rs @@ -437,9 +437,7 @@ mod test { #[rstest] fn flat_mut(mut simple_dfg_hugr: Hugr) { - simple_dfg_hugr - .infer_and_validate(&PRELUDE_REGISTRY) - .unwrap(); + simple_dfg_hugr.update_validate(&PRELUDE_REGISTRY).unwrap(); let root = simple_dfg_hugr.root(); let signature = simple_dfg_hugr.get_function_type().unwrap().clone();