diff --git a/tket-qsystem/tests/guppy_opt.rs b/tket-qsystem/tests/guppy_opt.rs index d8fbe9b57..5d87851a2 100644 --- a/tket-qsystem/tests/guppy_opt.rs +++ b/tket-qsystem/tests/guppy_opt.rs @@ -82,20 +82,14 @@ fn count_gates(h: &impl HugrView) -> HashMap { #[case::nested_array("nested_array", None)] #[should_panic = "xfail"] #[case::angles("angles", Some(vec![ - ("tket.quantum.Rz", 2), ("tket.quantum.MeasureFree", 1), ("tket.quantum.H", 2), ("tket.quantum.QAlloc", 1) + ("tket.quantum.H", 2), ("tket.quantum.MeasureFree", 1), ("tket.quantum.Rz", 10), ("tket.quantum.QAlloc", 1) ]))] #[should_panic = "xfail"] #[case::simple_cx("simple_cx", Some(vec![ ("tket.quantum.QAlloc", 2), ("tket.quantum.MeasureFree", 2), ]))] -#[should_panic = "xfail"] -#[case::nested("nested", Some(vec![ - ("tket.quantum.CZ", 6), ("tket.quantum.QAlloc", 3), ("tket.quantum.MeasureFree", 3), ("tket.quantum.H", 6) -]))] -#[should_panic = "xfail"] -#[case::ranges("ranges", Some(vec![ - ("tket.quantum.H", 8), ("tket.quantum.MeasureFree", 4), ("tket.quantum.QAlloc", 4), ("tket.quantum.CX", 6) -]))] +#[case::nested("nested", None)] +#[case::ranges("ranges", None)] #[should_panic = "xfail"] #[case::false_branch("false_branch", Some(vec![ ("TKET1.tk1op", 1), ("tket.quantum.H", 1), ("tket.quantum.QAlloc", 1), ("tket.quantum.MeasureFree", 1) @@ -127,23 +121,9 @@ fn optimize_flattened_guppy(#[case] name: &str, #[case] xfail: Option + 'static> ComposablePass for NormalizeGuppy { type Error = NormalizeGuppyErrors; type Result = (); fn run(&self, hugr: &mut H) -> Result { + // We probably shouldn't inline quite as aggressively as this, but + // the results demonstrate how much we need to do at least some of it: + let qubit_finder = TypeUnpacker::for_qubits(); + inline_acyclic(hugr, |h, call| { + // Look for qubits. Use instantiated type so that we inline generic + // (e.g. container) functions as this might enable better qubit tracking. + let inst = &h.get_optype(call).as_call().unwrap().instantiation; + inst.input_types() + .iter() + .chain(inst.output_types()) + .any(|ty| qubit_finder.contains_element_type(ty)) + }) + .unwrap(); + // Many functions now unreachable, so remove - this may improve compilation speed, + // although not if all remaining phases operate only beneath the entrypoint. + // Shouldn't be affected by anything else until we start removing untaken branches. + if self.dead_funcs { + RemoveDeadFuncsPass::default().run(hugr)?; + } + if self.simplify_cfgs { NormalizeCFGPass::default().run(hugr)?; } @@ -91,11 +113,6 @@ impl + 'static> ComposablePass for NormalizeGuppy { if self.constant_fold { ConstantFoldPass::default().run(hugr)?; } - // Only improves compilation speed, not affected by anything else - // until we start removing untaken branches - if self.dead_funcs { - RemoveDeadFuncsPass::default().run(hugr)?; - } // Do earlier? Nothing creates DFGs if self.inline_dfgs { InlineDFGsPass.run(hugr).unwrap_or_else(|e| match e {})