Skip to content

Commit c20176b

Browse files
committed
Merge 'origin/main' into 'lm/emptycommit'
2 parents ea1afe0 + 4f1e63b commit c20176b

Some content is hidden

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

44 files changed

+3536
-152
lines changed

.github/change-filters.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ rust: &rust
2424
- "hugr-cli/**"
2525
- "hugr-core/**"
2626
- "hugr-passes/**"
27+
- "hugr-persistent/**"
2728
- "specification/schema/**"
2829

2930
std-extensions:

.github/workflows/ci-rs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ env:
1919
CI: true # insta snapshots behave differently on ci
2020
SCCACHE_GHA_ENABLED: "true"
2121
RUSTC_WRAPPER: "sccache"
22+
HUGR_TEST_SCHEMA: "1"
2223
# different strings for install action and feature name
2324
# adapted from https://github.com/TheDan64/inkwell/blob/master/.github/workflows/test.yml
2425
LLVM_VERSION: "14.0"

.github/workflows/release-please.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
push:
77
branches:
88
- main
9+
- release/*
910

1011
permissions:
1112
contents: write
@@ -21,3 +22,4 @@ jobs:
2122
# Using a personal access token so releases created by this workflow can trigger the deployment workflow
2223
token: ${{ secrets.HUGRBOT_PAT }}
2324
config-file: release-please-config.json
25+
target-branch: ${{ github.ref_name }}

.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.2"
2+
"hugr-py": "0.12.4"
33
}

hugr-core/src/envelope/package_json.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ pub(super) fn to_json_writer<'h>(
5656
modules: hugrs.into_iter().map(HugrSer).collect(),
5757
extensions: extensions.iter().map(std::convert::AsRef::as_ref).collect(),
5858
};
59+
60+
// Validate the hugr serializations against the schema.
61+
//
62+
// NOTE: The schema definition is currently broken, so this check always succeeds.
63+
// See <https://github.com/CQCL/hugr/issues/2401>
64+
#[cfg(all(test, not(miri)))]
65+
if std::env::var("HUGR_TEST_SCHEMA").is_ok_and(|x| !x.is_empty()) {
66+
use crate::hugr::serialize::test::check_hugr_serialization_schema;
67+
68+
for hugr in &pkg_ser.modules {
69+
check_hugr_serialization_schema(hugr.0);
70+
}
71+
}
72+
5973
serde_json::to_writer(writer, &pkg_ser)?;
6074
Ok(())
6175
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,21 @@ fn ser_roundtrip_check_schema<TSer: Serialize, TDeser: serde::de::DeserializeOwn
175175
serde_json::from_value(val).unwrap()
176176
}
177177

178+
/// Serialize a Hugr and check that it is valid against the schema.
179+
///
180+
/// NOTE: The schema definition is currently broken, so this check always succeeds.
181+
/// See <https://github.com/CQCL/hugr/issues/2401>
182+
///
183+
/// # Panics
184+
///
185+
/// Panics if the serialization fails or if the schema validation fails.
186+
pub(crate) fn check_hugr_serialization_schema(hugr: &Hugr) {
187+
let schemas = get_schemas(true);
188+
let hugr_ser = HugrSer(hugr);
189+
let val = serde_json::to_value(hugr_ser).unwrap();
190+
NamedSchema::check_schemas(&val, schemas);
191+
}
192+
178193
/// Serialize and deserialize a HUGR, and check that the result is the same as the original.
179194
///
180195
/// If `check_schema` is true, checks the serialized json against the in-tree schema.

hugr-core/src/std_extensions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub fn std_reg() -> ExtensionRegistry {
2121
arithmetic::float_types::EXTENSION.to_owned(),
2222
collections::array::EXTENSION.to_owned(),
2323
collections::list::EXTENSION.to_owned(),
24+
collections::borrow_array::EXTENSION.to_owned(),
2425
collections::static_array::EXTENSION.to_owned(),
2526
collections::value_array::EXTENSION.to_owned(),
2627
logic::EXTENSION.to_owned(),
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! List type and operations.
22
33
pub mod array;
4+
pub mod borrow_array;
45
pub mod list;
56
pub mod static_array;
67
pub mod value_array;

hugr-core/src/std_extensions/collections/array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ pub trait ArrayOpBuilder: GenericArrayOpBuilder {
223223
self.add_generic_array_unpack::<Array>(elem_ty, size, input)
224224
}
225225
/// Adds an array clone operation to the dataflow graph and return the wires
226-
/// representing the originala and cloned array.
226+
/// representing the original and cloned array.
227227
///
228228
/// # Arguments
229229
///

hugr-core/src/std_extensions/collections/array/array_clone.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ mod tests {
194194

195195
use crate::extension::prelude::bool_t;
196196
use crate::std_extensions::collections::array::Array;
197+
use crate::std_extensions::collections::borrow_array::BorrowArray;
197198
use crate::{
198199
extension::prelude::qb_t,
199200
ops::{OpTrait, OpType},
@@ -203,6 +204,7 @@ mod tests {
203204

204205
#[rstest]
205206
#[case(Array)]
207+
#[case(BorrowArray)]
206208
fn test_clone_def<AK: ArrayKind>(#[case] _kind: AK) {
207209
let op = GenericArrayClone::<AK>::new(bool_t(), 2).unwrap();
208210
let optype: OpType = op.clone().into();
@@ -217,6 +219,7 @@ mod tests {
217219

218220
#[rstest]
219221
#[case(Array)]
222+
#[case(BorrowArray)]
220223
fn test_clone<AK: ArrayKind>(#[case] _kind: AK) {
221224
let size = 2;
222225
let element_ty = bool_t();

0 commit comments

Comments
 (0)