From 09bd748398ce5afb39f5628d838756ccc03fc775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Borgna?= Date: Mon, 20 Jan 2025 14:37:10 +0000 Subject: [PATCH] fix: Export `RemoveDeadFuncsError` --- hugr-passes/src/dead_funcs.rs | 16 +++++++++++----- hugr-passes/src/lib.rs | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/hugr-passes/src/dead_funcs.rs b/hugr-passes/src/dead_funcs.rs index 903d94c3a..fe1a7cb51 100644 --- a/hugr-passes/src/dead_funcs.rs +++ b/hugr-passes/src/dead_funcs.rs @@ -16,10 +16,16 @@ use super::call_graph::{CallGraph, CallGraphNode}; #[derive(Debug, thiserror::Error)] #[non_exhaustive] -/// Errors produced by [ConstantFoldPass]. +/// Errors produced by [RemoveDeadFuncsPass]. pub enum RemoveDeadFuncsError { - #[error("Node {0} was not a FuncDefn child of the Module root")] - InvalidEntryPoint(Node), + /// The specified entry point is not a FuncDefn node or is not a child of the root. + #[error( + "Entrypoint for RemoveDeadFuncsPass {node} was not a function definition in the root module" + )] + InvalidEntryPoint { + /// The invalid node. + node: Node, + }, #[error(transparent)] #[allow(missing_docs)] ValidationError(#[from] ValidatePassError), @@ -37,7 +43,7 @@ fn reachable_funcs<'a>( d.stack.clear(); for n in entry_points { if !h.get_optype(n).is_func_defn() || h.get_parent(n) != Some(h.root()) { - return Err(RemoveDeadFuncsError::InvalidEntryPoint(n)); + return Err(RemoveDeadFuncsError::InvalidEntryPoint { node: n }); } d.stack.push(cg.node_index(n).unwrap()) } @@ -45,7 +51,7 @@ fn reachable_funcs<'a>( } else { if let Some(n) = entry_points.next() { // Can't be a child of the module root as there isn't a module root! - return Err(RemoveDeadFuncsError::InvalidEntryPoint(n)); + return Err(RemoveDeadFuncsError::InvalidEntryPoint { node: n }); } Dfs::new(g, cg.node_index(h.root()).unwrap()) }; diff --git a/hugr-passes/src/lib.rs b/hugr-passes/src/lib.rs index ffc739933..6ce1a0961 100644 --- a/hugr-passes/src/lib.rs +++ b/hugr-passes/src/lib.rs @@ -4,7 +4,7 @@ pub mod call_graph; pub mod const_fold; pub mod dataflow; mod dead_funcs; -pub use dead_funcs::{remove_dead_funcs, RemoveDeadFuncsPass}; +pub use dead_funcs::{remove_dead_funcs, RemoveDeadFuncsError, RemoveDeadFuncsPass}; pub mod force_order; mod half_node; pub mod lower;