diff --git a/crates/fayalite-proc-macros-impl/src/fold.rs b/crates/fayalite-proc-macros-impl/src/fold.rs index 02c1a2e..0ef9490 100644 --- a/crates/fayalite-proc-macros-impl/src/fold.rs +++ b/crates/fayalite-proc-macros-impl/src/fold.rs @@ -85,7 +85,8 @@ macro_rules! impl_fold { $($field:ident: $field_ty:ty,)* } ) => { - impl $crate::fold::DoFold for $Struct<$($T,)*> + impl $crate::fold::DoFold + for $Struct<$($T,)*> where $($T: $crate::fold::DoFold,)* $($where)* @@ -107,7 +108,8 @@ macro_rules! impl_fold { ) $(where ($($where:tt)*))?; ) => { - impl $crate::fold::DoFold for $Struct<$($T,)*> + impl $crate::fold::DoFold + for $Struct<$($T,)*> where $($T: $crate::fold::DoFold,)* $($where)* @@ -133,7 +135,8 @@ macro_rules! impl_fold { ))?,)* } ) => { - impl $crate::fold::DoFold for $Enum<$($T,)*> + impl $crate::fold::DoFold + for $Enum<$($T,)*> where $($T: $crate::fold::DoFold,)* $($where)* diff --git a/crates/fayalite-proc-macros-impl/src/lib.rs b/crates/fayalite-proc-macros-impl/src/lib.rs index cbcdd70..7aafe66 100644 --- a/crates/fayalite-proc-macros-impl/src/lib.rs +++ b/crates/fayalite-proc-macros-impl/src/lib.rs @@ -504,7 +504,10 @@ macro_rules! options { separator.to_tokens(tokens); separator = Some(Default::default()); v.0.to_tokens(tokens); - $(v.1.surround(tokens, |tokens| <$value as quote::ToTokens>::to_tokens(&v.2, tokens));)? + $(v.1.surround( + tokens, + |tokens| <$value as quote::ToTokens>::to_tokens(&v.2, tokens), + );)? })* } } diff --git a/crates/fayalite-proc-macros-impl/src/module/transform_body.rs b/crates/fayalite-proc-macros-impl/src/module/transform_body.rs index 621aa7a..6d098d6 100644 --- a/crates/fayalite-proc-macros-impl/src/module/transform_body.rs +++ b/crates/fayalite-proc-macros-impl/src/module/transform_body.rs @@ -353,7 +353,10 @@ macro_rules! make_builder_method_enum { })+ Err(lookahead.error()) } - $vis fn parse_dot_prefixed(input: ParseStream, $($parse_arg: $parse_arg_ty),+) -> syn::Result<(Token![.], Self)> { + $vis fn parse_dot_prefixed( + input: ParseStream, + $($parse_arg: $parse_arg_ty,)+ + ) -> syn::Result<(Token![.], Self)> { let dot = input.parse()?; Ok((dot, Self::parse(input, $($parse_arg),+)?)) } @@ -1380,7 +1383,10 @@ impl Visitor { Sign::Plus => (false, value.magnitude().to_bytes_le()), }; Some(parse_quote_spanned! {span=> - ::fayalite::int::make_int_literal::<#signed, #width>(#negative, &[#(#bytes,)*]).to_int_expr() + ::fayalite::int::make_int_literal::<#signed, #width>( + #negative, + &[#(#bytes,)*], + ).to_int_expr() }) } fn process_literal(&mut self, literal: ExprLit) -> Expr { diff --git a/crates/fayalite-proc-macros-impl/src/module/transform_body/expand_match.rs b/crates/fayalite-proc-macros-impl/src/module/transform_body/expand_match.rs index b4d8ad2..58b0bbb 100644 --- a/crates/fayalite-proc-macros-impl/src/module/transform_body/expand_match.rs +++ b/crates/fayalite-proc-macros-impl/src/module/transform_body/expand_match.rs @@ -607,14 +607,18 @@ impl Visitor { ); parse_quote_spanned! {span=> { - type __MatchTy = <::Type as ::fayalite::ty::Type>::MatchVariant; + type __MatchTy = + <::Type as ::fayalite::ty::Type>::MatchVariant; let __match_expr = ::fayalite::expr::ToExpr::to_expr(&(#expr)); ::fayalite::expr::check_match_expr(__match_expr, |__match_value, __infallible| { #[allow(unused_variables)] #check_match }); for __match_variant in m.match_(__match_expr) { - let (__match_variant, __scope) = ::fayalite::ty::MatchVariantAndInactiveScope::match_activate_scope(__match_variant); + let (__match_variant, __scope) = + ::fayalite::ty::MatchVariantAndInactiveScope::match_activate_scope( + __match_variant, + ); #match_token __match_variant { #(#arms)* } 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 b9c6ffb..0ceac12 100644 --- a/crates/fayalite-proc-macros-impl/src/value_derive_common.rs +++ b/crates/fayalite-proc-macros-impl/src/value_derive_common.rs @@ -187,10 +187,21 @@ impl ValueDeriveGenerics { let fixed_type_predicates = &mut fixed_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}); + predicates.push(parse_quote! { + <#type_param as ::fayalite::expr::ToExpr>::Type: + ::fayalite::ty::Type + }); fixed_type_predicates.push(parse_quote! {#type_param: ::fayalite::ty::Value}); - fixed_type_predicates.push(parse_quote! {<#type_param as ::fayalite::expr::ToExpr>::Type: ::fayalite::ty::FixedType}); - fixed_type_predicates.push(parse_quote! {<<#type_param as ::fayalite::expr::ToExpr>::Type as ::fayalite::ty::Type>::MaskType: ::fayalite::ty::FixedType}); + fixed_type_predicates.push(parse_quote! { + <#type_param as ::fayalite::expr::ToExpr>::Type: + ::fayalite::ty::FixedType + }); + fixed_type_predicates.push(parse_quote! { + < + <#type_param as ::fayalite::expr::ToExpr>::Type + as ::fayalite::ty::Type + >::MaskType: ::fayalite::ty::FixedType + }); } } Self { @@ -241,8 +252,10 @@ pub(crate) fn derive_clone_hash_eq_partialeq_for_struct( #[allow(unused_variables)] #[allow(clippy::nonminimal_bool)] fn eq(&self, other: &Self) -> ::fayalite::__std::primitive::bool { - true - #(&& ::fayalite::__std::cmp::PartialEq::eq(&self.#field_names, &other.#field_names))* + true #(&& ::fayalite::__std::cmp::PartialEq::eq( + &self.#field_names, + &other.#field_names, + ))* } } } @@ -543,8 +556,22 @@ impl ToTokens for BuilderWithFields { quote_spanned! {span=> #[automatically_derived] #[allow(non_camel_case_types, dead_code)] - impl<#phantom_type_param #(, #initial_type_params)* #(, #final_type_params)*> #struct_name<#phantom_type_param #(, #initial_type_params)*, () #(, #final_type_params)*> { - #vis fn #builder_field_name<#type_param>(self, #builder_field_name: #type_param) -> #struct_name<#phantom_type_param #(, #initial_type_params)*, #mapped_type #(, #final_type_params)*> + impl<#phantom_type_param #(, #initial_type_params)* #(, #final_type_params)*> + #struct_name< + #phantom_type_param, + #(#initial_type_params,)* + (), #(#final_type_params,)* + > + { + #vis fn #builder_field_name<#type_param>( + self, + #builder_field_name: #type_param, + ) -> #struct_name< + #phantom_type_param, + #(#initial_type_params,)* + #mapped_type, + #(#final_type_params,)* + > #where_clause { let Self { @@ -738,7 +765,8 @@ pub(crate) fn make_connect_impl( quote_spanned! {span=> #[automatically_derived] #[allow(non_camel_case_types)] - impl #impl_generics ::fayalite::ty::Connect<#ty_ident #rhs_type_generics> for #ty_ident #lhs_type_generics + impl #impl_generics ::fayalite::ty::Connect<#ty_ident #rhs_type_generics> + for #ty_ident #lhs_type_generics #where_clause { } diff --git a/crates/fayalite-proc-macros-impl/src/value_derive_enum.rs b/crates/fayalite-proc-macros-impl/src/value_derive_enum.rs index 2c3da08..27a2974 100644 --- a/crates/fayalite-proc-macros-impl/src/value_derive_enum.rs +++ b/crates/fayalite-proc-macros-impl/src/value_derive_enum.rs @@ -323,7 +323,9 @@ impl ToTokens for ParsedEnum { f.debug_struct(#debug_ident).finish() }, FieldsKind::Named(_) => quote! { - f.debug_struct(#debug_ident)#(.field(#field_name_strs, &self.#field_names))*.finish() + f.debug_struct(#debug_ident) + #(.field(#field_name_strs, &self.#field_names))* + .finish() }, FieldsKind::Unnamed(_) => quote! { f.debug_tuple(#debug_ident)#(.field(&self.#field_names))*.finish() @@ -332,17 +334,25 @@ impl ToTokens for ParsedEnum { let value_struct_ident = &value_struct.ident; quote! { #[automatically_derived] - impl #fixed_type_impl_generics ::fayalite::__std::fmt::Debug for #value_struct_ident #fixed_type_type_generics + impl #fixed_type_impl_generics ::fayalite::__std::fmt::Debug + for #value_struct_ident #fixed_type_type_generics #fixed_type_where_clause { - fn fmt(&self, f: &mut ::fayalite::__std::fmt::Formatter<'_>) -> ::fayalite::__std::fmt::Result { + fn fmt( + &self, + f: &mut ::fayalite::__std::fmt::Formatter<'_>, + ) -> ::fayalite::__std::fmt::Result { #debug_body } } - }.to_tokens(tokens); - Some( - parse_quote! { <#value_struct_ident #fixed_type_type_generics as ::fayalite::expr::ToExpr>::Type }, - ) + } + .to_tokens(tokens); + Some(parse_quote! { + < + #value_struct_ident #fixed_type_type_generics + as ::fayalite::expr::ToExpr + >::Type + }) }; let type_struct_variants = Punctuated::from_iter(variants.iter().filter_map(|variant| { let VariantOptions {} = variant.options.body; @@ -382,7 +392,9 @@ impl ToTokens for ParsedEnum { let non_empty_variant_name_strs = Vec::from_iter(non_empty_variant_names.iter().map(|v| v.to_string())); let debug_type_body = quote! { - f.debug_struct(#type_struct_debug_ident)#(.field(#non_empty_variant_name_strs, &self.#non_empty_variant_names))*.finish() + f.debug_struct(#type_struct_debug_ident) + #(.field(#non_empty_variant_name_strs, &self.#non_empty_variant_names))* + .finish() }; derive_clone_hash_eq_partialeq_for_struct( type_struct_ident, @@ -415,13 +427,18 @@ impl ToTokens for ParsedEnum { parsed_struct, } => { let value_struct_ident = &value_struct.ident; - let phantom_field_name = &parsed_struct.fields.last().expect("missing phantom field").name; + let phantom_field_name = &parsed_struct + .fields + .last() + .expect("missing phantom field") + .name; let type_generics = fixed_type_type_generics.as_turbofish(); quote! { ::fayalite::__std::option::Option::Some( ::fayalite::ty::DynValueTrait::to_canonical_dyn( &#value_struct_ident #type_generics { - #(#field_names: ::fayalite::__std::clone::Clone::clone(#var_names),)* + #(#field_names: + ::fayalite::__std::clone::Clone::clone(#var_names),)* #phantom_field_name: ::fayalite::__std::marker::PhantomData, }, ), @@ -453,7 +470,10 @@ impl ToTokens for ParsedEnum { }, |t| { parse_quote_spanned! {t.span()=> - ::fayalite::expr::Expr<<<#t as ::fayalite::expr::ToExpr>::Type as ::fayalite::ty::Type>::Value> + ::fayalite::expr::Expr<< + <#t as ::fayalite::expr::ToExpr>::Type + as ::fayalite::ty::Type + >::Value> } }, |t| { @@ -549,7 +569,8 @@ impl ToTokens for ParsedEnum { }); if let Some(value_ty) = variant.value.value_ty() { from_canonical_type_variant_lets.push(quote! { - let #variant_var = #variant_var.from_canonical_type_helper_has_value(#variant_name_str); + let #variant_var = + #variant_var.from_canonical_type_helper_has_value(#variant_name_str); }); non_empty_variant_vars.push(variant_var.clone()); enum_type_variants.push(quote! { @@ -564,7 +585,9 @@ impl ToTokens for ParsedEnum { ::fayalite::enum_::VariantType { name: ::fayalite::intern::Intern::intern(#variant_name_str), ty: ::fayalite::__std::option::Option::Some( - ::fayalite::bundle::TypeHint::<<#value_ty as ::fayalite::expr::ToExpr>::Type>::intern_dyn(), + ::fayalite::bundle::TypeHint::< + <#value_ty as ::fayalite::expr::ToExpr>::Type, + >::intern_dyn(), ), } }); @@ -604,12 +627,14 @@ impl ToTokens for ParsedEnum { } => quote! { #variant_index => { let __variant_access = ::fayalite::expr::ToExpr::to_expr( - &__variant_access.downcast_unchecked::< - <#ident #fixed_type_type_generics as ::fayalite::expr::ToExpr>::Type, - >(), + &__variant_access.downcast_unchecked::<< + #ident #fixed_type_type_generics + as ::fayalite::expr::ToExpr + >::Type>(), ); #match_enum_ident::#variant_name { - #(#match_enum_field_names: (*__variant_access).#match_enum_field_names,)* + #(#match_enum_field_names: + (*__variant_access).#match_enum_field_names,)* } }, }, @@ -634,7 +659,9 @@ impl ToTokens for ParsedEnum { VariantValue::None => parse_quote! { { ::fayalite::expr::ToExpr::to_expr( - &::fayalite::expr::ops::EnumLiteral::<#type_struct_ident #fixed_type_type_generics>::new_unchecked( + &::fayalite::expr::ops::EnumLiteral::< + #type_struct_ident #fixed_type_type_generics + >::new_unchecked( ::fayalite::__std::option::Option::None, #variant_index, ::fayalite::ty::FixedType::fixed_type(), @@ -645,8 +672,12 @@ impl ToTokens for ParsedEnum { VariantValue::Direct { value_type: _ } => parse_quote! { { ::fayalite::expr::ToExpr::to_expr( - &::fayalite::expr::ops::EnumLiteral::<#type_struct_ident #fixed_type_type_generics>::new_unchecked( - ::fayalite::__std::option::Option::Some(#(#builder_field_vars)*.to_canonical_dyn()), + &::fayalite::expr::ops::EnumLiteral::< + #type_struct_ident #fixed_type_type_generics + >::new_unchecked( + ::fayalite::__std::option::Option::Some( + #(#builder_field_vars)*.to_canonical_dyn(), + ), #variant_index, ::fayalite::ty::FixedType::fixed_type(), ), @@ -666,11 +697,18 @@ impl ToTokens for ParsedEnum { .. } => parse_quote! { { - let __builder = <#field_type_struct_ident #fixed_type_type_generics as ::fayalite::bundle::BundleType>::builder(); + let __builder = < + #field_type_struct_ident #fixed_type_type_generics + as ::fayalite::bundle::BundleType + >::builder(); #(let __builder = __builder.#builder_field_vars(#builder_field_vars);)* ::fayalite::expr::ToExpr::to_expr( - &::fayalite::expr::ops::EnumLiteral::<#type_struct_ident #fixed_type_type_generics>::new_unchecked( - ::fayalite::__std::option::Option::Some(__builder.build().to_canonical_dyn()), + &::fayalite::expr::ops::EnumLiteral::< + #type_struct_ident #fixed_type_type_generics + >::new_unchecked( + ::fayalite::__std::option::Option::Some( + __builder.build().to_canonical_dyn(), + ), #variant_index, ::fayalite::ty::FixedType::fixed_type(), ), @@ -728,10 +766,14 @@ impl ToTokens for ParsedEnum { let empty_builder_ty = builder.ty([], Some(&parse_quote! { Self }), false); quote! { #[automatically_derived] - impl #fixed_type_impl_generics ::fayalite::__std::fmt::Debug for #match_enum_ident #fixed_type_type_generics + impl #fixed_type_impl_generics ::fayalite::__std::fmt::Debug + for #match_enum_ident #fixed_type_type_generics #fixed_type_where_clause { - fn fmt(&self, f: &mut ::fayalite::__std::fmt::Formatter<'_>) -> ::fayalite::__std::fmt::Result { + fn fmt( + &self, + f: &mut ::fayalite::__std::fmt::Formatter<'_>, + ) -> ::fayalite::__std::fmt::Result { match *self { #(#match_enum_debug_arms)* } @@ -739,7 +781,8 @@ impl ToTokens for ParsedEnum { } #[automatically_derived] - impl #fixed_type_impl_generics ::fayalite::ty::FixedType for #type_struct_ident #fixed_type_type_generics + impl #fixed_type_impl_generics ::fayalite::ty::FixedType + for #type_struct_ident #fixed_type_type_generics #fixed_type_where_clause { fn fixed_type() -> Self { @@ -760,16 +803,21 @@ impl ToTokens for ParsedEnum { } #[automatically_derived] - impl #fixed_type_impl_generics ::fayalite::__std::fmt::Debug for #type_struct_ident #fixed_type_type_generics + impl #fixed_type_impl_generics ::fayalite::__std::fmt::Debug + for #type_struct_ident #fixed_type_type_generics #fixed_type_where_clause { - fn fmt(&self, f: &mut ::fayalite::__std::fmt::Formatter<'_>) -> ::fayalite::__std::fmt::Result { + fn fmt( + &self, + f: &mut ::fayalite::__std::fmt::Formatter<'_>, + ) -> ::fayalite::__std::fmt::Result { #debug_type_body } } #[automatically_derived] - impl #fixed_type_impl_generics ::fayalite::ty::Type for #type_struct_ident #fixed_type_type_generics + impl #fixed_type_impl_generics ::fayalite::ty::Type + for #type_struct_ident #fixed_type_type_generics #fixed_type_where_clause { type CanonicalType = ::fayalite::enum_::DynEnumType; @@ -779,15 +827,20 @@ impl ToTokens for ParsedEnum { type MaskValue = ::fayalite::int::UInt<1>; type MatchVariant = #match_enum_ident #fixed_type_type_generics; type MatchActiveScope = ::fayalite::module::Scope; - type MatchVariantAndInactiveScope = ::fayalite::enum_::EnumMatchVariantAndInactiveScope; + type MatchVariantAndInactiveScope = + ::fayalite::enum_::EnumMatchVariantAndInactiveScope; type MatchVariantsIter = ::fayalite::enum_::EnumMatchVariantsIter; fn match_variants( this: ::fayalite::expr::Expr<::Value>, - module_builder: &mut ::fayalite::module::ModuleBuilder, + module_builder: &mut ::fayalite::module::ModuleBuilder< + IO, + ::fayalite::module::NormalModule, + >, source_location: ::fayalite::source_location::SourceLocation, ) -> ::MatchVariantsIter where - ::Type: ::fayalite::bundle::BundleType, + ::Type: + ::fayalite::bundle::BundleType, { module_builder.enum_match_variants_helper(this, source_location) } @@ -818,16 +871,22 @@ impl ToTokens for ParsedEnum { #[automatically_derived] #[allow(clippy::init_numbered_fields)] - impl #fixed_type_impl_generics ::fayalite::enum_::EnumType for #type_struct_ident #fixed_type_type_generics + impl #fixed_type_impl_generics ::fayalite::enum_::EnumType + for #type_struct_ident #fixed_type_type_generics #fixed_type_where_clause { type Builder = #empty_builder_ty; fn match_activate_scope( v: ::MatchVariantAndInactiveScope, - ) -> (::MatchVariant, ::MatchActiveScope) { + ) -> ( + ::MatchVariant, + ::MatchActiveScope, + ) { let (__variant_access, __scope) = v.activate(); ( - match ::fayalite::expr::ops::VariantAccess::variant_index(&*__variant_access) { + match ::fayalite::expr::ops::VariantAccess::variant_index( + &*__variant_access, + ) { #(#match_enum_arms)* #variant_count.. => ::fayalite::__std::panic!("invalid variant index"), }, @@ -837,7 +896,9 @@ impl ToTokens for ParsedEnum { fn builder() -> ::Builder { #empty_builder_ty::new() } - fn variants(&self) -> ::fayalite::intern::Interned<[::fayalite::enum_::VariantType<::fayalite::intern::Interned>]> { + fn variants(&self) -> ::fayalite::intern::Interned<[::fayalite::enum_::VariantType< + ::fayalite::intern::Interned, + >]> { ::fayalite::intern::Intern::intern(&[#(#enum_type_variants,)*][..]) } fn variants_hint() -> ::fayalite::enum_::VariantsHint { @@ -846,7 +907,8 @@ impl ToTokens for ParsedEnum { } #[automatically_derived] - impl #fixed_type_impl_generics ::fayalite::expr::ToExpr for #target #fixed_type_type_generics + impl #fixed_type_impl_generics ::fayalite::expr::ToExpr + for #target #fixed_type_type_generics #fixed_type_where_clause { type Type = #type_struct_ident #fixed_type_type_generics; @@ -859,10 +921,15 @@ impl ToTokens for ParsedEnum { } #[automatically_derived] - impl #fixed_type_impl_generics ::fayalite::ty::Value for #target #fixed_type_type_generics + impl #fixed_type_impl_generics ::fayalite::ty::Value + for #target #fixed_type_type_generics #fixed_type_where_clause { - fn to_canonical(&self) -> <::Type as ::fayalite::ty::Type>::CanonicalValue { + fn to_canonical(&self) -> < + ::Type + as ::fayalite::ty::Type + >::CanonicalValue + { let __ty = ::fayalite::ty::Type::canonical(&::fayalite::expr::ToExpr::ty(self)); match self { #(Self::#variant_names { #variant_field_pats } => { @@ -877,7 +944,8 @@ impl ToTokens for ParsedEnum { } #[automatically_derived] - impl #fixed_type_impl_generics ::fayalite::enum_::EnumValue for #target #fixed_type_type_generics + impl #fixed_type_impl_generics ::fayalite::enum_::EnumValue + for #target #fixed_type_type_generics #fixed_type_where_clause { } diff --git a/crates/fayalite-proc-macros-impl/src/value_derive_struct.rs b/crates/fayalite-proc-macros-impl/src/value_derive_struct.rs index 472e984..6363b55 100644 --- a/crates/fayalite-proc-macros-impl/src/value_derive_struct.rs +++ b/crates/fayalite-proc-macros-impl/src/value_derive_struct.rs @@ -303,25 +303,35 @@ impl ParsedStruct { f.debug_struct(#mask_value_debug_ident).finish() }, FieldsKind::Named(_) => quote! { - f.debug_struct(#mask_value_debug_ident)#(.field(#unskipped_field_name_strs, &self.#unskipped_field_names))*.finish() + f.debug_struct(#mask_value_debug_ident) + #(.field(#unskipped_field_name_strs, &self.#unskipped_field_names))* + .finish() }, FieldsKind::Unnamed(_) => quote! { - f.debug_tuple(#mask_value_debug_ident)#(.field(&self.#unskipped_field_names))*.finish() + f.debug_tuple(#mask_value_debug_ident) + #(.field(&self.#unskipped_field_names))* + .finish() }, }; quote! { #[automatically_derived] - impl #impl_generics ::fayalite::__std::fmt::Debug for #mask_value_ident #type_generics + impl #impl_generics ::fayalite::__std::fmt::Debug + for #mask_value_ident #type_generics #where_clause { - fn fmt(&self, f: &mut ::fayalite::__std::fmt::Formatter<'_>) -> ::fayalite::__std::fmt::Result { + fn fmt( + &self, + f: &mut ::fayalite::__std::fmt::Formatter<'_>, + ) -> ::fayalite::__std::fmt::Result { #debug_mask_value_body } } - }.to_tokens(tokens); + } + .to_tokens(tokens); quote! { #mask_type_ident { - #(#unskipped_field_names: ::fayalite::ty::Type::mask_type(&self.#unskipped_field_names),)* + #(#unskipped_field_names: + ::fayalite::ty::Type::mask_type(&self.#unskipped_field_names),)* #(#phantom_data_field_name_slice: ::fayalite::__std::marker::PhantomData,)* } } @@ -331,10 +341,14 @@ impl ParsedStruct { f.debug_struct(#type_struct_debug_ident).finish() }, FieldsKind::Named(_) => quote! { - f.debug_struct(#type_struct_debug_ident)#(.field(#unskipped_field_name_strs, &self.#unskipped_field_names))*.finish() + f.debug_struct(#type_struct_debug_ident) + #(.field(#unskipped_field_name_strs, &self.#unskipped_field_names))* + .finish() }, FieldsKind::Unnamed(_) => quote! { - f.debug_tuple(#type_struct_debug_ident)#(.field(&self.#unskipped_field_names))*.finish() + f.debug_tuple(#type_struct_debug_ident) + #(.field(&self.#unskipped_field_names))* + .finish() }, }; for the_struct_ident in [&type_struct_ident, match_variant_ident] @@ -369,7 +383,8 @@ impl ParsedStruct { fn fixed_type() -> Self { Self { #(#unskipped_field_names: ::fayalite::ty::FixedType::fixed_type(),)* - #(#phantom_data_field_name_slice: ::fayalite::__std::marker::PhantomData,)* + #(#phantom_data_field_name_slice: + ::fayalite::__std::marker::PhantomData,)* } } } @@ -393,24 +408,27 @@ impl ParsedStruct { let mut builder = Builder::new(builder_struct_ident.clone(), vis.clone()); for field in unskipped_fields.clone() { builder.insert_field( - field.name.clone(), - |v| { - parse_quote_spanned! {v.span()=> - ::fayalite::expr::ToExpr::to_expr(&#v) - } - }, - |t| { - parse_quote_spanned! {t.span()=> - ::fayalite::expr::Expr<<<#t as ::fayalite::expr::ToExpr>::Type as ::fayalite::ty::Type>::Value> - } - }, - |t| { - parse_quote_spanned! {t.span()=> - where - #t: ::fayalite::expr::ToExpr, - } - }, - ); + field.name.clone(), + |v| { + parse_quote_spanned! {v.span()=> + ::fayalite::expr::ToExpr::to_expr(&#v) + } + }, + |t| { + parse_quote_spanned! {t.span()=> + ::fayalite::expr::Expr<< + <#t as ::fayalite::expr::ToExpr>::Type + as ::fayalite::ty::Type + >::Value> + } + }, + |t| { + parse_quote_spanned! {t.span()=> + where + #t: ::fayalite::expr::ToExpr, + } + }, + ); } let builder = builder.finish_filling_in_fields(); builder.to_tokens(tokens); @@ -456,7 +474,8 @@ impl ParsedStruct { )*][..]), #type_struct_ident { #(#build_type_fields,)* - #(#phantom_data_field_name_slice: ::fayalite::__std::marker::PhantomData,)* + #(#phantom_data_field_name_slice: + ::fayalite::__std::marker::PhantomData,)* }, ), ) @@ -494,7 +513,10 @@ impl ParsedStruct { impl #impl_generics ::fayalite::__std::fmt::Debug for #type_struct_ident #type_generics #where_clause { - fn fmt(&self, f: &mut ::fayalite::__std::fmt::Formatter<'_>) -> ::fayalite::__std::fmt::Result { + fn fmt( + &self, + f: &mut ::fayalite::__std::fmt::Formatter<'_>, + ) -> ::fayalite::__std::fmt::Result { #debug_type_body } } @@ -510,21 +532,32 @@ impl ParsedStruct { type MaskValue = #mask_value_ident #type_generics; type MatchVariant = #match_variant_ident #type_generics; type MatchActiveScope = (); - type MatchVariantAndInactiveScope = ::fayalite::ty::MatchVariantWithoutScope<#match_variant_ident #type_generics>; - type MatchVariantsIter = ::fayalite::__std::iter::Once<::MatchVariantAndInactiveScope>; + type MatchVariantAndInactiveScope = ::fayalite::ty::MatchVariantWithoutScope< + #match_variant_ident #type_generics, + >; + type MatchVariantsIter = ::fayalite::__std::iter::Once< + ::MatchVariantAndInactiveScope, + >; #[allow(unused_variables)] fn match_variants( this: ::fayalite::expr::Expr<::Value>, - module_builder: &mut ::fayalite::module::ModuleBuilder, + module_builder: &mut ::fayalite::module::ModuleBuilder< + IO, + ::fayalite::module::NormalModule, + >, source_location: ::fayalite::source_location::SourceLocation, ) -> ::MatchVariantsIter where - ::Type: ::fayalite::bundle::BundleType, + ::Type: + ::fayalite::bundle::BundleType, { - ::fayalite::__std::iter::once(::fayalite::ty::MatchVariantWithoutScope(#match_variant_ident { - #(#unskipped_field_names: this.field(#unskipped_field_name_strs),)* - #(#phantom_data_field_name_slice: ::fayalite::__std::marker::PhantomData,)* - })) + ::fayalite::__std::iter::once(::fayalite::ty::MatchVariantWithoutScope( + #match_variant_ident { + #(#unskipped_field_names: this.field(#unskipped_field_name_strs),)* + #(#phantom_data_field_name_slice: + ::fayalite::__std::marker::PhantomData,)* + }, + )) } fn mask_type(&self) -> ::MaskType { #mask_type_body @@ -540,11 +573,15 @@ impl ParsedStruct { ::fayalite::ty::TypeEnum::BundleType(::fayalite::ty::Type::canonical(self)) } fn from_canonical_type(t: ::CanonicalType) -> Self { - let [#(#unskipped_field_vars),*] = *::fayalite::bundle::BundleType::fields(&t) else { + let [#(#unskipped_field_vars),*] = *::fayalite::bundle::BundleType::fields(&t) + else { ::fayalite::__std::panic!("wrong number of fields"); }; Self { - #(#unskipped_field_names: #unskipped_field_vars.from_canonical_type_helper(#unskipped_field_name_strs, #unskipped_field_flips),)* + #(#unskipped_field_names: #unskipped_field_vars.from_canonical_type_helper( + #unskipped_field_name_strs, + #unskipped_field_flips, + ),)* #(#phantom_data_field_name_slice: ::fayalite::__std::marker::PhantomData,)* } } @@ -555,13 +592,16 @@ impl ParsedStruct { #where_clause { #[allow(unused_variables)] - fn expr_deref(this: &::fayalite::expr::Expr<::Value>) -> &::MatchVariant { - ::fayalite::intern::Interned::<_>::into_inner(::fayalite::intern::Intern::intern_sized( - #match_variant_ident { + fn expr_deref(this: &::fayalite::expr::Expr<::Value>) + -> &::MatchVariant + { + ::fayalite::intern::Interned::<_>::into_inner( + ::fayalite::intern::Intern::intern_sized(#match_variant_ident { #(#unskipped_field_names: this.field(#unskipped_field_name_strs),)* - #(#phantom_data_field_name_slice: ::fayalite::__std::marker::PhantomData,)* - } - )) + #(#phantom_data_field_name_slice: + ::fayalite::__std::marker::PhantomData,)* + }), + ) } } @@ -573,12 +613,19 @@ impl ParsedStruct { fn builder() -> ::Builder { #empty_builder_ty::new() } - fn fields(&self) -> ::fayalite::intern::Interned<[::fayalite::bundle::FieldType<::fayalite::intern::Interned>]> { + fn fields(&self) -> ::fayalite::intern::Interned< + [::fayalite::bundle::FieldType<::fayalite::intern::Interned< + dyn ::fayalite::ty::DynCanonicalType, + >>], + > + { ::fayalite::intern::Intern::intern(&[#( ::fayalite::bundle::FieldType { name: ::fayalite::intern::Intern::intern(#unskipped_field_name_strs), flipped: #unskipped_field_flips, - ty: ::fayalite::ty::DynType::canonical_dyn(&self.#unskipped_field_names), + ty: ::fayalite::ty::DynType::canonical_dyn( + &self.#unskipped_field_names, + ), }, )*][..]) } @@ -600,7 +647,9 @@ impl ParsedStruct { type Type = #type_struct_ident #type_generics; fn ty(&self) -> ::Type { #type_struct_ident { - #(#unskipped_field_names: ::fayalite::expr::ToExpr::ty(&self.#unskipped_field_names),)* + #(#unskipped_field_names: ::fayalite::expr::ToExpr::ty( + &self.#unskipped_field_names, + ),)* #(#phantom_data_field_name_slice: ::fayalite::__std::marker::PhantomData,)* } } @@ -613,10 +662,16 @@ impl ParsedStruct { impl #impl_generics ::fayalite::ty::Value for #target #type_generics #where_clause { - fn to_canonical(&self) -> <::Type as ::fayalite::ty::Type>::CanonicalValue { + fn to_canonical(&self) -> < + ::Type + as ::fayalite::ty::Type + >::CanonicalValue + { let ty = ::fayalite::ty::Type::canonical(&::fayalite::expr::ToExpr::ty(self)); ::fayalite::bundle::DynBundle::new(ty, ::fayalite::__std::sync::Arc::new([ - #(::fayalite::ty::DynValueTrait::to_canonical_dyn(&self.#unskipped_field_names),)* + #(::fayalite::ty::DynValueTrait::to_canonical_dyn( + &self.#unskipped_field_names, + ),)* ])) } } diff --git a/crates/fayalite-visit-gen/src/lib.rs b/crates/fayalite-visit-gen/src/lib.rs index adf1d9b..008a4c6 100644 --- a/crates/fayalite-visit-gen/src/lib.rs +++ b/crates/fayalite-visit-gen/src/lib.rs @@ -66,7 +66,12 @@ impl DefinitionState { let folder_fn_name = self.folder_fn_name(); let (impl_generics, type_generics, where_clause) = self.folder_generics.split_for_impl(); quote! { - fn #folder_fn_name #impl_generics(&mut self, v: #path #type_generics) -> Result<#path #type_generics, Self::Error> #where_clause { + fn #folder_fn_name #impl_generics( + &mut self, + v: #path #type_generics, + ) -> Result<#path #type_generics, Self::Error> + #where_clause + { Fold::default_fold(v, self) } } @@ -75,7 +80,12 @@ impl DefinitionState { let visitor_fn_name = self.visitor_fn_name(); let (impl_generics, type_generics, where_clause) = self.visitor_generics.split_for_impl(); quote! { - fn #visitor_fn_name #impl_generics(&mut self, v: &#path #type_generics) -> Result<(), Self::Error> #where_clause { + fn #visitor_fn_name #impl_generics( + &mut self, + v: &#path #type_generics, + ) -> Result<(), Self::Error> + #where_clause + { Visit::default_visit(v, self) } } @@ -87,7 +97,9 @@ impl DefinitionState { quote! { #[automatically_derived] #[allow(clippy::init_numbered_fields)] - impl #trait_impl_generics Fold for #path #self_type_generics #trait_where_clause { + impl #trait_impl_generics Fold for #path #self_type_generics + #trait_where_clause + { fn fold(self, state: &mut State) -> Result { state.#folder_fn_name(self) } @@ -103,7 +115,9 @@ impl DefinitionState { let (trait_impl_generics, _, trait_where_clause) = self.visit_generics.split_for_impl(); quote! { #[automatically_derived] - impl #trait_impl_generics Visit for #path #self_type_generics #trait_where_clause { + impl #trait_impl_generics Visit for #path #self_type_generics + #trait_where_clause + { fn visit(&self, state: &mut State) -> Result<(), State::Error> { state.#visitor_fn_name(self) } @@ -257,7 +271,13 @@ pub fn generate(ast: &ast::Definitions) -> syn::Result { } else { let member = field_name.to_member(); if member.is_none() { - return Err(syn::Error::new(Span::call_site(), format!("struct must have `$constructor` since it contains a non-plain field: {def_path:?} {field_name:?}"))); + return Err(syn::Error::new( + Span::call_site(), + format!( + "struct must have `$constructor` since it contains a \ + non-plain field: {def_path:?} {field_name:?}" + ), + )); } member }; @@ -342,7 +362,8 @@ pub fn generate(ast: &ast::Definitions) -> syn::Result { Some(ast::Field::Visible) => { state_unused = false; fold_arm = quote! { - Self::#variant_name(v) => Fold::fold(v, state).map(Self::#variant_name), + Self::#variant_name(v) => Fold::fold(v, state) + .map(Self::#variant_name), }; visit_arm = quote! { Self::#variant_name(v) => Visit::visit(v, state), diff --git a/crates/fayalite/src/bundle.rs b/crates/fayalite/src/bundle.rs index e2b217b..7777493 100644 --- a/crates/fayalite/src/bundle.rs +++ b/crates/fayalite/src/bundle.rs @@ -564,8 +564,18 @@ macro_rules! impl_tuple_builder { $(($after_Ts $after_fields $after_members))* ]); - impl $builder { - pub fn $field<$T: ToExpr>(self, $field: $T) -> $builder::Value> $(, $after_Ts)*> { + impl $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: _, diff --git a/crates/fayalite/src/expr/ops.rs b/crates/fayalite/src/expr/ops.rs index 2ffe5d3..9c20385 100644 --- a/crates/fayalite/src/expr/ops.rs +++ b/crates/fayalite/src/expr/ops.rs @@ -208,7 +208,8 @@ macro_rules! unary_op { ).ty, #[cache] literal_bits: Result, ()> = { - 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 Not for _ where ( - T: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, + T: IntTypeTrait< + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, ) { fn expr_enum(&self) -> _ { @@ -262,7 +266,11 @@ unary_op! { #[method = neg] impl Neg for _ where ( - T: IntTypeTrait, CanonicalType = DynSIntType, CanonicalValue = DynSInt>, + T: IntTypeTrait< + Signed = ConstBool, + 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: < as ops::$Op>>::Output as ValuelessTr>::Type = ops::$Op::$op( + ty: < + as ops::$Op>>::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 = $Op, DynIntType>; } match ConstBoolDispatch::new::(self.canonical()) { ConstBoolDispatch::False(v) => ExprEnum::$expr_enum_u(v.intern_sized()), @@ -322,25 +339,45 @@ macro_rules! binary_op { } } - impl, $LhsType, $RhsType, Rhs: Value> ops::$Op> for Expr + impl< + Lhs: Value, + $LhsType, + $RhsType, + Rhs: Value, + > ops::$Op> for Expr where $($where)* { - type Output = Expr<< as ops::$Op>>::Output as ValuelessTr>::Value>; + type Output = Expr<< + as ops::$Op>>::Output + as ValuelessTr + >::Value>; fn $op(self, rhs: Expr) -> 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, $LhsType, $RhsType, Rhs: Value> ops::$Op for Expr + impl< + Lhs: Value, + $LhsType, + $RhsType, + Rhs: Value, + > ops::$Op for Expr where $($where)* { - type Output = Expr<< as ops::$Op>>::Output as ValuelessTr>::Value>; + type Output = Expr<< + as ops::$Op>>::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<< as ops::$Op>>::Output as ValuelessTr>::Value>; + type Output = Expr<< + as ops::$Op>>::Output + as ValuelessTr + >::Value>; fn $op(self, rhs: Expr) -> 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 BitAnd for _ where - L: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, - R: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, + L: IntTypeTrait< + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, + R: IntTypeTrait< + Signed = L::Signed, + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::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 BitOr for _ where - L: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, - R: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, + L: IntTypeTrait< + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, + R: IntTypeTrait< + Signed = L::Signed, + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::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 BitXor for _ where - L: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, - R: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, + L: IntTypeTrait< + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, + R: IntTypeTrait< + Signed = L::Signed, + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, } 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< + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, + R: IntTypeTrait< + Signed = L::Signed, + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, } 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< + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, + R: IntTypeTrait< + Signed = L::Signed, + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::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 Mul for _ where - L: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, - R: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, + L: IntTypeTrait< + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, + R: IntTypeTrait< + Signed = L::Signed, + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::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 where ( - LhsType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, + LhsType: IntTypeTrait< + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, ) { pub lhs: Expr, pub rhs: Expr, #[type] - ty: < as ops::$Op>>::Output as ValuelessTr>::Type = ops::$Op::$op( + ty: < + as ops::$Op>>::Output + as ValuelessTr + >::Type = ops::$Op::$op( lhs.valueless(), rhs.valueless(), ).ty, @@ -456,12 +571,27 @@ macro_rules! dyn_shift_op { } } - impl, LhsType, RhsType, Rhs: Value> ops::$Op> for Expr + impl< + Lhs: Value, + LhsType, + RhsType, + Rhs: Value, + > ops::$Op> for Expr where - LhsType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, - RhsType: IntTypeTrait, CanonicalType = DynUIntType, CanonicalValue = DynUInt>, + LhsType: IntTypeTrait< + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, + RhsType: IntTypeTrait< + Signed = ConstBool, + CanonicalType = DynUIntType, + CanonicalValue = DynUInt, + >, { - type Output = Expr<< as ops::$Op>>::Output as ValuelessTr>::Value>; + type Output = Expr<< + as ops::$Op>>::Output + as ValuelessTr + >::Value>; fn $op(self, rhs: Expr) -> Self::Output { $DynOp::::new_unchecked(self.canonical(), rhs.canonical()).to_expr() @@ -470,13 +600,23 @@ 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< + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, + RhsType: IntTypeTrait< + Signed = ConstBool, + CanonicalType = DynUIntType, + CanonicalValue = DynUInt, + >, { - type Output = Expr<< as ops::$Op>>::Output as ValuelessTr>::Value>; + type Output = Expr<< + as ops::$Op>>::Output as ValuelessTr>::Value, + >; fn $op(self, rhs: Expr) -> Self::Output { - $DynOp::::new_unchecked(self.to_expr().canonical(), rhs.canonical()).to_expr() + $DynOp::::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 where ( - LhsType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, + LhsType: IntTypeTrait< + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, ) { pub lhs: Expr, pub rhs: usize, #[type] - ty: < as ops::$Op>::Output as ValuelessTr>::Type = ops::$Op::$op( - lhs.valueless(), - rhs, - ).ty, + ty: < as ops::$Op>::Output as ValuelessTr>::Type = + ops::$Op::$op(lhs.valueless(), rhs).ty, #[cache] literal_bits: Result, ()> = { lhs.to_literal_bits() @@ -532,9 +677,13 @@ macro_rules! fixed_shift_op { impl, LhsType> ops::$Op for Expr where - LhsType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, + LhsType: IntTypeTrait< + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, { - type Output = Expr<< as ops::$Op>::Output as ValuelessTr>::Value>; + type Output = + Expr<< as ops::$Op>::Output as ValuelessTr>::Value>; fn $op(self, rhs: usize) -> Self::Output { $FixedOp::::new_unchecked(self.canonical(), rhs).to_expr() @@ -568,9 +717,21 @@ 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< + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, + RhsType: IntTypeTrait< + Signed = LhsType::Signed, + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, + Output: FixedOrDynIntType< + 1, + Signed = ConstBool, + CanonicalType = DynUIntType, + CanonicalValue = DynUInt, + >, ) { pub lhs: Expr, @@ -598,7 +759,8 @@ macro_rules! cmp_op { fn expr_enum(&self) -> _ { struct Tag; impl ConstBoolDispatchTag for Tag { - type Type = $CmpOp, DynIntType, DynUIntType>; } match ConstBoolDispatch::new::(self.canonical()) { ConstBoolDispatch::False(v) => ExprEnum::$CmpOpU(v.intern_sized()), @@ -612,15 +774,44 @@ macro_rules! cmp_op { } })* - impl::Signed>, CanonicalValue = DynInt<::Signed>>, RhsType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, Rhs: Value, Lhs: Value> IntCmp> for Expr { + impl< + LhsType: IntTypeTrait< + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, + RhsType: IntTypeTrait< + Signed = LhsType::Signed, + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, + Rhs: Value, + Lhs: Value, + > IntCmp> for Expr + { type Output = Expr>; $(fn $fn(self, rhs: Expr) -> Self::Output { - $CmpOp::>::new_unchecked(self.canonical(), rhs.canonical()).to_expr() + $CmpOp::>::new_unchecked( + self.canonical(), + rhs.canonical(), + ).to_expr() })* } - impl::Signed>, CanonicalValue = DynInt<::Signed>>, RhsType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, Rhs: Value, Lhs: Value> IntCmp for Expr { + impl< + LhsType: IntTypeTrait< + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, + RhsType: IntTypeTrait< + Signed = LhsType::Signed, + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, + Rhs: Value, + Lhs: Value, + > IntCmp for Expr + { type Output = Expr>; $(fn $fn(self, rhs: Rhs) -> Self::Output { @@ -628,7 +819,18 @@ macro_rules! cmp_op { })* } - impl::Signed>, CanonicalValue = DynInt<::Signed>>, RhsType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, Rhs: Value> IntCmp> for IntValue { + impl< + LhsType: IntTypeTrait< + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, + RhsType: IntTypeTrait< + Signed = LhsType::Signed, + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, + Rhs: Value, + > IntCmp> for IntValue { type Output = Expr>; $(fn $fn(self, rhs: Expr) -> Self::Output { @@ -636,7 +838,10 @@ macro_rules! cmp_op { })* } - impl> IntCmp> for Valueless { + impl< + LhsType: IntTypeTrait, + RhsType: IntTypeTrait, + > IntCmp> for Valueless { type Output = Valueless>; $(fn $fn(self, _rhs: Valueless) -> Self::Output { @@ -658,8 +863,14 @@ cmp_op! { fixed_ary_op! { pub struct CastInt where ( - FromType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, - ToType: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, + FromType: IntTypeTrait< + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, + ToType: IntTypeTrait< + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, ) { pub value: Expr, @@ -669,7 +880,8 @@ fixed_ary_op! { literal_bits: Result, ()> = { 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); impl ConstBoolDispatchTag for Tag2 { - type Type = CastInt, DynIntType>; } - match ConstBoolDispatch::new::(ConstBoolDispatch::new::, 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::( + ConstBoolDispatch::new::, 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 where ( - Base: IntTypeTrait::Signed>, CanonicalValue = DynInt<::Signed>>, + Base: IntTypeTrait< + CanonicalType = DynIntType<::Signed>, + CanonicalValue = DynInt<::Signed>, + >, ) { pub base: Expr, @@ -890,7 +1116,12 @@ 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, + CanonicalType = DynUIntType, + CanonicalValue = DynUInt, + >, ) { pub arg: Expr, diff --git a/crates/fayalite/src/firrtl.rs b/crates/fayalite/src/firrtl.rs index 623e2a7..4a85902 100644 --- a/crates/fayalite/src/firrtl.rs +++ b/crates/fayalite/src/firrtl.rs @@ -2297,7 +2297,7 @@ pub struct TestBackend { pub files: BTreeMap, pub error_after: Option, #[doc(hidden)] - /// #[non_exhaustive] except allowing struct update syntax + /// `#[non_exhaustive]` except allowing struct update syntax pub __private: TestBackendPrivate, } diff --git a/crates/fayalite/src/module.rs b/crates/fayalite/src/module.rs index 1537b3a..e503b4c 100644 --- a/crates/fayalite/src/module.rs +++ b/crates/fayalite/src/module.rs @@ -92,7 +92,7 @@ pub struct BuilderModuleBody { memory_map: HashMap>>, } -/// 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 fmt::Debug for StmtMatch { 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 { } wrapper_enum! { - #[impl(() self: StmtDeclaration = self, () self: Stmt = self.declaration()?)] + #[impl( + () self: StmtDeclaration = self, + () self: Stmt = self.declaration()? + )] #[to(() StmtDeclaration, () Stmt)] #[derive(Clone, PartialEq, Eq, Hash)] pub enum StmtDeclaration { @@ -1705,7 +1711,7 @@ impl Module where T::Type: BundleType, { - /// 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, diff --git a/crates/fayalite/src/module/transform/visit.rs b/crates/fayalite/src/module/transform/visit.rs index 95c4772..3e2ee03 100644 --- a/crates/fayalite/src/module/transform/visit.rs +++ b/crates/fayalite/src/module/transform/visit.rs @@ -45,20 +45,34 @@ pub trait Visit { 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 diff --git a/crates/fayalite/src/source_location.rs b/crates/fayalite/src/source_location.rs index 9b55f99..d143f22 100644 --- a/crates/fayalite/src/source_location.rs +++ b/crates/fayalite/src/source_location.rs @@ -109,7 +109,9 @@ const FILE_PATTERNS: &[FilePattern] = &[ ]; thread_local! { - static NORMALIZE_FILES_FOR_TESTS: RefCell> = const { RefCell::new(None) }; + static NORMALIZE_FILES_FOR_TESTS: RefCell> = const { + RefCell::new(None) + }; } impl From<&'_ panic::Location<'_>> for SourceLocation {