diff --git a/specification/hugr.md b/specification/hugr.md index fc5f6f65b..2033aea2a 100644 --- a/specification/hugr.md +++ b/specification/hugr.md @@ -1355,7 +1355,7 @@ omitted it defaults to the parent of `c` (in this case said `c` will have to be in a DSG or CSG rather than under the Module Root.) If `P` is provided, it must be a descendent of the parent of `c`. -###### `RemoveConstIgnore` +###### `RemoveLoadConstant` Given a `LoadConstant` node `n` that has no outgoing edges, remove it (and its incoming Static edge and any Order edges) from the hugr. @@ -1408,7 +1408,7 @@ using `Replace` (with a set of `identity` nodes) followed by ### Normalisation We envisage that some kind of pass can be used after a rewrite or series -of rewrites to automatically apply RemoveConstIgnore for any unused +of rewrites to automatically apply RemoveLoadConstant for any unused load\_constants, and other such tidies. This might be global, or by tracking which parts of the Hugr have been touched. diff --git a/src/algorithm/const_fold.rs b/src/algorithm/const_fold.rs index 6ae55f8a9..531181d58 100644 --- a/src/algorithm/const_fold.rs +++ b/src/algorithm/const_fold.rs @@ -8,7 +8,7 @@ use crate::{ builder::{DFGBuilder, Dataflow, DataflowHugr}, extension::{ConstFoldResult, ExtensionRegistry}, hugr::{ - rewrite::consts::{RemoveConst, RemoveConstIgnore}, + rewrite::consts::{RemoveConst, RemoveLoadConstant}, views::SiblingSubgraph, HugrMut, }, @@ -96,14 +96,14 @@ fn const_graph(consts: Vec, reg: &ExtensionRegistry) -> Hugr { /// return an iterator of possible constant folding rewrites. The /// [`SimpleReplacement`] replaces an operation with constants that result from /// evaluating it, the extension registry `reg` is used to validate the -/// replacement HUGR. The vector of [`RemoveConstIgnore`] refer to the +/// replacement HUGR. The vector of [`RemoveLoadConstant`] refer to the /// LoadConstant nodes that could be removed - they are not automatically /// removed as they may be used by other operations. pub fn find_consts<'a, 'r: 'a>( hugr: &'a impl HugrView, candidate_nodes: impl IntoIterator + 'a, reg: &'r ExtensionRegistry, -) -> impl Iterator)> + 'a { +) -> impl Iterator)> + 'a { // track nodes for operations that have already been considered for folding let mut used_neighbours = BTreeSet::new(); @@ -135,14 +135,14 @@ fn fold_op( hugr: &impl HugrView, op_node: Node, reg: &ExtensionRegistry, -) -> Option<(SimpleReplacement, Vec)> { +) -> Option<(SimpleReplacement, Vec)> { // only support leaf folding for now. let neighbour_op = hugr.get_optype(op_node).as_leaf_op()?; let (in_consts, removals): (Vec<_>, Vec<_>) = hugr .node_inputs(op_node) .filter_map(|in_p| { let (con_op, load_n) = get_const(hugr, op_node, in_p)?; - Some(((in_p, con_op), RemoveConstIgnore(load_n))) + Some(((in_p, con_op), RemoveLoadConstant(load_n))) }) .unzip(); // attempt to evaluate op diff --git a/src/hugr/rewrite/consts.rs b/src/hugr/rewrite/consts.rs index 2fee7a53d..e1a0fd487 100644 --- a/src/hugr/rewrite/consts.rs +++ b/src/hugr/rewrite/consts.rs @@ -13,9 +13,9 @@ use super::Rewrite; /// Remove a [`crate::ops::LoadConstant`] node with no consumers. #[derive(Debug, Clone)] -pub struct RemoveConstIgnore(pub Node); +pub struct RemoveLoadConstant(pub Node); -/// Error from an [`RemoveConst`] or [`RemoveConstIgnore`] operation. +/// Error from an [`RemoveConst`] or [`RemoveLoadConstant`] operation. #[derive(Debug, Clone, Error, PartialEq, Eq)] pub enum RemoveError { /// Invalid node. @@ -29,7 +29,7 @@ pub enum RemoveError { RemoveFail(#[from] HugrError), } -impl Rewrite for RemoveConstIgnore { +impl Rewrite for RemoveLoadConstant { type Error = RemoveError; // The Const node the LoadConstant was connected to. @@ -161,20 +161,20 @@ mod test { ); assert_eq!( - h.apply_rewrite(RemoveConstIgnore(tup_node)), + h.apply_rewrite(RemoveLoadConstant(tup_node)), Err(RemoveError::InvalidNode(tup_node)) ); let load_1_node = load_1.node(); let load_2_node = load_2.node(); let con_node = con_node.node(); - let remove_1 = RemoveConstIgnore(load_1_node); + let remove_1 = RemoveLoadConstant(load_1_node); assert_eq!( remove_1.invalidation_set().exactly_one().ok(), Some(load_1_node) ); - let remove_2 = RemoveConstIgnore(load_2_node); + let remove_2 = RemoveLoadConstant(load_2_node); let remove_con = RemoveConst(con_node); assert_eq!(