diff --git a/hugr-core/src/hugr/views.rs b/hugr-core/src/hugr/views.rs index 0deb8531e0..4e0211b6e6 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; @@ -389,6 +391,11 @@ 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." + )] + #[expect(deprecated)] // Remove at same time as PetgraphWrapper fn as_petgraph(&self) -> PetgraphWrapper<'_, Self> where Self: Sized, 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, diff --git a/hugr-passes/src/force_order.rs b/hugr-passes/src/force_order.rs index dcb42f431c..1924de734b 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,8 +278,11 @@ mod test { }) .unwrap(); - let topo_sorted = Topo::new(&hugr.as_petgraph()) - .iter(&hugr.as_petgraph()) + 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();