diff --git a/.forgejo/workflows/test.yml b/.forgejo/workflows/test.yml index 503c5fe..99a907b 100644 --- a/.forgejo/workflows/test.yml +++ b/.forgejo/workflows/test.yml @@ -15,4 +15,3 @@ jobs: with: save-if: ${{ github.ref == 'refs/heads/master' }} - run: cargo test - - run: cargo doc diff --git a/crates/fayalite/src/expr.rs b/crates/fayalite/src/expr.rs index 43d2a51..0ffaf53 100644 --- a/crates/fayalite/src/expr.rs +++ b/crates/fayalite/src/expr.rs @@ -4,7 +4,7 @@ use crate::{ array::ArrayType, bundle::{BundleType, BundleValue, DynBundle, DynBundleType, FieldType}, enum_::{DynEnumType, EnumType, EnumValue}, - int::{DynSIntType, DynUInt, DynUIntType, FixedOrDynIntType, IntValue, UInt, UIntType}, + int::{DynSIntType, DynUIntType, FixedOrDynIntType, IntValue, UInt, UIntType}, intern::{Intern, Interned, InternedCompare, PtrEqWithTypeId, SupportsPtrEqWithTypeId}, memory::{DynPortType, MemPort, PortType}, module::{ @@ -288,12 +288,7 @@ impl Hash for Expr { impl Expr> where - T: FixedOrDynIntType< - 1, - Signed = ConstBool, - CanonicalType = DynUIntType, - CanonicalValue = DynUInt, - >, + T: FixedOrDynIntType<1, Signed = ConstBool>, { pub fn as_bool(self) -> Expr> { assert_eq!(self.canonical_type().width, 1); diff --git a/crates/fayalite/src/expr/ops.rs b/crates/fayalite/src/expr/ops.rs index 2ffe5d3..a2c242d 100644 --- a/crates/fayalite/src/expr/ops.rs +++ b/crates/fayalite/src/expr/ops.rs @@ -10,8 +10,8 @@ use crate::{ TargetPathDynArrayElement, TargetPathElement, ToExpr, }, int::{ - DynInt, DynIntType, DynSInt, DynSIntType, DynUInt, DynUIntType, FixedOrDynIntType, Int, - IntCmp, IntTypeTrait, IntValue, UInt, UIntType, + DynIntType, DynSInt, DynSIntType, DynUInt, DynUIntType, FixedOrDynIntType, Int, IntCmp, + IntTypeTrait, IntValue, UInt, UIntType, }, intern::{Intern, Interned}, reset::{ @@ -242,7 +242,7 @@ unary_op! { #[method = not] impl Not for _ where ( - T: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, + T: IntTypeTrait, ) { fn expr_enum(&self) -> _ { @@ -262,7 +262,7 @@ unary_op! { #[method = neg] impl Neg for _ where ( - T: IntTypeTrait, CanonicalType = DynSIntType, CanonicalValue = DynSInt>, + T: IntTypeTrait>, ) { fn expr_enum(&self) -> _ { @@ -361,48 +361,48 @@ binary_op! { #[method = bitand, rhs_to_canonical_dyn = to_canonical_dyn, expr_enum_u = BitAndU, expr_enum_s = BitAndS] impl BitAnd for _ where - L: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, - R: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, + L: IntTypeTrait, + R: IntTypeTrait, } binary_op! { #[method = bitor, rhs_to_canonical_dyn = to_canonical_dyn, expr_enum_u = BitOrU, expr_enum_s = BitOrS] impl BitOr for _ where - L: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, - R: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, + L: IntTypeTrait, + R: IntTypeTrait, } binary_op! { #[method = bitxor, rhs_to_canonical_dyn = to_canonical_dyn, expr_enum_u = BitXorU, expr_enum_s = BitXorS] impl BitXor for _ where - L: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, - R: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, + L: IntTypeTrait, + R: IntTypeTrait, } binary_op! { #[method = add, rhs_to_canonical_dyn = to_canonical_dyn, expr_enum_u = AddU, expr_enum_s = AddS] impl Add for _ where - L: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, - R: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, + L: IntTypeTrait, + R: IntTypeTrait, } binary_op! { #[method = sub, rhs_to_canonical_dyn = to_canonical_dyn, expr_enum_u = SubU, expr_enum_s = SubS] impl Sub for _ where - L: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, - R: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, + L: IntTypeTrait, + R: IntTypeTrait, } binary_op! { #[method = mul, rhs_to_canonical_dyn = to_canonical_dyn, expr_enum_u = MulU, expr_enum_s = MulS] impl Mul for _ where - L: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, - R: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, + L: IntTypeTrait, + R: IntTypeTrait, } macro_rules! dyn_shift_op { @@ -413,7 +413,7 @@ macro_rules! dyn_shift_op { fixed_ary_op! { pub struct $DynOp where ( - LhsType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, + LhsType: IntTypeTrait, ) { pub lhs: Expr, @@ -458,8 +458,8 @@ macro_rules! dyn_shift_op { impl, LhsType, RhsType, Rhs: Value> ops::$Op> for Expr where - LhsType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, - RhsType: IntTypeTrait, CanonicalType = DynUIntType, CanonicalValue = DynUInt>, + LhsType: IntTypeTrait, + RhsType: IntTypeTrait>, { type Output = Expr<< as ops::$Op>>::Output as ValuelessTr>::Value>; @@ -470,8 +470,8 @@ macro_rules! dyn_shift_op { impl> ops::$Op> for IntValue where - LhsType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, - RhsType: IntTypeTrait, CanonicalType = DynUIntType, CanonicalValue = DynUInt>, + LhsType: IntTypeTrait, + RhsType: IntTypeTrait>, { type Output = Expr<< as ops::$Op>>::Output as ValuelessTr>::Value>; @@ -490,7 +490,7 @@ macro_rules! fixed_shift_op { fixed_ary_op! { pub struct $FixedOp where ( - LhsType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, + LhsType: IntTypeTrait, ) { pub lhs: Expr, @@ -532,7 +532,7 @@ macro_rules! fixed_shift_op { impl, LhsType> ops::$Op for Expr where - LhsType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, + LhsType: IntTypeTrait, { type Output = Expr<< as ops::$Op>::Output as ValuelessTr>::Value>; @@ -568,9 +568,9 @@ macro_rules! cmp_op { $(fixed_ary_op! { pub struct $CmpOp where ( - LhsType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, - RhsType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, - Output: FixedOrDynIntType<1, Signed = ConstBool, CanonicalType = DynUIntType, CanonicalValue = DynUInt>, + LhsType: IntTypeTrait, + RhsType: IntTypeTrait, + Output: FixedOrDynIntType<1, Signed = ConstBool>, ) { pub lhs: Expr, @@ -612,7 +612,7 @@ macro_rules! cmp_op { } })* - impl::Signed>, CanonicalValue = DynInt<::Signed>>, RhsType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, Rhs: Value, Lhs: Value> IntCmp> for Expr { + impl, Rhs: Value, Lhs: Value> IntCmp> for Expr { type Output = Expr>; $(fn $fn(self, rhs: Expr) -> Self::Output { @@ -620,7 +620,7 @@ macro_rules! cmp_op { })* } - impl::Signed>, CanonicalValue = DynInt<::Signed>>, RhsType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, Rhs: Value, Lhs: Value> IntCmp for Expr { + impl, Rhs: Value, Lhs: Value> IntCmp for Expr { type Output = Expr>; $(fn $fn(self, rhs: Rhs) -> Self::Output { @@ -628,7 +628,7 @@ macro_rules! cmp_op { })* } - impl::Signed>, CanonicalValue = DynInt<::Signed>>, RhsType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, Rhs: Value> IntCmp> for IntValue { + impl, Rhs: Value> IntCmp> for IntValue { type Output = Expr>; $(fn $fn(self, rhs: Expr) -> Self::Output { @@ -658,8 +658,8 @@ cmp_op! { fixed_ary_op! { pub struct CastInt where ( - FromType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, - ToType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, + FromType: IntTypeTrait, + ToType: IntTypeTrait, ) { pub value: Expr, @@ -705,18 +705,9 @@ fixed_ary_op! { } } -impl< - FromType: IntTypeTrait< - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - > Expr> -{ +impl Expr> { pub fn cast< - ToType: IntTypeTrait< - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, + ToType: IntTypeTrait::Signed>>, >( self, ty: ToType, @@ -740,7 +731,7 @@ impl< fixed_ary_op! { pub struct Slice where ( - Base: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, + Base: IntTypeTrait, ) { pub base: Expr, @@ -774,13 +765,7 @@ fixed_ary_op! { } } -impl< - T: IntTypeTrait< - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - > Expr> -{ +impl Expr> { pub fn slice>(self, index: I) -> Expr { Slice::::new_unchecked( self.canonical(), @@ -856,14 +841,7 @@ impl_built_in_range!( std::ops::RangeInclusive); impl_built_in_range!( std::ops::RangeTo); impl_built_in_range!( std::ops::RangeToInclusive); -impl< - T: IntTypeTrait< - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - I: BuiltInRange, - > ExprIndex for IntValue -{ +impl> ExprIndex for IntValue { type OutputValue = DynUInt; fn expr_index(this: Expr, index: I) -> Expr { @@ -871,13 +849,7 @@ impl< } } -impl< - T: IntTypeTrait< - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - > ExprIndex for IntValue -{ +impl ExprIndex for IntValue { type OutputValue = UInt<1>; fn expr_index(this: Expr, index: usize) -> Expr { @@ -890,7 +862,7 @@ macro_rules! reduce_bit_op { fixed_ary_op! { pub struct $name where ( - Output: FixedOrDynIntType<1, Signed = ConstBool, CanonicalType = DynUIntType, CanonicalValue = DynUInt>, + Output: FixedOrDynIntType<1, Signed = ConstBool>, ) { pub arg: Expr, @@ -920,14 +892,7 @@ reduce_bit_op!(ReduceBitAnd; |bits| bits.all()); reduce_bit_op!(ReduceBitOr; |bits| bits.any()); reduce_bit_op!(ReduceBitXor; |bits| bits.count_ones() % 2 == 1); -impl< - T: IntTypeTrait< - Signed = ConstBool, - CanonicalType = DynUIntType, - CanonicalValue = DynUInt, - >, - > Expr> -{ +impl>> Expr> { pub fn reduce_bitand(self) -> Expr> { ReduceBitAnd::>::new_unchecked(self.canonical()).to_expr() } @@ -974,9 +939,7 @@ fixed_ary_op! { }, #[target] target: Option> = base.target().map(|base| { - Intern::intern_sized(base.join( - TargetPathElement::intern_sized(TargetPathBundleField{ name: field.name }.into()), - )) + Intern::intern_sized(base.join(TargetPathElement::intern_sized(TargetPathBundleField{name:field.name}.into()))) }), fn simulate(&self, sim_state: &mut SimState) -> _ { todo!() @@ -1022,9 +985,9 @@ fixed_ary_op! { #[cache] base_ty: DynEnumType = base.canonical_type(), #[type] - ty: VariantTy = VariantTy::from_dyn_canonical_type( - base_ty.variants()[variant_index].ty.unwrap_or_else(|| ().canonical_dyn()), - ), + ty: VariantTy = VariantTy::from_dyn_canonical_type(base_ty.variants()[variant_index].ty.unwrap_or_else( + || ().canonical_dyn(), + )), #[cache] literal_bits: Result, ()> = { base.to_literal_bits().map(|base| { @@ -1123,9 +1086,7 @@ fixed_ary_op! { } fn expr_enum(&self) -> _ { - ExprEnum::CastBitsTo( - CastBitsTo::new_unchecked(self.value, self.ty.canonical_dyn()).intern_sized(), - ) + ExprEnum::CastBitsTo(CastBitsTo::new_unchecked(self.value, self.ty.canonical_dyn()).intern_sized()) } fn to_literal_bits(&self) -> Result, ()> { @@ -1144,14 +1105,7 @@ where } } -impl< - T: IntTypeTrait< - Signed = ConstBool, - CanonicalType = DynUIntType, - CanonicalValue = DynUInt, - >, - > Expr> -{ +impl>> Expr> { pub fn cast_bits_to(self, ty: U::Type) -> Expr where U::Type: Type, @@ -1161,11 +1115,11 @@ impl< } macro_rules! cast_bit_to_typed_bit { - (pub struct $Op:ident$(<$T:ident: $Bound:path>)?; $FromType:ty => $ToType:ty) => { + (pub struct $Op:ident$(<$T:ident: $Bound:ident<$BoundArg:tt>>)?; $FromType:ty => $ToType:ty) => { fixed_ary_op! { pub struct $Op<$($T,)?> where ( - $($T: $Bound,)? + $($T: $Bound<$BoundArg>,)? ) { pub value: Expr<<$FromType as Type>::Value>, @@ -1290,7 +1244,7 @@ where } } -cast_bit_to_typed_bit!(pub struct CastClockToBit::Signed>, CanonicalValue = DynInt<::Signed>>>; ClockType => ToType); +cast_bit_to_typed_bit!(pub struct CastClockToBit>; ClockType => ToType); impl ToBit for Clock { fn to_bit(v: Expr) -> Expr> { @@ -1298,7 +1252,7 @@ impl ToBit for Clock { } } -cast_bit_to_typed_bit!(pub struct CastSyncResetToBit::Signed>, CanonicalValue = DynInt<::Signed>>>; SyncResetType => ToType); +cast_bit_to_typed_bit!(pub struct CastSyncResetToBit>; SyncResetType => ToType); impl ToBit for SyncReset { fn to_bit(v: Expr) -> Expr> { @@ -1306,7 +1260,7 @@ impl ToBit for SyncReset { } } -cast_bit_to_typed_bit!(pub struct CastAsyncResetToBit::Signed>, CanonicalValue = DynInt<::Signed>>>; AsyncResetType => ToType); +cast_bit_to_typed_bit!(pub struct CastAsyncResetToBit>; AsyncResetType => ToType); impl ToBit for AsyncReset { fn to_bit(v: Expr) -> Expr> { @@ -1314,7 +1268,7 @@ impl ToBit for AsyncReset { } } -cast_bit_to_typed_bit!(pub struct CastResetToBit::Signed>, CanonicalValue = DynInt<::Signed>>>; ResetType => ToType); +cast_bit_to_typed_bit!(pub struct CastResetToBit>; ResetType => ToType); impl ToBit for Reset { fn to_bit(v: Expr) -> Expr> { @@ -1401,9 +1355,7 @@ fixed_ary_op! { }, #[target] target: Option> = base.target().map(|base| { - Intern::intern_sized(base.join( - TargetPathElement::ArrayElement(TargetPathArrayElement { index }).intern(), - )) + Intern::intern_sized(base.join(TargetPathElement::ArrayElement(TargetPathArrayElement { index }).intern())) }), fn simulate(&self, sim_state: &mut SimState) -> _ { todo!() @@ -1446,28 +1398,21 @@ fixed_ary_op! { let base_ty = base.ty(); let element_bit_width = base_ty.element().bit_width(); base.to_literal_bits().ok().zip(index.to_literal_bits().ok()).and_then(|(base, index)| { - let start = DynUInt::from_bit_slice(&index) - .uint_value() - .to_usize()? - .checked_mul(element_bit_width)?; + let start = DynUInt::from_bit_slice(&index).uint_value().to_usize()?.checked_mul(element_bit_width)?; let end = start.checked_add(element_bit_width)?; Some(base.get(start..end)?.intern()) }).ok_or(()) }, #[target] target: Option> = base.target().map(|base| { - Intern::intern_sized(base.join( - TargetPathElement::DynArrayElement(TargetPathDynArrayElement {}).intern(), - )) + Intern::intern_sized(base.join(TargetPathElement::DynArrayElement(TargetPathDynArrayElement {}).intern())) }), fn simulate(&self, sim_state: &mut SimState) -> _ { todo!() } fn expr_enum(&self) -> _ { - ExprEnum::DynArrayIndex( - DynArrayIndex::new_unchecked(self.base, self.index).intern_sized(), - ) + ExprEnum::DynArrayIndex(DynArrayIndex::new_unchecked(self.base, self.index).intern_sized()) } fn to_literal_bits(&self) -> Result, ()> { @@ -1487,11 +1432,7 @@ impl DynArrayIndex { impl< VA: ?Sized + ValueArrayOrSlice, - Idx: IntTypeTrait< - Signed = ConstBool, - CanonicalType = DynUIntType, - CanonicalValue = DynUInt, - >, + Idx: IntTypeTrait, CanonicalType = DynUIntType>, > ExprIndex> for Array { type OutputValue = VA::Element; @@ -1504,11 +1445,7 @@ impl< impl< VA: ?Sized + ValueArrayOrSlice, - Idx: IntTypeTrait< - Signed = ConstBool, - CanonicalType = DynUIntType, - CanonicalValue = DynUInt, - >, + Idx: IntTypeTrait, CanonicalType = DynUIntType>, > ExprIndex>> for Array { type OutputValue = VA::Element; @@ -1618,8 +1555,7 @@ fixed_ary_op! { ty }, #[cache] - literal_bits: Result, ()> = - ty.variant_to_bits(variant_index, variant_value.as_ref()), + literal_bits: Result, ()> = ty.variant_to_bits(variant_index, variant_value.as_ref()), fn simulate(&self, sim_state: &mut SimState) -> _ { todo!() } diff --git a/crates/fayalite/src/int.rs b/crates/fayalite/src/int.rs index adfa0df..63f9f6f 100644 --- a/crates/fayalite/src/int.rs +++ b/crates/fayalite/src/int.rs @@ -35,13 +35,7 @@ pub type Int = IntValue>; pub type UInt = Int, WIDTH>; pub type SInt = Int, WIDTH>; -impl< - T: IntTypeTrait< - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - > ToExpr for IntValue -{ +impl ToExpr for IntValue { type Type = T; fn ty(&self) -> Self::Type { @@ -53,25 +47,13 @@ impl< } } -impl< - T: IntTypeTrait< - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - > fmt::Display for IntValue -{ +impl fmt::Display for IntValue { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&self.to_canonical(), f) } } -impl< - T: IntTypeTrait< - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - > fmt::Debug for IntValue -{ +impl fmt::Debug for IntValue { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let neg; let (sign, magnitude) = if self.is_negative() { @@ -111,13 +93,7 @@ impl DynInt { } } -impl< - T: IntTypeTrait< - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - > IntValue -{ +impl IntValue { pub fn with_type>(ty: T, value: I) -> Self { let int_type = ty.canonical(); let mut value: BigInt = value.into(); @@ -196,30 +172,14 @@ impl< let width = self.ty.width(); T::Signed::VALUE && width > 0 && self.uint_value.bit((width - 1).try_into().unwrap()) } - pub fn into_cast< - NewType: IntTypeTrait< - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - >( - self, - new_type: NewType, - ) -> IntValue { + pub fn into_cast(self, new_type: NewType) -> IntValue { if new_type.width() > self.ty.width() && self.is_negative() { IntValue::with_type(new_type, self.into_value()) } else { IntValue::with_type(new_type, self.into_uint_value()) } } - pub fn cast< - NewType: IntTypeTrait< - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - >( - &self, - new_type: NewType, - ) -> IntValue { + pub fn cast(&self, new_type: NewType) -> IntValue { if new_type.width() > self.ty.width() && self.is_negative() { IntValue::with_type(new_type, self.value()) } else { @@ -261,14 +221,7 @@ impl< assert!(index < self.ty.width(), "bit index out of range"); self.uint_value.set_bit(index.try_into().unwrap(), value) } - pub fn set_slice< - I: RangeBounds, - RhsType: IntTypeTrait< - Signed = ConstBool, - CanonicalType = DynUIntType, - CanonicalValue = DynUInt, - >, - >( + pub fn set_slice, RhsType: IntTypeTrait>>( &mut self, index: I, value: impl Into>, @@ -287,11 +240,7 @@ impl< } pub fn with_replaced_slice< I: RangeBounds, - RhsType: IntTypeTrait< - Signed = ConstBool, - CanonicalType = DynUIntType, - CanonicalValue = DynUInt, - >, + RhsType: IntTypeTrait>, >( mut self, index: I, @@ -300,12 +249,7 @@ impl< self.set_slice(index, value); self } - pub fn concat< - HighType: IntTypeTrait< - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - >( + pub fn concat( &self, high_part: IntValue, ) -> IntValue> { @@ -335,13 +279,7 @@ impl< } } -impl< - Ty: IntTypeTrait< - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - > Value for IntValue -{ +impl Value for IntValue { fn to_canonical(&self) -> ::CanonicalValue { IntValue { ty: self.ty.canonical(), @@ -357,13 +295,7 @@ impl< } } impl Copy for ToBitsMemoize {} - impl< - Ty: IntTypeTrait< - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - > Memoize for ToBitsMemoize> - { + impl Memoize for ToBitsMemoize> { type Input = IntValue; type InputOwned = IntValue; type Output = Interned; @@ -389,15 +321,8 @@ macro_rules! impl_add_sub { ($Op:ident::$op:ident) => { impl $Op> for IntValue where - LhsType: IntTypeTrait< - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - RhsType: IntTypeTrait< - Signed = ::Signed, - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, + LhsType: IntTypeTrait, + RhsType: IntTypeTrait::Signed>, { type Output = IntValue>; @@ -409,15 +334,8 @@ macro_rules! impl_add_sub { impl $Op> for Valueless where - LhsType: IntTypeTrait< - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - RhsType: IntTypeTrait< - Signed = ::Signed, - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, + LhsType: IntTypeTrait, + RhsType: IntTypeTrait::Signed>, { type Output = Valueless>; @@ -439,16 +357,8 @@ macro_rules! impl_bitwise { ($Op:ident::$op:ident) => { impl< Signed: GenericConstBool, - LhsType: IntTypeTrait< - Signed = Signed, - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - RhsType: IntTypeTrait< - Signed = Signed, - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, + LhsType: IntTypeTrait, + RhsType: IntTypeTrait, > $Op> for IntValue { type Output = IntValue>; @@ -461,16 +371,8 @@ macro_rules! impl_bitwise { impl< Signed: GenericConstBool, - LhsType: IntTypeTrait< - Signed = Signed, - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - RhsType: IntTypeTrait< - Signed = Signed, - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, + LhsType: IntTypeTrait, + RhsType: IntTypeTrait, > $Op> for Valueless { type Output = Valueless>; @@ -488,16 +390,8 @@ impl_add_sub!(Sub::sub); impl< Signed: GenericConstBool, - LhsType: IntTypeTrait< - Signed = Signed, - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - RhsType: IntTypeTrait< - Signed = Signed, - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, + LhsType: IntTypeTrait, + RhsType: IntTypeTrait, > Mul> for IntValue { type Output = IntValue>; @@ -509,16 +403,8 @@ impl< impl< Signed: GenericConstBool, - LhsType: IntTypeTrait< - Signed = Signed, - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - RhsType: IntTypeTrait< - Signed = Signed, - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, + LhsType: IntTypeTrait, + RhsType: IntTypeTrait, > Mul> for Valueless { type Output = Valueless>; @@ -539,16 +425,8 @@ impl_bitwise!(BitXor::bitxor); impl< Signed: GenericConstBool, - LhsType: IntTypeTrait< - Signed = Signed, - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - RhsType: IntTypeTrait< - Signed = ConstBool, - CanonicalType = DynUIntType, - CanonicalValue = DynUInt, - >, + LhsType: IntTypeTrait, + RhsType: IntTypeTrait>, > Shl> for IntValue { type Output = IntValue>; @@ -569,16 +447,8 @@ impl< impl< Signed: GenericConstBool, - LhsType: IntTypeTrait< - Signed = Signed, - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - RhsType: IntTypeTrait< - Signed = ConstBool, - CanonicalType = DynUIntType, - CanonicalValue = DynUInt, - >, + LhsType: IntTypeTrait, + RhsType: IntTypeTrait>, > Shl> for Valueless { type Output = Valueless>; @@ -599,16 +469,8 @@ impl< impl< Signed: GenericConstBool, - LhsType: IntTypeTrait< - Signed = Signed, - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - RhsType: IntTypeTrait< - Signed = ConstBool, - CanonicalType = DynUIntType, - CanonicalValue = DynUInt, - >, + LhsType: IntTypeTrait, + RhsType: IntTypeTrait>, > Shr> for IntValue { type Output = IntValue>; @@ -626,12 +488,8 @@ impl< impl< Signed: GenericConstBool, - LhsType: IntTypeTrait>, - RhsType: IntTypeTrait< - Signed = ConstBool, - CanonicalType = DynUIntType, - CanonicalValue = DynUInt, - >, + LhsType: IntTypeTrait, + RhsType: IntTypeTrait>, > Shr> for Valueless { type Output = Valueless>; @@ -643,14 +501,8 @@ impl< } } -impl< - Signed: GenericConstBool, - LhsType: IntTypeTrait< - Signed = Signed, - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - > Shl for IntValue +impl> Shl + for IntValue { type Output = IntValue>; @@ -660,14 +512,8 @@ impl< } } -impl< - Signed: GenericConstBool, - LhsType: IntTypeTrait< - Signed = Signed, - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - > Shl for Valueless +impl> Shl + for Valueless { type Output = Valueless>; @@ -682,14 +528,8 @@ impl< } } -impl< - Signed: GenericConstBool, - LhsType: IntTypeTrait< - Signed = Signed, - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - > Shr for IntValue +impl> Shr + for IntValue { type Output = IntValue>; @@ -701,14 +541,8 @@ impl< } } -impl< - Signed: GenericConstBool, - LhsType: IntTypeTrait< - Signed = Signed, - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - > Shr for Valueless +impl> Shr + for Valueless { type Output = Valueless>; @@ -718,14 +552,7 @@ impl< } } -impl< - T: IntTypeTrait< - Signed = ConstBool, - CanonicalType = DynSIntType, - CanonicalValue = DynSInt, - >, - > Neg for IntValue -{ +impl>> Neg for IntValue { type Output = IntValue; fn neg(self) -> Self::Output { let ty = self.valueless().neg().ty; @@ -733,14 +560,7 @@ impl< } } -impl< - T: IntTypeTrait< - Signed = ConstBool, - CanonicalType = DynSIntType, - CanonicalValue = DynSInt, - >, - > Neg for Valueless -{ +impl>> Neg for Valueless { type Output = Valueless; fn neg(self) -> Self::Output { let ty = DynIntType::new( @@ -753,26 +573,14 @@ impl< } } -impl< - T: IntTypeTrait< - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - > Not for IntValue -{ +impl Not for IntValue { type Output = IntValue; fn not(self) -> Self::Output { IntValue::with_type(self.valueless().not().ty, Not::not(self.into_value())) } } -impl< - T: IntTypeTrait< - CanonicalType = DynIntType<::Signed>, - CanonicalValue = DynInt<::Signed>, - >, - > Not for Valueless -{ +impl Not for Valueless { type Output = Valueless; fn not(self) -> Self::Output { self @@ -818,15 +626,7 @@ impl_int!(i32, true); impl_int!(i64, true); impl_int!(i128, true); -impl< - T: FixedOrDynIntType< - 1, - Signed = ConstBool, - CanonicalType = DynUIntType, - CanonicalValue = DynUInt, - >, - > From for IntValue -{ +impl>> From for IntValue { fn from(v: bool) -> Self { IntValue::with_type(T::new(), v) } @@ -865,7 +665,11 @@ pub trait IntTypeTrait: + Eq + Hash + fmt::Debug - + Type> + + Type< + Value = IntValue, + CanonicalType = DynIntType<::Signed>, + CanonicalValue = IntValue::Signed>>, + > + Connect + Connect::Signed>> { @@ -874,15 +678,11 @@ pub trait IntTypeTrait: Signed = ConstBool, SameWidthUInt = Self::SameWidthUInt, SameWidthSInt = Self::SameWidthSInt, - CanonicalType = DynUIntType, - CanonicalValue = DynUInt, >; type SameWidthSInt: IntTypeTrait< Signed = ConstBool, SameWidthUInt = Self::SameWidthUInt, SameWidthSInt = Self::SameWidthSInt, - CanonicalType = DynSIntType, - CanonicalValue = DynSInt, >; fn from_width_unchecked(width: usize) -> Self; fn width(self) -> usize; @@ -935,12 +735,12 @@ pub trait IntTypeTrait: start..end } fn slice_and_shift>(self, index: I) -> (DynUIntType, usize) { - let range = self.slice_index_to_range(index); + let range = self.canonical().slice_index_to_range(index); let width = range.end - range.start; (DynUIntType::new(width), range.start) } fn slice>(self, index: I) -> DynUIntType { - self.slice_and_shift(index).0 + self.canonical().slice_and_shift(index).0 } } diff --git a/crates/fayalite/src/module.rs b/crates/fayalite/src/module.rs index 1537b3a..99bf99b 100644 --- a/crates/fayalite/src/module.rs +++ b/crates/fayalite/src/module.rs @@ -11,7 +11,7 @@ use crate::{ ops::VariantAccess, Expr, Flow, Target, TargetBase, TargetPathArrayElement, TargetPathBundleField, TargetPathElement, ToExpr, }, - int::{DynUInt, DynUIntType, FixedOrDynIntType, UInt}, + int::{FixedOrDynIntType, UInt}, intern::{Intern, Interned}, memory::{Mem, MemBuilder, MemBuilderTarget, PortName}, reg::Reg, @@ -2254,12 +2254,7 @@ where #[track_caller] pub fn if_(&mut self, cond: impl ToExpr) -> IfScope where - Ty: FixedOrDynIntType< - 1, - Signed = ConstBool, - CanonicalType = DynUIntType, - CanonicalValue = DynUInt, - >, + Ty: FixedOrDynIntType<1, Signed = ConstBool>, { self.if_with_loc(cond, SourceLocation::caller()) } @@ -2269,12 +2264,7 @@ where source_location: SourceLocation, ) -> IfScope where - Ty: FixedOrDynIntType< - 1, - Signed = ConstBool, - CanonicalType = DynUIntType, - CanonicalValue = DynUInt, - >, + Ty: FixedOrDynIntType<1, Signed = ConstBool>, { let cond = cond.to_expr().as_bool(); let outer_block = self.block_stack.top(); diff --git a/crates/fayalite/src/module/transform/visit.rs b/crates/fayalite/src/module/transform/visit.rs index 95c4772..88af5c3 100644 --- a/crates/fayalite/src/module/transform/visit.rs +++ b/crates/fayalite/src/module/transform/visit.rs @@ -11,10 +11,7 @@ use crate::{ ops, Expr, ExprEnum, Literal, Target, TargetBase, TargetChild, TargetPathArrayElement, TargetPathBundleField, TargetPathDynArrayElement, TargetPathElement, ToExpr, }, - int::{ - DynInt, DynIntType, DynSInt, DynSIntType, DynUInt, DynUIntType, FixedOrDynIntType, IntType, - IntTypeTrait, - }, + int::{DynInt, DynIntType, FixedOrDynIntType, IntType, IntTypeTrait}, intern::{Intern, Interned}, memory::{Mem, MemPort, PortKind, PortName, PortType, ReadUnderWrite}, module::{ diff --git a/crates/fayalite/src/valueless.rs b/crates/fayalite/src/valueless.rs index d34905e..4aa6437 100644 --- a/crates/fayalite/src/valueless.rs +++ b/crates/fayalite/src/valueless.rs @@ -68,9 +68,10 @@ impl Valueless { &self, high_part: Valueless, ) -> Valueless> { + let self_type = self.ty.canonical(); let ty = DynIntType::new( - self.ty - .width() + self_type + .width .checked_add(high_part.ty.width()) .expect("result has too many bits"), ); diff --git a/crates/fayalite/visit_types.json b/crates/fayalite/visit_types.json index 0304e06..9a8e524 100644 --- a/crates/fayalite/visit_types.json +++ b/crates/fayalite/visit_types.json @@ -376,7 +376,7 @@ "$constructor": "ops::Not::new_unchecked", "arg": "Visible" }, - "generics": "::Signed>, CanonicalValue = DynInt<::Signed>>>" + "generics": "" }, "ops::Neg": { "data": { @@ -384,7 +384,7 @@ "$constructor": "ops::Neg::new_unchecked", "arg": "Visible" }, - "generics": ", CanonicalType = DynSIntType, CanonicalValue = DynSInt>>" + "generics": ">>" }, "ops::BitAnd": { "data": { @@ -395,7 +395,7 @@ }, "generics": { "generics": "", - "where": "L: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, R: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>" + "where": "L: IntTypeTrait, R: IntTypeTrait" } }, "ops::BitOr": { @@ -407,7 +407,7 @@ }, "generics": { "generics": "", - "where": "L: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, R: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>" + "where": "L: IntTypeTrait, R: IntTypeTrait" } }, "ops::BitXor": { @@ -419,7 +419,7 @@ }, "generics": { "generics": "", - "where": "L: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, R: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>" + "where": "L: IntTypeTrait, R: IntTypeTrait" } }, "ops::Add": { @@ -431,7 +431,7 @@ }, "generics": { "generics": "", - "where": "L: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, R: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>" + "where": "L: IntTypeTrait, R: IntTypeTrait" } }, "ops::Sub": { @@ -443,7 +443,7 @@ }, "generics": { "generics": "", - "where": "L: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, R: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>" + "where": "L: IntTypeTrait, R: IntTypeTrait" } }, "ops::Mul": { @@ -455,7 +455,7 @@ }, "generics": { "generics": "", - "where": "L: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, R: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>" + "where": "L: IntTypeTrait, R: IntTypeTrait" } }, "ops::DynShl": { @@ -465,7 +465,7 @@ "lhs": "Visible", "rhs": "Visible" }, - "generics": "::Signed>, CanonicalValue = DynInt<::Signed>>>" + "generics": "" }, "ops::DynShr": { "data": { @@ -474,7 +474,7 @@ "lhs": "Visible", "rhs": "Visible" }, - "generics": "::Signed>, CanonicalValue = DynInt<::Signed>>>" + "generics": "" }, "ops::FixedShl": { "data": { @@ -483,7 +483,7 @@ "lhs": "Visible", "rhs": "Visible" }, - "generics": "::Signed>, CanonicalValue = DynInt<::Signed>>>" + "generics": "" }, "ops::FixedShr": { "data": { @@ -492,7 +492,7 @@ "lhs": "Visible", "rhs": "Visible" }, - "generics": "::Signed>, CanonicalValue = DynInt<::Signed>>>" + "generics": "" }, "ops::CmpLt": { "data": { @@ -501,7 +501,7 @@ "lhs": "Visible", "rhs": "Visible" }, - "generics": "::Signed>, CanonicalValue = DynInt<::Signed>>, RhsType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, Output: FixedOrDynIntType<1, Signed = ConstBool, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>" + "generics": ", Output: FixedOrDynIntType<1, Signed = ConstBool>>" }, "ops::CmpLe": { "data": { @@ -510,7 +510,7 @@ "lhs": "Visible", "rhs": "Visible" }, - "generics": "::Signed>, CanonicalValue = DynInt<::Signed>>, RhsType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, Output: FixedOrDynIntType<1, Signed = ConstBool, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>" + "generics": ", Output: FixedOrDynIntType<1, Signed = ConstBool>>" }, "ops::CmpGt": { "data": { @@ -519,7 +519,7 @@ "lhs": "Visible", "rhs": "Visible" }, - "generics": "::Signed>, CanonicalValue = DynInt<::Signed>>, RhsType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, Output: FixedOrDynIntType<1, Signed = ConstBool, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>" + "generics": ", Output: FixedOrDynIntType<1, Signed = ConstBool>>" }, "ops::CmpGe": { "data": { @@ -528,7 +528,7 @@ "lhs": "Visible", "rhs": "Visible" }, - "generics": "::Signed>, CanonicalValue = DynInt<::Signed>>, RhsType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, Output: FixedOrDynIntType<1, Signed = ConstBool, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>" + "generics": ", Output: FixedOrDynIntType<1, Signed = ConstBool>>" }, "ops::CmpEq": { "data": { @@ -537,7 +537,7 @@ "lhs": "Visible", "rhs": "Visible" }, - "generics": "::Signed>, CanonicalValue = DynInt<::Signed>>, RhsType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, Output: FixedOrDynIntType<1, Signed = ConstBool, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>" + "generics": ", Output: FixedOrDynIntType<1, Signed = ConstBool>>" }, "ops::CmpNe": { "data": { @@ -546,7 +546,7 @@ "lhs": "Visible", "rhs": "Visible" }, - "generics": "::Signed>, CanonicalValue = DynInt<::Signed>>, RhsType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, Output: FixedOrDynIntType<1, Signed = ConstBool, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>" + "generics": ", Output: FixedOrDynIntType<1, Signed = ConstBool>>" }, "ops::CastInt": { "data": { @@ -555,7 +555,7 @@ "value": "Visible", "ty()": "Visible" }, - "generics": "::Signed>, CanonicalValue = DynInt<::Signed>>, ToType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>>", + "generics": "", "fold_where": "ToType: Fold", "visit_where": "ToType: Visit" }, @@ -566,7 +566,7 @@ "base": "Visible", "range": "Opaque" }, - "generics": "::Signed>, CanonicalValue = DynInt<::Signed>>>" + "generics": "" }, "ops::ReduceBitAnd": { "data": { @@ -574,7 +574,7 @@ "$constructor": "ops::ReduceBitAnd::new_unchecked", "arg": "Visible" }, - "generics": ", CanonicalType = DynUIntType, CanonicalValue = DynUInt>>" + "generics": ">>" }, "ops::ReduceBitOr": { "data": { @@ -582,7 +582,7 @@ "$constructor": "ops::ReduceBitOr::new_unchecked", "arg": "Visible" }, - "generics": ", CanonicalType = DynUIntType, CanonicalValue = DynUInt>>" + "generics": ">>" }, "ops::ReduceBitXor": { "data": { @@ -590,7 +590,7 @@ "$constructor": "ops::ReduceBitXor::new_unchecked", "arg": "Visible" }, - "generics": ", CanonicalType = DynUIntType, CanonicalValue = DynUInt>>" + "generics": ">>" }, "ops::FieldAccess": { "data": { @@ -696,7 +696,7 @@ "$constructor": "ops::CastClockToBit::new_unchecked", "value": "Visible" }, - "generics": "::Signed>, CanonicalValue = DynInt<::Signed>>>" + "generics": ">" }, "ops::CastSyncResetToBit": { "data": { @@ -704,7 +704,7 @@ "$constructor": "ops::CastSyncResetToBit::new_unchecked", "value": "Visible" }, - "generics": "::Signed>, CanonicalValue = DynInt<::Signed>>>" + "generics": ">" }, "ops::CastAsyncResetToBit": { "data": { @@ -712,7 +712,7 @@ "$constructor": "ops::CastAsyncResetToBit::new_unchecked", "value": "Visible" }, - "generics": "::Signed>, CanonicalValue = DynInt<::Signed>>>" + "generics": ">" }, "ops::CastResetToBit": { "data": { @@ -720,7 +720,7 @@ "$constructor": "ops::CastResetToBit::new_unchecked", "value": "Visible" }, - "generics": "::Signed>, CanonicalValue = DynInt<::Signed>>>" + "generics": ">" }, "BlockId": { "data": {