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 /src/test | |
| 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 'src/test')
| -rw-r--r-- | src/test/ui-fulldeps/extern-mod-syntax.rs | 4 | ||||
| -rw-r--r-- | src/test/ui-fulldeps/issue-11881.rs | 66 | ||||
| -rw-r--r-- | src/test/ui-fulldeps/issue-15924.rs | 43 | ||||
| -rw-r--r-- | src/test/ui-fulldeps/issue-2804.rs | 33 | ||||
| -rw-r--r-- | src/test/ui/ast-json/ast-json-ice.rs | 56 | ||||
| -rw-r--r-- | src/test/ui/ast-json/ast-json-noexpand-output.rs | 10 | ||||
| -rw-r--r-- | src/test/ui/ast-json/ast-json-noexpand-output.stdout | 1 | ||||
| -rw-r--r-- | src/test/ui/ast-json/ast-json-output.rs | 10 | ||||
| -rw-r--r-- | src/test/ui/ast-json/ast-json-output.stdout | 1 |
9 files changed, 111 insertions, 113 deletions
diff --git a/src/test/ui-fulldeps/extern-mod-syntax.rs b/src/test/ui-fulldeps/extern-mod-syntax.rs index a90ab7ac438..230194c5377 100644 --- a/src/test/ui-fulldeps/extern-mod-syntax.rs +++ b/src/test/ui-fulldeps/extern-mod-syntax.rs @@ -3,8 +3,8 @@ #![allow(unused_imports)] #![feature(rustc_private)] -extern crate rustc_serialize; -use rustc_serialize::json::Object; +extern crate libc; +use libc::c_void; pub fn main() { println!("Hello world!"); diff --git a/src/test/ui-fulldeps/issue-11881.rs b/src/test/ui-fulldeps/issue-11881.rs index 6d64aeeda7e..9641470a68b 100644 --- a/src/test/ui-fulldeps/issue-11881.rs +++ b/src/test/ui-fulldeps/issue-11881.rs @@ -3,42 +3,80 @@ #![allow(unused_must_use)] #![allow(dead_code)] #![allow(unused_imports)] -#![feature(rustc_private)] - -extern crate rustc_macros; -extern crate rustc_serialize; use std::fmt; use std::io::prelude::*; use std::io::Cursor; use std::slice; +use std::marker::PhantomData; + +trait Encoder { + type Error; +} + +trait Encodable<S: Encoder> { + fn encode(&self, s: &mut S) -> Result<(), S::Error>; +} + +struct JsonEncoder<'a>(PhantomData<&'a mut ()>); + +impl Encoder for JsonEncoder<'_> { + type Error = (); +} + +struct AsJson<'a, T> { + inner: &'a T, +} + +impl<'a, T: for<'r> Encodable<JsonEncoder<'r>>> fmt::Display for AsJson<'a, T> { + /// Encodes a json value into a string + fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { + Ok(()) + } +} + +fn as_json<T>(t: &T) -> AsJson<'_, T> { + AsJson { inner: t } +} + +struct OpaqueEncoder(Vec<u8>); + +impl Encoder for OpaqueEncoder { + type Error = (); +} -use rustc_macros::Encodable; -use rustc_serialize::json; -use rustc_serialize::opaque; -use rustc_serialize::{Encodable, Encoder}; -#[derive(Encodable)] struct Foo { baz: bool, } -#[derive(Encodable)] +impl<S: Encoder> Encodable<S> for Foo { + fn encode(&self, _s: &mut S) -> Result<(), S::Error> { + Ok(()) + } +} + struct Bar { froboz: usize, } +impl<S: Encoder> Encodable<S> for Bar { + fn encode(&self, _s: &mut S) -> Result<(), S::Error> { + Ok(()) + } +} + enum WireProtocol { JSON, Opaque, // ... } -fn encode_json<T: for<'a> Encodable<json::Encoder<'a>>>(val: &T, wr: &mut Cursor<Vec<u8>>) { - write!(wr, "{}", json::as_json(val)); +fn encode_json<T: for<'a> Encodable<JsonEncoder<'a>>>(val: &T, wr: &mut Cursor<Vec<u8>>) { + write!(wr, "{}", as_json(val)); } -fn encode_opaque<T: Encodable<opaque::Encoder>>(val: &T, wr: Vec<u8>) { - let mut encoder = opaque::Encoder::new(wr); +fn encode_opaque<T: Encodable<OpaqueEncoder>>(val: &T, wr: Vec<u8>) { + let mut encoder = OpaqueEncoder(wr); val.encode(&mut encoder); } diff --git a/src/test/ui-fulldeps/issue-15924.rs b/src/test/ui-fulldeps/issue-15924.rs index 5adc2c482f5..d8b3914d0d4 100644 --- a/src/test/ui-fulldeps/issue-15924.rs +++ b/src/test/ui-fulldeps/issue-15924.rs @@ -3,21 +3,48 @@ #![allow(unused_imports)] #![allow(unused_must_use)] // pretty-expanded FIXME #23616 -#![feature(rustc_private)] -extern crate rustc_serialize; - -use rustc_serialize::json; -use rustc_serialize::{Encodable, Encoder}; use std::fmt; +use std::marker::PhantomData; + +trait Encoder { + type Error; +} + +trait Encodable<S: Encoder> { + fn encode(&self, s: &mut S) -> Result<(), S::Error>; +} + +impl<S: Encoder> Encodable<S> for i32 { + fn encode(&self, _s: &mut S) -> Result<(), S::Error> { + Ok(()) + } +} + +struct JsonEncoder<'a>(PhantomData<&'a mut ()>); + +impl Encoder for JsonEncoder<'_> { + type Error = (); +} + +fn encode_json<T: for<'r> Encodable<JsonEncoder<'r>>>( + object: &T, +) -> Result<String, ()> { + let s = String::new(); + { + let mut encoder = JsonEncoder(PhantomData); + object.encode(&mut encoder)?; + } + Ok(s) +} -struct Foo<T: for<'a> Encodable<json::Encoder<'a>>> { +struct Foo<T: for<'a> Encodable<JsonEncoder<'a>>> { v: T, } -impl<T: for<'a> Encodable<json::Encoder<'a>>> Drop for Foo<T> { +impl<T: for<'a> Encodable<JsonEncoder<'a>>> Drop for Foo<T> { fn drop(&mut self) { - json::encode(&self.v); + encode_json(&self.v); } } diff --git a/src/test/ui-fulldeps/issue-2804.rs b/src/test/ui-fulldeps/issue-2804.rs index 3d5922d155f..571028c5e40 100644 --- a/src/test/ui-fulldeps/issue-2804.rs +++ b/src/test/ui-fulldeps/issue-2804.rs @@ -2,27 +2,38 @@ #![allow(non_camel_case_types)] #![allow(dead_code)] -#![feature(rustc_private)] -extern crate rustc_serialize; - -use std::collections::HashMap; -use rustc_serialize::json::{self, Json}; +use std::collections::{BTreeMap, HashMap}; use std::option; +#[derive(Clone, Debug)] +enum Json { + I64(i64), + U64(u64), + F64(f64), + String(String), + Boolean(bool), + Array(Array), + Object(Object), + Null, +} + +type Array = Vec<Json>; +type Object = BTreeMap<String, Json>; + enum object { bool_value(bool), int_value(i64), } -fn lookup(table: json::Object, key: String, default: String) -> String +fn lookup(table: Object, key: String, default: String) -> String { match table.get(&key) { option::Option::Some(&Json::String(ref s)) => { s.to_string() } option::Option::Some(value) => { - println!("{} was expected to be a string but is a {}", key, value); + println!("{} was expected to be a string but is a {:?}", key, value); default } option::Option::None => { @@ -31,7 +42,7 @@ fn lookup(table: json::Object, key: String, default: String) -> String } } -fn add_interface(_store: isize, managed_ip: String, data: json::Json) -> (String, object) +fn add_interface(_store: isize, managed_ip: String, data: Json) -> (String, object) { match &data { &Json::Object(ref interface) => { @@ -43,13 +54,13 @@ fn add_interface(_store: isize, managed_ip: String, data: json::Json) -> (String (label, object::bool_value(false)) } _ => { - println!("Expected dict for {} interfaces, found {}", managed_ip, data); + println!("Expected dict for {} interfaces, found {:?}", managed_ip, data); ("gnos:missing-interface".to_string(), object::bool_value(true)) } } } -fn add_interfaces(store: isize, managed_ip: String, device: HashMap<String, json::Json>) +fn add_interfaces(store: isize, managed_ip: String, device: HashMap<String, Json>) -> Vec<(String, object)> { match device["interfaces"] { Json::Array(ref interfaces) => @@ -60,7 +71,7 @@ fn add_interfaces(store: isize, managed_ip: String, device: HashMap<String, json } _ => { - println!("Expected list for {} interfaces, found {}", managed_ip, + println!("Expected list for {} interfaces, found {:?}", managed_ip, device["interfaces"]); Vec::new() } diff --git a/src/test/ui/ast-json/ast-json-ice.rs b/src/test/ui/ast-json/ast-json-ice.rs deleted file mode 100644 index ce93e4b5d4b..00000000000 --- a/src/test/ui/ast-json/ast-json-ice.rs +++ /dev/null @@ -1,56 +0,0 @@ -// Test that AST json serialization doesn't ICE (#63728). - -// revisions: expand noexpand - -//[expand] compile-flags: -Zast-json -//[noexpand] compile-flags: -Zast-json-noexpand - -// check-pass -// dont-check-compiler-stdout - don't check for any AST change. - -enum V { - A(i32), - B { f: [i64; 3 + 4] } -} - -trait X { - type Output; - fn read(&self) -> Self::Output; - fn write(&mut self, _: Self::Output); -} - -macro_rules! call_println { - ($y:ident) => { println!("{}", $y) } -} - -fn main() { - let x: (i32) = 35; - let y = x as i64<> + 5; - - call_println!(y); - - struct A; -} - -// Regressions tests for issues #78398 and #78510 (captured tokens in associated and foreign items) - -struct S; - -macro_rules! mac_extern { - ($i:item) => { - extern "C" { $i } - } -} -macro_rules! mac_assoc { - ($i:item) => { - impl S { $i } - trait Bar { $i } - } -} - -mac_extern! { - fn foo(); -} -mac_assoc! { - fn foo() {} -} diff --git a/src/test/ui/ast-json/ast-json-noexpand-output.rs b/src/test/ui/ast-json/ast-json-noexpand-output.rs deleted file mode 100644 index cba539f0065..00000000000 --- a/src/test/ui/ast-json/ast-json-noexpand-output.rs +++ /dev/null @@ -1,10 +0,0 @@ -// Check that AST json printing works. -#![crate_type = "lib"] - -// check-pass -// compile-flags: -Zast-json-noexpand -// normalize-stdout-test ":\d+" -> ":0" - -// Only include a single item to reduce how often the test output needs -// updating. -extern crate core; diff --git a/src/test/ui/ast-json/ast-json-noexpand-output.stdout b/src/test/ui/ast-json/ast-json-noexpand-output.stdout deleted file mode 100644 index 6f6e9b38e94..00000000000 --- a/src/test/ui/ast-json/ast-json-noexpand-output.stdout +++ /dev/null @@ -1 +0,0 @@ -{"attrs":[{"kind":{"variant":"Normal","fields":[{"path":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"crate_type","span":{"lo":0,"hi":0}},"id":0,"args":null}],"tokens":null},"args":{"variant":"Eq","fields":[{"lo":0,"hi":0},{"variant":"Ast","fields":[{"id":0,"kind":{"variant":"Lit","fields":[{"token":{"kind":"Str","symbol":"lib","suffix":null},"kind":{"variant":"Str","fields":["lib","Cooked"]},"span":{"lo":0,"hi":0}}]},"span":{"lo":0,"hi":0},"attrs":{"0":null},"tokens":{"0":[[{"variant":"Token","fields":[{"kind":{"variant":"Literal","fields":[{"kind":"Str","symbol":"lib","suffix":null}]},"span":{"lo":0,"hi":0}}]},"Alone"]]}}]}]},"tokens":null},{"0":[[{"variant":"Token","fields":[{"kind":"Pound","span":{"lo":0,"hi":0}}]},"Joint"],[{"variant":"Token","fields":[{"kind":"Not","span":{"lo":0,"hi":0}}]},"Alone"],[{"variant":"Delimited","fields":[{"open":{"lo":0,"hi":0},"close":{"lo":0,"hi":0}},"Bracket",{"0":[[{"variant":"Token","fields":[{"kind":{"variant":"Ident","fields":["crate_type",false]},"span":{"lo":0,"hi":0}}]},"Alone"],[{"variant":"Token","fields":[{"kind":"Eq","span":{"lo":0,"hi":0}}]},"Alone"],[{"variant":"Token","fields":[{"kind":{"variant":"Literal","fields":[{"kind":"Str","symbol":"lib","suffix":null}]},"span":{"lo":0,"hi":0}}]},"Alone"]]}]},"Alone"]]}]},"id":null,"style":"Inner","span":{"lo":0,"hi":0}}],"items":[{"attrs":[],"id":0,"span":{"lo":0,"hi":0},"vis":{"kind":"Inherited","span":{"lo":0,"hi":0},"tokens":null},"ident":{"name":"core","span":{"lo":0,"hi":0}},"kind":{"variant":"ExternCrate","fields":[null]},"tokens":null}],"spans":{"inner_span":{"lo":0,"hi":0},"inject_use_span":{"lo":0,"hi":0}},"id":0,"is_placeholder":false} diff --git a/src/test/ui/ast-json/ast-json-output.rs b/src/test/ui/ast-json/ast-json-output.rs deleted file mode 100644 index 2e009149ed6..00000000000 --- a/src/test/ui/ast-json/ast-json-output.rs +++ /dev/null @@ -1,10 +0,0 @@ -// Check that AST json printing works. -#![crate_type = "lib"] - -// check-pass -// compile-flags: -Zast-json -// normalize-stdout-test ":\d+" -> ":0" - -// Only include a single item to reduce how often the test output needs -// updating. -extern crate core; diff --git a/src/test/ui/ast-json/ast-json-output.stdout b/src/test/ui/ast-json/ast-json-output.stdout deleted file mode 100644 index 5637ce596b3..00000000000 --- a/src/test/ui/ast-json/ast-json-output.stdout +++ /dev/null @@ -1 +0,0 @@ -{"attrs":[{"kind":{"variant":"Normal","fields":[{"path":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"crate_type","span":{"lo":0,"hi":0}},"id":0,"args":null}],"tokens":null},"args":{"variant":"Eq","fields":[{"lo":0,"hi":0},{"variant":"Ast","fields":[{"id":0,"kind":{"variant":"Lit","fields":[{"token":{"kind":"Str","symbol":"lib","suffix":null},"kind":{"variant":"Str","fields":["lib","Cooked"]},"span":{"lo":0,"hi":0}}]},"span":{"lo":0,"hi":0},"attrs":{"0":null},"tokens":{"0":[[{"variant":"Token","fields":[{"kind":{"variant":"Literal","fields":[{"kind":"Str","symbol":"lib","suffix":null}]},"span":{"lo":0,"hi":0}}]},"Alone"]]}}]}]},"tokens":null},{"0":[[{"variant":"Token","fields":[{"kind":"Pound","span":{"lo":0,"hi":0}}]},"Joint"],[{"variant":"Token","fields":[{"kind":"Not","span":{"lo":0,"hi":0}}]},"Alone"],[{"variant":"Delimited","fields":[{"open":{"lo":0,"hi":0},"close":{"lo":0,"hi":0}},"Bracket",{"0":[[{"variant":"Token","fields":[{"kind":{"variant":"Ident","fields":["crate_type",false]},"span":{"lo":0,"hi":0}}]},"Alone"],[{"variant":"Token","fields":[{"kind":"Eq","span":{"lo":0,"hi":0}}]},"Alone"],[{"variant":"Token","fields":[{"kind":{"variant":"Literal","fields":[{"kind":"Str","symbol":"lib","suffix":null}]},"span":{"lo":0,"hi":0}}]},"Alone"]]}]},"Alone"]]}]},"id":null,"style":"Inner","span":{"lo":0,"hi":0}}],"items":[{"attrs":[{"kind":{"variant":"Normal","fields":[{"path":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"prelude_import","span":{"lo":0,"hi":0}},"id":0,"args":null}],"tokens":null},"args":"Empty","tokens":null},null]},"id":null,"style":"Outer","span":{"lo":0,"hi":0}}],"id":0,"span":{"lo":0,"hi":0},"vis":{"kind":"Inherited","span":{"lo":0,"hi":0},"tokens":null},"ident":{"name":"","span":{"lo":0,"hi":0}},"kind":{"variant":"Use","fields":[{"prefix":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"{{root}}","span":{"lo":0,"hi":0}},"id":0,"args":null},{"ident":{"name":"std","span":{"lo":0,"hi":0}},"id":0,"args":null},{"ident":{"name":"prelude","span":{"lo":0,"hi":0}},"id":0,"args":null},{"ident":{"name":"rust_2015","span":{"lo":0,"hi":0}},"id":0,"args":null}],"tokens":null},"kind":"Glob","span":{"lo":0,"hi":0}}]},"tokens":null},{"attrs":[{"kind":{"variant":"Normal","fields":[{"path":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"macro_use","span":{"lo":0,"hi":0}},"id":0,"args":null}],"tokens":null},"args":"Empty","tokens":null},null]},"id":null,"style":"Outer","span":{"lo":0,"hi":0}}],"id":0,"span":{"lo":0,"hi":0},"vis":{"kind":"Inherited","span":{"lo":0,"hi":0},"tokens":null},"ident":{"name":"std","span":{"lo":0,"hi":0}},"kind":{"variant":"ExternCrate","fields":[null]},"tokens":null},{"attrs":[],"id":0,"span":{"lo":0,"hi":0},"vis":{"kind":"Inherited","span":{"lo":0,"hi":0},"tokens":null},"ident":{"name":"core","span":{"lo":0,"hi":0}},"kind":{"variant":"ExternCrate","fields":[null]},"tokens":null}],"spans":{"inner_span":{"lo":0,"hi":0},"inject_use_span":{"lo":0,"hi":0}},"id":0,"is_placeholder":false} |
