Skip to content

Commit

Permalink
rename to DataflowBlock and ExitBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 committed Jan 4, 2024
1 parent 9859978 commit 13c6188
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 55 deletions.
20 changes: 10 additions & 10 deletions src/builder/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{
BasicBlockID, BuildError, CfgID, Container, Dataflow, HugrBuilder, Wire,
};

use crate::ops::{self, Exit, OpType, DFB};
use crate::ops::{self, DataflowBlock, ExitBlock, OpType};
use crate::{
extension::{ExtensionRegistry, ExtensionSet},
types::FunctionType,
Expand Down Expand Up @@ -86,7 +86,7 @@ impl<B: AsMut<Hugr> + AsRef<Hugr>> CFGBuilder<B> {
output: TypeRow,
) -> Result<Self, BuildError> {
let n_out_wires = output.len();
let exit_block_type = OpType::Exit(Exit {
let exit_block_type = OpType::ExitBlock(ExitBlock {
cfg_outputs: output,
});
let exit_node = base
Expand All @@ -102,7 +102,7 @@ impl<B: AsMut<Hugr> + AsRef<Hugr>> CFGBuilder<B> {
})
}

/// Return a builder for a non-entry [`DFB`] child graph with `inputs`
/// Return a builder for a non-entry [`DataflowBlock`] child graph with `inputs`
/// and `outputs` and the variants of the branching TupleSum value
/// specified by `tuple_sum_rows`.
///
Expand Down Expand Up @@ -134,7 +134,7 @@ impl<B: AsMut<Hugr> + AsRef<Hugr>> CFGBuilder<B> {
entry: bool,
) -> Result<BlockBuilder<&mut Hugr>, BuildError> {
let tuple_sum_rows: Vec<_> = tuple_sum_rows.into_iter().collect();
let op = OpType::DFB(DFB {
let op = OpType::DataflowBlock(DataflowBlock {
inputs: inputs.clone(),
other_outputs: other_outputs.clone(),
tuple_sum_rows: tuple_sum_rows.clone(),
Expand All @@ -159,7 +159,7 @@ impl<B: AsMut<Hugr> + AsRef<Hugr>> CFGBuilder<B> {
)
}

/// Return a builder for a non-entry [`DFB`] child graph with `inputs`
/// Return a builder for a non-entry [`DataflowBlock`] child graph with `inputs`
/// and `outputs` and a UnitSum type: a Sum of `n_cases` unit types.
///
/// # Errors
Expand All @@ -178,7 +178,7 @@ impl<B: AsMut<Hugr> + AsRef<Hugr>> CFGBuilder<B> {
)
}

/// Return a builder for the entry [`DFB`] child graph with `inputs`
/// Return a builder for the entry [`DataflowBlock`] child graph with `inputs`
/// and `outputs` and the variants of the branching TupleSum value
/// specified by `tuple_sum_rows`.
///
Expand All @@ -198,7 +198,7 @@ impl<B: AsMut<Hugr> + AsRef<Hugr>> CFGBuilder<B> {
self.any_block_builder(inputs, tuple_sum_rows, other_outputs, extension_delta, true)
}

/// Return a builder for the entry [`DFB`] child graph with `inputs`
/// Return a builder for the entry [`DataflowBlock`] child graph with `inputs`
/// and `outputs` and a UnitSum type: a Sum of `n_cases` unit types.
///
/// # Errors
Expand Down Expand Up @@ -235,7 +235,7 @@ impl<B: AsMut<Hugr> + AsRef<Hugr>> CFGBuilder<B> {
}
}

/// Builder for a [`DFB`] child graph.
/// Builder for a [`DataflowBlock`] child graph.
pub type BlockBuilder<B> = DFGWrapper<B, BasicBlockID>;

impl<B: AsMut<Hugr> + AsRef<Hugr>> BlockBuilder<B> {
Expand Down Expand Up @@ -285,7 +285,7 @@ impl<B: AsMut<Hugr> + AsRef<Hugr>> BlockBuilder<B> {
}

impl BlockBuilder<Hugr> {
/// Initialize a [`DFB`] rooted HUGR builder
/// Initialize a [`DataflowBlock`] rooted HUGR builder
pub fn new(
inputs: impl Into<TypeRow>,
input_extensions: impl Into<Option<ExtensionSet>>,
Expand All @@ -296,7 +296,7 @@ impl BlockBuilder<Hugr> {
let inputs = inputs.into();
let tuple_sum_rows: Vec<_> = tuple_sum_rows.into_iter().collect();
let other_outputs = other_outputs.into();
let op = DFB {
let op = DataflowBlock {
inputs: inputs.clone(),
other_outputs: other_outputs.clone(),
tuple_sum_rows: tuple_sum_rows.clone(),
Expand Down
6 changes: 3 additions & 3 deletions src/extension/infer/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ fn make_block(
let tuple_sum_type = Type::new_tuple_sum(tuple_sum_rows.clone());
let dfb_sig = FunctionType::new(inputs.clone(), vec![tuple_sum_type])
.with_extension_delta(&extension_delta.clone());
let dfb = ops::DFB {
let dfb = ops::DataflowBlock {
inputs,
other_outputs: type_row![],
tuple_sum_rows,
Expand Down Expand Up @@ -496,7 +496,7 @@ fn create_entry_exit(
exit_types: impl Into<TypeRow>,
) -> Result<([Node; 3], Node), Box<dyn Error>> {
let entry_tuple_sum = Type::new_tuple_sum(entry_variants.clone());
let dfb = ops::DFB {
let dfb = ops::DataflowBlock {
inputs: inputs.clone(),
other_outputs: type_row![],
tuple_sum_rows: entry_variants,
Expand All @@ -505,7 +505,7 @@ fn create_entry_exit(

let exit = hugr.add_node_with_parent(
root,
ops::Exit {
ops::ExitBlock {
cfg_outputs: exit_types.into(),
},
)?;
Expand Down
12 changes: 6 additions & 6 deletions src/hugr/rewrite/outline_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::ops;
use crate::ops::controlflow::BasicBlock;
use crate::ops::dataflow::DataflowOpTrait;
use crate::ops::handle::{BasicBlockID, CfgID, NodeHandle};
use crate::ops::{OpType, DFB};
use crate::ops::{DataflowBlock, OpType};
use crate::PortIndex;
use crate::{type_row, Node};

Expand Down Expand Up @@ -115,13 +115,13 @@ impl Rewrite for OutlineCfg {
self.compute_entry_exit_outside_extensions(h)?;
// 1. Compute signature
// These panic()s only happen if the Hugr would not have passed validate()
let OpType::DFB(DFB { inputs, .. }) = h.get_optype(entry) else {
let OpType::DataflowBlock(DataflowBlock { inputs, .. }) = h.get_optype(entry) else {
panic!("Entry node is not a basic block")
};
let inputs = inputs.clone();
let outputs = match h.get_optype(outside) {
OpType::DFB(dfb) => dfb.dataflow_input().clone(),
OpType::Exit(exit) => exit.dataflow_input().clone(),
OpType::DataflowBlock(dfb) => dfb.dataflow_input().clone(),
OpType::ExitBlock(exit) => exit.dataflow_input().clone(),
_ => panic!("External successor not a basic block"),
};
let outer_cfg = h.get_parent(entry).unwrap();
Expand Down Expand Up @@ -349,7 +349,7 @@ mod test {
h.output_neighbours(tail).take(2).collect::<HashSet<Node>>(),
HashSet::from([exit, new_block])
);
assert!(h.get_optype(new_block).is_dfb());
assert!(h.get_optype(new_block).is_dataflow_block());
assert_eq!(h.base_hugr().get_parent(new_cfg), Some(new_block));
assert!(h.base_hugr().get_optype(new_cfg).is_cfg());
}
Expand Down Expand Up @@ -407,7 +407,7 @@ mod test {
.unwrap();
h.update_validate(&PRELUDE_REGISTRY).unwrap();
assert_eq!(new_block, h.children(h.root()).next().unwrap());
assert!(h.get_optype(new_block).is_dfb());
assert!(h.get_optype(new_block).is_dataflow_block());
assert_eq!(h.get_parent(new_cfg), Some(new_block));
assert!(h.get_optype(new_cfg).is_cfg());
for n in other_blocks {
Expand Down
10 changes: 5 additions & 5 deletions src/hugr/rewrite/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ mod test {
use crate::ops::custom::{ExternalOp, OpaqueOp};
use crate::ops::dataflow::DataflowOpTrait;
use crate::ops::handle::{BasicBlockID, ConstID, NodeHandle};
use crate::ops::{self, Case, LeafOp, OpTag, OpType, DFB, DFG};
use crate::ops::{self, Case, DataflowBlock, LeafOp, OpTag, OpType, DFG};
use crate::std_extensions::collections;
use crate::types::{FunctionType, Type, TypeArg, TypeRow};
use crate::{type_row, Direction, Hugr, HugrView, OutgoingPort};
Expand Down Expand Up @@ -504,8 +504,8 @@ mod test {
let popp = h.get_parent(pop).unwrap();
let pushp = h.get_parent(push).unwrap();
assert_ne!(popp, pushp); // Two different BBs
assert!(h.get_optype(popp).is_dfb());
assert!(h.get_optype(pushp).is_dfb());
assert!(h.get_optype(popp).is_dataflow_block());
assert!(h.get_optype(pushp).is_dataflow_block());

assert_eq!(h.get_parent(popp).unwrap(), h.get_parent(pushp).unwrap());
}
Expand All @@ -517,7 +517,7 @@ mod test {
}));
let r_bb = replacement.add_node_with_parent(
replacement.root(),
DFB {
DataflowBlock {
inputs: vec![listy.clone()].into(),
tuple_sum_rows: vec![type_row![]],
other_outputs: vec![listy.clone()].into(),
Expand Down Expand Up @@ -590,7 +590,7 @@ mod test {

let grandp = h.get_parent(popp).unwrap();
assert_eq!(grandp, h.get_parent(pushp).unwrap());
assert!(h.get_optype(grandp).is_dfb());
assert!(h.get_optype(grandp).is_dataflow_block());
}

Ok(())
Expand Down
8 changes: 4 additions & 4 deletions src/hugr/validate/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ fn cfg_children_restrictions() {
let block = b
.add_node_with_parent(
cfg,
ops::DFB {
ops::DataflowBlock {
inputs: type_row![BOOL_T],
tuple_sum_rows: vec![type_row![]],
other_outputs: type_row![BOOL_T],
Expand All @@ -301,7 +301,7 @@ fn cfg_children_restrictions() {
let exit = b
.add_node_with_parent(
cfg,
ops::Exit {
ops::ExitBlock {
cfg_outputs: type_row![BOOL_T],
},
)
Expand All @@ -315,7 +315,7 @@ fn cfg_children_restrictions() {
let exit2 = b
.add_node_after(
exit,
ops::Exit {
ops::ExitBlock {
cfg_outputs: type_row![BOOL_T],
},
)
Expand All @@ -330,7 +330,7 @@ fn cfg_children_restrictions() {
// Change the types in the BasicBlock node to work on qubits instead of bits
b.replace_op(
block,
NodeType::new_pure(ops::DFB {
NodeType::new_pure(ops::DataflowBlock {
inputs: type_row![Q],
tuple_sum_rows: vec![type_row![]],
other_outputs: type_row![Q],
Expand Down
4 changes: 2 additions & 2 deletions src/hugr/views/root_checked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ mod test {
use crate::hugr::hugrmut::sealed::HugrMutInternals;
use crate::hugr::{HugrError, HugrMut, NodeType};
use crate::ops::handle::{BasicBlockID, CfgID, DataflowParentID, DfgID};
use crate::ops::{LeafOp, OpTag, DFB};
use crate::ops::{DataflowBlock, LeafOp, OpTag};
use crate::{ops, type_row, types::FunctionType, Hugr, HugrView};

#[test]
Expand All @@ -94,7 +94,7 @@ mod test {
let mut dfg_v = RootChecked::<&mut Hugr, DfgID>::try_new(&mut h).unwrap();
// That is a HugrMutInternal, so we can try:
let root = dfg_v.root();
let bb = NodeType::new_pure(DFB {
let bb = NodeType::new_pure(DataflowBlock {
inputs: type_row![],
other_outputs: type_row![],
tuple_sum_rows: vec![type_row![]],
Expand Down
10 changes: 5 additions & 5 deletions src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use smol_str::SmolStr;
use enum_dispatch::enum_dispatch;

pub use constant::Const;
pub use controlflow::{Case, Conditional, Exit, TailLoop, CFG, DFB};
pub use controlflow::{Case, Conditional, DataflowBlock, ExitBlock, TailLoop, CFG};
pub use dataflow::{Call, CallIndirect, Input, LoadConstant, Output, DFG};
pub use leaf::LeafOp;
pub use module::{AliasDecl, AliasDefn, FuncDecl, FuncDefn, Module};
Expand All @@ -48,8 +48,8 @@ pub enum OpType {
LoadConstant,
DFG,
LeafOp,
DFB,
Exit,
DataflowBlock,
ExitBlock,
TailLoop,
CFG,
Conditional,
Expand Down Expand Up @@ -94,8 +94,8 @@ impl_op_ref_try_into!(CallIndirect);
impl_op_ref_try_into!(LoadConstant);
impl_op_ref_try_into!(DFG, dfg);
impl_op_ref_try_into!(LeafOp);
impl_op_ref_try_into!(DFB, dfb);
impl_op_ref_try_into!(Exit);
impl_op_ref_try_into!(DataflowBlock);
impl_op_ref_try_into!(ExitBlock);
impl_op_ref_try_into!(TailLoop);
impl_op_ref_try_into!(CFG, cfg);
impl_op_ref_try_into!(Conditional);
Expand Down
26 changes: 13 additions & 13 deletions src/ops/controlflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl DataflowOpTrait for CFG {
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
/// A CFG basic block node. The signature is that of the internal Dataflow graph.
#[allow(missing_docs)]
pub struct DFB {
pub struct DataflowBlock {
pub inputs: TypeRow,
pub other_outputs: TypeRow,
pub tuple_sum_rows: Vec<TypeRow>,
Expand All @@ -127,32 +127,32 @@ pub struct DFB {
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
/// The single exit node of the CFG, has no children,
/// stores the types of the CFG node output.
pub struct Exit {
pub struct ExitBlock {
/// Output type row of the CFG.
pub cfg_outputs: TypeRow,
}

impl OpName for DFB {
impl OpName for DataflowBlock {
fn name(&self) -> SmolStr {
"DFB".into()
"DataflowBlock".into()
}
}

impl OpName for Exit {
impl OpName for ExitBlock {
fn name(&self) -> SmolStr {
"Exit".into()
}
}

impl StaticTag for DFB {
impl StaticTag for DataflowBlock {
const TAG: OpTag = OpTag::BasicBlock;
}

impl StaticTag for Exit {
impl StaticTag for ExitBlock {
const TAG: OpTag = OpTag::BasicBlockExit;
}

impl OpTrait for DFB {
impl OpTrait for DataflowBlock {
fn description(&self) -> &str {
"A CFG basic block node"
}
Expand Down Expand Up @@ -183,7 +183,7 @@ impl OpTrait for DFB {
}
}

impl OpTrait for Exit {
impl OpTrait for ExitBlock {
fn description(&self) -> &str {
"A CFG exit block node"
}
Expand Down Expand Up @@ -212,18 +212,18 @@ impl OpTrait for Exit {
}
}

/// Functionality shared by DFB and Exit CFG block types.
/// Functionality shared by DataflowBlock and Exit CFG block types.
pub trait BasicBlock {
/// The input dataflow signature of the CFG block.
fn dataflow_input(&self) -> &TypeRow;
}

impl BasicBlock for DFB {
impl BasicBlock for DataflowBlock {
fn dataflow_input(&self) -> &TypeRow {
&self.inputs
}
}
impl DFB {
impl DataflowBlock {
/// The correct inputs of any successors. Returns None if successor is not a
/// valid index.
pub fn successor_input(&self, successor: usize) -> Option<TypeRow> {
Expand All @@ -234,7 +234,7 @@ impl DFB {
}
}

impl BasicBlock for Exit {
impl BasicBlock for ExitBlock {
fn dataflow_input(&self) -> &TypeRow {
&self.cfg_outputs
}
Expand Down
2 changes: 1 addition & 1 deletion src/ops/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl<const DEF: bool> AliasID<DEF> {
pub struct ConstID(Node);

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, DerFrom, Debug)]
/// Handle to a [DFB](crate::ops::DFB) or [Exit](crate::ops::Exit) node.
/// Handle to a [DataflowBlock](crate::ops::DataflowBlock) or [Exit](crate::ops::ExitBlock) node.
pub struct BasicBlockID(Node);

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, DerFrom, Debug)]
Expand Down
Loading

0 comments on commit 13c6188

Please sign in to comment.