Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Extend LowerTypes pass to linearize by inserting copy/discard #2018

Merged
merged 129 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
937cd14
Add TypeTransformer and (Sum/Function)Type(Arg/Row)::transform
acl-cqc Mar 11, 2025
815536b
trait Transformable to common up all the 'let mut any_change = false'…
acl-cqc Mar 12, 2025
cc1e8f2
Transformable v2: implement for [E], works without iter_mut/etc. in a…
acl-cqc Mar 12, 2025
4888184
first test, fix CustomType bound caching
acl-cqc Mar 17, 2025
7002e4d
Second test, fix SumType caching
acl-cqc Mar 17, 2025
6cc7cea
Make clippy happy
acl-cqc Mar 17, 2025
d43784b
Add HugrMut::optype_mut (v2, allow mutating root if RootHandle == Node)
acl-cqc Mar 11, 2025
422c496
WIP add hugr-passes/src/lower_types.rs (w/ change_node, subst_ty)
acl-cqc Mar 5, 2025
76ed391
Add def_arc
acl-cqc Mar 11, 2025
ed5b5dd
change_node, change_type, and the rest
acl-cqc Mar 10, 2025
adcbbf6
Use TypeTransformer framework, removing most type_stuff from lower_ty…
acl-cqc Mar 11, 2025
d84ae4e
Add a load of copy/discard lowering stuff, OpReplacement
acl-cqc Mar 12, 2025
bfa52cf
OpHashWrapper
acl-cqc Mar 12, 2025
b373571
Parametrized type support
acl-cqc Mar 17, 2025
a8e613a
remove copy_discard stuff
acl-cqc Mar 17, 2025
24ed15c
Assume less in OpReplacement::replace
acl-cqc Mar 17, 2025
9153fcf
parametrized ops
acl-cqc Mar 17, 2025
a89879c
Comments, renaming, use const_fn
acl-cqc Mar 17, 2025
c78d88a
Comment const_fn TODO
acl-cqc Mar 17, 2025
bf6a9a4
Test panics on unexpected argument - simpler, better
acl-cqc Mar 18, 2025
5ecd9e6
test functiontype
acl-cqc Mar 18, 2025
d9a6d29
clippy that new test
acl-cqc Mar 18, 2025
83e798e
Merge remote-tracking branch 'origin/main' into acl/type_transform
acl-cqc Mar 18, 2025
84fe82d
WIP setup for test
acl-cqc Mar 18, 2025
6168353
First test
acl-cqc Mar 18, 2025
fcb85a2
read only makes sense for Copyables
acl-cqc Mar 18, 2025
0f9aa17
Extend test to Calls of polyfunc; comments, monomorphize first
acl-cqc Mar 18, 2025
74c6775
no, instantiate the calls with types being lowered
acl-cqc Mar 18, 2025
00fd284
Consts: HashMap keyed by either, add lower_ methods. Test TailLoop an…
acl-cqc Mar 18, 2025
9f02acf
clippy, turn off type-complexity
acl-cqc Mar 18, 2025
a0ac6d6
Actual Error for check_sig, add setter method
acl-cqc Mar 19, 2025
6ac9efc
docs
acl-cqc Mar 19, 2025
044ff32
Test variable, boundednat; use list_type
acl-cqc Mar 19, 2025
b539e2f
Yet Another ValidationLevel interface
acl-cqc Mar 19, 2025
2c7e035
Merge remote-tracking branch 'origin/main' into acl/type_transform
acl-cqc Mar 19, 2025
6b190a6
Merge branch 'acl/type_transform' into acl/lower_types
acl-cqc Mar 19, 2025
bd24d1a
clippy
acl-cqc Mar 19, 2025
a5d8b65
doclinxs
acl-cqc Mar 19, 2025
6b1438c
pub re-export
acl-cqc Mar 19, 2025
d1036bc
fix const_loop for extensions
acl-cqc Mar 19, 2025
d19dc5a
fix other test for extensions, but turn off extension validation afte…
acl-cqc Mar 19, 2025
d0fddde
Add another test of Conditional + Case
acl-cqc Mar 21, 2025
3494887
common up read_op
acl-cqc Mar 21, 2025
ffdcaf2
test tidies
acl-cqc Mar 21, 2025
6f8f43c
No need to validate, run() does it for us
acl-cqc Mar 21, 2025
e3da259
check_sig: use Option::unzip to tuple-ize
acl-cqc Mar 21, 2025
28f2470
Move private utility classes below the pub ones; add comments
acl-cqc Mar 21, 2025
bef90b0
Comments - all callbacks return Option
acl-cqc Mar 24, 2025
85df7ff
test: Rename lower_types to lowerer
acl-cqc Mar 25, 2025
507f027
Extend loop_const test
acl-cqc Mar 25, 2025
bae0ebe
Add copy/dup linearization stuff
acl-cqc Mar 25, 2025
8fa79bd
do_copy_chain => insert_copy_discard
acl-cqc Mar 21, 2025
6a186a5
Move insert_copy_discard into Linearizer
acl-cqc Mar 25, 2025
6d8a89b
Add LinearizeError
acl-cqc Mar 21, 2025
3f0f1e6
pass Linearizer to callbacks
acl-cqc Mar 21, 2025
974a25b
comments
acl-cqc Mar 24, 2025
2bbf663
first test, don't linearize root node outputs, reject nonlocal edges
acl-cqc Mar 21, 2025
290a8ae
copy_fn/discard_fn return Result
acl-cqc Mar 23, 2025
19b1442
linearize takes &TypeDef not TypeDef
acl-cqc Mar 23, 2025
269f0f1
OpReplacement::add(&self, ...) -> add_hugr(self, ...)
acl-cqc Mar 24, 2025
f6a1af5
Drop an else-continue
acl-cqc Mar 25, 2025
ac9adac
Add OpReplacement::add for builder
acl-cqc Mar 24, 2025
65eaf52
Handle Sum Types in copy_op/discard_op
acl-cqc Mar 25, 2025
354a89c
drop redundant allow-missing_docs
acl-cqc Mar 25, 2025
1b31631
Refactor test code, fix --all-features
acl-cqc Mar 23, 2025
d5cbd58
Test copying+discarding an option of two elements
acl-cqc Mar 25, 2025
63bdd3b
tidy imports
acl-cqc Mar 25, 2025
1ac3728
Combine lower_consts(_parametric) with lower_(parametric_)type
acl-cqc Mar 25, 2025
e768814
Test sig checking
acl-cqc Mar 25, 2025
506570b
No, remove sig checking
acl-cqc Mar 25, 2025
0958e2a
Test funky partial replace
acl-cqc Mar 25, 2025
74cfdb1
common up just_elem_type
acl-cqc Mar 25, 2025
dc79c93
comment spacing
acl-cqc Mar 25, 2025
63d24b0
RIP SignatureMismatch
acl-cqc Mar 25, 2025
ba63fbe
Reinstate separate lower_consts/lower_consts_parametric
acl-cqc Mar 26, 2025
2c7bb80
Remove the boxes
acl-cqc Mar 26, 2025
08d3227
drop comment re. validation_level
acl-cqc Mar 26, 2025
dedc3d5
rename module lower_types -> replace_types
acl-cqc Mar 26, 2025
9993467
rename LowerTypes=>ReplaceTypes, ChangeTypeError => ReplaceTypesError
acl-cqc Mar 26, 2025
cc81d87
rename methods, parametric => parametrized
acl-cqc Mar 26, 2025
74c6492
doc notes
acl-cqc Mar 26, 2025
18316de
comment/doc updates
acl-cqc Mar 26, 2025
520e414
fmt
acl-cqc Mar 26, 2025
0814bf2
callbacks for Const take &ReplaceTypes
acl-cqc Mar 26, 2025
0a82fef
Replace that break 'changed block with a match, + map_or_else to avoi…
acl-cqc Mar 26, 2025
94c0ff3
Add Type::as_extension
acl-cqc Mar 26, 2025
e9ff81c
wip
acl-cqc Mar 26, 2025
cf6451f
add list_const handler, use in test
acl-cqc Mar 26, 2025
9a355d5
Clarify replace_consts_parametrized callback
acl-cqc Mar 26, 2025
ec2d0ba
const callbacks report errors via Result
acl-cqc Mar 26, 2025
c9d7033
fmt+fix
acl-cqc Mar 26, 2025
812ac89
comment tweaks
acl-cqc Mar 26, 2025
ae7bd6e
Merge remote-tracking branch 'origin/main' into acl/lower_types
acl-cqc Mar 26, 2025
e0937ee
docs
acl-cqc Mar 26, 2025
36df03c
and some more - warn on missing_docs except ReplaceTypesError
acl-cqc Mar 26, 2025
71f8c0b
Merge remote-tracking branch 'origin/main' into acl/lower_types
acl-cqc Mar 26, 2025
dc0c7dd
Merge branch 'acl/lower_types' into acl/lower_types_linearize
acl-cqc Mar 26, 2025
31ba4e0
docs, make pub, more errors
acl-cqc Mar 26, 2025
86c73ed
Test copyable element inside Sum - breaks test
acl-cqc Mar 26, 2025
92d7a51
Error on copyable; handle copyable elements of sums - fixes
acl-cqc Mar 26, 2025
582b9f1
register errors with type; panic on function as already ruled out
acl-cqc Mar 26, 2025
95da97d
more docs - no overriding copy/discard of non-extension types
acl-cqc Mar 26, 2025
c7e56e6
pub discard_op
acl-cqc Mar 27, 2025
a1e63de
rm Boxes
acl-cqc Mar 28, 2025
7634e92
Only allow copy/discard funcs for *Custom*Type's
acl-cqc Mar 28, 2025
0cd31e0
single callback taking num_outports != 1
acl-cqc Mar 28, 2025
65b8993
In insert_copy_discard, a discard really is a 0-way copy
acl-cqc Mar 28, 2025
198f990
renaming
acl-cqc Mar 28, 2025
517cd0d
Generalize test 2,3,4 copies
acl-cqc Mar 28, 2025
272f024
Simplify test w/binary copy to just option type, add more complex w/ …
acl-cqc Mar 28, 2025
e74b12b
combine the two test extensions
acl-cqc Mar 28, 2025
34bd90d
tweaks
acl-cqc Mar 28, 2025
a2cba09
filter
acl-cqc Mar 28, 2025
3084004
so that
acl-cqc Mar 28, 2025
cec9162
insert_copy_discard takes Wire, no Type
acl-cqc Mar 28, 2025
bf74996
Rename OpReplacement -> NodeTemplate
acl-cqc Mar 28, 2025
221bf7d
fix dataflowparent doclink
acl-cqc Mar 28, 2025
f6312bc
Remove linearize() proxy methods, add linearizer() getter - docs a mess
acl-cqc Mar 30, 2025
5fe25c0
docs+notes
acl-cqc Mar 30, 2025
edd2126
fix lists in docs
acl-cqc Mar 30, 2025
5ea9763
Add Linearizer trait, rename to DelegatingLinearizer
acl-cqc Mar 31, 2025
cc4fd68
Pass &dyn Linearizer - requires making object-safe
acl-cqc Mar 31, 2025
8a1ff0c
No - revert - instead pass ref to new CallbackHandler struct
acl-cqc Mar 31, 2025
d5e4ac3
Add LinearizeError::WrongSignature
acl-cqc Apr 1, 2025
b259426
Remove NeedDiscard, rename NeedCopy
acl-cqc Apr 1, 2025
a14fafa
test, also check sig for register(CustTy, NodeTempl*2)
acl-cqc Apr 1, 2025
a4686d3
lint
doug-q Apr 2, 2025
1abf1b4
docs
doug-q Apr 2, 2025
7e3efcc
Rename register(=>_simple,_parametric=>_callback), docs
acl-cqc Apr 2, 2025
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
154 changes: 126 additions & 28 deletions hugr-passes/src/replace_types.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,47 @@
#![allow(clippy::type_complexity)]
#![warn(missing_docs)]
//! Replace types with other types across the Hugr.
//! Replace types with other types across the Hugr. See [ReplaceTypes] and [Linearizer].
//!
//! Parametrized types and ops will be reparametrized taking into account the replacements,
//! but any ops taking/returning the replaced types *not* as a result of parametrization,
//! will also need to be replaced - see [ReplaceTypes::replace_op]. (Similarly [Const]s.)
use std::borrow::Cow;
use std::collections::HashMap;
use std::sync::Arc;

use thiserror::Error;

use hugr_core::builder::{BuildError, BuildHandle, Dataflow};
use hugr_core::extension::{ExtensionId, OpDef, SignatureError, TypeDef};
use hugr_core::hugr::hugrmut::HugrMut;
use hugr_core::ops::constant::{OpaqueValue, Sum};
use hugr_core::ops::handle::DataflowOpID;
use hugr_core::ops::{
AliasDefn, Call, CallIndirect, Case, Conditional, Const, DataflowBlock, ExitBlock, ExtensionOp,
FuncDecl, FuncDefn, Input, LoadConstant, LoadFunction, OpType, Output, Tag, TailLoop, Value,
CFG, DFG,
FuncDecl, FuncDefn, Input, LoadConstant, LoadFunction, OpTrait, OpType, Output, Tag, TailLoop,
Value, CFG, DFG,
};
use hugr_core::types::{CustomType, Transformable, Type, TypeArg, TypeEnum, TypeTransformer};
use hugr_core::{Hugr, Node};
use hugr_core::types::{
CustomType, Signature, Transformable, Type, TypeArg, TypeEnum, TypeTransformer,
};
use hugr_core::{Hugr, HugrView, Node, Wire};

use crate::validation::{ValidatePassError, ValidationLevel};

/// A thing with which an Op (i.e. node) can be replaced
mod linearize;
pub use linearize::{CallbackHandler, DelegatingLinearizer, LinearizeError, Linearizer};

/// A recipe for creating a dataflow Node - as a new child of a [DataflowParent]
/// or in order to replace an existing node.
///
/// [DataflowParent]: hugr_core::ops::OpTag::DataflowParent
#[derive(Clone, Debug, PartialEq)]
pub enum OpReplacement {
/// Keep the same node, change only the op (updating types of inputs/outputs)
pub enum NodeTemplate {
/// A single node - so if replacing an existing node, change only the op
SingleOp(OpType),
/// Defines a sub-Hugr to splice in place of the op - a [CFG], [Conditional], [DFG]
/// or [TailLoop], which must have the same inputs and outputs as the original op,
/// modulo replacement.
/// Defines a sub-Hugr to insert, whose root becomes (or replaces) the desired Node.
/// The root must be a [CFG], [Conditional], [DFG] or [TailLoop].
// Not a FuncDefn, nor Case/DataflowBlock
/// Note this will be of limited use before [monomorphization](super::monomorphize()) because
/// the sub-Hugr will not be able to use type variables present in the op.
/// Note this will be of limited use before [monomorphization](super::monomorphize())
/// because the new subtree will not be able to use type variables present in the
/// parent Hugr or previous op.
// TODO: store also a vec<TypeParam>, and update Hugr::validate to take &[TypeParam]s
// (defaulting to empty list) - see https://github.com/CQCL/hugr/issues/709
CompoundOp(Box<Hugr>),
Expand All @@ -42,12 +50,33 @@ pub enum OpReplacement {
// So client should add the functions before replacement, then remove unused ones afterwards.)
}

impl OpReplacement {
impl NodeTemplate {
/// Adds this instance to the specified [HugrMut] as a new node or subtree under a
/// given parent, returning the unique new child (of that parent) thus created
pub fn add_hugr(self, hugr: &mut impl HugrMut, parent: Node) -> Node {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two are pub because other extensions may want them for defining their own copy/discard handlers (that build nested Hugrs that copy elements of collections, etc.)

match self {
NodeTemplate::SingleOp(op_type) => hugr.add_node_with_parent(parent, op_type),
NodeTemplate::CompoundOp(new_h) => hugr.insert_hugr(parent, *new_h).new_root,
}
}

/// Adds this instance to the specified [Dataflow] builder as a new node or subtree
pub fn add(
self,
dfb: &mut impl Dataflow,
inputs: impl IntoIterator<Item = Wire>,
) -> Result<BuildHandle<DataflowOpID>, BuildError> {
match self {
NodeTemplate::SingleOp(opty) => dfb.add_dataflow_op(opty, inputs),
NodeTemplate::CompoundOp(h) => dfb.add_hugr_with_wires(*h, inputs),
}
}

fn replace(&self, hugr: &mut impl HugrMut, n: Node) {
assert_eq!(hugr.children(n).count(), 0);
let new_optype = match self.clone() {
OpReplacement::SingleOp(op_type) => op_type,
OpReplacement::CompoundOp(new_h) => {
NodeTemplate::SingleOp(op_type) => op_type,
NodeTemplate::CompoundOp(new_h) => {
let new_root = hugr.insert_hugr(n, *new_h).new_root;
let children = hugr.children(new_root).collect::<Vec<_>>();
let root_opty = hugr.remove_node(new_root);
Expand All @@ -59,16 +88,50 @@ impl OpReplacement {
};
*hugr.optype_mut(n) = new_optype;
}

fn signature(&self) -> Option<Cow<'_, Signature>> {
match self {
NodeTemplate::SingleOp(op_type) => op_type,
NodeTemplate::CompoundOp(hugr) => hugr.root_type(),
}
.dataflow_signature()
}
}

/// A configuration of what types, ops, and constants should be replaced with what.
/// May be applied to a Hugr via [Self::run].
///
/// Parametrized types and ops will be reparametrized taking into account the
/// replacements, but any ops taking/returning the replaced types *not* as a result of
/// parametrization, will also need to be replaced - see [Self::replace_op].
/// Similarly [Const]s.
///
/// Types that are [Copyable](hugr_core::types::TypeBound::Copyable) may also be replaced
/// with types that are not, see [Linearizer].
///
/// Note that although this pass may be used before [monomorphization], there are some
/// limitations (that do not apply if done after [monomorphization]):
/// * [NodeTemplate::CompoundOp] only works for operations that do not use type variables
/// * "Overrides" of specific instantiations of polymorphic types will not be detected if
/// the instantiations are created inside polymorphic functions. For example, suppose
/// we [Self::replace_type] type `A` with `X`, [Self::replace_parametrized_type]
/// container `MyList` with `List`, and [Self::replace_type] `MyList<A>` with
/// `SpecialListOfXs`. If a function `foo` polymorphic over a type variable `T` dealing
/// with `MyList<T>`s, that is called with type argument `A`, then `foo<T>` will be
/// updated to deal with `List<T>`s and the call `foo<A>` updated to `foo<X>`, but this
/// will still result in using `List<X>` rather than `SpecialListOfXs`. (However this
/// would be fine *after* [monomorphization]: the monomorphic definition of `foo_A`
/// would use `SpecialListOfXs`.)
/// * See also limitations noted for [Linearizer].
///
/// [monomorphization]: super::monomorphize()
#[derive(Clone, Default)]
pub struct ReplaceTypes {
type_map: HashMap<CustomType, Type>,
param_types: HashMap<ParametricType, Arc<dyn Fn(&[TypeArg]) -> Option<Type>>>,
op_map: HashMap<OpHashWrapper, OpReplacement>,
param_ops: HashMap<ParametricOp, Arc<dyn Fn(&[TypeArg]) -> Option<OpReplacement>>>,
linearize: DelegatingLinearizer,
op_map: HashMap<OpHashWrapper, NodeTemplate>,
param_ops: HashMap<ParametricOp, Arc<dyn Fn(&[TypeArg]) -> Option<NodeTemplate>>>,
consts: HashMap<
CustomType,
Arc<dyn Fn(&OpaqueValue, &ReplaceTypes) -> Result<Value, ReplaceTypesError>>,
Expand Down Expand Up @@ -109,6 +172,8 @@ pub enum ReplaceTypesError {
SignatureError(#[from] SignatureError),
#[error(transparent)]
ValidationError(#[from] ValidatePassError),
#[error(transparent)]
LinearizeError(#[from] LinearizeError),
}

impl ReplaceTypes {
Expand Down Expand Up @@ -157,16 +222,33 @@ impl ReplaceTypes {
// (depending on arguments - i.e. if src's TypeDefBound is anything other than
// `TypeDefBound::Explicit(TypeBound::Copyable)`) but that seems an annoying
// overapproximation. Moreover, these depend upon the *return type* of the Fn.
// It would be too awkward to require:
// dest_fn: impl Fn(&TypeArg) -> (Type,
// Fn(&Linearizer) -> NodeTemplate, // copy
// Fn(&Linearizer) -> NodeTemplate)` // discard
self.param_types.insert(src.into(), Arc::new(dest_fn));
}

/// Allows to configure how to deal with types/wires that were [Copyable]
/// but have become linear as a result of type-changing. Specifically,
/// the [Linearizer] is used whenever lowering produces an outport which both
/// * has a non-[Copyable] type - perhaps a direct substitution, or perhaps e.g.
/// as a result of changing the element type of a collection such as an [`array`]
/// * has other than one connected inport,
///
/// [Copyable]: hugr_core::types::TypeBound::Copyable
/// [`array`]: hugr_core::std_extensions::collections::array::array_type
pub fn linearizer(&mut self) -> &mut DelegatingLinearizer {
&mut self.linearize
}

/// Configures this instance to change occurrences of `src` to `dest`.
/// Note that if `src` is an instance of a *parametrized* [OpDef], this takes
/// precedence over [Self::replace_parametrized_op] where the `src`s overlap. Thus,
/// this should only be used on already-*[monomorphize](super::monomorphize())d*
/// Hugrs, as substitution (parametric polymorphism) happening later will not respect
/// this replacement.
pub fn replace_op(&mut self, src: &ExtensionOp, dest: OpReplacement) {
pub fn replace_op(&mut self, src: &ExtensionOp, dest: NodeTemplate) {
self.op_map.insert(OpHashWrapper::from(src), dest);
}

Expand All @@ -179,7 +261,7 @@ impl ReplaceTypes {
pub fn replace_parametrized_op(
&mut self,
src: &OpDef,
dest_fn: impl Fn(&[TypeArg]) -> Option<OpReplacement> + 'static,
dest_fn: impl Fn(&[TypeArg]) -> Option<NodeTemplate> + 'static,
) {
self.param_ops.insert(src.into(), Arc::new(dest_fn));
}
Expand Down Expand Up @@ -221,6 +303,22 @@ impl ReplaceTypes {
let mut changed = false;
for n in hugr.nodes().collect::<Vec<_>>() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

collect_vec can be used here

changed |= self.change_node(hugr, n)?;
let new_dfsig = hugr.get_optype(n).dataflow_signature();
if let Some(new_sig) = new_dfsig
.filter(|_| changed && n != hugr.root())
.map(Cow::into_owned)
{
for outp in new_sig.output_ports() {
if !new_sig.out_port_type(outp).unwrap().copyable() {
let targets = hugr.linked_inputs(n, outp).collect::<Vec<_>>();
if targets.len() != 1 {
hugr.disconnect(n, outp);
let src = Wire::new(n, outp);
self.linearize.insert_copy_discard(hugr, src, &targets)?;
}
}
}
}
}
Ok(changed)
}
Expand Down Expand Up @@ -452,7 +550,7 @@ mod test {
use hugr_core::{hugr::IdentList, type_row, Extension, HugrView};
use itertools::Itertools;

use super::{handlers::list_const, OpReplacement, ReplaceTypes};
use super::{handlers::list_const, NodeTemplate, ReplaceTypes};

const PACKED_VEC: &str = "PackedVec";
const READ: &str = "read";
Expand Down Expand Up @@ -513,7 +611,7 @@ mod test {
}

fn lowerer(ext: &Arc<Extension>) -> ReplaceTypes {
fn lowered_read(args: &[TypeArg]) -> Option<OpReplacement> {
fn lowered_read(args: &[TypeArg]) -> Option<NodeTemplate> {
let ty = just_elem_type(args);
let mut dfb = DFGBuilder::new(inout_sig(
vec![array_type(64, ty.clone()), i64_t()],
Expand All @@ -532,7 +630,7 @@ mod test {
let [res] = dfb
.build_unwrap_sum(1, option_type(Type::from(ty.clone())), opt)
.unwrap();
Some(OpReplacement::CompoundOp(Box::new(
Some(NodeTemplate::CompoundOp(Box::new(
dfb.finish_hugr_with_outputs([res]).unwrap(),
)))
}
Expand All @@ -545,7 +643,7 @@ mod test {
);
lw.replace_op(
&read_op(ext, bool_t()),
OpReplacement::SingleOp(
NodeTemplate::SingleOp(
ExtensionOp::new(ext.get_op("lowered_read_bool").unwrap().clone(), [])
.unwrap()
.into(),
Expand Down Expand Up @@ -824,7 +922,7 @@ mod test {
e.get_op(READ).unwrap().as_ref(),
Box::new(|args: &[TypeArg]| {
option_contents(just_elem_type(args)).map(|elem| {
OpReplacement::SingleOp(
NodeTemplate::SingleOp(
ListOp::get
.with_type(elem)
.to_extension_op()
Expand Down
Loading
Loading