make [T; N]: ToExpr for any N instead of a fixed list

This commit is contained in:
Jacob Lifshay 2024-07-25 22:08:28 -07:00
parent 7963f0a5cd
commit ef4b3b4081
Signed by: programmerjake
SSH key fingerprint: SHA256:B1iRVvUJkvd7upMIiMqn6OyxvD2SgJkAH3ZnUOj6z+c

View file

@ -548,70 +548,21 @@ impl<E: ToExpr<Type = T>, T: FixedType> ToExpr for Vec<E> {
}
}
impl<E: ToExpr<Type = T>, T: FixedType> ToExpr for [E; 0] {
type Type = ArrayType<[T::Value; 0]>;
impl<E: ToExpr<Type = T>, T: FixedType, const N: usize> ToExpr for [E; N] {
type Type = ArrayType<[T::Value; N]>;
fn ty(&self) -> Self::Type {
ArrayType::new_with_len_type(FixedType::fixed_type(), ())
}
fn to_expr(&self) -> Expr<<Self::Type as Type>::Value> {
Array::new(FixedType::fixed_type(), Arc::new([])).to_expr()
let elements = Intern::intern_owned(Vec::from_iter(
self.iter().map(|v| v.to_expr().to_canonical_dyn()),
));
ArrayLiteral::new_unchecked(elements, self.ty()).to_expr()
}
}
macro_rules! impl_to_expr_for_non_empty_array {
($N:literal) => {
impl<E: ToExpr<Type = T>, T: Type> ToExpr for [E; $N] {
type Type = ArrayType<[T::Value; $N]>;
fn ty(&self) -> Self::Type {
ArrayType::new_with_len_type(self[0].ty(), ())
}
fn to_expr(&self) -> Expr<<Self::Type as Type>::Value> {
let elements = Intern::intern_owned(Vec::from_iter(
self.iter().map(|v| v.to_expr().to_canonical_dyn()),
));
ArrayLiteral::new_unchecked(elements, self.ty()).to_expr()
}
}
};
}
impl_to_expr_for_non_empty_array!(1);
impl_to_expr_for_non_empty_array!(2);
impl_to_expr_for_non_empty_array!(3);
impl_to_expr_for_non_empty_array!(4);
impl_to_expr_for_non_empty_array!(5);
impl_to_expr_for_non_empty_array!(6);
impl_to_expr_for_non_empty_array!(7);
impl_to_expr_for_non_empty_array!(8);
impl_to_expr_for_non_empty_array!(9);
impl_to_expr_for_non_empty_array!(10);
impl_to_expr_for_non_empty_array!(11);
impl_to_expr_for_non_empty_array!(12);
impl_to_expr_for_non_empty_array!(13);
impl_to_expr_for_non_empty_array!(14);
impl_to_expr_for_non_empty_array!(15);
impl_to_expr_for_non_empty_array!(16);
impl_to_expr_for_non_empty_array!(17);
impl_to_expr_for_non_empty_array!(18);
impl_to_expr_for_non_empty_array!(19);
impl_to_expr_for_non_empty_array!(20);
impl_to_expr_for_non_empty_array!(21);
impl_to_expr_for_non_empty_array!(22);
impl_to_expr_for_non_empty_array!(23);
impl_to_expr_for_non_empty_array!(24);
impl_to_expr_for_non_empty_array!(25);
impl_to_expr_for_non_empty_array!(26);
impl_to_expr_for_non_empty_array!(27);
impl_to_expr_for_non_empty_array!(28);
impl_to_expr_for_non_empty_array!(29);
impl_to_expr_for_non_empty_array!(30);
impl_to_expr_for_non_empty_array!(31);
impl_to_expr_for_non_empty_array!(32);
#[derive(Clone, Debug)]
pub struct ArrayIntoIter<VA: ValueArrayOrSlice> {
array: Arc<VA>,