Skip to content

Commit a5e1881

Browse files
authored
fix: correct CallIndirect tag from FnCall to DataflowChild (#2006)
Closes #2005
1 parent 6ed4ecf commit a5e1881

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

hugr-core/src/ops/dataflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ pub struct CallIndirect {
300300
impl_op_name!(CallIndirect);
301301

302302
impl DataflowOpTrait for CallIndirect {
303-
const TAG: OpTag = OpTag::FnCall;
303+
const TAG: OpTag = OpTag::DataflowChild;
304304

305305
fn description(&self) -> &str {
306306
"Call a function indirectly"

hugr-passes/src/force_order.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ mod test {
207207
use hugr_core::builder::{endo_sig, BuildHandle, Dataflow, DataflowHugr};
208208
use hugr_core::ops::handle::{DataflowOpID, NodeHandle};
209209

210-
use hugr_core::ops::Value;
210+
use hugr_core::ops::{self, Value};
211211
use hugr_core::std_extensions::arithmetic::int_ops::IntOpDef;
212212
use hugr_core::std_extensions::arithmetic::int_types::INT_TYPES;
213213
use hugr_core::types::{Signature, Type};
@@ -326,4 +326,30 @@ mod test {
326326
let root = hugr.root();
327327
force_order(&mut hugr, root, |_, _| 0).unwrap();
328328
}
329+
330+
#[test]
331+
/// test for https://github.com/CQCL/hugr/issues/2005
332+
fn call_indirect_bug() {
333+
let fn_type = Signature::new(Type::UNIT, vec![Type::UNIT]);
334+
let mut hugr = {
335+
let mut builder = DFGBuilder::new(Signature::new(
336+
vec![Type::new_function(fn_type.clone()), Type::UNIT],
337+
vec![Type::UNIT, Type::UNIT],
338+
))
339+
.unwrap();
340+
let out = builder
341+
.add_dataflow_op(
342+
ops::CallIndirect { signature: fn_type },
343+
builder.input_wires(),
344+
)
345+
.unwrap()
346+
.out_wire(0);
347+
// requires another op to induce an order edge
348+
let other_unit = builder.add_load_value(Value::unary_unit_sum());
349+
builder.finish_hugr_with_outputs([out, other_unit]).unwrap()
350+
};
351+
let root = hugr.root();
352+
353+
force_order(&mut hugr, root, |_, _| 0).unwrap();
354+
}
329355
}

0 commit comments

Comments
 (0)