diff options
| author | bors <bors@rust-lang.org> | 2024-01-06 09:56:00 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-01-06 09:56:00 +0000 |
| commit | e21f4cd98fcf03fb7895f13421699f58132e4beb (patch) | |
| tree | 335591df79611c47f490696a7da548e097b77e38 /compiler/rustc_macros/src | |
| parent | 5cb2e7dfc362662b0036faad3bab88d73027fd05 (diff) | |
| parent | 8fb8e6eefb27313523be937ff9de557dd3bcf4fe (diff) | |
| download | rust-e21f4cd98fcf03fb7895f13421699f58132e4beb.tar.gz rust-e21f4cd98fcf03fb7895f13421699f58132e4beb.zip | |
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.
Diffstat (limited to 'compiler/rustc_macros/src')
| -rw-r--r-- | compiler/rustc_macros/src/lib.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_macros/src/serialize.rs | 16 |
2 files changed, 18 insertions, 0 deletions
diff --git a/compiler/rustc_macros/src/lib.rs b/compiler/rustc_macros/src/lib.rs index f558b74be9a..f5d942b924e 100644 --- a/compiler/rustc_macros/src/lib.rs +++ b/compiler/rustc_macros/src/lib.rs @@ -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); diff --git a/compiler/rustc_macros/src/serialize.rs b/compiler/rustc_macros/src/serialize.rs index 047066ac681..9ca7ce09ba6 100644 --- a/compiler/rustc_macros/src/serialize.rs +++ b/compiler/rustc_macros/src/serialize.rs @@ -32,6 +32,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); @@ -130,6 +138,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); |
