Skip to content
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
9 changes: 5 additions & 4 deletions hugr-passes/src/call_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,20 @@ impl<N: HugrNode> CallGraph<N> {
/// Makes a new `CallGraph` for a Hugr.
pub fn new(hugr: &impl HugrView<Node = N>) -> Self {
let mut g = Graph::default();
let non_func_root =
(!hugr.get_optype(hugr.entrypoint()).is_module()).then_some(hugr.entrypoint());
let node_to_g = hugr
let mut node_to_g = hugr
.children(hugr.module_root())
.filter_map(|n| {
let weight = match hugr.get_optype(n) {
OpType::FuncDecl(_) => CallGraphNode::FuncDecl(n),
OpType::FuncDefn(_) => CallGraphNode::FuncDefn(n),
_ => (Some(n) == non_func_root).then_some(CallGraphNode::NonFuncRoot)?,
_ => return None,
};
Some((n, g.add_node(weight)))
})
.collect::<HashMap<_, _>>();
if !hugr.entrypoint_optype().is_module() && !node_to_g.contains_key(&hugr.entrypoint()) {
node_to_g.insert(hugr.entrypoint(), g.add_node(CallGraphNode::NonFuncRoot));
}
for (func, cg_node) in &node_to_g {
traverse(hugr, *cg_node, *func, &mut g, &node_to_g);
}
Expand Down
9 changes: 6 additions & 3 deletions hugr-passes/src/dead_funcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,15 @@ mod test {
let f_inp = fm.input_wires();
let fm = fm.finish_with_outputs(f_inp)?;
let mut m = hb.define_function("main", Signature::new_endo(usize_t()))?;
let mc = m.call(fm.handle(), &[], m.input_wires())?;
let m = m.finish_with_outputs(mc.outputs())?;
let m_in = m.input_wires();
let mut dfg = m.dfg_builder(Signature::new_endo(usize_t()), m_in)?;
let c = dfg.call(fm.handle(), &[], dfg.input_wires())?;
let dfg = dfg.finish_with_outputs(c.outputs()).unwrap();
m.finish_with_outputs(dfg.outputs())?;

let mut hugr = hb.finish_hugr()?;
if use_hugr_entrypoint {
hugr.set_entrypoint(m.node());
hugr.set_entrypoint(dfg.node());
}

let avail_funcs = hugr
Expand Down
Loading