Skip to content

Commit

Permalink
interpret_leaf_op is &mut to allow impls that do caching etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
acl-cqc committed Dec 4, 2024
1 parent c5bd7b0 commit eecdb22
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions hugr-passes/src/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ use hugr_core::{Hugr, Node};
/// must implement this trait (including providing an appropriate domain type `V`).
pub trait DFContext<V>: ConstLoader<V> {
/// Given lattice values for each input, update lattice values for the (dataflow) outputs.
/// For extension ops only, excluding [MakeTuple] and [UnpackTuple].
/// For extension ops only, excluding [MakeTuple] and [UnpackTuple] which are handled automatically.
/// `_outs` is an array with one element per dataflow output, each initialized to [PartialValue::Top]
/// which is the correct value to leave if nothing can be deduced about that output.
/// (The default does nothing, i.e. leaves `Top` for all outputs.)
///
/// [MakeTuple]: hugr_core::extension::prelude::MakeTuple
/// [UnpackTuple]: hugr_core::extension::prelude::UnpackTuple
fn interpret_leaf_op(
&self,
&mut self,
_node: Node,
_e: &ExtensionOp,
_ins: &[PartialValue<V>],
Expand Down
6 changes: 3 additions & 3 deletions hugr-passes/src/dataflow/datalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl<H: HugrView, V: AbstractValue> Machine<H, V> {
}

pub(super) fn run_datalog<V: AbstractValue, H: HugrView>(
ctx: impl DFContext<V>,
mut ctx: impl DFContext<V>,
hugr: H,
in_wire_value_proto: Vec<(Node, IncomingPort, PV<V>)>,
) -> AnalysisResults<V, H> {
Expand Down Expand Up @@ -187,7 +187,7 @@ pub(super) fn run_datalog<V: AbstractValue, H: HugrView>(
if !op_t.is_container(),
if let Some(sig) = op_t.dataflow_signature(),
node_in_value_row(n, vs),
if let Some(outs) = propagate_leaf_op(&ctx, &hugr, *n, &vs[..], sig.output_count()),
if let Some(outs) = propagate_leaf_op(&mut ctx, &hugr, *n, &vs[..], sig.output_count()),
for (p, v) in (0..).map(OutgoingPort::from).zip(outs);

// DFG --------------------
Expand Down Expand Up @@ -329,7 +329,7 @@ pub(super) fn run_datalog<V: AbstractValue, H: HugrView>(
}

fn propagate_leaf_op<V: AbstractValue>(
ctx: &impl DFContext<V>,
ctx: &mut impl DFContext<V>,
hugr: &impl HugrView,
n: Node,
ins: &[PV<V>],
Expand Down
3 changes: 1 addition & 2 deletions hugr-passes/src/dataflow/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,7 @@ fn test_cfg(
xor_and_cfg: Hugr,
) {
let root = xor_and_cfg.root();
let results =
Machine::new(&xor_and_cfg).run(TestContext, [(0.into(), inp0), (1.into(), inp1)]);
let results = Machine::new(&xor_and_cfg).run(TestContext, [(0.into(), inp0), (1.into(), inp1)]);

assert_eq!(results.read_out_wire(Wire::new(root, 0)).unwrap(), out0);
assert_eq!(results.read_out_wire(Wire::new(root, 1)).unwrap(), out1);
Expand Down

0 comments on commit eecdb22

Please sign in to comment.