reformat messy code that rustfmt doesn't format

This commit is contained in:
Jacob Lifshay 2024-07-10 23:34:41 -07:00
parent 929e9f8b16
commit 8bd7fcfa27
Signed by: programmerjake
SSH key fingerprint: SHA256:B1iRVvUJkvd7upMIiMqn6OyxvD2SgJkAH3ZnUOj6z+c
14 changed files with 647 additions and 196 deletions

View file

@ -564,8 +564,18 @@ macro_rules! impl_tuple_builder {
$(($after_Ts $after_fields $after_members))*
]);
impl<Phantom, $($before_Ts,)* $($after_Ts,)*> $builder<Phantom, $($before_Ts,)* () $(, $after_Ts)*> {
pub fn $field<$T: ToExpr>(self, $field: $T) -> $builder<Phantom, $($before_Ts,)* Expr<<$T::Type as Type>::Value> $(, $after_Ts)*> {
impl<Phantom, $($before_Ts,)* $($after_Ts,)*> $builder<
Phantom,
$($before_Ts,)*
(),
$($after_Ts,)*
> {
pub fn $field<$T: ToExpr>(self, $field: $T) -> $builder<
Phantom,
$($before_Ts,)*
Expr<<$T::Type as Type>::Value>,
$($after_Ts,)*
> {
let Self {
$($before_fields,)*
$field: _,

View file

@ -208,7 +208,8 @@ macro_rules! unary_op {
).ty,
#[cache]
literal_bits: Result<Interned<BitSlice>, ()> = {
arg.to_literal_bits().map(|v| ops::$Op::$op($T::CanonicalValue::from_bit_slice(&v)).to_bits())
arg.to_literal_bits()
.map(|v| ops::$Op::$op($T::CanonicalValue::from_bit_slice(&v)).to_bits())
},
fn simulate(&self, sim_state: &mut SimState) -> _ {
@ -242,7 +243,10 @@ unary_op! {
#[method = not]
impl<T> Not for _
where (
T: IntTypeTrait<CanonicalType = DynIntType<<T as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<T as IntTypeTrait>::Signed>>,
T: IntTypeTrait<
CanonicalType = DynIntType<<T as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<T as IntTypeTrait>::Signed>,
>,
)
{
fn expr_enum(&self) -> _ {
@ -262,7 +266,11 @@ unary_op! {
#[method = neg]
impl<T> Neg for _
where (
T: IntTypeTrait<Signed = ConstBool<true>, CanonicalType = DynSIntType, CanonicalValue = DynSInt>,
T: IntTypeTrait<
Signed = ConstBool<true>,
CanonicalType = DynSIntType,
CanonicalValue = DynSInt,
>,
)
{
fn expr_enum(&self) -> _ {
@ -273,7 +281,12 @@ unary_op! {
macro_rules! binary_op {
(
#[method = $op:ident, rhs_to_canonical_dyn = $rhs_to_canonical_dyn:ident, expr_enum_u = $expr_enum_u:ident, expr_enum_s = $expr_enum_s:ident]
#[
method = $op:ident,
rhs_to_canonical_dyn = $rhs_to_canonical_dyn:ident,
expr_enum_u = $expr_enum_u:ident,
expr_enum_s = $expr_enum_s:ident
]
impl<$LhsType:ident, $RhsType:ident> $Op:ident for _ where $($where:tt)*
) => {
fixed_ary_op! {
@ -285,7 +298,10 @@ macro_rules! binary_op {
pub lhs: Expr<$LhsType::CanonicalValue>,
pub rhs: Expr<$RhsType::CanonicalValue>,
#[type]
ty: <<Valueless<$LhsType> as ops::$Op<Valueless<$RhsType>>>::Output as ValuelessTr>::Type = ops::$Op::$op(
ty: <
<Valueless<$LhsType> as ops::$Op<Valueless<$RhsType>>>::Output
as ValuelessTr
>::Type = ops::$Op::$op(
Valueless::<$LhsType>::from_canonical(lhs.valueless()),
Valueless::<$RhsType>::from_canonical(rhs.valueless()),
).ty,
@ -309,7 +325,8 @@ macro_rules! binary_op {
fn expr_enum(&self) -> _ {
struct Tag;
impl ConstBoolDispatchTag for Tag {
type Type<Select: GenericConstBool> = $Op<DynIntType<Select>, DynIntType<Select>>;
type Type<Select: GenericConstBool> =
$Op<DynIntType<Select>, DynIntType<Select>>;
}
match ConstBoolDispatch::new::<Tag, $LhsType::Signed>(self.canonical()) {
ConstBoolDispatch::False(v) => ExprEnum::$expr_enum_u(v.intern_sized()),
@ -322,25 +339,45 @@ macro_rules! binary_op {
}
}
impl<Lhs: Value<Type = $LhsType>, $LhsType, $RhsType, Rhs: Value<Type = $RhsType>> ops::$Op<Expr<Rhs>> for Expr<Lhs>
impl<
Lhs: Value<Type = $LhsType>,
$LhsType,
$RhsType,
Rhs: Value<Type = $RhsType>,
> ops::$Op<Expr<Rhs>> for Expr<Lhs>
where
$($where)*
{
type Output = Expr<<<Valueless<$LhsType> as ops::$Op<Valueless<$RhsType>>>::Output as ValuelessTr>::Value>;
type Output = Expr<<
<Valueless<$LhsType> as ops::$Op<Valueless<$RhsType>>>::Output
as ValuelessTr
>::Value>;
fn $op(self, rhs: Expr<Rhs>) -> Self::Output {
$Op::<$LhsType, $RhsType>::new_unchecked(self.canonical(), rhs.canonical()).to_expr()
$Op::<$LhsType, $RhsType>::new_unchecked(self.canonical(), rhs.canonical())
.to_expr()
}
}
impl<Lhs: Value<Type = $LhsType>, $LhsType, $RhsType, Rhs: Value<Type = $RhsType>> ops::$Op<Rhs> for Expr<Lhs>
impl<
Lhs: Value<Type = $LhsType>,
$LhsType,
$RhsType,
Rhs: Value<Type = $RhsType>,
> ops::$Op<Rhs> for Expr<Lhs>
where
$($where)*
{
type Output = Expr<<<Valueless<$LhsType> as ops::$Op<Valueless<$RhsType>>>::Output as ValuelessTr>::Value>;
type Output = Expr<<
<Valueless<$LhsType> as ops::$Op<Valueless<$RhsType>>>::Output
as ValuelessTr
>::Value>;
fn $op(self, rhs: Rhs) -> Self::Output {
$Op::<$LhsType, $RhsType>::new_unchecked(self.canonical(), rhs.to_expr().canonical()).to_expr()
$Op::<$LhsType, $RhsType>::new_unchecked(
self.canonical(),
rhs.to_expr().canonical(),
).to_expr()
}
}
@ -348,78 +385,156 @@ macro_rules! binary_op {
where
$($where)*
{
type Output = Expr<<<Valueless<$LhsType> as ops::$Op<Valueless<$RhsType>>>::Output as ValuelessTr>::Value>;
type Output = Expr<<
<Valueless<$LhsType> as ops::$Op<Valueless<$RhsType>>>::Output
as ValuelessTr
>::Value>;
fn $op(self, rhs: Expr<Rhs>) -> Self::Output {
$Op::<$LhsType, $RhsType>::new_unchecked(self.to_expr().canonical(), rhs.canonical()).to_expr()
$Op::<$LhsType, $RhsType>::new_unchecked(
self.to_expr().canonical(),
rhs.canonical(),
).to_expr()
}
}
};
}
binary_op! {
#[method = bitand, rhs_to_canonical_dyn = to_canonical_dyn, expr_enum_u = BitAndU, expr_enum_s = BitAndS]
#[
method = bitand,
rhs_to_canonical_dyn = to_canonical_dyn,
expr_enum_u = BitAndU,
expr_enum_s = BitAndS
]
impl<L, R> BitAnd for _
where
L: IntTypeTrait<CanonicalType = DynIntType<<L as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<L as IntTypeTrait>::Signed>>,
R: IntTypeTrait<Signed = L::Signed, CanonicalType = DynIntType<<R as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<R as IntTypeTrait>::Signed>>,
L: IntTypeTrait<
CanonicalType = DynIntType<<L as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<L as IntTypeTrait>::Signed>,
>,
R: IntTypeTrait<
Signed = L::Signed,
CanonicalType = DynIntType<<R as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<R as IntTypeTrait>::Signed>,
>,
}
binary_op! {
#[method = bitor, rhs_to_canonical_dyn = to_canonical_dyn, expr_enum_u = BitOrU, expr_enum_s = BitOrS]
#[
method = bitor,
rhs_to_canonical_dyn = to_canonical_dyn,
expr_enum_u = BitOrU,
expr_enum_s = BitOrS
]
impl<L, R> BitOr for _
where
L: IntTypeTrait<CanonicalType = DynIntType<<L as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<L as IntTypeTrait>::Signed>>,
R: IntTypeTrait<Signed = L::Signed, CanonicalType = DynIntType<<R as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<R as IntTypeTrait>::Signed>>,
L: IntTypeTrait<
CanonicalType = DynIntType<<L as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<L as IntTypeTrait>::Signed>,
>,
R: IntTypeTrait<
Signed = L::Signed,
CanonicalType = DynIntType<<R as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<R as IntTypeTrait>::Signed>,
>,
}
binary_op! {
#[method = bitxor, rhs_to_canonical_dyn = to_canonical_dyn, expr_enum_u = BitXorU, expr_enum_s = BitXorS]
#[
method = bitxor,
rhs_to_canonical_dyn = to_canonical_dyn,
expr_enum_u = BitXorU,
expr_enum_s = BitXorS
]
impl<L, R> BitXor for _
where
L: IntTypeTrait<CanonicalType = DynIntType<<L as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<L as IntTypeTrait>::Signed>>,
R: IntTypeTrait<Signed = L::Signed, CanonicalType = DynIntType<<R as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<R as IntTypeTrait>::Signed>>,
L: IntTypeTrait<
CanonicalType = DynIntType<<L as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<L as IntTypeTrait>::Signed>,
>,
R: IntTypeTrait<
Signed = L::Signed,
CanonicalType = DynIntType<<R as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<R as IntTypeTrait>::Signed>,
>,
}
binary_op! {
#[method = add, rhs_to_canonical_dyn = to_canonical_dyn, expr_enum_u = AddU, expr_enum_s = AddS]
impl<L, R> Add for _
where
L: IntTypeTrait<CanonicalType = DynIntType<<L as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<L as IntTypeTrait>::Signed>>,
R: IntTypeTrait<Signed = L::Signed, CanonicalType = DynIntType<<R as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<R as IntTypeTrait>::Signed>>,
L: IntTypeTrait<
CanonicalType = DynIntType<<L as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<L as IntTypeTrait>::Signed>,
>,
R: IntTypeTrait<
Signed = L::Signed,
CanonicalType = DynIntType<<R as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<R as IntTypeTrait>::Signed>,
>,
}
binary_op! {
#[method = sub, rhs_to_canonical_dyn = to_canonical_dyn, expr_enum_u = SubU, expr_enum_s = SubS]
impl<L, R> Sub for _
where
L: IntTypeTrait<CanonicalType = DynIntType<<L as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<L as IntTypeTrait>::Signed>>,
R: IntTypeTrait<Signed = L::Signed, CanonicalType = DynIntType<<R as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<R as IntTypeTrait>::Signed>>,
L: IntTypeTrait<
CanonicalType = DynIntType<<L as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<L as IntTypeTrait>::Signed>,
>,
R: IntTypeTrait<
Signed = L::Signed,
CanonicalType = DynIntType<<R as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<R as IntTypeTrait>::Signed>,
>,
}
binary_op! {
#[method = mul, rhs_to_canonical_dyn = to_canonical_dyn, expr_enum_u = MulU, expr_enum_s = MulS]
#[
method = mul,
rhs_to_canonical_dyn = to_canonical_dyn,
expr_enum_u = MulU,
expr_enum_s = MulS
]
impl<L, R> Mul for _
where
L: IntTypeTrait<CanonicalType = DynIntType<<L as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<L as IntTypeTrait>::Signed>>,
R: IntTypeTrait<Signed = L::Signed, CanonicalType = DynIntType<<R as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<R as IntTypeTrait>::Signed>>,
L: IntTypeTrait<
CanonicalType = DynIntType<<L as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<L as IntTypeTrait>::Signed>,
>,
R: IntTypeTrait<
Signed = L::Signed,
CanonicalType = DynIntType<<R as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<R as IntTypeTrait>::Signed>,
>,
}
macro_rules! dyn_shift_op {
(
#[method = $Op:ident::$op:ident, expr_enum_u = $expr_enum_u:ident, expr_enum_s = $expr_enum_s:ident]
#[
method = $Op:ident::$op:ident,
expr_enum_u = $expr_enum_u:ident,
expr_enum_s = $expr_enum_s:ident
]
impl $DynOp:ident
) => {
fixed_ary_op! {
pub struct $DynOp<LhsType,>
where (
LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>,
LhsType: IntTypeTrait<
CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>,
>,
)
{
pub lhs: Expr<LhsType::CanonicalValue>,
pub rhs: Expr<DynUInt>,
#[type]
ty: <<Valueless<LhsType> as ops::$Op<Valueless<DynUIntType>>>::Output as ValuelessTr>::Type = ops::$Op::$op(
ty: <
<Valueless<LhsType> as ops::$Op<Valueless<DynUIntType>>>::Output
as ValuelessTr
>::Type = ops::$Op::$op(
lhs.valueless(),
rhs.valueless(),
).ty,
@ -456,12 +571,27 @@ macro_rules! dyn_shift_op {
}
}
impl<Lhs: Value<Type = LhsType>, LhsType, RhsType, Rhs: Value<Type = RhsType>> ops::$Op<Expr<Rhs>> for Expr<Lhs>
impl<
Lhs: Value<Type = LhsType>,
LhsType,
RhsType,
Rhs: Value<Type = RhsType>,
> ops::$Op<Expr<Rhs>> for Expr<Lhs>
where
LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>,
RhsType: IntTypeTrait<Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>,
LhsType: IntTypeTrait<
CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>,
>,
RhsType: IntTypeTrait<
Signed = ConstBool<false>,
CanonicalType = DynUIntType,
CanonicalValue = DynUInt,
>,
{
type Output = Expr<<<Valueless<LhsType> as ops::$Op<Valueless<RhsType>>>::Output as ValuelessTr>::Value>;
type Output = Expr<<
<Valueless<LhsType> as ops::$Op<Valueless<RhsType>>>::Output
as ValuelessTr
>::Value>;
fn $op(self, rhs: Expr<Rhs>) -> Self::Output {
$DynOp::<LhsType>::new_unchecked(self.canonical(), rhs.canonical()).to_expr()
@ -470,13 +600,23 @@ macro_rules! dyn_shift_op {
impl<LhsType, RhsType, Rhs: Value<Type = RhsType>> ops::$Op<Expr<Rhs>> for IntValue<LhsType>
where
LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>,
RhsType: IntTypeTrait<Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>,
LhsType: IntTypeTrait<
CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>,
>,
RhsType: IntTypeTrait<
Signed = ConstBool<false>,
CanonicalType = DynUIntType,
CanonicalValue = DynUInt,
>,
{
type Output = Expr<<<Valueless<LhsType> as ops::$Op<Valueless<RhsType>>>::Output as ValuelessTr>::Value>;
type Output = Expr<<
<Valueless<LhsType> as ops::$Op<Valueless<RhsType>>>::Output as ValuelessTr>::Value,
>;
fn $op(self, rhs: Expr<Rhs>) -> Self::Output {
$DynOp::<LhsType>::new_unchecked(self.to_expr().canonical(), rhs.canonical()).to_expr()
$DynOp::<LhsType>::new_unchecked(self.to_expr().canonical(), rhs.canonical())
.to_expr()
}
}
};
@ -484,22 +624,27 @@ macro_rules! dyn_shift_op {
macro_rules! fixed_shift_op {
(
#[method = $Op:ident::$op:ident, expr_enum_u = $expr_enum_u:ident, expr_enum_s = $expr_enum_s:ident]
#[
method = $Op:ident::$op:ident,
expr_enum_u = $expr_enum_u:ident,
expr_enum_s = $expr_enum_s:ident
]
impl $FixedOp:ident
) => {
fixed_ary_op! {
pub struct $FixedOp<LhsType,>
where (
LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>,
LhsType: IntTypeTrait<
CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>,
>,
)
{
pub lhs: Expr<LhsType::CanonicalValue>,
pub rhs: usize,
#[type]
ty: <<Valueless<LhsType> as ops::$Op<usize>>::Output as ValuelessTr>::Type = ops::$Op::$op(
lhs.valueless(),
rhs,
).ty,
ty: <<Valueless<LhsType> as ops::$Op<usize>>::Output as ValuelessTr>::Type =
ops::$Op::$op(lhs.valueless(), rhs).ty,
#[cache]
literal_bits: Result<Interned<BitSlice>, ()> = {
lhs.to_literal_bits()
@ -532,9 +677,13 @@ macro_rules! fixed_shift_op {
impl<Lhs: Value<Type = LhsType>, LhsType> ops::$Op<usize> for Expr<Lhs>
where
LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>,
LhsType: IntTypeTrait<
CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>,
>,
{
type Output = Expr<<<Valueless<LhsType> as ops::$Op<usize>>::Output as ValuelessTr>::Value>;
type Output =
Expr<<<Valueless<LhsType> as ops::$Op<usize>>::Output as ValuelessTr>::Value>;
fn $op(self, rhs: usize) -> Self::Output {
$FixedOp::<LhsType>::new_unchecked(self.canonical(), rhs).to_expr()
@ -568,9 +717,21 @@ macro_rules! cmp_op {
$(fixed_ary_op! {
pub struct $CmpOp<LhsType, RhsType, Output,>
where (
LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>,
RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>,
Output: FixedOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>,
LhsType: IntTypeTrait<
CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>,
>,
RhsType: IntTypeTrait<
Signed = LhsType::Signed,
CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>,
>,
Output: FixedOrDynIntType<
1,
Signed = ConstBool<false>,
CanonicalType = DynUIntType,
CanonicalValue = DynUInt,
>,
)
{
pub lhs: Expr<LhsType::CanonicalValue>,
@ -598,7 +759,8 @@ macro_rules! cmp_op {
fn expr_enum(&self) -> _ {
struct Tag;
impl ConstBoolDispatchTag for Tag {
type Type<Select: GenericConstBool> = $CmpOp<DynIntType<Select>, DynIntType<Select>, DynUIntType>;
type Type<Select: GenericConstBool> =
$CmpOp<DynIntType<Select>, DynIntType<Select>, DynUIntType>;
}
match ConstBoolDispatch::new::<Tag, LhsType::Signed>(self.canonical()) {
ConstBoolDispatch::False(v) => ExprEnum::$CmpOpU(v.intern_sized()),
@ -612,15 +774,44 @@ macro_rules! cmp_op {
}
})*
impl<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>, RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>, Rhs: Value<Type = RhsType>, Lhs: Value<Type = LhsType>> IntCmp<Expr<Rhs>> for Expr<Lhs> {
impl<
LhsType: IntTypeTrait<
CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>,
>,
RhsType: IntTypeTrait<
Signed = LhsType::Signed,
CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>,
>,
Rhs: Value<Type = RhsType>,
Lhs: Value<Type = LhsType>,
> IntCmp<Expr<Rhs>> for Expr<Lhs>
{
type Output = Expr<UInt<1>>;
$(fn $fn(self, rhs: Expr<Rhs>) -> Self::Output {
$CmpOp::<LhsType, RhsType, UIntType<1>>::new_unchecked(self.canonical(), rhs.canonical()).to_expr()
$CmpOp::<LhsType, RhsType, UIntType<1>>::new_unchecked(
self.canonical(),
rhs.canonical(),
).to_expr()
})*
}
impl<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>, RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>, Rhs: Value<Type = RhsType>, Lhs: Value<Type = LhsType>> IntCmp<Rhs> for Expr<Lhs> {
impl<
LhsType: IntTypeTrait<
CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>,
>,
RhsType: IntTypeTrait<
Signed = LhsType::Signed,
CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>,
>,
Rhs: Value<Type = RhsType>,
Lhs: Value<Type = LhsType>,
> IntCmp<Rhs> for Expr<Lhs>
{
type Output = Expr<UInt<1>>;
$(fn $fn(self, rhs: Rhs) -> Self::Output {
@ -628,7 +819,18 @@ macro_rules! cmp_op {
})*
}
impl<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>, RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>, Rhs: Value<Type = RhsType>> IntCmp<Expr<Rhs>> for IntValue<LhsType> {
impl<
LhsType: IntTypeTrait<
CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>,
>,
RhsType: IntTypeTrait<
Signed = LhsType::Signed,
CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>,
>,
Rhs: Value<Type = RhsType>,
> IntCmp<Expr<Rhs>> for IntValue<LhsType> {
type Output = Expr<UInt<1>>;
$(fn $fn(self, rhs: Expr<Rhs>) -> Self::Output {
@ -636,7 +838,10 @@ macro_rules! cmp_op {
})*
}
impl<LhsType: IntTypeTrait, RhsType: IntTypeTrait<Signed = LhsType::Signed>> IntCmp<Valueless<RhsType>> for Valueless<LhsType> {
impl<
LhsType: IntTypeTrait,
RhsType: IntTypeTrait<Signed = LhsType::Signed>,
> IntCmp<Valueless<RhsType>> for Valueless<LhsType> {
type Output = Valueless<UIntType<1>>;
$(fn $fn(self, _rhs: Valueless<RhsType>) -> Self::Output {
@ -658,8 +863,14 @@ cmp_op! {
fixed_ary_op! {
pub struct CastInt<FromType, ToType,>
where (
FromType: IntTypeTrait<CanonicalType = DynIntType<<FromType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<FromType as IntTypeTrait>::Signed>>,
ToType: IntTypeTrait<CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>,
FromType: IntTypeTrait<
CanonicalType = DynIntType<<FromType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<FromType as IntTypeTrait>::Signed>,
>,
ToType: IntTypeTrait<
CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>,
>,
)
{
pub value: Expr<FromType::CanonicalValue>,
@ -669,7 +880,8 @@ fixed_ary_op! {
literal_bits: Result<Interned<BitSlice>, ()> = {
value.to_literal_bits().map(|literal_bits| {
let mut bits = literal_bits.to_bitvec();
let fill = FromType::Signed::VALUE && bits.len().checked_sub(1).map(|i| bits[i]).unwrap_or(false);
let fill = FromType::Signed::VALUE
&& bits.len().checked_sub(1).map(|i| bits[i]).unwrap_or(false);
bits.resize(ty.width(), fill);
Intern::intern_owned(bits)
})
@ -689,13 +901,24 @@ fixed_ary_op! {
}
struct Tag2<FromSigned: GenericConstBool>(FromSigned);
impl<FromSigned: GenericConstBool> ConstBoolDispatchTag for Tag2<FromSigned> {
type Type<Select: GenericConstBool> = CastInt<DynIntType<FromSigned>, DynIntType<Select>>;
type Type<Select: GenericConstBool> =
CastInt<DynIntType<FromSigned>, DynIntType<Select>>;
}
match ConstBoolDispatch::new::<Tag1, FromType::Signed>(ConstBoolDispatch::new::<Tag2<FromType::Signed>, ToType::Signed>(self.canonical())) {
ConstBoolDispatch::False(ConstBoolDispatch::False(v)) => ExprEnum::CastUIntToUInt(v.intern_sized()),
ConstBoolDispatch::False(ConstBoolDispatch::True(v)) => ExprEnum::CastUIntToSInt(v.intern_sized()),
ConstBoolDispatch::True(ConstBoolDispatch::False(v)) => ExprEnum::CastSIntToUInt(v.intern_sized()),
ConstBoolDispatch::True(ConstBoolDispatch::True(v)) => ExprEnum::CastSIntToSInt(v.intern_sized()),
match ConstBoolDispatch::new::<Tag1, FromType::Signed>(
ConstBoolDispatch::new::<Tag2<FromType::Signed>, ToType::Signed>(self.canonical()),
) {
ConstBoolDispatch::False(ConstBoolDispatch::False(v)) => {
ExprEnum::CastUIntToUInt(v.intern_sized())
}
ConstBoolDispatch::False(ConstBoolDispatch::True(v)) => {
ExprEnum::CastUIntToSInt(v.intern_sized())
}
ConstBoolDispatch::True(ConstBoolDispatch::False(v)) => {
ExprEnum::CastSIntToUInt(v.intern_sized())
}
ConstBoolDispatch::True(ConstBoolDispatch::True(v)) => {
ExprEnum::CastSIntToSInt(v.intern_sized())
}
}
}
@ -740,7 +963,10 @@ impl<
fixed_ary_op! {
pub struct Slice<Base,>
where (
Base: IntTypeTrait<CanonicalType = DynIntType<<Base as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<Base as IntTypeTrait>::Signed>>,
Base: IntTypeTrait<
CanonicalType = DynIntType<<Base as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<Base as IntTypeTrait>::Signed>,
>,
)
{
pub base: Expr<Base::CanonicalValue>,
@ -890,7 +1116,12 @@ macro_rules! reduce_bit_op {
fixed_ary_op! {
pub struct $name<Output,>
where (
Output: FixedOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>,
Output: FixedOrDynIntType<
1,
Signed = ConstBool<false>,
CanonicalType = DynUIntType,
CanonicalValue = DynUInt,
>,
)
{
pub arg: Expr<DynUInt>,

View file

@ -2297,7 +2297,7 @@ pub struct TestBackend {
pub files: BTreeMap<String, String>,
pub error_after: Option<i64>,
#[doc(hidden)]
/// #[non_exhaustive] except allowing struct update syntax
/// `#[non_exhaustive]` except allowing struct update syntax
pub __private: TestBackendPrivate,
}

View file

@ -92,7 +92,7 @@ pub struct BuilderModuleBody {
memory_map: HashMap<ScopedNameId, Rc<RefCell<MemBuilderTarget>>>,
}
/// implicit name argument that's automatically provided by #[hdl] let
/// implicit name argument that's automatically provided by `#[hdl]` let
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct ImplicitName<'a>(pub &'a str);
@ -225,7 +225,10 @@ impl<S: ModuleBuildingStatus> fmt::Debug for StmtMatch<S> {
macro_rules! wrapper_enum {
(
#[impl(($($T_impl:tt)*) $impl_self:ident: $impl_type:ty = $impl_self_expr:expr $(, ($($T_impls:tt)*) $impls_self:ident: $impls_type:ty = $impls_self_expr:expr)*)]
#[impl(
($($T_impl:tt)*) $impl_self:ident: $impl_type:ty = $impl_self_expr:expr
$(, ($($T_impls:tt)*) $impls_self:ident: $impls_type:ty = $impls_self_expr:expr)*
)]
#[to($($T_to:tt $to_types:ty),*)]
$(#[$enum_meta:meta])*
$vis:vis enum $enum_name:ident<$T_enum:ident: $T_bound:ident = $T_enum_default:ident> {
@ -356,7 +359,10 @@ pub struct StmtInstance<S: ModuleBuildingStatus = ModuleBuilt> {
}
wrapper_enum! {
#[impl((<S: ModuleBuildingStatus>) self: StmtDeclaration<S> = self, (<S: ModuleBuildingStatus>) self: Stmt<S> = self.declaration()?)]
#[impl(
(<S: ModuleBuildingStatus>) self: StmtDeclaration<S> = self,
(<S: ModuleBuildingStatus>) self: Stmt<S> = self.declaration()?
)]
#[to((<S: ModuleBuildingStatus>) StmtDeclaration<S>, (<S: ModuleBuildingStatus>) Stmt<S>)]
#[derive(Clone, PartialEq, Eq, Hash)]
pub enum StmtDeclaration<S: ModuleBuildingStatus = ModuleBuilt> {
@ -1705,7 +1711,7 @@ impl<T: BundleValue> Module<T>
where
T::Type: BundleType<Value = T>,
{
/// you generally should use the #[hdl_module] proc-macro and [`ModuleBuilder`] instead
/// you generally should use the [`#[hdl_module]`][`crate::hdl_module`] proc-macro and [`ModuleBuilder`] instead
pub fn new_unchecked(
name_id: NameId,
source_location: SourceLocation,

View file

@ -45,20 +45,34 @@ pub trait Visit<State: ?Sized + Visitor> {
macro_rules! impl_visit_fold {
(
impl<$T:ident, $State:ident $(, const $Const:ident: $const_ty:ty)*> _ for $ty:ty $(where ($($where_tt:tt)*))? {
fn fold($($fold_args:tt)*) -> $fold_ret_ty:ty $fold_block:block
fn default_fold($($default_fold_args:tt)*) -> $default_fold_ret_ty:ty $default_fold_block:block
fn visit($($visit_args:tt)*) -> $visit_ret_ty:ty $visit_block:block
fn default_visit($($default_visit_args:tt)*) -> $default_visit_ret_ty:ty $default_visit_block:block
impl<$T:ident, $State:ident $(, const $Const:ident: $const_ty:ty)*> _ for $ty:ty
$(where ($($where_tt:tt)*))?
{
fn fold($($fold_args:tt)*) -> $fold_ret_ty:ty
$fold_block:block
fn default_fold($($default_fold_args:tt)*) -> $default_fold_ret_ty:ty
$default_fold_block:block
fn visit($($visit_args:tt)*) -> $visit_ret_ty:ty
$visit_block:block
fn default_visit($($default_visit_args:tt)*) -> $default_visit_ret_ty:ty
$default_visit_block:block
}
) => {
impl<$T: Fold<$State>, $State: ?Sized + Folder $(, const $Const: $const_ty)*> Fold<$State> for $ty
impl<
$T: Fold<$State>,
$State: ?Sized + Folder,
$(const $Const: $const_ty,)*
> Fold<$State> for $ty
$(where $($where_tt)*)?
{
fn fold($($fold_args)*) -> $fold_ret_ty $fold_block
fn default_fold($($default_fold_args)*) -> $default_fold_ret_ty $default_fold_block
}
impl<$T: Visit<$State>, $State: ?Sized + Visitor $(, const $Const: $const_ty)*> Visit<$State> for $ty
impl<
$T: Visit<$State>,
$State: ?Sized + Visitor,
$(const $Const: $const_ty,)*
> Visit<$State> for $ty
$(where $($where_tt)*)?
{
fn visit($($visit_args)*) -> $visit_ret_ty $visit_block

View file

@ -109,7 +109,9 @@ const FILE_PATTERNS: &[FilePattern] = &[
];
thread_local! {
static NORMALIZE_FILES_FOR_TESTS: RefCell<Option<NormalizeFilesForTestsState>> = const { RefCell::new(None) };
static NORMALIZE_FILES_FOR_TESTS: RefCell<Option<NormalizeFilesForTestsState>> = const {
RefCell::new(None)
};
}
impl From<&'_ panic::Location<'_>> for SourceLocation {