forked from libre-chip/fayalite
		
	properly bound with StaticValue or StaticType<MaskType: StaticType>
This commit is contained in:
		
							parent
							
								
									2dce478d48
								
							
						
					
					
						commit
						cd99dbc849
					
				
					 8 changed files with 37 additions and 45 deletions
				
			
		|  | @ -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<Value = #type_param> | ||||
|                 }); | ||||
|                 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<Value = #type_param> | ||||
|                 }); | ||||
|                 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<Type: ::fayalite::ty::Type<Value = #type_param>>}); | ||||
|                 static_type_predicates | ||||
|                     .push(parse_quote! {#type_param: ::fayalite::ty::StaticValue}); | ||||
|             } | ||||
|         } | ||||
|         Self { | ||||
|  |  | |||
|  | @ -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<V: Value, const N: usize> ArrayType<[V; N]> | ||||
| where | ||||
|     V::Type: Type<Value = V>, | ||||
| { | ||||
| impl<V: Value<Type: Type<Value = V>>, const N: usize> ArrayType<[V; N]> { | ||||
|     pub fn new_array(element: V::Type) -> Self { | ||||
|         ArrayType::new_with_len_type(element, ()) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl<V: Value, const N: usize> StaticType for ArrayType<[V; N]> | ||||
| where | ||||
|     V::Type: StaticType<Value = V>, | ||||
| { | ||||
| impl<V: StaticValue, const N: usize> StaticType for ArrayType<[V; N]> { | ||||
|     fn static_type() -> Self { | ||||
|         Self::new_array(StaticType::static_type()) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl<V: Value> ArrayType<[V]> | ||||
| where | ||||
|     V::Type: Type<Value = V>, | ||||
| { | ||||
| impl<V: Value<Type: Type<Value = V>>> ArrayType<[V]> { | ||||
|     pub fn new_slice(element: V::Type, len: usize) -> Self { | ||||
|         ArrayType::new_with_len_type(element, len) | ||||
|     } | ||||
|  | @ -514,14 +505,14 @@ impl<VA: ValueArrayOrSlice + ?Sized> Array<VA> { | |||
| 
 | ||||
| impl<VA: ValueArrayOrSlice + ?Sized, T: Into<Arc<VA>>> From<T> for Array<VA> | ||||
| where | ||||
|     VA::ElementType: StaticType, | ||||
|     VA::Element: StaticValue, | ||||
| { | ||||
|     fn from(value: T) -> Self { | ||||
|         Self::new(StaticType::static_type(), value.into()) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl<E: ToExpr<Type = T>, T: StaticType> ToExpr for [E] { | ||||
| impl<E: ToExpr<Type = T>, T: StaticType<MaskType: StaticType>> ToExpr for [E] { | ||||
|     type Type = ArrayType<[T::Value]>; | ||||
| 
 | ||||
|     fn ty(&self) -> Self::Type { | ||||
|  | @ -536,7 +527,7 @@ impl<E: ToExpr<Type = T>, T: StaticType> ToExpr for [E] { | |||
|     } | ||||
| } | ||||
| 
 | ||||
| impl<E: ToExpr<Type = T>, T: StaticType> ToExpr for Vec<E> { | ||||
| impl<E: ToExpr<Type = T>, T: StaticType<MaskType: StaticType>> ToExpr for Vec<E> { | ||||
|     type Type = ArrayType<[T::Value]>; | ||||
| 
 | ||||
|     fn ty(&self) -> Self::Type { | ||||
|  | @ -548,7 +539,7 @@ impl<E: ToExpr<Type = T>, T: StaticType> ToExpr for Vec<E> { | |||
|     } | ||||
| } | ||||
| 
 | ||||
| impl<E: ToExpr<Type = T>, T: StaticType, const N: usize> ToExpr for [E; N] { | ||||
| impl<E: ToExpr<Type = T>, T: StaticType<MaskType: StaticType>, const N: usize> ToExpr for [E; N] { | ||||
|     type Type = ArrayType<[T::Value; N]>; | ||||
| 
 | ||||
|     fn ty(&self) -> Self::Type { | ||||
|  |  | |||
|  | @ -755,7 +755,7 @@ macro_rules! impl_tuple { | |||
|             } | ||||
|         } | ||||
| 
 | ||||
|         impl<$($T: StaticType,)*> StaticType for ($($T,)*) | ||||
|         impl<$($T: StaticType<MaskType: StaticType>,)*> StaticType for ($($T,)*) | ||||
|         where | ||||
|             $($T::Value: Value<Type = $T>,)* | ||||
|         { | ||||
|  |  | |||
|  | @ -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<V: Value + Default>(self) -> RegBuilder<'a, CD, Option<Expr<V>>, V> | ||||
|     where | ||||
|         V::Type: StaticType<Value = V>, | ||||
|     { | ||||
|     pub fn reset_default<V: StaticValue + Default>(self) -> RegBuilder<'a, CD, Option<Expr<V>>, V> { | ||||
|         self.reset(V::default().to_expr()) | ||||
|     } | ||||
|     pub fn opt_reset<T: Type>( | ||||
|  |  | |||
|  | @ -13,7 +13,7 @@ use crate::{ | |||
| }; | ||||
| use bitvec::slice::BitSlice; | ||||
| 
 | ||||
| pub trait ResetTypeTrait: CanonicalType + StaticType {} | ||||
| pub trait ResetTypeTrait: CanonicalType + StaticType<MaskType = UIntType<1>> {} | ||||
| 
 | ||||
| #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Default)] | ||||
| pub struct AsyncResetType; | ||||
|  |  | |||
|  | @ -626,7 +626,11 @@ pub trait CanonicalType: | |||
| impl<T: CanonicalType> 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<Type = Self>, | ||||
|         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<Type: StaticType<Value = Self, MaskType: StaticType>> {} | ||||
| 
 | ||||
| impl<T: Value<Type: StaticType<Value = Self, MaskType: StaticType>>> StaticValue for T {} | ||||
| 
 | ||||
| pub trait DynCanonicalValueTrait: DynValueTrait + sealed::Sealed { | ||||
|     fn ty_dyn_canonical(&self) -> Interned<dyn DynCanonicalType>; | ||||
|     fn value_enum(&self) -> ValueEnum; | ||||
|  |  | |||
|  | @ -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<T, #[hdl(skip)] U, const N: usize, #[hdl(skip)] const M: usize>(v: U) | ||||
| where | ||||
|     T: Value<Type: StaticType<Value = T>>, | ||||
|     T: StaticValue, | ||||
|     U: std::fmt::Display, | ||||
| { | ||||
|     dbg!(M); | ||||
|  |  | |||
|  | @ -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<T> { | |||
|     G(T), | ||||
|     H(T, UInt<1>), | ||||
| } | ||||
| 
 | ||||
| #[derive(Value, Clone, Hash, PartialEq, Eq, Debug)] | ||||
| #[hdl(outline_generated, static, where(T: StaticValue))] | ||||
| pub struct S2<T> { | ||||
|     pub v: E<T>, | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue