Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ missing_docs = "warn"
# https://github.com/rust-lang/rust-clippy/issues/5112
debug_assert_with_mut_call = "warn"

# TODO: Reduce the size of error types.
result_large_err = "allow"
large_enum_variant = "allow"

[workspace.dependencies]
anyhow = "1.0.98"
insta = { version = "1.43.1" }
Expand Down
8 changes: 4 additions & 4 deletions hugr-core/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ pub enum BuildError {
#[error("Found an error while setting the outputs of a {} container, {container_node}. {error}", .container_op.name())]
#[allow(missing_docs)]
OutputWiring {
container_op: OpType,
container_op: Box<OpType>,
container_node: Node,
#[source]
error: BuilderWiringError,
Expand All @@ -201,7 +201,7 @@ pub enum BuildError {
#[error("Got an input wire while adding a {} to the circuit. {error}", .op.name())]
#[allow(missing_docs)]
OperationWiring {
op: OpType,
op: Box<OpType>,
#[source]
error: BuilderWiringError,
},
Expand All @@ -219,7 +219,7 @@ pub enum BuilderWiringError {
#[error("Cannot copy linear type {typ} from output {src_offset} of node {src}")]
#[allow(missing_docs)]
NoCopyLinear {
typ: Type,
typ: Box<Type>,
src: Node,
src_offset: Port,
},
Expand All @@ -244,7 +244,7 @@ pub enum BuilderWiringError {
src_offset: Port,
dst: Node,
dst_offset: Port,
typ: Type,
typ: Box<Type>,
},
}

Expand Down
24 changes: 15 additions & 9 deletions hugr-core/src/builder/build_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,10 @@ pub trait Dataflow: Container {
let num_outputs = optype.value_output_count();
let node = self.add_hugr(hugr).inserted_entrypoint;

wire_up_inputs(input_wires, node, self)
.map_err(|error| BuildError::OperationWiring { op: optype, error })?;
wire_up_inputs(input_wires, node, self).map_err(|error| BuildError::OperationWiring {
op: Box::new(optype),
error,
})?;

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

wire_up_inputs(input_wires, node, self)
.map_err(|error| BuildError::OperationWiring { op: optype, error })?;
wire_up_inputs(input_wires, node, self).map_err(|error| BuildError::OperationWiring {
op: Box::new(optype),
error,
})?;

Ok((node, num_outputs).into())
}
Expand All @@ -253,7 +257,7 @@ pub trait Dataflow: Container {
let [_, out] = self.io();
wire_up_inputs(output_wires.into_iter().collect_vec(), out, self).map_err(|error| {
BuildError::OutputWiring {
container_op: self.hugr().get_optype(self.container_node()).clone(),
container_op: Box::new(self.hugr().get_optype(self.container_node()).clone()),
container_node: self.container_node(),
error,
}
Expand Down Expand Up @@ -662,8 +666,10 @@ fn add_node_with_wires<T: Dataflow + ?Sized>(
let num_outputs = op.value_output_count();
let op_node = data_builder.add_child_node(op.clone());

wire_up_inputs(inputs, op_node, data_builder)
.map_err(|error| BuildError::OperationWiring { op, error })?;
wire_up_inputs(inputs, op_node, data_builder).map_err(|error| BuildError::OperationWiring {
op: Box::new(op),
error,
})?;

Ok((op_node, num_outputs))
}
Expand Down Expand Up @@ -715,7 +721,7 @@ fn wire_up<T: Dataflow + ?Sized>(
src_offset: src_port.into(),
dst,
dst_offset: dst_port.into(),
typ,
typ: Box::new(typ),
});
}

Expand Down Expand Up @@ -746,7 +752,7 @@ fn wire_up<T: Dataflow + ?Sized>(
} else if !typ.copyable() & base.linked_ports(src, src_port).next().is_some() {
// Don't copy linear edges.
return Err(BuilderWiringError::NoCopyLinear {
typ,
typ: Box::new(typ),
src,
src_offset: src_port.into(),
});
Expand Down
14 changes: 7 additions & 7 deletions hugr-core/src/builder/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ pub struct CircuitBuilder<'a, T: ?Sized> {
#[non_exhaustive]
pub enum CircuitBuildError {
/// Invalid index for stored wires.
#[error("Invalid wire index {invalid_index} while attempting to add operation {}.", .op.as_ref().map(NamedOp::name).unwrap_or_default())]
#[error("Invalid wire index {invalid_index} while attempting to add operation {}.", .op.as_ref().map(|op| op.name()).unwrap_or_default())]
InvalidWireIndex {
/// The operation.
op: Option<OpType>,
op: Option<Box<OpType>>,
/// The invalid indices.
invalid_index: usize,
},
/// Some linear inputs had no corresponding output wire.
#[error("The linear inputs {:?} had no corresponding output wire in operation {}.", .index.as_slice(), .op.name())]
MismatchedLinearInputs {
/// The operation.
op: OpType,
op: Box<OpType>,
/// The index of the input that had no corresponding output wire.
index: Vec<usize>,
},
Expand Down Expand Up @@ -143,7 +143,7 @@ impl<'a, T: Dataflow + ?Sized> CircuitBuilder<'a, T> {

let input_wires =
input_wires.map_err(|invalid_index| CircuitBuildError::InvalidWireIndex {
op: Some(op.clone()),
op: Some(Box::new(op.clone())),
invalid_index,
})?;

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

if !linear_inputs.is_empty() {
return Err(CircuitBuildError::MismatchedLinearInputs {
op,
op: Box::new(op),
index: linear_inputs.values().copied().collect(),
}
.into());
Expand Down Expand Up @@ -389,7 +389,7 @@ mod test {
assert_matches!(
circ.append(cx_gate(), [q0, invalid_index]),
Err(BuildError::CircuitError(CircuitBuildError::InvalidWireIndex { op, invalid_index: idx }))
if op == Some(cx_gate().into()) && idx == invalid_index,
if op == Some(Box::new(cx_gate().into())) && idx == invalid_index,
);

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

let outs = circ.finish();
Expand Down
2 changes: 1 addition & 1 deletion hugr-core/src/builder/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ pub(crate) mod test {
error: BuilderWiringError::NoCopyLinear { typ, .. },
..
})
if typ == qb_t()
if *typ == qb_t()
);
}

Expand Down
4 changes: 2 additions & 2 deletions hugr-core/src/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ fn gen_str(generator: &Option<String>) -> String {
#[derive(Error, Debug)]
#[error("{inner}{}", gen_str(&self.generator))]
pub struct WithGenerator<E: std::fmt::Display> {
inner: E,
inner: Box<E>,
/// The name of the generator that produced the envelope, if any.
generator: Option<String>,
}

impl<E: std::fmt::Display> WithGenerator<E> {
fn new(err: E, modules: &[impl HugrView]) -> Self {
Self {
inner: err,
inner: Box::new(err),
generator: get_generator(modules),
}
}
Expand Down
30 changes: 18 additions & 12 deletions hugr-core/src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ impl ExtensionRegistry {
match self.exts.entry(extension.name().clone()) {
btree_map::Entry::Occupied(prev) => Err(ExtensionRegistryError::AlreadyRegistered(
extension.name().clone(),
prev.get().version().clone(),
extension.version().clone(),
Box::new(prev.get().version().clone()),
Box::new(extension.version().clone()),
)),
btree_map::Entry::Vacant(ve) => {
ve.insert(extension);
Expand Down Expand Up @@ -408,8 +408,8 @@ pub enum SignatureError {
/// A Type Variable's cache of its declared kind is incorrect
#[error("Type Variable claims to be {cached} but actual declaration {actual}")]
TypeVarDoesNotMatchDeclaration {
actual: TypeParam,
cached: TypeParam,
actual: Box<TypeParam>,
cached: Box<TypeParam>,
},
/// A type variable that was used has not been declared
#[error("Type variable {idx} was not declared ({num_decls} in scope)")]
Expand All @@ -425,8 +425,8 @@ pub enum SignatureError {
"Incorrect result of type application in Call - cached {cached} but expected {expected}"
)]
CallIncorrectlyAppliesType {
cached: Signature,
expected: Signature,
cached: Box<Signature>,
expected: Box<Signature>,
},
/// The result of the type application stored in a [`LoadFunction`]
/// is not what we get by applying the type-args to the polymorphic function
Expand All @@ -436,8 +436,8 @@ pub enum SignatureError {
"Incorrect result of type application in LoadFunction - cached {cached} but expected {expected}"
)]
LoadFunctionIncorrectlyAppliesType {
cached: Signature,
expected: Signature,
cached: Box<Signature>,
expected: Box<Signature>,
},

/// Extension declaration specifies a binary compute signature function, but none
Expand Down Expand Up @@ -697,7 +697,7 @@ pub enum ExtensionRegistryError {
#[error(
"The registry already contains an extension with id {0} and version {1}. New extension has version {2}."
)]
AlreadyRegistered(ExtensionId, Version, Version),
AlreadyRegistered(ExtensionId, Box<Version>, Box<Version>),
/// A registered extension has invalid signatures.
#[error("The extension {0} contains an invalid signature, {1}.")]
InvalidSignature(ExtensionId, #[source] SignatureError),
Expand All @@ -712,7 +712,13 @@ pub enum ExtensionRegistryLoadError {
SerdeError(#[from] serde_json::Error),
/// Error when resolving internal extension references.
#[error(transparent)]
ExtensionResolutionError(#[from] ExtensionResolutionError),
ExtensionResolutionError(Box<ExtensionResolutionError>),
}

impl From<ExtensionResolutionError> for ExtensionRegistryLoadError {
fn from(error: ExtensionResolutionError) -> Self {
Self::ExtensionResolutionError(Box::new(error))
}
}

/// An error that can occur in building a new extension.
Expand Down Expand Up @@ -889,8 +895,8 @@ pub mod test {
reg.register(ext1_1.clone()),
Err(ExtensionRegistryError::AlreadyRegistered(
ext_1_id.clone(),
Version::new(1, 0, 0),
Version::new(1, 1, 0)
Box::new(Version::new(1, 0, 0)),
Box::new(Version::new(1, 1, 0))
))
);

Expand Down
18 changes: 9 additions & 9 deletions hugr-core/src/extension/op_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ pub enum LowerFunc {
/// [OpDef]
///
/// [ExtensionOp]: crate::ops::ExtensionOp
#[serde_as(as = "AsStringEnvelope")]
hugr: Hugr,
#[serde_as(as = "Box<AsStringEnvelope>")]
hugr: Box<Hugr>,
},
/// Custom binary function that can (fallibly) compute a Hugr
/// for the particular instance and set of available extensions.
Expand Down Expand Up @@ -377,7 +377,7 @@ impl OpDef {
.filter_map(|f| match f {
LowerFunc::FixedHugr { extensions, hugr } => {
if available_extensions.is_superset(extensions) {
Some(hugr.clone())
Some(hugr.as_ref().clone())
} else {
None
}
Expand Down Expand Up @@ -664,7 +664,7 @@ pub(super) mod test {
let def = ext.add_op(OP_NAME, "desc".into(), type_scheme, extension_ref)?;
def.add_lower_func(LowerFunc::FixedHugr {
extensions: ExtensionSet::new(),
hugr: crate::builder::test::simple_dfg_hugr(), // this is nonsense, but we are not testing the actual lowering here
hugr: Box::new(crate::builder::test::simple_dfg_hugr()), // this is nonsense, but we are not testing the actual lowering here
});
def.add_misc("key", Default::default());
assert_eq!(def.description(), "desc");
Expand Down Expand Up @@ -754,8 +754,8 @@ pub(super) mod test {
assert_eq!(
def.validate_args(&args, &[TypeBound::Linear.into()]),
Err(SignatureError::TypeVarDoesNotMatchDeclaration {
actual: TypeBound::Linear.into(),
cached: TypeBound::Copyable.into()
actual: Box::new(TypeBound::Linear.into()),
cached: Box::new(TypeBound::Copyable.into())
})
);

Expand Down Expand Up @@ -807,8 +807,8 @@ pub(super) mod test {
def.compute_signature(&[arg.clone()]),
Err(SignatureError::TypeArgMismatch(
TermTypeError::TypeMismatch {
type_: TypeBound::Linear.into(),
term: arg,
type_: Box::new(TypeBound::Linear.into()),
term: Box::new(arg),
}
))
);
Expand Down Expand Up @@ -851,7 +851,7 @@ pub(super) mod test {
any::<ExtensionSet>()
.prop_map(|extensions| LowerFunc::FixedHugr {
extensions,
hugr: simple_dfg_hugr(),
hugr: Box::new(simple_dfg_hugr()),
})
.boxed()
}
Expand Down
4 changes: 2 additions & 2 deletions hugr-core/src/extension/resolution/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ pub(crate) fn resolve_op_extensions<'e>(
node,
extension: opaque.extension().clone(),
op: def.name().clone(),
computed: ext_op.signature().into_owned(),
stored: opaque.signature().into_owned(),
computed: Box::new(ext_op.signature().into_owned()),
stored: Box::new(opaque.signature().into_owned()),
}
.into());
}
Expand Down
4 changes: 2 additions & 2 deletions hugr-core/src/extension/type_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ mod test {
def.instantiate([qb_t().into()]),
Err(SignatureError::TypeArgMismatch(
TermTypeError::TypeMismatch {
term: qb_t().into(),
type_: TypeBound::Copyable.into()
term: Box::new(qb_t().into()),
type_: Box::new(TypeBound::Copyable.into())
}
))
);
Expand Down
4 changes: 2 additions & 2 deletions hugr-core/src/hugr/patch/outline_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl OutlineCfg {
};
let o = h.get_optype(cfg_n);
let OpType::CFG(_) = o else {
return Err(OutlineCfgError::ParentNotCfg(cfg_n, o.clone()));
return Err(OutlineCfgError::ParentNotCfg(cfg_n, Box::new(o.clone())));
};
let cfg_entry = h.children(cfg_n).next().unwrap();
let mut entry = None;
Expand Down Expand Up @@ -215,7 +215,7 @@ pub enum OutlineCfgError {
NotSiblings,
/// The parent node was not a CFG node
#[error("The parent node {0} was not a CFG but a {1}")]
ParentNotCfg(Node, OpType),
ParentNotCfg(Node, Box<OpType>),
/// Multiple blocks had incoming edges
#[error("Multiple blocks had predecessors outside the set - at least {0} and {1}")]
MultipleEntryNodes(Node, Node),
Expand Down
6 changes: 3 additions & 3 deletions hugr-core/src/hugr/patch/simple_replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ impl<HostNode: HugrNode> SimpleReplacement<HostNode> {
.inner_function_type()
.ok_or(InvalidReplacement::InvalidDataflowGraph {
node: replacement.entrypoint(),
op: replacement.get_optype(replacement.entrypoint()).to_owned(),
op: Box::new(replacement.get_optype(replacement.entrypoint()).to_owned()),
})?;
if subgraph_sig != repl_sig {
return Err(InvalidReplacement::InvalidSignature {
expected: subgraph_sig,
actual: Some(repl_sig.into_owned()),
expected: Box::new(subgraph_sig),
actual: Some(Box::new(repl_sig.into_owned())),
});
}
Ok(Self {
Expand Down
Loading
Loading