Skip to content

Commit db08327

Browse files
committed
Merge branch 'main' into lm/emptycommit
2 parents e13ab90 + 5bbe0cd commit db08327

File tree

99 files changed

+1582
-808
lines changed

Some content is hidden

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

99 files changed

+1582
-808
lines changed

.github/workflows/ci-py.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ jobs:
191191
fetch-depth: 0 # Need full history to compare with main
192192

193193
- name: Set up Python
194-
uses: actions/setup-python@v4
194+
uses: actions/setup-python@v5
195195
with:
196196
python-version: '3.10'
197197

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"hugr-py": "0.12.4"
2+
"hugr-py": "0.12.5"
33
}

Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ missing_docs = "warn"
3838
# https://github.com/rust-lang/rust-clippy/issues/5112
3939
debug_assert_with_mut_call = "warn"
4040

41-
# TODO: Reduce the size of error types.
42-
result_large_err = "allow"
43-
large_enum_variant = "allow"
44-
4541
[workspace.dependencies]
4642
anyhow = "1.0.98"
4743
insta = { version = "1.43.1" }

hugr-core/src/builder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pub enum BuildError {
189189
#[error("Found an error while setting the outputs of a {} container, {container_node}. {error}", .container_op.name())]
190190
#[allow(missing_docs)]
191191
OutputWiring {
192-
container_op: OpType,
192+
container_op: Box<OpType>,
193193
container_node: Node,
194194
#[source]
195195
error: BuilderWiringError,
@@ -201,7 +201,7 @@ pub enum BuildError {
201201
#[error("Got an input wire while adding a {} to the circuit. {error}", .op.name())]
202202
#[allow(missing_docs)]
203203
OperationWiring {
204-
op: OpType,
204+
op: Box<OpType>,
205205
#[source]
206206
error: BuilderWiringError,
207207
},
@@ -219,7 +219,7 @@ pub enum BuilderWiringError {
219219
#[error("Cannot copy linear type {typ} from output {src_offset} of node {src}")]
220220
#[allow(missing_docs)]
221221
NoCopyLinear {
222-
typ: Type,
222+
typ: Box<Type>,
223223
src: Node,
224224
src_offset: Port,
225225
},
@@ -244,7 +244,7 @@ pub enum BuilderWiringError {
244244
src_offset: Port,
245245
dst: Node,
246246
dst_offset: Port,
247-
typ: Type,
247+
typ: Box<Type>,
248248
},
249249
}
250250

hugr-core/src/builder/build_traits.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,10 @@ pub trait Dataflow: Container {
213213
let num_outputs = optype.value_output_count();
214214
let node = self.add_hugr(hugr).inserted_entrypoint;
215215

216-
wire_up_inputs(input_wires, node, self)
217-
.map_err(|error| BuildError::OperationWiring { op: optype, error })?;
216+
wire_up_inputs(input_wires, node, self).map_err(|error| BuildError::OperationWiring {
217+
op: Box::new(optype),
218+
error,
219+
})?;
218220

219221
Ok((node, num_outputs).into())
220222
}
@@ -235,8 +237,10 @@ pub trait Dataflow: Container {
235237
let optype = hugr.get_optype(hugr.entrypoint()).clone();
236238
let num_outputs = optype.value_output_count();
237239

238-
wire_up_inputs(input_wires, node, self)
239-
.map_err(|error| BuildError::OperationWiring { op: optype, error })?;
240+
wire_up_inputs(input_wires, node, self).map_err(|error| BuildError::OperationWiring {
241+
op: Box::new(optype),
242+
error,
243+
})?;
240244

241245
Ok((node, num_outputs).into())
242246
}
@@ -253,7 +257,7 @@ pub trait Dataflow: Container {
253257
let [_, out] = self.io();
254258
wire_up_inputs(output_wires.into_iter().collect_vec(), out, self).map_err(|error| {
255259
BuildError::OutputWiring {
256-
container_op: self.hugr().get_optype(self.container_node()).clone(),
260+
container_op: Box::new(self.hugr().get_optype(self.container_node()).clone()),
257261
container_node: self.container_node(),
258262
error,
259263
}
@@ -662,8 +666,10 @@ fn add_node_with_wires<T: Dataflow + ?Sized>(
662666
let num_outputs = op.value_output_count();
663667
let op_node = data_builder.add_child_node(op.clone());
664668

665-
wire_up_inputs(inputs, op_node, data_builder)
666-
.map_err(|error| BuildError::OperationWiring { op, error })?;
669+
wire_up_inputs(inputs, op_node, data_builder).map_err(|error| BuildError::OperationWiring {
670+
op: Box::new(op),
671+
error,
672+
})?;
667673

668674
Ok((op_node, num_outputs))
669675
}
@@ -715,7 +721,7 @@ fn wire_up<T: Dataflow + ?Sized>(
715721
src_offset: src_port.into(),
716722
dst,
717723
dst_offset: dst_port.into(),
718-
typ,
724+
typ: Box::new(typ),
719725
});
720726
}
721727

@@ -746,7 +752,7 @@ fn wire_up<T: Dataflow + ?Sized>(
746752
} else if !typ.copyable() & base.linked_ports(src, src_port).next().is_some() {
747753
// Don't copy linear edges.
748754
return Err(BuilderWiringError::NoCopyLinear {
749-
typ,
755+
typ: Box::new(typ),
750756
src,
751757
src_offset: src_port.into(),
752758
});

hugr-core/src/builder/circuit.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ pub struct CircuitBuilder<'a, T: ?Sized> {
2727
#[non_exhaustive]
2828
pub enum CircuitBuildError {
2929
/// Invalid index for stored wires.
30-
#[error("Invalid wire index {invalid_index} while attempting to add operation {}.", .op.as_ref().map(NamedOp::name).unwrap_or_default())]
30+
#[error("Invalid wire index {invalid_index} while attempting to add operation {}.", .op.as_ref().map(|op| op.name()).unwrap_or_default())]
3131
InvalidWireIndex {
3232
/// The operation.
33-
op: Option<OpType>,
33+
op: Option<Box<OpType>>,
3434
/// The invalid indices.
3535
invalid_index: usize,
3636
},
3737
/// Some linear inputs had no corresponding output wire.
3838
#[error("The linear inputs {:?} had no corresponding output wire in operation {}.", .index.as_slice(), .op.name())]
3939
MismatchedLinearInputs {
4040
/// The operation.
41-
op: OpType,
41+
op: Box<OpType>,
4242
/// The index of the input that had no corresponding output wire.
4343
index: Vec<usize>,
4444
},
@@ -143,7 +143,7 @@ impl<'a, T: Dataflow + ?Sized> CircuitBuilder<'a, T> {
143143

144144
let input_wires =
145145
input_wires.map_err(|invalid_index| CircuitBuildError::InvalidWireIndex {
146-
op: Some(op.clone()),
146+
op: Some(Box::new(op.clone())),
147147
invalid_index,
148148
})?;
149149

@@ -169,7 +169,7 @@ impl<'a, T: Dataflow + ?Sized> CircuitBuilder<'a, T> {
169169

170170
if !linear_inputs.is_empty() {
171171
return Err(CircuitBuildError::MismatchedLinearInputs {
172-
op,
172+
op: Box::new(op),
173173
index: linear_inputs.values().copied().collect(),
174174
}
175175
.into());
@@ -389,7 +389,7 @@ mod test {
389389
assert_matches!(
390390
circ.append(cx_gate(), [q0, invalid_index]),
391391
Err(BuildError::CircuitError(CircuitBuildError::InvalidWireIndex { op, invalid_index: idx }))
392-
if op == Some(cx_gate().into()) && idx == invalid_index,
392+
if op == Some(Box::new(cx_gate().into())) && idx == invalid_index,
393393
);
394394

395395
// Untracking an invalid index returns an error
@@ -403,7 +403,7 @@ mod test {
403403
assert_matches!(
404404
circ.append(q_discard(), [q1]),
405405
Err(BuildError::CircuitError(CircuitBuildError::MismatchedLinearInputs { op, index }))
406-
if op == q_discard().into() && index == [q1],
406+
if *op == q_discard().into() && index == [q1],
407407
);
408408

409409
let outs = circ.finish();

hugr-core/src/builder/dataflow.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,9 @@ use std::marker::PhantomData;
88

99
use crate::hugr::internal::HugrMutInternals;
1010
use crate::hugr::{HugrView, ValidationError};
11-
use crate::ops::{self, OpParent};
12-
use crate::ops::{DataflowParent, Input, Output};
13-
use crate::{Direction, IncomingPort, OutgoingPort, Wire};
14-
11+
use crate::ops::{self, DataflowParent, FuncDefn, Input, OpParent, Output};
1512
use crate::types::{PolyFuncType, Signature, Type};
16-
17-
use crate::Node;
18-
use crate::{Hugr, hugr::HugrMut};
13+
use crate::{Direction, Hugr, IncomingPort, Node, OutgoingPort, Visibility, Wire, hugr::HugrMut};
1914

2015
/// Builder for a [`ops::DFG`] node.
2116
#[derive(Debug, Clone, PartialEq)]
@@ -152,17 +147,35 @@ impl<B, T> DFGWrapper<B, T> {
152147
pub type FunctionBuilder<B> = DFGWrapper<B, BuildHandle<FuncID<true>>>;
153148

154149
impl FunctionBuilder<Hugr> {
155-
/// Initialize a builder for a `FuncDefn` rooted HUGR
150+
/// Initialize a builder for a [`FuncDefn`](ops::FuncDefn)-rooted HUGR;
151+
/// the function will be private. (See also [Self::new_vis].)
152+
///
156153
/// # Errors
157154
///
158155
/// Error in adding DFG child nodes.
159156
pub fn new(
160157
name: impl Into<String>,
161158
signature: impl Into<PolyFuncType>,
162159
) -> Result<Self, BuildError> {
163-
let signature: PolyFuncType = signature.into();
164-
let body = signature.body().clone();
165-
let op = ops::FuncDefn::new(name, signature);
160+
Self::new_with_op(FuncDefn::new(name, signature))
161+
}
162+
163+
/// Initialize a builder for a FuncDefn-rooted HUGR, with the specified
164+
/// [Visibility].
165+
///
166+
/// # Errors
167+
///
168+
/// Error in adding DFG child nodes.
169+
pub fn new_vis(
170+
name: impl Into<String>,
171+
signature: impl Into<PolyFuncType>,
172+
visibility: Visibility,
173+
) -> Result<Self, BuildError> {
174+
Self::new_with_op(FuncDefn::new_vis(name, signature, visibility))
175+
}
176+
177+
fn new_with_op(op: FuncDefn) -> Result<Self, BuildError> {
178+
let body = op.signature().body().clone();
166179

167180
let base = Hugr::new_with_entrypoint(op).expect("FuncDefn entrypoint should be valid");
168181
let root = base.entrypoint();
@@ -437,7 +450,7 @@ pub(crate) mod test {
437450
error: BuilderWiringError::NoCopyLinear { typ, .. },
438451
..
439452
})
440-
if typ == qb_t()
453+
if *typ == qb_t()
441454
);
442455
}
443456

0 commit comments

Comments
 (0)