diff options
| author | bors <bors@rust-lang.org> | 2022-06-03 17:55:02 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-06-03 17:55:02 +0000 |
| commit | 7e9b92cb43a489b34e2bcb8d21f36198e02eedbc (patch) | |
| tree | e2731c205d38c4d2c11fdb1789add435a21bab23 /compiler/rustc_macros/src/serialize.rs | |
| parent | 9a74608543d499bcc7dd505e195e8bfab9447315 (diff) | |
| parent | 5cc3593c17360edd92977301ca66551a45119619 (diff) | |
| download | rust-7e9b92cb43a489b34e2bcb8d21f36198e02eedbc.tar.gz rust-7e9b92cb43a489b34e2bcb8d21f36198e02eedbc.zip | |
Auto merge of #85993 - bjorn3:serde_json, r=wesleywiser
Remove all json handling from rustc_serialize Json is now handled using serde_json. Where appropriate I have replaced json usage with binary serialization (rmeta files) or manual string formatting (emcc linker arg generation). This allowed for removing and simplifying a lot of code, which hopefully results in faster serialization/deserialization and faster compiles of rustc itself. Where sensible we now use serde. Metadata and incr cache serialization keeps using a heavily modified (compared to crates.io) rustc-serialize version that in the future could probably be extended with zero-copy deserialization or other perf tricks that serde can't support due to supporting more than one serialization format. Note that I had to remove `-Zast-json` and `-Zast-json-noexpand` as the relevant AST types don't implement `serde::Serialize`. Fixes #40177 See also https://github.com/rust-lang/compiler-team/issues/418
Diffstat (limited to 'compiler/rustc_macros/src/serialize.rs')
| -rw-r--r-- | compiler/rustc_macros/src/serialize.rs | 44 |
1 files changed, 9 insertions, 35 deletions
diff --git a/compiler/rustc_macros/src/serialize.rs b/compiler/rustc_macros/src/serialize.rs index a39b4413981..e99fa6c113b 100644 --- a/compiler/rustc_macros/src/serialize.rs +++ b/compiler/rustc_macros/src/serialize.rs @@ -140,79 +140,56 @@ fn encodable_body( let encode_body = match s.variants() { [_] => { - let mut field_idx = 0usize; let encode_inner = s.each_variant(|vi| { vi.bindings() .iter() .map(|binding| { let bind_ident = &binding.binding; - let field_name = binding - .ast() - .ident - .as_ref() - .map_or_else(|| field_idx.to_string(), |i| i.to_string()); - let first = field_idx == 0; let result = quote! { - match ::rustc_serialize::Encoder::emit_struct_field( + match ::rustc_serialize::Encodable::<#encoder_ty>::encode( + #bind_ident, __encoder, - #field_name, - #first, - |__encoder| - ::rustc_serialize::Encodable::<#encoder_ty>::encode(#bind_ident, __encoder), ) { ::std::result::Result::Ok(()) => (), ::std::result::Result::Err(__err) => return ::std::result::Result::Err(__err), } }; - field_idx += 1; result }) .collect::<TokenStream>() }); - let no_fields = field_idx == 0; quote! { - ::rustc_serialize::Encoder::emit_struct(__encoder, #no_fields, |__encoder| { - ::std::result::Result::Ok(match *self { #encode_inner }) - }) + ::std::result::Result::Ok(match *self { #encode_inner }) } } _ => { let mut variant_idx = 0usize; let encode_inner = s.each_variant(|vi| { - let variant_name = vi.ast().ident.to_string(); - let mut field_idx = 0usize; - let encode_fields: TokenStream = vi .bindings() .iter() .map(|binding| { let bind_ident = &binding.binding; - let first = field_idx == 0; let result = quote! { - match ::rustc_serialize::Encoder::emit_enum_variant_arg( + match ::rustc_serialize::Encodable::<#encoder_ty>::encode( + #bind_ident, __encoder, - #first, - |__encoder| - ::rustc_serialize::Encodable::<#encoder_ty>::encode(#bind_ident, __encoder), ) { ::std::result::Result::Ok(()) => (), ::std::result::Result::Err(__err) => return ::std::result::Result::Err(__err), } }; - field_idx += 1; result }) .collect(); - let result = if field_idx != 0 { + let result = if !vi.bindings().is_empty() { quote! { ::rustc_serialize::Encoder::emit_enum_variant( __encoder, - #variant_name, #variant_idx, - #field_idx, |__encoder| { ::std::result::Result::Ok({ #encode_fields }) } ) } @@ -220,7 +197,6 @@ fn encodable_body( quote! { ::rustc_serialize::Encoder::emit_fieldless_enum_variant::<#variant_idx>( __encoder, - #variant_name, ) } }; @@ -228,11 +204,9 @@ fn encodable_body( result }); quote! { - ::rustc_serialize::Encoder::emit_enum(__encoder, |__encoder| { - match *self { - #encode_inner - } - }) + match *self { + #encode_inner + } } } }; |
