Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Export RemoveDeadFuncsError #1883

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading