Skip to content

Commit

Permalink
fix: Export RemoveDeadFuncsError
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q committed Jan 20, 2025
1 parent e26a31f commit 09bd748
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions hugr-passes/src/dead_funcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -37,15 +43,15 @@ 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())
}
d
} 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())
};
Expand Down
2 changes: 1 addition & 1 deletion hugr-passes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 09bd748

Please sign in to comment.