Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions hugr-core/src/ops/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ pub(crate) mod test {
use crate::extension::PRELUDE;
use crate::std_extensions::arithmetic::int_types::ConstInt;
use crate::std_extensions::collections::array::{array_type, ArrayValue};
use crate::std_extensions::collections::value_array::{value_array_type, VArrayValue};
use crate::{
builder::{BuildError, DFGBuilder, Dataflow, DataflowHugr},
extension::{
Expand Down Expand Up @@ -754,6 +755,11 @@ pub(crate) mod test {
ArrayValue::new(bool_t(), [Value::true_val(), Value::false_val()]).into()
}

#[fixture]
fn const_value_array_bool() -> Value {
VArrayValue::new(bool_t(), [Value::true_val(), Value::false_val()]).into()
}

#[fixture]
fn const_array_options() -> Value {
let some_true = Value::some([Value::true_val()]);
Expand All @@ -762,17 +768,35 @@ pub(crate) mod test {
ArrayValue::new(elem_ty.into(), [some_true, none]).into()
}

#[fixture]
fn const_value_array_options() -> Value {
let some_true = Value::some([Value::true_val()]);
let none = Value::none(vec![bool_t()]);
let elem_ty = SumType::new_option(vec![bool_t()]);
VArrayValue::new(elem_ty.into(), [some_true, none]).into()
}

#[rstest]
#[case(Value::unit(), Type::UNIT, "const:seq:{}")]
#[case(const_usize(), usize_t(), "const:custom:ConstUsize(")]
#[case(serialized_float(17.4), float64_type(), "const:custom:json:Object")]
#[case(const_tuple(), Type::new_tuple(vec![usize_t(), bool_t()]), "const:seq:{")]
#[case(const_array_bool(), array_type(2, bool_t()), "const:custom:array")]
#[case(
const_value_array_bool(),
value_array_type(2, bool_t()),
"const:custom:value_array"
)]
#[case(
const_array_options(),
array_type(2, SumType::new_option(vec![bool_t()]).into()),
"const:custom:array"
)]
#[case(
const_value_array_options(),
value_array_type(2, SumType::new_option(vec![bool_t()]).into()),
"const:custom:value_array"
)]
fn const_type(
#[case] const_value: Value,
#[case] expected_type: Type,
Expand All @@ -792,7 +816,9 @@ pub(crate) mod test {
#[case(const_serialized_usize(), const_usize())]
#[case(const_tuple_serialized(), const_tuple())]
#[case(const_array_bool(), const_array_bool())]
#[case(const_value_array_bool(), const_value_array_bool())]
#[case(const_array_options(), const_array_options())]
#[case(const_value_array_options(), const_value_array_options())]
// Opaque constants don't get resolved into concrete types when running miri,
// as the `typetag` machinery is not available.
#[cfg_attr(miri, ignore)]
Expand Down
1 change: 1 addition & 0 deletions hugr-core/src/std_extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub fn std_reg() -> ExtensionRegistry {
collections::array::EXTENSION.to_owned(),
collections::list::EXTENSION.to_owned(),
collections::static_array::EXTENSION.to_owned(),
collections::value_array::EXTENSION.to_owned(),
logic::EXTENSION.to_owned(),
ptr::EXTENSION.to_owned(),
]);
Expand Down
1 change: 1 addition & 0 deletions hugr-core/src/std_extensions/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
pub mod array;
pub mod list;
pub mod static_array;
pub mod value_array;
Loading
Loading