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

refactor!: Separate Signature from FuncValueType by parametrizing Type(/Row)/etc. #1138

Merged
merged 123 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 120 commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
b5ddc8f
FunctionType<bool> defaults true, false->Signature, PFT<bool>::new ta…
acl-cqc May 26, 2024
066259e
PartialEq FunctionType for Signature (?)
acl-cqc May 17, 2024
077dabe
PolyFuncType defaults to <true>
acl-cqc May 24, 2024
f2f420e
Fix a few more funcs to return Signature
acl-cqc May 25, 2024
71b6782
Fix called_function_type to return PFT<false>, update a validate
acl-cqc May 25, 2024
6aeffbc
imports
acl-cqc May 25, 2024
748b49f
Builder/validation checks against rowvars now impossible
acl-cqc May 25, 2024
b180d96
Try parametrizing Type(,Row, but not Enum)
acl-cqc May 26, 2024
7e0c49e
Fix a few new_sums
acl-cqc May 25, 2024
f4b8ad2
imports
acl-cqc May 25, 2024
02aca28
Drop any_non_row_var, use any::<Type<false>>
acl-cqc May 26, 2024
824ca29
Oops, missed a Signature::try_new, no need now
acl-cqc May 26, 2024
12936c6
Restore Eq for EdgeKind
acl-cqc May 26, 2024
db11b17
Make type_row! macro always produce a TypeRow<false>, keep EMPTY_TYPE…
acl-cqc May 26, 2024
2fa7feb
Parametrize new_tuple over <RV2:bool>, also new_sum (awkwardly)
acl-cqc May 26, 2024
825e911
Comment in leaf.rs re. Tag - could take some TypeRow<true>s
acl-cqc May 26, 2024
d82e3a7
Merge remote-tracking branch 'origin/main' into refactor/parametrize_…
acl-cqc May 30, 2024
b83bee1
Double-parametrized PartialEq for TypeRow
acl-cqc May 30, 2024
3ccef19
(FunctionType,PolyFuncType,TypeRow)::validate for <RV>
acl-cqc May 30, 2024
c9b80f9
sum_with_error: fix with 2*.into
acl-cqc May 30, 2024
5849a4f
TypeRow: drop false->true Into, add TypeRow<RV>::into_rv() -> TypeRow…
acl-cqc May 30, 2024
0e3691c
Signature -> SignatureFunc
acl-cqc May 30, 2024
d3ccd79
logic.rs: add extra TypeRow::from
acl-cqc May 30, 2024
c2c0cd9
Add SumTypeError::VariantNotConcrete
acl-cqc May 30, 2024
eefc35d
fmt
acl-cqc May 30, 2024
a22e5a1
Various clippy's
acl-cqc May 30, 2024
15a1bbd
Rename Type<false>::substitute(=>substitute1), Type<RV>::subst_vec(=>…
acl-cqc May 30, 2024
38ae464
PolyFuncType::new avoids impl; add SignatureType from PFT<false> and …
acl-cqc May 31, 2024
d25b1c6
Revert "PolyFuncType::new avoids impl; add SignatureType from PFT<fal…
acl-cqc May 31, 2024
609785f
Add PFT<false> --into--> PFT<true>, fix/undup declarative/signature.rs
acl-cqc May 31, 2024
c92350b
PFT<true> from FT<RV>, PFT<false> from FT<false>, add FT<RV>.into_rv-…
acl-cqc Jun 1, 2024
05c7780
TypeArg from Type<RV> via try_into_no_rv
acl-cqc Jun 1, 2024
b2885fb
fix builder/dataflow.rs - another call to make into_rv pub?
acl-cqc Jun 1, 2024
a65a4c0
Missed/use import(s)
acl-cqc Jun 1, 2024
67167ab
Ooops, still had some try_new(_endo)
acl-cqc Jun 1, 2024
21193fd
WIP serialize tests
acl-cqc Jun 1, 2024
1610564
Combine conversions as into_ using generic static asserts
acl-cqc Jun 1, 2024
2d2815c
Simplify logic.rs (no change to errors)
acl-cqc Jun 1, 2024
28ed814
Combine SignatureFunc Into's using into_ (no change to errors)
acl-cqc Jun 1, 2024
0cdee97
More flex in TypeRow::from (too much - errors in "cargo build" nvm "c…
acl-cqc Jun 1, 2024
57407e1
PFT::new and FT -> SigFunc don't convert. Build the correct FunctionT…
acl-cqc Jun 1, 2024
1c81a2b
Various build fixes - only new_tuple / Sum remain
acl-cqc Jun 1, 2024
4d59b0c
new_tuple takes only into-TypeRow<true>
acl-cqc Jun 1, 2024
736938f
int_ops.rs: add sum_ty_with_err
acl-cqc Jun 1, 2024
3939776
No TypeRow<false> --Into-> TypeRow<true> - too many type-annots-reqd …
acl-cqc Jun 10, 2024
3724965
Reduce error count to zero and a bunch new ones show up in new places
acl-cqc Jun 10, 2024
28431c4
Remove Signature --Into--> FunctionType, fix 5 errors reported --> ma…
acl-cqc Jun 10, 2024
2f627cd
Don't double-var w/assert TypeRow-from-Type: causes type-annots-reqd
acl-cqc Jun 10, 2024
6731985
FunctionType::into_ is not polymorphic; we don't expect parametrizati…
acl-cqc Jun 11, 2024
9e4e4a2
...and remove flexibility in FunctionType --Into-> PolyFuncType
acl-cqc Jun 11, 2024
f47ad71
Reinstate FuncTypeBase<RV>; FunctionType is thus always ::<true>
acl-cqc Jun 11, 2024
59f599d
RIP Signature; FunctionType and FunTypeVarArgs. Note: maybe convert i…
acl-cqc Jun 11, 2024
695ce29
Reinstate conversion in PFT::new, FunctionType --Into-> FunTypeVarArgs
acl-cqc Jun 11, 2024
ddbfbdd
Change some Fun{ctionType->TypeVarArgs}::new
acl-cqc Jun 11, 2024
b36001f
FuncTypeBase double-RV PartialEq; PolyFuncType generic new_validated
acl-cqc Jun 11, 2024
5438065
Add could-be-anything annotations
acl-cqc Jun 11, 2024
279fdae
fix tests in type_param.rs
acl-cqc Jun 11, 2024
d220467
fix tests constructing PolyFuncType...return to this
acl-cqc Jun 11, 2024
4a3d643
Generalize new_sum like SumType::new. Fixes all but 4, really?
acl-cqc Jun 11, 2024
79679ca
Fix the 4 errors with into_; now we get 26, and maybe don't want to u…
acl-cqc Jun 11, 2024
ffd0cf7
Revert "Fix the 4 errors with into_; now we get 26, and maybe don't w…
acl-cqc Jun 11, 2024
7ddb6bf
Add TypeRow --Into-> TypeRow<true>, fix missing-type-annots by skippi…
acl-cqc Jun 11, 2024
68fac60
Fix proptest Arbitrary's
acl-cqc Jun 11, 2024
0b492b3
dataflow.rs test (does this now duplicate validate?)
acl-cqc Jun 11, 2024
a1d1574
fix substitution logic
acl-cqc Jun 11, 2024
d723076
Fix doctests
acl-cqc Jun 11, 2024
2e9a284
clippy/lint
acl-cqc Jun 11, 2024
e740184
Drop FunctionType.into_(), we have impl Into now
acl-cqc Jun 11, 2024
b109271
Drop TypeRow::into_, similarly
acl-cqc Jun 11, 2024
8c3aa91
Hide Type::into_, allow let_unit_value; and method docs
acl-cqc Jun 11, 2024
818a285
Merge remote-tracking branch 'origin/main' into refactor/parametrize_…
acl-cqc Jun 11, 2024
9ea9c61
Fix...and then fmt, oops
acl-cqc Jun 11, 2024
d8b4f3e
Revert change to hugr-py
acl-cqc Jun 12, 2024
017830e
fix bad merge of imports
acl-cqc Jun 12, 2024
42c6f68
Rewrite serialize Into's for clippy
acl-cqc Jun 12, 2024
4f8b4ac
Reduce change to main, and some tweaks
acl-cqc Jun 12, 2024
3ecc2b0
Accidentally deleted pub docs
acl-cqc Jun 12, 2024
620a96d
Simplify check_type_arg using bound_if_row_var
acl-cqc Jun 12, 2024
d819008
Drop some commented-out impls in type_row.rs
acl-cqc Jun 12, 2024
51941fd
More change reduction
acl-cqc Jun 12, 2024
c173926
and more
acl-cqc Jun 12, 2024
4e07fc0
correct doc
acl-cqc Jun 12, 2024
49dd488
Fix that annoying use
acl-cqc Jun 12, 2024
f5a54f2
Merge remote-tracking branch 'origin/main' into refactor/parametrize_…
acl-cqc Jun 26, 2024
592a3c3
remove/inline try_into_no_rv
acl-cqc Jun 26, 2024
edca745
review: remove bogus comments and #[cfg(test)]s
acl-cqc Jun 26, 2024
bc565ba
Add TypeBase<RV> w/out default, Type is alias for TypeBase<false>
acl-cqc Jun 26, 2024
7cebf4d
TypeRowBase, TypeRowRV
acl-cqc Jun 26, 2024
0334406
FunTypeVarArgs -> FunctionTypeRV
acl-cqc Jun 26, 2024
00f9a40
TypeScheme(,Base,RV) w/out defaults..in Rust only
acl-cqc Jun 26, 2024
5c7ecfa
Merge remote-tracking branch 'origin/main' into refactor/parametrize_…
acl-cqc Jun 28, 2024
c558ed8
(type(row)+serialize).rs only: Type(Row)Base<T: MaybeRV> not const bool
acl-cqc Jun 26, 2024
536b233
try_into_+try_from_rv err w/ RowVariable not SigError; SigError conta…
acl-cqc Jun 26, 2024
a59b1ea
Fix type_param.rs
acl-cqc Jun 26, 2024
c234442
signature.rs
acl-cqc Jun 26, 2024
dd099ac
poly_func.rs
acl-cqc Jun 26, 2024
9eef77b
impl Default explicitly, regardless of RV
acl-cqc Jun 26, 2024
538946e
proptest - no RowVars at all atm
acl-cqc Jun 27, 2024
4783d29
Try to add RowVars, but derive constraints breaking
acl-cqc Jun 27, 2024
db5e77e
Add #[cfg(test)] fn arb() to MaybeRV, use in impl Arbitrary for TypeBase
acl-cqc Jun 27, 2024
43f5a08
Move stuff into row_var.rs (sealed), fix cargo doc's
acl-cqc Jul 1, 2024
270675b
make MaybeRV require Into<RowVariable> as well as From<NoRV>
acl-cqc Jul 1, 2024
0297d7c
Remove commented-out derive
acl-cqc Jul 1, 2024
af0f818
Missed PolyFuncType -> TypeSchemeBase
acl-cqc Jul 1, 2024
aa54aff
Remove try_into_ via TryFrom
acl-cqc Jul 1, 2024
3270b93
find_rowvar via try_from, at cost of extra clone
acl-cqc Jul 1, 2024
eff0907
fmt
acl-cqc Jul 1, 2024
3477596
Merge remote-tracking branch 'origin/main' into refactor/parametrize_…
acl-cqc Jul 2, 2024
23db41d
remove type annots, fix doclinks, various comments
acl-cqc Jul 15, 2024
9421011
Merge 'origin/main', fix as_tuple
acl-cqc Jul 15, 2024
3245b45
fmt
acl-cqc Jul 15, 2024
eb3e86c
TypeScheme(RV/Base) back to PolyFuncType(RV/Base)
acl-cqc Jul 16, 2024
4a40b9b
FunctionTypeRV -> FuncValueType
acl-cqc Jul 16, 2024
f173c50
Merge remote-tracking branch 'origin/main' into refactor/parametrize_…
acl-cqc Jul 16, 2024
dcef178
FunctionType -> Signature (take 2)
acl-cqc Jul 16, 2024
849fd35
Rename {in_out,endo}_{ft=>sig}
acl-cqc Jul 16, 2024
889b91f
fix extension tests
acl-cqc Jul 16, 2024
46b54e3
doc fixes
acl-cqc Jul 16, 2024
bb2cb35
Merge remote-tracking branch 'origin/main' into refactor/parametrize_…
acl-cqc Jul 16, 2024
58d66ff
Give exact expected error in dataflow.rs / no_outer_row_variables
acl-cqc Jul 16, 2024
40c989b
Add From<PolyFuncType> for SignatureFunc
acl-cqc Jul 17, 2024
17ea37e
Add TypeBase<RV>::try_into_type(), combine From<TypeBase<RV>> for Typ…
acl-cqc Jul 17, 2024
eb4152a
oops, fix doc
acl-cqc Jul 17, 2024
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
6 changes: 3 additions & 3 deletions hugr-cli/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use hugr_core::{
builder::{Container, Dataflow, DataflowHugr},
extension::prelude::{BOOL_T, QB_T},
type_row,
types::FunctionType,
types::Signature,
Hugr,
};
use predicates::{prelude::*, str::contains};
Expand All @@ -25,7 +25,7 @@ fn cmd() -> Command {

#[fixture]
fn test_hugr() -> Hugr {
let df = DFGBuilder::new(FunctionType::new_endo(type_row![BOOL_T])).unwrap();
let df = DFGBuilder::new(Signature::new_endo(type_row![BOOL_T])).unwrap();
let [i] = df.input_wires_arr();
df.finish_prelude_hugr_with_outputs([i]).unwrap()
}
Expand Down Expand Up @@ -83,7 +83,7 @@ fn test_mermaid(test_hugr_file: NamedTempFile, mut cmd: Command) {

#[rstest]
fn test_bad_hugr(mut cmd: Command) {
let df = DFGBuilder::new(FunctionType::new_endo(type_row![QB_T])).unwrap();
let df = DFGBuilder::new(Signature::new_endo(type_row![QB_T])).unwrap();
let bad_hugr = df.hugr().clone();

let bad_hugr_string = serde_json::to_string(&bad_hugr).unwrap();
Expand Down
25 changes: 12 additions & 13 deletions hugr-core/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
//! # use hugr::builder::{BuildError, BuildHandle, Container, DFGBuilder, Dataflow, DataflowHugr, ModuleBuilder, DataflowSubContainer, HugrBuilder};
//! use hugr::extension::prelude::BOOL_T;
//! use hugr::std_extensions::logic::{EXTENSION_ID, LOGIC_REG, NotOp};
//! use hugr::types::FunctionType;
//! use hugr::types::Signature;
//!
//! # fn doctest() -> Result<(), BuildError> {
//! let hugr = {
Expand All @@ -42,7 +42,7 @@
//! let _dfg_handle = {
//! let mut dfg = module_builder.define_function(
//! "main",
//! FunctionType::new_endo(BOOL_T).with_extension_delta(EXTENSION_ID),
//! Signature::new_endo(BOOL_T).with_extension_delta(EXTENSION_ID),
//! )?;
//!
//! // Get the wires from the function inputs.
Expand All @@ -59,7 +59,7 @@
//! let _circuit_handle = {
//! let mut dfg = module_builder.define_function(
//! "circuit",
//! FunctionType::new_endo(vec![BOOL_T, BOOL_T])
//! Signature::new_endo(vec![BOOL_T, BOOL_T])
//! .with_extension_delta(EXTENSION_ID),
//! )?;
//! let mut circuit = dfg.as_circuit(dfg.input_wires());
Expand Down Expand Up @@ -93,7 +93,7 @@ use crate::hugr::ValidationError;
use crate::ops::handle::{BasicBlockID, CfgID, ConditionalID, DfgID, FuncID, TailLoopID};
use crate::ops::{NamedOp, OpType};
use crate::types::Type;
use crate::types::{ConstTypeError, FunctionType, TypeRow};
use crate::types::{ConstTypeError, Signature, TypeRow};
use crate::{Node, Port, Wire};

pub mod handle;
Expand Down Expand Up @@ -124,14 +124,14 @@ pub use circuit::{CircuitBuildError, CircuitBuilder};

/// Return a FunctionType with the same input and output types (specified)
/// whose extension delta, when used in a non-FuncDefn container, will be inferred.
pub fn endo_ft(types: impl Into<TypeRow>) -> FunctionType {
FunctionType::new_endo(types).with_extension_delta(TO_BE_INFERRED)
pub fn endo_sig(types: impl Into<TypeRow>) -> Signature {
Signature::new_endo(types).with_extension_delta(TO_BE_INFERRED)
}

/// Return a FunctionType with the specified input and output types
/// whose extension delta, when used in a non-FuncDefn container, will be inferred.
pub fn inout_ft(inputs: impl Into<TypeRow>, outputs: impl Into<TypeRow>) -> FunctionType {
FunctionType::new(inputs, outputs).with_extension_delta(TO_BE_INFERRED)
pub fn inout_sig(inputs: impl Into<TypeRow>, outputs: impl Into<TypeRow>) -> Signature {
Signature::new(inputs, outputs).with_extension_delta(TO_BE_INFERRED)
}

#[derive(Debug, Clone, PartialEq, Error)]
Expand Down Expand Up @@ -236,7 +236,7 @@ pub(crate) mod test {
use crate::hugr::{views::HugrView, HugrMut};
use crate::ops;
use crate::std_extensions::arithmetic::float_ops::FLOAT_OPS_REGISTRY;
use crate::types::{FunctionType, PolyFuncType, Type};
use crate::types::{PolyFuncType, Signature, Type};
use crate::{type_row, Hugr};

use super::handle::BuildHandle;
Expand Down Expand Up @@ -272,24 +272,23 @@ pub(crate) mod test {

#[fixture]
pub(crate) fn simple_dfg_hugr() -> Hugr {
let dfg_builder =
DFGBuilder::new(FunctionType::new(type_row![BIT], type_row![BIT])).unwrap();
let dfg_builder = DFGBuilder::new(Signature::new(type_row![BIT], type_row![BIT])).unwrap();
let [i1] = dfg_builder.input_wires_arr();
dfg_builder.finish_prelude_hugr_with_outputs([i1]).unwrap()
}

#[fixture]
pub(crate) fn simple_cfg_hugr() -> Hugr {
let mut cfg_builder =
CFGBuilder::new(FunctionType::new(type_row![NAT], type_row![NAT])).unwrap();
CFGBuilder::new(Signature::new(type_row![NAT], type_row![NAT])).unwrap();
super::cfg::test::build_basic_cfg(&mut cfg_builder).unwrap();
cfg_builder.finish_prelude_hugr().unwrap()
}

/// A helper method which creates a DFG rooted hugr with Input and Output node
/// only (no wires), given a function type with extension delta.
// TODO consider taking two type rows and using TO_BE_INFERRED
pub(crate) fn closed_dfg_root_hugr(signature: FunctionType) -> Hugr {
pub(crate) fn closed_dfg_root_hugr(signature: Signature) -> Hugr {
let mut hugr = Hugr::new(ops::DFG {
signature: signature.clone(),
});
Expand Down
20 changes: 5 additions & 15 deletions hugr-core/src/builder/build_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ use crate::{
types::EdgeKind,
};

use crate::extension::{
ExtensionRegistry, ExtensionSet, SignatureError, PRELUDE_REGISTRY, TO_BE_INFERRED,
};
use crate::types::{FunctionType, PolyFuncType, Type, TypeArg, TypeRow};
use crate::extension::{ExtensionRegistry, ExtensionSet, PRELUDE_REGISTRY, TO_BE_INFERRED};
use crate::types::{PolyFuncType, Signature, Type, TypeArg, TypeRow};

use itertools::Itertools;

Expand Down Expand Up @@ -276,7 +274,7 @@ pub trait Dataflow: Container {
// TODO: Should this be one function, or should there be a temporary "op" one like with the others?
fn dfg_builder(
&mut self,
signature: FunctionType,
signature: Signature,
input_wires: impl IntoIterator<Item = Wire>,
) -> Result<DFGBuilder<&mut Hugr>, BuildError> {
let op = ops::DFG {
Expand All @@ -297,7 +295,7 @@ pub trait Dataflow: Container {
) -> Result<DFGBuilder<&mut Hugr>, BuildError> {
let (types, input_wires): (Vec<Type>, Vec<Wire>) = inputs.into_iter().unzip();
self.dfg_builder(
FunctionType::new_endo(types).with_extension_delta(TO_BE_INFERRED),
Signature::new_endo(types).with_extension_delta(TO_BE_INFERRED),
input_wires,
)
}
Expand Down Expand Up @@ -325,7 +323,7 @@ pub trait Dataflow: Container {
let (cfg_node, _) = add_node_with_wires(
self,
ops::CFG {
signature: FunctionType::new(inputs.clone(), output_types.clone())
signature: Signature::new(inputs.clone(), output_types.clone())
.with_extension_delta(extension_delta),
},
input_wires,
Expand Down Expand Up @@ -658,14 +656,6 @@ fn add_node_with_wires<T: Dataflow + ?Sized>(
inputs: impl IntoIterator<Item = Wire>,
) -> Result<(Node, usize), BuildError> {
let op = nodetype.into();
// Check there are no row variables, as that would prevent us
// from indexing into the node's ports in order to wire up
op.dataflow_signature()
.as_ref()
.and_then(FunctionType::find_rowvar)
.map_or(Ok(()), |(idx, _)| {
Err(SignatureError::RowVarWhereTypeExpected { idx })
})?;
let num_outputs = op.value_output_count();
let op_node = data_builder.add_child_node(op.clone());

Expand Down
34 changes: 17 additions & 17 deletions hugr-core/src/builder/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
};
use crate::{
extension::{ExtensionRegistry, ExtensionSet},
types::FunctionType,
types::Signature,
};
use crate::{hugr::views::HugrView, types::TypeRow};

Expand Down Expand Up @@ -46,17 +46,17 @@ use crate::{hugr::HugrMut, type_row, Hugr};
/// +------------+
/// */
/// use hugr::{
/// builder::{BuildError, CFGBuilder, Container, Dataflow, HugrBuilder, endo_ft, inout_ft},
/// builder::{BuildError, CFGBuilder, Container, Dataflow, HugrBuilder, endo_sig, inout_sig},
/// extension::{prelude, ExtensionSet},
/// ops, type_row,
/// types::{FunctionType, SumType, Type},
/// types::{Signature, SumType, Type},
/// Hugr,
/// };
///
/// const NAT: Type = prelude::USIZE_T;
///
/// fn make_cfg() -> Result<Hugr, BuildError> {
/// let mut cfg_builder = CFGBuilder::new(FunctionType::new(type_row![NAT], type_row![NAT]))?;
/// let mut cfg_builder = CFGBuilder::new(Signature::new_endo(NAT))?;
///
/// // Outputs from basic blocks must be packed in a sum which corresponds to
/// // which successor to pick. We'll either choose the first branch and pass
Expand Down Expand Up @@ -84,7 +84,7 @@ use crate::{hugr::HugrMut, type_row, Hugr};
/// // `NAT` arguments: one from the `sum_variants` type, and another from the
/// // entry node's `other_outputs`.
/// let mut successor_builder = cfg_builder.simple_block_builder(
/// inout_ft(type_row![NAT, NAT], NAT),
/// inout_sig(type_row![NAT, NAT], NAT),
/// 1, // only one successor to this block
/// )?;
/// let successor_a = {
Expand All @@ -98,7 +98,7 @@ use crate::{hugr::HugrMut, type_row, Hugr};
/// };
///
/// // The only argument to this block is the entry node's `other_outputs`.
/// let mut successor_builder = cfg_builder.simple_block_builder(endo_ft(NAT), 1)?;
/// let mut successor_builder = cfg_builder.simple_block_builder(endo_sig(NAT), 1)?;
/// let successor_b = {
/// let sum_unary = successor_builder.add_load_value(ops::Value::unary_unit_sum());
/// let [in_wire] = successor_builder.input_wires_arr();
Expand Down Expand Up @@ -151,7 +151,7 @@ impl<H: AsMut<Hugr> + AsRef<Hugr>> SubContainer for CFGBuilder<H> {

impl CFGBuilder<Hugr> {
/// New CFG rooted HUGR builder
pub fn new(signature: FunctionType) -> Result<Self, BuildError> {
pub fn new(signature: Signature) -> Result<Self, BuildError> {
let cfg_op = ops::CFG {
signature: signature.clone(),
};
Expand Down Expand Up @@ -272,7 +272,7 @@ impl<B: AsMut<Hugr> + AsRef<Hugr>> CFGBuilder<B> {
/// This function will return an error if there is an error adding the node.
pub fn simple_block_builder(
&mut self,
signature: FunctionType,
signature: Signature,
n_cases: usize,
) -> Result<BlockBuilder<&mut Hugr>, BuildError> {
self.block_builder_exts(
Expand Down Expand Up @@ -463,7 +463,7 @@ pub(crate) mod test {
let build_result = {
let mut module_builder = ModuleBuilder::new();
let mut func_builder = module_builder
.define_function("main", FunctionType::new(vec![NAT], type_row![NAT]))?;
.define_function("main", Signature::new(vec![NAT], type_row![NAT]))?;
let _f_id = {
let [int] = func_builder.input_wires_arr();

Expand All @@ -489,7 +489,7 @@ pub(crate) mod test {
}
#[test]
fn basic_cfg_hugr() -> Result<(), BuildError> {
let mut cfg_builder = CFGBuilder::new(FunctionType::new(type_row![NAT], type_row![NAT]))?;
let mut cfg_builder = CFGBuilder::new(Signature::new(type_row![NAT], type_row![NAT]))?;
build_basic_cfg(&mut cfg_builder)?;
assert_matches!(cfg_builder.finish_prelude_hugr(), Ok(_));

Expand All @@ -511,8 +511,8 @@ pub(crate) mod test {
let sum = entry_b.make_sum(1, sum2_variants, [inw])?;
entry_b.finish_with_outputs(sum, [])?
};
let mut middle_b = cfg_builder
.simple_block_builder(FunctionType::new(type_row![NAT], type_row![NAT]), 1)?;
let mut middle_b =
cfg_builder.simple_block_builder(Signature::new(type_row![NAT], type_row![NAT]), 1)?;
let middle = {
let c = middle_b.add_load_const(ops::Value::unary_unit_sum());
let [inw] = middle_b.input_wires_arr();
Expand All @@ -526,7 +526,7 @@ pub(crate) mod test {
}
#[test]
fn test_dom_edge() -> Result<(), BuildError> {
let mut cfg_builder = CFGBuilder::new(FunctionType::new(type_row![NAT], type_row![NAT]))?;
let mut cfg_builder = CFGBuilder::new(Signature::new(type_row![NAT], type_row![NAT]))?;
let sum_tuple_const = cfg_builder.add_constant(ops::Value::unary_unit_sum());
let sum_variants = vec![type_row![]];

Expand All @@ -542,7 +542,7 @@ pub(crate) mod test {
entry_b.finish_with_outputs(sum, [])?
};
let mut middle_b =
cfg_builder.simple_block_builder(FunctionType::new(type_row![], type_row![NAT]), 1)?;
cfg_builder.simple_block_builder(Signature::new(type_row![], type_row![NAT]), 1)?;
let middle = {
let c = middle_b.load_const(&sum_tuple_const);
middle_b.finish_with_outputs(c, [inw])?
Expand All @@ -557,11 +557,11 @@ pub(crate) mod test {

#[test]
fn test_non_dom_edge() -> Result<(), BuildError> {
let mut cfg_builder = CFGBuilder::new(FunctionType::new(type_row![NAT], type_row![NAT]))?;
let mut cfg_builder = CFGBuilder::new(Signature::new(type_row![NAT], type_row![NAT]))?;
let sum_tuple_const = cfg_builder.add_constant(ops::Value::unary_unit_sum());
let sum_variants = vec![type_row![]];
let mut middle_b = cfg_builder
.simple_block_builder(FunctionType::new(type_row![NAT], type_row![NAT]), 1)?;
let mut middle_b =
cfg_builder.simple_block_builder(Signature::new(type_row![NAT], type_row![NAT]), 1)?;
let [inw] = middle_b.input_wires_arr();
let middle = {
let c = middle_b.load_const(&sum_tuple_const);
Expand Down
12 changes: 6 additions & 6 deletions hugr-core/src/builder/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,13 @@ mod test {
extension::prelude::BOOL_T,
ops::{custom::OpaqueOp, CustomOp},
type_row,
types::FunctionType,
types::Signature,
};

#[test]
fn simple_linear() {
let build_res = build_main(
FunctionType::new(type_row![QB, QB], type_row![QB, QB])
Signature::new(type_row![QB, QB], type_row![QB, QB])
.with_extension_delta(test_quantum_extension::EXTENSION_ID)
.with_extension_delta(float_types::EXTENSION_ID)
.into(),
Expand Down Expand Up @@ -300,10 +300,10 @@ mod test {
"MyOp",
"unknown op".to_string(),
vec![],
FunctionType::new(vec![QB, NAT], vec![QB]),
Signature::new(vec![QB, NAT], vec![QB]),
));
let build_res = build_main(
FunctionType::new(type_row![QB, QB, NAT], type_row![QB, QB, BOOL_T])
Signature::new(type_row![QB, QB, NAT], type_row![QB, QB, BOOL_T])
.with_extension_delta(test_quantum_extension::EXTENSION_ID)
.into(),
|mut f_build| {
Expand All @@ -330,7 +330,7 @@ mod test {
#[test]
fn ancillae() {
let build_res = build_main(
FunctionType::new_endo(QB)
Signature::new_endo(QB)
.with_extension_delta(test_quantum_extension::EXTENSION_ID)
.into(),
|mut f_build| {
Expand Down Expand Up @@ -368,7 +368,7 @@ mod test {
#[test]
fn circuit_builder_errors() {
let _build_res = build_main(
FunctionType::new_endo(type_row![QB, QB]).into(),
Signature::new_endo(type_row![QB, QB]).into(),
|mut f_build| {
let mut circ = f_build.as_circuit(f_build.input_wires());
let [q0, q1] = circ.tracked_units_arr();
Expand Down
10 changes: 5 additions & 5 deletions hugr-core/src/builder/conditional.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::extension::ExtensionRegistry;
use crate::hugr::views::HugrView;
use crate::ops::dataflow::DataflowOpTrait;
use crate::types::{FunctionType, TypeRow};
use crate::types::{Signature, TypeRow};

use crate::ops;
use crate::ops::handle::CaseID;
Expand Down Expand Up @@ -118,7 +118,7 @@ impl<B: AsMut<Hugr> + AsRef<Hugr>> ConditionalBuilder<B> {

let outputs = cond.outputs;
let case_op = ops::Case {
signature: FunctionType::new(inputs.clone(), outputs.clone())
signature: Signature::new(inputs.clone(), outputs.clone())
.with_extension_delta(extension_delta.clone()),
};
let case_node =
Expand All @@ -134,7 +134,7 @@ impl<B: AsMut<Hugr> + AsRef<Hugr>> ConditionalBuilder<B> {
let dfg_builder = DFGBuilder::create_with_io(
self.hugr_mut(),
case_node,
FunctionType::new(inputs, outputs).with_extension_delta(extension_delta),
Signature::new(inputs, outputs).with_extension_delta(extension_delta),
)?;

Ok(CaseBuilder::from_dfg_builder(dfg_builder))
Expand Down Expand Up @@ -186,7 +186,7 @@ impl ConditionalBuilder<Hugr> {

impl CaseBuilder<Hugr> {
/// Initialize a Case rooted HUGR
pub fn new(signature: FunctionType) -> Result<Self, BuildError> {
pub fn new(signature: Signature) -> Result<Self, BuildError> {
let op = ops::Case {
signature: signature.clone(),
};
Expand Down Expand Up @@ -233,7 +233,7 @@ mod test {
let build_result: Result<Hugr, BuildError> = {
let mut module_builder = ModuleBuilder::new();
let mut fbuild = module_builder
.define_function("main", FunctionType::new(type_row![NAT], type_row![NAT]))?;
.define_function("main", Signature::new(type_row![NAT], type_row![NAT]))?;
let tru_const = fbuild.add_constant(Value::true_val());
let _fdef = {
let const_wire = fbuild.load_const(&tru_const);
Expand Down
Loading
Loading