Skip to content

Commit 53e1c4d

Browse files
committed
FunctionType -> Signature
1 parent 4a40b9b commit 53e1c4d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+389
-423
lines changed

hugr-cli/tests/cli.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use hugr_core::{
1212
builder::{Container, Dataflow, DataflowHugr},
1313
extension::prelude::{BOOL_T, QB_T},
1414
type_row,
15-
types::FunctionType,
15+
types::Signature,
1616
Hugr,
1717
};
1818
use predicates::{prelude::*, str::contains};
@@ -25,7 +25,7 @@ fn cmd() -> Command {
2525

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

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

8989
let bad_hugr_string = serde_json::to_string(&bad_hugr).unwrap();

hugr-core/src/builder.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
//! # use hugr::builder::{BuildError, BuildHandle, Container, DFGBuilder, Dataflow, DataflowHugr, ModuleBuilder, DataflowSubContainer, HugrBuilder};
3131
//! use hugr::extension::prelude::BOOL_T;
3232
//! use hugr::std_extensions::logic::{NotOp, LOGIC_REG};
33-
//! use hugr::types::FunctionType;
33+
//! use hugr::types::Signature;
3434
//!
3535
//! # fn doctest() -> Result<(), BuildError> {
3636
//! let hugr = {
@@ -42,7 +42,7 @@
4242
//! let _dfg_handle = {
4343
//! let mut dfg = module_builder.define_function(
4444
//! "main",
45-
//! FunctionType::new(vec![BOOL_T], vec![BOOL_T]),
45+
//! Signature::new(vec![BOOL_T], vec![BOOL_T]),
4646
//! )?;
4747
//!
4848
//! // Get the wires from the function inputs.
@@ -59,7 +59,7 @@
5959
//! let _circuit_handle = {
6060
//! let mut dfg = module_builder.define_function(
6161
//! "circuit",
62-
//! FunctionType::new_endo(vec![BOOL_T, BOOL_T]),
62+
//! Signature::new_endo(vec![BOOL_T, BOOL_T]),
6363
//! )?;
6464
//! let mut circuit = dfg.as_circuit(dfg.input_wires());
6565
//!
@@ -92,7 +92,7 @@ use crate::hugr::ValidationError;
9292
use crate::ops::handle::{BasicBlockID, CfgID, ConditionalID, DfgID, FuncID, TailLoopID};
9393
use crate::ops::{NamedOp, OpType};
9494
use crate::types::Type;
95-
use crate::types::{ConstTypeError, FunctionType, TypeRow};
95+
use crate::types::{ConstTypeError, Signature, TypeRow};
9696
use crate::{Node, Port, Wire};
9797

9898
pub mod handle;
@@ -121,16 +121,16 @@ pub use conditional::{CaseBuilder, ConditionalBuilder};
121121
mod circuit;
122122
pub use circuit::{CircuitBuildError, CircuitBuilder};
123123

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

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

136136
#[derive(Debug, Clone, PartialEq, Error)]
@@ -235,7 +235,7 @@ pub(crate) mod test {
235235
use crate::hugr::{views::HugrView, HugrMut};
236236
use crate::ops;
237237
use crate::std_extensions::arithmetic::float_ops::FLOAT_OPS_REGISTRY;
238-
use crate::types::{FunctionType, PolyFuncType, Type};
238+
use crate::types::{PolyFuncType, Signature, Type};
239239
use crate::{type_row, Hugr};
240240

241241
use super::handle::BuildHandle;
@@ -271,16 +271,15 @@ pub(crate) mod test {
271271

272272
#[fixture]
273273
pub(crate) fn simple_dfg_hugr() -> Hugr {
274-
let dfg_builder =
275-
DFGBuilder::new(FunctionType::new(type_row![BIT], type_row![BIT])).unwrap();
274+
let dfg_builder = DFGBuilder::new(Signature::new(type_row![BIT], type_row![BIT])).unwrap();
276275
let [i1] = dfg_builder.input_wires_arr();
277276
dfg_builder.finish_prelude_hugr_with_outputs([i1]).unwrap()
278277
}
279278

280279
#[fixture]
281280
pub(crate) fn simple_cfg_hugr() -> Hugr {
282281
let mut cfg_builder =
283-
CFGBuilder::new(FunctionType::new(type_row![NAT], type_row![NAT])).unwrap();
282+
CFGBuilder::new(Signature::new(type_row![NAT], type_row![NAT])).unwrap();
284283
super::cfg::test::build_basic_cfg(&mut cfg_builder).unwrap();
285284
cfg_builder.finish_prelude_hugr().unwrap()
286285
}
@@ -289,7 +288,7 @@ pub(crate) mod test {
289288
/// for tests which want to avoid having open extension variables after
290289
/// inference. Using DFGBuilder will default to a root node with an open
291290
/// extension variable
292-
pub(crate) fn closed_dfg_root_hugr(signature: FunctionType) -> Hugr {
291+
pub(crate) fn closed_dfg_root_hugr(signature: Signature) -> Hugr {
293292
let mut hugr = Hugr::new(ops::DFG {
294293
signature: signature.clone(),
295294
});

hugr-core/src/builder/build_traits.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::{
1919
};
2020

2121
use crate::extension::{ExtensionRegistry, ExtensionSet, PRELUDE_REGISTRY, TO_BE_INFERRED};
22-
use crate::types::{FunctionType, PolyFuncType, Type, TypeArg, TypeRow};
22+
use crate::types::{PolyFuncType, Signature, Type, TypeArg, TypeRow};
2323

2424
use itertools::Itertools;
2525

@@ -274,7 +274,7 @@ pub trait Dataflow: Container {
274274
// TODO: Should this be one function, or should there be a temporary "op" one like with the others?
275275
fn dfg_builder(
276276
&mut self,
277-
signature: FunctionType,
277+
signature: Signature,
278278
input_wires: impl IntoIterator<Item = Wire>,
279279
) -> Result<DFGBuilder<&mut Hugr>, BuildError> {
280280
let op = ops::DFG {
@@ -295,7 +295,7 @@ pub trait Dataflow: Container {
295295
) -> Result<DFGBuilder<&mut Hugr>, BuildError> {
296296
let (types, input_wires): (Vec<Type>, Vec<Wire>) = inputs.into_iter().unzip();
297297
self.dfg_builder(
298-
FunctionType::new_endo(types).with_extension_delta(TO_BE_INFERRED),
298+
Signature::new_endo(types).with_extension_delta(TO_BE_INFERRED),
299299
input_wires,
300300
)
301301
}
@@ -323,7 +323,7 @@ pub trait Dataflow: Container {
323323
let (cfg_node, _) = add_node_with_wires(
324324
self,
325325
ops::CFG {
326-
signature: FunctionType::new(inputs.clone(), output_types.clone())
326+
signature: Signature::new(inputs.clone(), output_types.clone())
327327
.with_extension_delta(extension_delta),
328328
},
329329
input_wires,

hugr-core/src/builder/cfg.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use super::{
88
use crate::ops::{self, handle::NodeHandle, DataflowBlock, DataflowParent, ExitBlock, OpType};
99
use crate::{
1010
extension::{ExtensionRegistry, ExtensionSet},
11-
types::FunctionType,
11+
types::Signature,
1212
};
1313
use crate::{hugr::views::HugrView, types::TypeRow};
1414

@@ -46,14 +46,14 @@ use crate::{hugr::HugrMut, type_row, Hugr};
4646
/// builder::{BuildError, CFGBuilder, Container, Dataflow, HugrBuilder},
4747
/// extension::{prelude, ExtensionSet},
4848
/// ops, type_row,
49-
/// types::{FunctionType, SumType, Type},
49+
/// types::{Signature, SumType, Type},
5050
/// Hugr,
5151
/// };
5252
///
5353
/// const NAT: Type = prelude::USIZE_T;
5454
///
5555
/// fn make_cfg() -> Result<Hugr, BuildError> {
56-
/// let mut cfg_builder = CFGBuilder::new(FunctionType::new(type_row![NAT], type_row![NAT]))?;
56+
/// let mut cfg_builder = CFGBuilder::new(Signature::new(type_row![NAT], type_row![NAT]))?;
5757
///
5858
/// // Outputs from basic blocks must be packed in a sum which corresponds to
5959
/// // which successor to pick. We'll either choose the first branch and pass
@@ -82,7 +82,7 @@ use crate::{hugr::HugrMut, type_row, Hugr};
8282
/// // `NAT` arguments: one from the `sum_variants` type, and another from the
8383
/// // entry node's `other_outputs`.
8484
/// let mut successor_builder = cfg_builder.simple_block_builder(
85-
/// FunctionType::new(type_row![NAT, NAT], type_row![NAT]),
85+
/// Signature::new(type_row![NAT, NAT], type_row![NAT]),
8686
/// 1, // only one successor to this block
8787
/// )?;
8888
/// let successor_a = {
@@ -97,7 +97,7 @@ use crate::{hugr::HugrMut, type_row, Hugr};
9797
///
9898
/// // The only argument to this block is the entry node's `other_outputs`.
9999
/// let mut successor_builder = cfg_builder
100-
/// .simple_block_builder(FunctionType::new(type_row![NAT], type_row![NAT]), 1)?;
100+
/// .simple_block_builder(Signature::new(type_row![NAT], type_row![NAT]), 1)?;
101101
/// let successor_b = {
102102
/// let sum_unary = successor_builder.add_load_value(ops::Value::unary_unit_sum());
103103
/// let [in_wire] = successor_builder.input_wires_arr();
@@ -150,7 +150,7 @@ impl<H: AsMut<Hugr> + AsRef<Hugr>> SubContainer for CFGBuilder<H> {
150150

151151
impl CFGBuilder<Hugr> {
152152
/// New CFG rooted HUGR builder
153-
pub fn new(signature: FunctionType) -> Result<Self, BuildError> {
153+
pub fn new(signature: Signature) -> Result<Self, BuildError> {
154154
let cfg_op = ops::CFG {
155155
signature: signature.clone(),
156156
};
@@ -248,7 +248,7 @@ impl<B: AsMut<Hugr> + AsRef<Hugr>> CFGBuilder<B> {
248248
/// This function will return an error if there is an error adding the node.
249249
pub fn simple_block_builder(
250250
&mut self,
251-
signature: FunctionType,
251+
signature: Signature,
252252
n_cases: usize,
253253
) -> Result<BlockBuilder<&mut Hugr>, BuildError> {
254254
self.block_builder(
@@ -402,7 +402,7 @@ pub(crate) mod test {
402402
let build_result = {
403403
let mut module_builder = ModuleBuilder::new();
404404
let mut func_builder = module_builder
405-
.define_function("main", FunctionType::new(vec![NAT], type_row![NAT]))?;
405+
.define_function("main", Signature::new(vec![NAT], type_row![NAT]))?;
406406
let _f_id = {
407407
let [int] = func_builder.input_wires_arr();
408408

@@ -428,7 +428,7 @@ pub(crate) mod test {
428428
}
429429
#[test]
430430
fn basic_cfg_hugr() -> Result<(), BuildError> {
431-
let mut cfg_builder = CFGBuilder::new(FunctionType::new(type_row![NAT], type_row![NAT]))?;
431+
let mut cfg_builder = CFGBuilder::new(Signature::new(type_row![NAT], type_row![NAT]))?;
432432
build_basic_cfg(&mut cfg_builder)?;
433433
assert_matches!(cfg_builder.finish_prelude_hugr(), Ok(_));
434434

@@ -447,8 +447,8 @@ pub(crate) mod test {
447447
let sum = entry_b.make_sum(1, sum2_variants, [inw])?;
448448
entry_b.finish_with_outputs(sum, [])?
449449
};
450-
let mut middle_b = cfg_builder
451-
.simple_block_builder(FunctionType::new(type_row![NAT], type_row![NAT]), 1)?;
450+
let mut middle_b =
451+
cfg_builder.simple_block_builder(Signature::new(type_row![NAT], type_row![NAT]), 1)?;
452452
let middle = {
453453
let c = middle_b.add_load_const(ops::Value::unary_unit_sum());
454454
let [inw] = middle_b.input_wires_arr();
@@ -462,7 +462,7 @@ pub(crate) mod test {
462462
}
463463
#[test]
464464
fn test_dom_edge() -> Result<(), BuildError> {
465-
let mut cfg_builder = CFGBuilder::new(FunctionType::new(type_row![NAT], type_row![NAT]))?;
465+
let mut cfg_builder = CFGBuilder::new(Signature::new(type_row![NAT], type_row![NAT]))?;
466466
let sum_tuple_const = cfg_builder.add_constant(ops::Value::unary_unit_sum());
467467
let sum_variants = vec![type_row![]];
468468

@@ -475,7 +475,7 @@ pub(crate) mod test {
475475
entry_b.finish_with_outputs(sum, [])?
476476
};
477477
let mut middle_b =
478-
cfg_builder.simple_block_builder(FunctionType::new(type_row![], type_row![NAT]), 1)?;
478+
cfg_builder.simple_block_builder(Signature::new(type_row![], type_row![NAT]), 1)?;
479479
let middle = {
480480
let c = middle_b.load_const(&sum_tuple_const);
481481
middle_b.finish_with_outputs(c, [inw])?
@@ -490,11 +490,11 @@ pub(crate) mod test {
490490

491491
#[test]
492492
fn test_non_dom_edge() -> Result<(), BuildError> {
493-
let mut cfg_builder = CFGBuilder::new(FunctionType::new(type_row![NAT], type_row![NAT]))?;
493+
let mut cfg_builder = CFGBuilder::new(Signature::new(type_row![NAT], type_row![NAT]))?;
494494
let sum_tuple_const = cfg_builder.add_constant(ops::Value::unary_unit_sum());
495495
let sum_variants = vec![type_row![]];
496-
let mut middle_b = cfg_builder
497-
.simple_block_builder(FunctionType::new(type_row![NAT], type_row![NAT]), 1)?;
496+
let mut middle_b =
497+
cfg_builder.simple_block_builder(Signature::new(type_row![NAT], type_row![NAT]), 1)?;
498498
let [inw] = middle_b.input_wires_arr();
499499
let middle = {
500500
let c = middle_b.load_const(&sum_tuple_const);

hugr-core/src/builder/circuit.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,13 @@ mod test {
254254
extension::prelude::BOOL_T,
255255
ops::{custom::OpaqueOp, CustomOp},
256256
type_row,
257-
types::FunctionType,
257+
types::Signature,
258258
};
259259

260260
#[test]
261261
fn simple_linear() {
262262
let build_res = build_main(
263-
FunctionType::new(type_row![QB, QB], type_row![QB, QB])
263+
Signature::new(type_row![QB, QB], type_row![QB, QB])
264264
.with_extension_delta(float_types::EXTENSION_ID)
265265
.into(),
266266
|mut f_build| {
@@ -299,10 +299,10 @@ mod test {
299299
"MyOp",
300300
"unknown op".to_string(),
301301
vec![],
302-
FunctionType::new(vec![QB, NAT], vec![QB]),
302+
Signature::new(vec![QB, NAT], vec![QB]),
303303
));
304304
let build_res = build_main(
305-
FunctionType::new(type_row![QB, QB, NAT], type_row![QB, QB, BOOL_T]).into(),
305+
Signature::new(type_row![QB, QB, NAT], type_row![QB, QB, BOOL_T]).into(),
306306
|mut f_build| {
307307
let [q0, q1, angle]: [Wire; 3] = f_build.input_wires_arr();
308308

@@ -327,7 +327,7 @@ mod test {
327327
#[test]
328328
fn ancillae() {
329329
let build_res = build_main(
330-
FunctionType::new(type_row![QB], type_row![QB]).into(),
330+
Signature::new(type_row![QB], type_row![QB]).into(),
331331
|mut f_build| {
332332
let mut circ = f_build.as_circuit(f_build.input_wires());
333333
assert_eq!(circ.n_wires(), 1);
@@ -363,7 +363,7 @@ mod test {
363363
#[test]
364364
fn circuit_builder_errors() {
365365
let _build_res = build_main(
366-
FunctionType::new_endo(type_row![QB, QB]).into(),
366+
Signature::new_endo(type_row![QB, QB]).into(),
367367
|mut f_build| {
368368
let mut circ = f_build.as_circuit(f_build.input_wires());
369369
let [q0, q1] = circ.tracked_units_arr();

hugr-core/src/builder/conditional.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::extension::ExtensionRegistry;
22
use crate::hugr::views::HugrView;
33
use crate::ops::dataflow::DataflowOpTrait;
4-
use crate::types::{FunctionType, TypeRow};
4+
use crate::types::{Signature, TypeRow};
55

66
use crate::ops;
77
use crate::ops::handle::CaseID;
@@ -118,7 +118,7 @@ impl<B: AsMut<Hugr> + AsRef<Hugr>> ConditionalBuilder<B> {
118118

119119
let outputs = cond.outputs;
120120
let case_op = ops::Case {
121-
signature: FunctionType::new(inputs.clone(), outputs.clone())
121+
signature: Signature::new(inputs.clone(), outputs.clone())
122122
.with_extension_delta(extension_delta.clone()),
123123
};
124124
let case_node =
@@ -134,7 +134,7 @@ impl<B: AsMut<Hugr> + AsRef<Hugr>> ConditionalBuilder<B> {
134134
let dfg_builder = DFGBuilder::create_with_io(
135135
self.hugr_mut(),
136136
case_node,
137-
FunctionType::new(inputs, outputs).with_extension_delta(extension_delta),
137+
Signature::new(inputs, outputs).with_extension_delta(extension_delta),
138138
)?;
139139

140140
Ok(CaseBuilder::from_dfg_builder(dfg_builder))
@@ -186,7 +186,7 @@ impl ConditionalBuilder<Hugr> {
186186

187187
impl CaseBuilder<Hugr> {
188188
/// Initialize a Case rooted HUGR
189-
pub fn new(signature: FunctionType) -> Result<Self, BuildError> {
189+
pub fn new(signature: Signature) -> Result<Self, BuildError> {
190190
let op = ops::Case {
191191
signature: signature.clone(),
192192
};
@@ -233,7 +233,7 @@ mod test {
233233
let build_result: Result<Hugr, BuildError> = {
234234
let mut module_builder = ModuleBuilder::new();
235235
let mut fbuild = module_builder
236-
.define_function("main", FunctionType::new(type_row![NAT], type_row![NAT]))?;
236+
.define_function("main", Signature::new(type_row![NAT], type_row![NAT]))?;
237237
let tru_const = fbuild.add_constant(Value::true_val());
238238
let _fdef = {
239239
let const_wire = fbuild.load_const(&tru_const);

0 commit comments

Comments
 (0)