Skip to content

Commit

Permalink
fix!: ops::Module to empty struct rather than unit struct
Browse files Browse the repository at this point in the history
Fixes #1270

A simpler test json might be better but kept the original just to show it is fixed.

BREAKING CHANGE: `ops::Module` no longer unit struct, must be constructed with `new()` or `default()`
  • Loading branch information
ss2165 committed Jul 8, 2024
1 parent bbff0c9 commit 59201d5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
4 changes: 0 additions & 4 deletions hugr-core/src/hugr/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ struct NodeSer {
parent: Node,
#[serde(flatten)]
op: OpType,

#[serde(skip_serializing, default)]
input_extensions: Option<crate::extension::ExtensionSet>,
}

/// Version 1 of the HUGR serialization format.
Expand Down Expand Up @@ -149,7 +146,6 @@ impl TryFrom<&Hugr> for SerHugrV1 {
nodes[new_node] = Some(NodeSer {
parent,
op: opt.clone(),
input_extensions: None,
});
metadata[new_node].clone_from(hugr.metadata.get(n.pg_index()));
}
Expand Down
7 changes: 1 addition & 6 deletions hugr-core/src/hugr/serialize/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ fn roundtrip_optype(#[case] optype: impl Into<OpType> + std::fmt::Debug) {
check_testing_roundtrip(NodeSer {
parent: portgraph::NodeIndex::new(0).into(),
op: optype.into(),
input_extensions: None,
});
}

Expand Down Expand Up @@ -495,11 +494,7 @@ mod proptest {
(0..i32::MAX as usize).prop_map(|x| portgraph::NodeIndex::new(x).into()),
any::<OpType>(),
)
.prop_map(|(parent, op)| NodeSer {
parent,
op,
input_extensions: None,
})
.prop_map(|(parent, op)| NodeSer { parent, op })
.boxed()
}
}
Expand Down
8 changes: 6 additions & 2 deletions hugr-core/src/ops/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ use super::{impl_op_name, OpTag, OpTrait};
/// The root of a module, parent of all other `OpType`s.
#[derive(Debug, Clone, PartialEq, Eq, Default, serde::Serialize, serde::Deserialize)]
#[cfg_attr(test, derive(Arbitrary))]
pub struct Module;
pub struct Module {
// can't be simple unit struct due to flattened serialization issues
// see https://github.com/CQCL/hugr/issues/1270
}

impl Module {
/// Construct a new Module.
pub const fn new() -> Self {
Self
Self {}
}
}

Expand Down

0 comments on commit 59201d5

Please sign in to comment.