Skip to content

Commit dc638c4

Browse files
committed
feat: Make arrays linear and add copyable value arrays
1 parent 54c2e9c commit dc638c4

33 files changed

+2300
-539
lines changed

hugr-core/src/ops/constant.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ pub(crate) mod test {
605605
use crate::extension::PRELUDE;
606606
use crate::std_extensions::arithmetic::int_types::ConstInt;
607607
use crate::std_extensions::collections::array::{array_type, ArrayValue};
608+
use crate::std_extensions::collections::value_array::{value_array_type, VArrayValue};
608609
use crate::{
609610
builder::{BuildError, DFGBuilder, Dataflow, DataflowHugr},
610611
extension::{
@@ -778,6 +779,11 @@ pub(crate) mod test {
778779
ArrayValue::new(bool_t(), [Value::true_val(), Value::false_val()]).into()
779780
}
780781

782+
#[fixture]
783+
fn const_value_array_bool() -> Value {
784+
VArrayValue::new(bool_t(), [Value::true_val(), Value::false_val()]).into()
785+
}
786+
781787
#[fixture]
782788
fn const_array_options() -> Value {
783789
let some_true = Value::some([Value::true_val()]);
@@ -786,17 +792,35 @@ pub(crate) mod test {
786792
ArrayValue::new(elem_ty.into(), [some_true, none]).into()
787793
}
788794

795+
#[fixture]
796+
fn const_value_array_options() -> Value {
797+
let some_true = Value::some([Value::true_val()]);
798+
let none = Value::none(vec![bool_t()]);
799+
let elem_ty = SumType::new_option(vec![bool_t()]);
800+
VArrayValue::new(elem_ty.into(), [some_true, none]).into()
801+
}
802+
789803
#[rstest]
790804
#[case(Value::unit(), Type::UNIT, "const:seq:{}")]
791805
#[case(const_usize(), usize_t(), "const:custom:ConstUsize(")]
792806
#[case(serialized_float(17.4), float64_type(), "const:custom:json:Object")]
793807
#[case(const_tuple(), Type::new_tuple(vec![usize_t(), bool_t()]), "const:seq:{")]
794808
#[case(const_array_bool(), array_type(2, bool_t()), "const:custom:array")]
809+
#[case(
810+
const_value_array_bool(),
811+
value_array_type(2, bool_t()),
812+
"const:custom:value_array"
813+
)]
795814
#[case(
796815
const_array_options(),
797816
array_type(2, SumType::new_option(vec![bool_t()]).into()),
798817
"const:custom:array"
799818
)]
819+
#[case(
820+
const_value_array_options(),
821+
value_array_type(2, SumType::new_option(vec![bool_t()]).into()),
822+
"const:custom:value_array"
823+
)]
800824
fn const_type(
801825
#[case] const_value: Value,
802826
#[case] expected_type: Type,
@@ -816,7 +840,9 @@ pub(crate) mod test {
816840
#[case(const_serialized_usize(), const_usize())]
817841
#[case(const_tuple_serialized(), const_tuple())]
818842
#[case(const_array_bool(), const_array_bool())]
843+
#[case(const_value_array_bool(), const_value_array_bool())]
819844
#[case(const_array_options(), const_array_options())]
845+
#[case(const_value_array_options(), const_value_array_options())]
820846
// Opaque constants don't get resolved into concrete types when running miri,
821847
// as the `typetag` machinery is not available.
822848
#[cfg_attr(miri, ignore)]

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
collections::array::EXTENSION.to_owned(),
2222
collections::list::EXTENSION.to_owned(),
2323
collections::static_array::EXTENSION.to_owned(),
24+
collections::value_array::EXTENSION.to_owned(),
2425
logic::EXTENSION.to_owned(),
2526
ptr::EXTENSION.to_owned(),
2627
]);

hugr-core/src/std_extensions/collections.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
pub mod array;
44
pub mod list;
55
pub mod static_array;
6+
pub mod value_array;

0 commit comments

Comments
 (0)