forked from libre-chip/fayalite
properly bound with StaticValue or StaticType<MaskType: StaticType>
This commit is contained in:
parent
2dce478d48
commit
cd99dbc849
|
@ -186,22 +186,9 @@ impl ValueDeriveGenerics {
|
||||||
let predicates = &mut generics.make_where_clause().predicates;
|
let predicates = &mut generics.make_where_clause().predicates;
|
||||||
let static_type_predicates = &mut static_type_generics.make_where_clause().predicates;
|
let static_type_predicates = &mut static_type_generics.make_where_clause().predicates;
|
||||||
for type_param in type_params {
|
for type_param in type_params {
|
||||||
predicates.push(parse_quote! {#type_param: ::fayalite::ty::Value});
|
predicates.push(parse_quote! {#type_param: ::fayalite::ty::Value<Type: ::fayalite::ty::Type<Value = #type_param>>});
|
||||||
predicates.push(parse_quote! {
|
static_type_predicates
|
||||||
<#type_param as ::fayalite::expr::ToExpr>::Type:
|
.push(parse_quote! {#type_param: ::fayalite::ty::StaticValue});
|
||||||
::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
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Self {
|
Self {
|
||||||
|
|
|
@ -14,8 +14,8 @@ use crate::{
|
||||||
source_location::SourceLocation,
|
source_location::SourceLocation,
|
||||||
ty::{
|
ty::{
|
||||||
CanonicalType, CanonicalTypeKind, CanonicalValue, Connect, DynCanonicalType,
|
CanonicalType, CanonicalTypeKind, CanonicalValue, Connect, DynCanonicalType,
|
||||||
DynCanonicalValue, DynType, DynValueTrait, MatchVariantWithoutScope, StaticType, Type,
|
DynCanonicalValue, DynType, DynValueTrait, MatchVariantWithoutScope, StaticType,
|
||||||
TypeEnum, Value, ValueEnum,
|
StaticValue, Type, TypeEnum, Value, ValueEnum,
|
||||||
},
|
},
|
||||||
util::{ConstBool, GenericConstBool, MakeMutSlice},
|
util::{ConstBool, GenericConstBool, MakeMutSlice},
|
||||||
};
|
};
|
||||||
|
@ -302,28 +302,19 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: Value, const N: usize> ArrayType<[V; N]>
|
impl<V: Value<Type: Type<Value = V>>, const N: usize> ArrayType<[V; N]> {
|
||||||
where
|
|
||||||
V::Type: Type<Value = V>,
|
|
||||||
{
|
|
||||||
pub fn new_array(element: V::Type) -> Self {
|
pub fn new_array(element: V::Type) -> Self {
|
||||||
ArrayType::new_with_len_type(element, ())
|
ArrayType::new_with_len_type(element, ())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: Value, const N: usize> StaticType for ArrayType<[V; N]>
|
impl<V: StaticValue, const N: usize> StaticType for ArrayType<[V; N]> {
|
||||||
where
|
|
||||||
V::Type: StaticType<Value = V>,
|
|
||||||
{
|
|
||||||
fn static_type() -> Self {
|
fn static_type() -> Self {
|
||||||
Self::new_array(StaticType::static_type())
|
Self::new_array(StaticType::static_type())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: Value> ArrayType<[V]>
|
impl<V: Value<Type: Type<Value = V>>> ArrayType<[V]> {
|
||||||
where
|
|
||||||
V::Type: Type<Value = V>,
|
|
||||||
{
|
|
||||||
pub fn new_slice(element: V::Type, len: usize) -> Self {
|
pub fn new_slice(element: V::Type, len: usize) -> Self {
|
||||||
ArrayType::new_with_len_type(element, len)
|
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>
|
impl<VA: ValueArrayOrSlice + ?Sized, T: Into<Arc<VA>>> From<T> for Array<VA>
|
||||||
where
|
where
|
||||||
VA::ElementType: StaticType,
|
VA::Element: StaticValue,
|
||||||
{
|
{
|
||||||
fn from(value: T) -> Self {
|
fn from(value: T) -> Self {
|
||||||
Self::new(StaticType::static_type(), value.into())
|
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]>;
|
type Type = ArrayType<[T::Value]>;
|
||||||
|
|
||||||
fn ty(&self) -> Self::Type {
|
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]>;
|
type Type = ArrayType<[T::Value]>;
|
||||||
|
|
||||||
fn ty(&self) -> Self::Type {
|
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]>;
|
type Type = ArrayType<[T::Value; N]>;
|
||||||
|
|
||||||
fn ty(&self) -> Self::Type {
|
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
|
where
|
||||||
$($T::Value: Value<Type = $T>,)*
|
$($T::Value: Value<Type = $T>,)*
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,7 +17,7 @@ use crate::{
|
||||||
reg::Reg,
|
reg::Reg,
|
||||||
source_location::SourceLocation,
|
source_location::SourceLocation,
|
||||||
ty::{
|
ty::{
|
||||||
CanonicalType, Connect, DynCanonicalType, DynCanonicalValue, DynType, StaticType, Type,
|
CanonicalType, Connect, DynCanonicalType, DynCanonicalValue, DynType, StaticValue, Type,
|
||||||
TypeEnum, Value,
|
TypeEnum, Value,
|
||||||
},
|
},
|
||||||
util::ConstBool,
|
util::ConstBool,
|
||||||
|
@ -1827,10 +1827,7 @@ impl<'a, CD> RegBuilder<'a, CD, (), ()> {
|
||||||
stmts,
|
stmts,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn reset_default<V: Value + Default>(self) -> RegBuilder<'a, CD, Option<Expr<V>>, V>
|
pub fn reset_default<V: StaticValue + Default>(self) -> RegBuilder<'a, CD, Option<Expr<V>>, V> {
|
||||||
where
|
|
||||||
V::Type: StaticType<Value = V>,
|
|
||||||
{
|
|
||||||
self.reset(V::default().to_expr())
|
self.reset(V::default().to_expr())
|
||||||
}
|
}
|
||||||
pub fn opt_reset<T: Type>(
|
pub fn opt_reset<T: Type>(
|
||||||
|
|
|
@ -13,7 +13,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use bitvec::slice::BitSlice;
|
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)]
|
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Default)]
|
||||||
pub struct AsyncResetType;
|
pub struct AsyncResetType;
|
||||||
|
|
|
@ -626,7 +626,11 @@ pub trait CanonicalType:
|
||||||
impl<T: CanonicalType> DynCanonicalType for T {}
|
impl<T: CanonicalType> DynCanonicalType for T {}
|
||||||
|
|
||||||
pub trait StaticType: Type {
|
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 {
|
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 {
|
pub trait DynCanonicalValueTrait: DynValueTrait + sealed::Sealed {
|
||||||
fn ty_dyn_canonical(&self) -> Interned<dyn DynCanonicalType>;
|
fn ty_dyn_canonical(&self) -> Interned<dyn DynCanonicalType>;
|
||||||
fn value_enum(&self) -> ValueEnum;
|
fn value_enum(&self) -> ValueEnum;
|
||||||
|
|
|
@ -13,7 +13,7 @@ use fayalite::{
|
||||||
module::transform::simplify_enums::{simplify_enums, SimplifyEnumsKind},
|
module::transform::simplify_enums::{simplify_enums, SimplifyEnumsKind},
|
||||||
reset::{SyncReset, ToReset},
|
reset::{SyncReset, ToReset},
|
||||||
source_location::SourceLocation,
|
source_location::SourceLocation,
|
||||||
ty::{StaticType, Value},
|
ty::{StaticValue, Value},
|
||||||
};
|
};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ circuit check_array_repeat_1:
|
||||||
#[hdl_module(outline_generated)]
|
#[hdl_module(outline_generated)]
|
||||||
pub fn check_skipped_generics<T, #[hdl(skip)] U, const N: usize, #[hdl(skip)] const M: usize>(v: U)
|
pub fn check_skipped_generics<T, #[hdl(skip)] U, const N: usize, #[hdl(skip)] const M: usize>(v: U)
|
||||||
where
|
where
|
||||||
T: Value<Type: StaticType<Value = T>>,
|
T: StaticValue,
|
||||||
U: std::fmt::Display,
|
U: std::fmt::Display,
|
||||||
{
|
{
|
||||||
dbg!(M);
|
dbg!(M);
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||||
// See Notices.txt for copyright information
|
// 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)]
|
#[derive(Value, Clone, Hash, PartialEq, Eq, Debug)]
|
||||||
#[hdl(outline_generated)]
|
#[hdl(outline_generated)]
|
||||||
|
@ -21,3 +24,9 @@ pub enum E<T> {
|
||||||
G(T),
|
G(T),
|
||||||
H(T, UInt<1>),
|
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…
Reference in a new issue