From 8899b0c030d3304f473c916e72aba6d3153c76c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Borgna?= Date: Fri, 13 Mar 2026 16:33:21 +0000 Subject: [PATCH 1/5] feat: Deprecate HugrView::as_petgraph --- hugr-core/src/hugr/views.rs | 4 ++++ hugr-passes/src/force_order.rs | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/hugr-core/src/hugr/views.rs b/hugr-core/src/hugr/views.rs index 0deb8531e0..6f07e0f19b 100644 --- a/hugr-core/src/hugr/views.rs +++ b/hugr-core/src/hugr/views.rs @@ -389,6 +389,10 @@ pub trait HugrView: HugrInternals { /// Return a wrapper over the view that can be used in petgraph algorithms. #[inline] + #[deprecated( + since = "0.26.0", + note = "Use hugr_core::internal::HugrInternals::region_portgraph instead." + )] fn as_petgraph(&self) -> PetgraphWrapper<'_, Self> where Self: Sized, diff --git a/hugr-passes/src/force_order.rs b/hugr-passes/src/force_order.rs index dcb42f431c..2b0a3c7918 100644 --- a/hugr-passes/src/force_order.rs +++ b/hugr-passes/src/force_order.rs @@ -208,6 +208,7 @@ mod test { use super::*; use hugr_core::builder::{BuildHandle, Dataflow, DataflowHugr, endo_sig}; + use hugr_core::hugr::internal::HugrInternals; use hugr_core::ops::handle::{DataflowOpID, NodeHandle}; use hugr_core::ops::{self, Value}; @@ -277,9 +278,12 @@ mod test { }) .unwrap(); - let topo_sorted = Topo::new(&hugr.as_petgraph()) - .iter(&hugr.as_petgraph()) - .filter(|n| rank_map.contains_key(n)) + let (graph, node_map) = hugr.region_portgraph(hugr.entrypoint()); + + let topo_sorted = Topo::new(&graph) + .iter(&graph) + .map(|n| node_map.from_portgraph(n)) + .filter(|n| rank_map.contains_key(&n)) .collect_vec(); hugr.validate().unwrap(); From 11af44f9d0e7273117d1d2f1359a8f3a83dbec70 Mon Sep 17 00:00:00 2001 From: Alan Lawrence Date: Fri, 13 Mar 2026 16:38:38 +0000 Subject: [PATCH 2/5] deprecate PetgraphWrapper --- hugr-core/src/hugr/views.rs | 2 ++ hugr-core/src/hugr/views/petgraph.rs | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/hugr-core/src/hugr/views.rs b/hugr-core/src/hugr/views.rs index 6f07e0f19b..d35676404f 100644 --- a/hugr-core/src/hugr/views.rs +++ b/hugr-core/src/hugr/views.rs @@ -15,6 +15,8 @@ use serde::de::Deserialize; use std::borrow::Cow; use std::collections::HashMap; +#[deprecated(since = "0.26.0")] +#[expect(deprecated)] // Remove at same time pub use self::petgraph::PetgraphWrapper; use self::render::MermaidFormatter; pub use nodes_iter::NodesIter; diff --git a/hugr-core/src/hugr/views/petgraph.rs b/hugr-core/src/hugr/views/petgraph.rs index bff727bb4d..6ab151bb3d 100644 --- a/hugr-core/src/hugr/views/petgraph.rs +++ b/hugr-core/src/hugr/views/petgraph.rs @@ -1,5 +1,5 @@ //! Implementations of petgraph's traits for Hugr Region views. - +#![allow(deprecated)] // Remove whole file when PetgraphWrapper is removed use crate::core::HugrNode; use crate::hugr::HugrView; use crate::ops::OpType; @@ -11,6 +11,7 @@ use petgraph::visit as pv; /// Wrapper for a `HugrView` that implements petgraph's traits. /// /// It can be used to apply petgraph's algorithms to a Hugr. +#[deprecated(since = "0.26.0")] #[derive(Debug)] pub struct PetgraphWrapper<'a, T> { pub(crate) hugr: &'a T, From f4165ae6b873022fb1f28fbc4e9be1b150d4c7fe Mon Sep 17 00:00:00 2001 From: Alan Lawrence Date: Fri, 13 Mar 2026 16:43:19 +0000 Subject: [PATCH 3/5] Missing expect-deprecated --- hugr-core/src/hugr/views.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/hugr-core/src/hugr/views.rs b/hugr-core/src/hugr/views.rs index d35676404f..4e0211b6e6 100644 --- a/hugr-core/src/hugr/views.rs +++ b/hugr-core/src/hugr/views.rs @@ -395,6 +395,7 @@ pub trait HugrView: HugrInternals { since = "0.26.0", note = "Use hugr_core::internal::HugrInternals::region_portgraph instead." )] + #[expect(deprecated)] // Remove at same time as PetgraphWrapper fn as_petgraph(&self) -> PetgraphWrapper<'_, Self> where Self: Sized, From b9210cd06072bf29706490bef572da321e65c256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Borgna?= Date: Fri, 13 Mar 2026 16:48:45 +0000 Subject: [PATCH 4/5] fix lints --- hugr-core/src/hugr/views.rs | 2 +- hugr-passes/src/force_order.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hugr-core/src/hugr/views.rs b/hugr-core/src/hugr/views.rs index 4e0211b6e6..65e709c22e 100644 --- a/hugr-core/src/hugr/views.rs +++ b/hugr-core/src/hugr/views.rs @@ -395,11 +395,11 @@ pub trait HugrView: HugrInternals { since = "0.26.0", note = "Use hugr_core::internal::HugrInternals::region_portgraph instead." )] - #[expect(deprecated)] // Remove at same time as PetgraphWrapper fn as_petgraph(&self) -> PetgraphWrapper<'_, Self> where Self: Sized, { + #[expect(deprecated)] // Remove at same time as PetgraphWrapper PetgraphWrapper { hugr: self } } diff --git a/hugr-passes/src/force_order.rs b/hugr-passes/src/force_order.rs index 2b0a3c7918..1924de734b 100644 --- a/hugr-passes/src/force_order.rs +++ b/hugr-passes/src/force_order.rs @@ -283,7 +283,7 @@ mod test { let topo_sorted = Topo::new(&graph) .iter(&graph) .map(|n| node_map.from_portgraph(n)) - .filter(|n| rank_map.contains_key(&n)) + .filter(|n| rank_map.contains_key(n)) .collect_vec(); hugr.validate().unwrap(); From 315ed856281a579a9f621a39d5c133339ad965b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Borgna?= Date: Fri, 13 Mar 2026 16:58:31 +0000 Subject: [PATCH 5/5] fix lints --- hugr-core/src/hugr/views.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hugr-core/src/hugr/views.rs b/hugr-core/src/hugr/views.rs index 65e709c22e..4e0211b6e6 100644 --- a/hugr-core/src/hugr/views.rs +++ b/hugr-core/src/hugr/views.rs @@ -395,11 +395,11 @@ pub trait HugrView: HugrInternals { since = "0.26.0", note = "Use hugr_core::internal::HugrInternals::region_portgraph instead." )] + #[expect(deprecated)] // Remove at same time as PetgraphWrapper fn as_petgraph(&self) -> PetgraphWrapper<'_, Self> where Self: Sized, { - #[expect(deprecated)] // Remove at same time as PetgraphWrapper PetgraphWrapper { hugr: self } }