Skip to content

Commit 59201d5

Browse files
committedJul 8, 2024
fix!: ops::Module to empty struct rather than unit struct
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()`
1 parent bbff0c9 commit 59201d5

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed
 

‎hugr-core/src/hugr/serialize.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ struct NodeSer {
4949
parent: Node,
5050
#[serde(flatten)]
5151
op: OpType,
52-
53-
#[serde(skip_serializing, default)]
54-
input_extensions: Option<crate::extension::ExtensionSet>,
5552
}
5653

5754
/// Version 1 of the HUGR serialization format.
@@ -149,7 +146,6 @@ impl TryFrom<&Hugr> for SerHugrV1 {
149146
nodes[new_node] = Some(NodeSer {
150147
parent,
151148
op: opt.clone(),
152-
input_extensions: None,
153149
});
154150
metadata[new_node].clone_from(hugr.metadata.get(n.pg_index()));
155151
}

‎hugr-core/src/hugr/serialize/test.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,6 @@ fn roundtrip_optype(#[case] optype: impl Into<OpType> + std::fmt::Debug) {
466466
check_testing_roundtrip(NodeSer {
467467
parent: portgraph::NodeIndex::new(0).into(),
468468
op: optype.into(),
469-
input_extensions: None,
470469
});
471470
}
472471

@@ -495,11 +494,7 @@ mod proptest {
495494
(0..i32::MAX as usize).prop_map(|x| portgraph::NodeIndex::new(x).into()),
496495
any::<OpType>(),
497496
)
498-
.prop_map(|(parent, op)| NodeSer {
499-
parent,
500-
op,
501-
input_extensions: None,
502-
})
497+
.prop_map(|(parent, op)| NodeSer { parent, op })
503498
.boxed()
504499
}
505500
}

‎hugr-core/src/ops/module.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ use super::{impl_op_name, OpTag, OpTrait};
1717
/// The root of a module, parent of all other `OpType`s.
1818
#[derive(Debug, Clone, PartialEq, Eq, Default, serde::Serialize, serde::Deserialize)]
1919
#[cfg_attr(test, derive(Arbitrary))]
20-
pub struct Module;
20+
pub struct Module {
21+
// can't be simple unit struct due to flattened serialization issues
22+
// see https://github.com/CQCL/hugr/issues/1270
23+
}
24+
2125
impl Module {
2226
/// Construct a new Module.
2327
pub const fn new() -> Self {
24-
Self
28+
Self {}
2529
}
2630
}
2731

0 commit comments

Comments
 (0)