Auto merge of #119478 - bjorn3:no_serialize_specialization, r=wesleywiser
Avoid specialization in the metadata serialization code With the exception of a perf-only specialization for byte slices and byte vectors. This uses the same trick of introducing a new trait and having the Encodable and Decodable derives add a bound to it as used for TyEncoder/TyDecoder. The new code is clearer about which encoder/decoder uses which impl and it reduces the dependency of rustc on specialization, making it easier to remove support for specialization entirely or turn it into a construct that is only allowed for perf optimizations if we decide to do this.
This commit is contained in:
commit
e21f4cd98f
24 changed files with 478 additions and 400 deletions
|
@ -56,6 +56,8 @@ decl_derive!(
|
|||
hash_stable::hash_stable_no_context_derive
|
||||
);
|
||||
|
||||
decl_derive!([Decodable_Generic] => serialize::decodable_generic_derive);
|
||||
decl_derive!([Encodable_Generic] => serialize::encodable_generic_derive);
|
||||
decl_derive!([Decodable] => serialize::decodable_derive);
|
||||
decl_derive!([Encodable] => serialize::encodable_derive);
|
||||
decl_derive!([TyDecodable] => serialize::type_decodable_derive);
|
||||
|
|
|
@ -31,6 +31,14 @@ pub fn meta_decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
|
|||
}
|
||||
|
||||
pub fn decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
|
||||
let decoder_ty = quote! { __D };
|
||||
s.add_impl_generic(parse_quote! {#decoder_ty: ::rustc_span::SpanDecoder});
|
||||
s.add_bounds(synstructure::AddBounds::Generics);
|
||||
|
||||
decodable_body(s, decoder_ty)
|
||||
}
|
||||
|
||||
pub fn decodable_generic_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
|
||||
let decoder_ty = quote! { __D };
|
||||
s.add_impl_generic(parse_quote! {#decoder_ty: ::rustc_serialize::Decoder});
|
||||
s.add_bounds(synstructure::AddBounds::Generics);
|
||||
|
@ -129,6 +137,14 @@ pub fn meta_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
|
|||
}
|
||||
|
||||
pub fn encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
|
||||
let encoder_ty = quote! { __E };
|
||||
s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_span::SpanEncoder});
|
||||
s.add_bounds(synstructure::AddBounds::Generics);
|
||||
|
||||
encodable_body(s, encoder_ty, false)
|
||||
}
|
||||
|
||||
pub fn encodable_generic_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
|
||||
let encoder_ty = quote! { __E };
|
||||
s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_serialize::Encoder});
|
||||
s.add_bounds(synstructure::AddBounds::Generics);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue