Skip to content

Commit c04f921

Browse files
committed
Merge remote-tracking branch 'origin/arrays/clone-discard' into arrays/conversion
2 parents 96ab540 + 98a5691 commit c04f921

File tree

4 files changed

+37
-29
lines changed

4 files changed

+37
-29
lines changed

Cargo.lock

+16-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ static_assertions = "1.1.0"
6666
strum = "0.27.0"
6767
thiserror = "2.0.12"
6868
typetag = "0.2.20"
69-
clap = { version = "4.5.36" }
69+
clap = { version = "4.5.37" }
7070
clio = "0.3.5"
7171
clap-verbosity-flag = "3.0.1"
72-
assert_cmd = "2.0.14"
72+
assert_cmd = "2.0.17"
7373
assert_fs = "1.1.1"
7474
predicates = "3.1.0"
7575
indexmap = "2.9.0"

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ use crate::types::type_param::{TypeArg, TypeParam};
2323
use crate::types::{CustomCheckFailure, Type, TypeBound, TypeName};
2424
use crate::Extension;
2525

26-
pub use array_clone::{GenericArrayClone, GenericArrayCloneDef};
26+
pub use array_clone::{GenericArrayClone, GenericArrayCloneDef, ARRAY_CLONE_OP_ID};
2727
pub use array_conversion::{Direction, GenericArrayConvert, GenericArrayConvertDef, FROM, INTO};
28-
pub use array_discard::{GenericArrayDiscard, GenericArrayDiscardDef};
28+
pub use array_discard::{GenericArrayDiscard, GenericArrayDiscardDef, ARRAY_DISCARD_OP_ID};
2929
pub use array_kind::ArrayKind;
3030
pub use array_op::{GenericArrayOp, GenericArrayOpDef};
3131
pub use array_repeat::{GenericArrayRepeat, GenericArrayRepeatDef, ARRAY_REPEAT_OP_ID};
@@ -75,9 +75,9 @@ pub type ArrayScanDef = GenericArrayScanDef<Array>;
7575
/// Array operations.
7676
pub type ArrayOp = GenericArrayOp<Array>;
7777
/// The array clone operation.
78-
pub type ArrayClone = GenericArrayRepeat<Array>;
78+
pub type ArrayClone = GenericArrayClone<Array>;
7979
/// The array discard operation.
80-
pub type ArrayDiscard = GenericArrayRepeat<Array>;
80+
pub type ArrayDiscard = GenericArrayDiscard<Array>;
8181
/// The array repeat operation.
8282
pub type ArrayRepeat = GenericArrayRepeat<Array>;
8383
/// The array scan operation.

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

+15-7
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,17 @@ pub struct GenericArrayClone<AK: ArrayKind> {
122122

123123
impl<AK: ArrayKind> GenericArrayClone<AK> {
124124
/// Creates a new array clone op.
125-
pub fn new(elem_ty: Type, size: u64) -> Option<Self> {
126-
elem_ty.copyable().then_some(GenericArrayClone {
127-
elem_ty,
128-
size,
129-
_kind: PhantomData,
130-
})
125+
///
126+
/// Returns an error if the proveded element type is not copyable.
127+
pub fn new(elem_ty: Type, size: u64) -> Result<Self, OpLoadError> {
128+
elem_ty
129+
.copyable()
130+
.then_some(GenericArrayClone {
131+
elem_ty,
132+
size,
133+
_kind: PhantomData,
134+
})
135+
.ok_or(SignatureError::InvalidTypeArgs.into())
131136
}
132137
}
133138

@@ -202,7 +207,10 @@ mod tests {
202207
let new_op: GenericArrayClone<AK> = optype.cast().unwrap();
203208
assert_eq!(new_op, op);
204209

205-
assert_eq!(GenericArrayClone::<AK>::new(qb_t(), 2), None);
210+
assert_eq!(
211+
GenericArrayClone::<AK>::new(qb_t(), 2),
212+
Err(OpLoadError::InvalidArgs(SignatureError::InvalidTypeArgs))
213+
);
206214
}
207215

208216
#[rstest]

0 commit comments

Comments
 (0)