diff --git a/crates/fayalite-proc-macros-impl/src/value_derive_common.rs b/crates/fayalite-proc-macros-impl/src/value_derive_common.rs index 68532e7..9f495ff 100644 --- a/crates/fayalite-proc-macros-impl/src/value_derive_common.rs +++ b/crates/fayalite-proc-macros-impl/src/value_derive_common.rs @@ -186,22 +186,9 @@ impl ValueDeriveGenerics { let predicates = &mut generics.make_where_clause().predicates; let static_type_predicates = &mut static_type_generics.make_where_clause().predicates; for type_param in type_params { - predicates.push(parse_quote! {#type_param: ::fayalite::ty::Value}); - predicates.push(parse_quote! { - <#type_param as ::fayalite::expr::ToExpr>::Type: - ::fayalite::ty::Type - }); - static_type_predicates.push(parse_quote! {#type_param: ::fayalite::ty::Value}); - static_type_predicates.push(parse_quote! { - <#type_param as ::fayalite::expr::ToExpr>::Type: - ::fayalite::ty::StaticType - }); - static_type_predicates.push(parse_quote! { - < - <#type_param as ::fayalite::expr::ToExpr>::Type - as ::fayalite::ty::Type - >::MaskType: ::fayalite::ty::StaticType - }); + predicates.push(parse_quote! {#type_param: ::fayalite::ty::Value>}); + static_type_predicates + .push(parse_quote! {#type_param: ::fayalite::ty::StaticValue}); } } Self { diff --git a/crates/fayalite/src/array.rs b/crates/fayalite/src/array.rs index a430738..3763cae 100644 --- a/crates/fayalite/src/array.rs +++ b/crates/fayalite/src/array.rs @@ -14,8 +14,8 @@ use crate::{ source_location::SourceLocation, ty::{ CanonicalType, CanonicalTypeKind, CanonicalValue, Connect, DynCanonicalType, - DynCanonicalValue, DynType, DynValueTrait, MatchVariantWithoutScope, StaticType, Type, - TypeEnum, Value, ValueEnum, + DynCanonicalValue, DynType, DynValueTrait, MatchVariantWithoutScope, StaticType, + StaticValue, Type, TypeEnum, Value, ValueEnum, }, util::{ConstBool, GenericConstBool, MakeMutSlice}, }; @@ -302,28 +302,19 @@ where } } -impl ArrayType<[V; N]> -where - V::Type: Type, -{ +impl>, const N: usize> ArrayType<[V; N]> { pub fn new_array(element: V::Type) -> Self { ArrayType::new_with_len_type(element, ()) } } -impl StaticType for ArrayType<[V; N]> -where - V::Type: StaticType, -{ +impl StaticType for ArrayType<[V; N]> { fn static_type() -> Self { Self::new_array(StaticType::static_type()) } } -impl ArrayType<[V]> -where - V::Type: Type, -{ +impl>> ArrayType<[V]> { pub fn new_slice(element: V::Type, len: usize) -> Self { ArrayType::new_with_len_type(element, len) } @@ -514,14 +505,14 @@ impl Array { impl>> From for Array where - VA::ElementType: StaticType, + VA::Element: StaticValue, { fn from(value: T) -> Self { Self::new(StaticType::static_type(), value.into()) } } -impl, T: StaticType> ToExpr for [E] { +impl, T: StaticType> ToExpr for [E] { type Type = ArrayType<[T::Value]>; fn ty(&self) -> Self::Type { @@ -536,7 +527,7 @@ impl, T: StaticType> ToExpr for [E] { } } -impl, T: StaticType> ToExpr for Vec { +impl, T: StaticType> ToExpr for Vec { type Type = ArrayType<[T::Value]>; fn ty(&self) -> Self::Type { @@ -548,7 +539,7 @@ impl, T: StaticType> ToExpr for Vec { } } -impl, T: StaticType, const N: usize> ToExpr for [E; N] { +impl, T: StaticType, const N: usize> ToExpr for [E; N] { type Type = ArrayType<[T::Value; N]>; fn ty(&self) -> Self::Type { diff --git a/crates/fayalite/src/bundle.rs b/crates/fayalite/src/bundle.rs index 39b0d8e..2d43031 100644 --- a/crates/fayalite/src/bundle.rs +++ b/crates/fayalite/src/bundle.rs @@ -755,7 +755,7 @@ macro_rules! impl_tuple { } } - impl<$($T: StaticType,)*> StaticType for ($($T,)*) + impl<$($T: StaticType,)*> StaticType for ($($T,)*) where $($T::Value: Value,)* { diff --git a/crates/fayalite/src/module.rs b/crates/fayalite/src/module.rs index 81706ef..178bd25 100644 --- a/crates/fayalite/src/module.rs +++ b/crates/fayalite/src/module.rs @@ -17,7 +17,7 @@ use crate::{ reg::Reg, source_location::SourceLocation, ty::{ - CanonicalType, Connect, DynCanonicalType, DynCanonicalValue, DynType, StaticType, Type, + CanonicalType, Connect, DynCanonicalType, DynCanonicalValue, DynType, StaticValue, Type, TypeEnum, Value, }, util::ConstBool, @@ -1827,10 +1827,7 @@ impl<'a, CD> RegBuilder<'a, CD, (), ()> { stmts, } } - pub fn reset_default(self) -> RegBuilder<'a, CD, Option>, V> - where - V::Type: StaticType, - { + pub fn reset_default(self) -> RegBuilder<'a, CD, Option>, V> { self.reset(V::default().to_expr()) } pub fn opt_reset( diff --git a/crates/fayalite/src/reset.rs b/crates/fayalite/src/reset.rs index ee422a3..58080ad 100644 --- a/crates/fayalite/src/reset.rs +++ b/crates/fayalite/src/reset.rs @@ -13,7 +13,7 @@ use crate::{ }; use bitvec::slice::BitSlice; -pub trait ResetTypeTrait: CanonicalType + StaticType {} +pub trait ResetTypeTrait: CanonicalType + StaticType> {} #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Default)] pub struct AsyncResetType; diff --git a/crates/fayalite/src/ty.rs b/crates/fayalite/src/ty.rs index e45afdf..1d7b7e9 100644 --- a/crates/fayalite/src/ty.rs +++ b/crates/fayalite/src/ty.rs @@ -626,7 +626,11 @@ pub trait CanonicalType: impl DynCanonicalType for T {} pub trait StaticType: Type { - fn static_type() -> Self; + // can't put bounds on full trait, so put it here instead + fn static_type() -> Self + where + Self::Value: Value, + Self::MaskType: StaticType; } pub trait DynValueTrait: fmt::Debug + Send + Sync + Any { @@ -808,6 +812,10 @@ pub trait Value: DynValueTrait + Clone + Eq + Hash + ToExpr { } } +pub trait StaticValue: Value> {} + +impl>> StaticValue for T {} + pub trait DynCanonicalValueTrait: DynValueTrait + sealed::Sealed { fn ty_dyn_canonical(&self) -> Interned; fn value_enum(&self) -> ValueEnum; diff --git a/crates/fayalite/tests/module.rs b/crates/fayalite/tests/module.rs index 96001e3..228d98b 100644 --- a/crates/fayalite/tests/module.rs +++ b/crates/fayalite/tests/module.rs @@ -13,7 +13,7 @@ use fayalite::{ module::transform::simplify_enums::{simplify_enums, SimplifyEnumsKind}, reset::{SyncReset, ToReset}, source_location::SourceLocation, - ty::{StaticType, Value}, + ty::{StaticValue, Value}, }; use serde_json::json; @@ -195,7 +195,7 @@ circuit check_array_repeat_1: #[hdl_module(outline_generated)] pub fn check_skipped_generics(v: U) where - T: Value>, + T: StaticValue, U: std::fmt::Display, { dbg!(M); diff --git a/crates/fayalite/tests/value_derive.rs b/crates/fayalite/tests/value_derive.rs index 10f632c..b998ff4 100644 --- a/crates/fayalite/tests/value_derive.rs +++ b/crates/fayalite/tests/value_derive.rs @@ -1,6 +1,9 @@ // SPDX-License-Identifier: LGPL-3.0-or-later // See Notices.txt for copyright information -use fayalite::{int::UInt, ty::Value}; +use fayalite::{ + int::UInt, + ty::{StaticValue, Value}, +}; #[derive(Value, Clone, Hash, PartialEq, Eq, Debug)] #[hdl(outline_generated)] @@ -21,3 +24,9 @@ pub enum E { G(T), H(T, UInt<1>), } + +#[derive(Value, Clone, Hash, PartialEq, Eq, Debug)] +#[hdl(outline_generated, static, where(T: StaticValue))] +pub struct S2 { + pub v: E, +}