mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1550640 - P4: Remove bincode. r=Gankro
Differential Revision: https://phabricator.services.mozilla.com/D32783 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
866dcdad61
commit
be87d8ce17
25
Cargo.lock
generated
25
Cargo.lock
generated
@ -106,7 +106,7 @@ dependencies = [
|
||||
"mio-named-pipes 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"scoped-tls 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.88 (git+https://github.com/servo/serde?branch=deserialize_from_enums10)",
|
||||
"serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio-core 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio-io 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio-uds 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -315,7 +315,7 @@ dependencies = [
|
||||
"filetime_win 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"guid_win 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.88 (git+https://github.com/servo/serde?branch=deserialize_from_enums10)",
|
||||
"serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.6 (git+https://github.com/froydnj/winapi-rs?branch=aarch64)",
|
||||
]
|
||||
|
||||
@ -976,7 +976,7 @@ dependencies = [
|
||||
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.88 (git+https://github.com/servo/serde?branch=deserialize_from_enums10)",
|
||||
"serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.6 (git+https://github.com/froydnj/winapi-rs?branch=aarch64)",
|
||||
]
|
||||
|
||||
@ -1183,7 +1183,7 @@ dependencies = [
|
||||
"mozversion 0.2.0",
|
||||
"regex 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.88 (git+https://github.com/servo/serde?branch=deserialize_from_enums10)",
|
||||
"serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"uuid 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"webdriver 0.39.0",
|
||||
@ -1911,7 +1911,7 @@ dependencies = [
|
||||
"proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.88 (git+https://github.com/servo/serde?branch=deserialize_from_enums10)",
|
||||
"serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.6 (git+https://github.com/froydnj/winapi-rs?branch=aarch64)",
|
||||
@ -2592,7 +2592,7 @@ dependencies = [
|
||||
"lmdb-rkv 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ordered-float 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.88 (git+https://github.com/servo/serde?branch=deserialize_from_enums10)",
|
||||
"serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@ -2759,7 +2759,7 @@ name = "serde"
|
||||
version = "1.0.88"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"serde_derive 1.0.88 (git+https://github.com/servo/serde?branch=deserialize_from_enums10)",
|
||||
"serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2773,7 +2773,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.88"
|
||||
source = "git+https://github.com/servo/serde?branch=deserialize_from_enums10#84b2795d2a7b5312125a99b1ef11c67fd8d17c35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -3594,7 +3594,7 @@ dependencies = [
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.88 (git+https://github.com/servo/serde?branch=deserialize_from_enums10)",
|
||||
"serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -3648,7 +3648,6 @@ name = "webrender_api"
|
||||
version = "0.60.0"
|
||||
dependencies = [
|
||||
"app_units 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bincode 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"core-foundation 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -3659,7 +3658,7 @@ dependencies = [
|
||||
"peek-poke 0.2.0",
|
||||
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_bytes 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.88 (git+https://github.com/servo/serde?branch=deserialize_from_enums10)",
|
||||
"serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wr_malloc_size_of 0.0.1",
|
||||
]
|
||||
@ -3700,7 +3699,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.88 (git+https://github.com/servo/serde?branch=deserialize_from_enums10)",
|
||||
"serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@ -4127,7 +4126,7 @@ dependencies = [
|
||||
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
"checksum serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)" = "9f301d728f2b94c9a7691c90f07b0b4e8a4517181d9461be94c04bddeb4bd850"
|
||||
"checksum serde_bytes 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)" = "adb6e51a6b3696b301bc221d785f898b4457c619b51d7ce195a6d20baecb37b3"
|
||||
"checksum serde_derive 1.0.88 (git+https://github.com/servo/serde?branch=deserialize_from_enums10)" = "<none>"
|
||||
"checksum serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)" = "beed18e6f5175aef3ba670e57c60ef3b1b74d250d962a26604bff4c80e970dd4"
|
||||
"checksum serde_json 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)" = "44dd2cfde475037451fa99b7e5df77aa3cfd1536575fa8e7a538ab36dcde49ae"
|
||||
"checksum serde_repr 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "29a734c298df0346c4cd5919595981c266dabbf12dc747c85e1a95e96077a52b"
|
||||
"checksum serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "642dd69105886af2efd227f75a520ec9b44a820d65bc133a9131f7d229fd165a"
|
||||
|
@ -58,7 +58,6 @@ codegen-units = 1
|
||||
|
||||
[patch.crates-io]
|
||||
libudev-sys = { path = "dom/webauthn/libudev-sys" }
|
||||
serde_derive = { git = "https://github.com/servo/serde", branch = "deserialize_from_enums10" }
|
||||
winapi = { git = "https://github.com/froydnj/winapi-rs", branch = "aarch64" }
|
||||
packed_simd = { git = "https://github.com/hsivonen/packed_simd", branch = "rust_1_32" }
|
||||
|
||||
|
17
gfx/wr/Cargo.lock
generated
17
gfx/wr/Cargo.lock
generated
@ -462,7 +462,7 @@ dependencies = [
|
||||
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.88 (git+https://github.com/servo/serde?branch=deserialize_from_enums10)",
|
||||
"serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@ -1186,7 +1186,7 @@ dependencies = [
|
||||
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lyon_path 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.88 (git+https://github.com/servo/serde?branch=deserialize_from_enums10)",
|
||||
"serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@ -1215,7 +1215,7 @@ dependencies = [
|
||||
"lyon_path 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pathfinder_path_utils 0.2.0 (git+https://github.com/pcwalton/pathfinder?branch=webrender)",
|
||||
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.88 (git+https://github.com/servo/serde?branch=deserialize_from_enums10)",
|
||||
"serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1226,7 +1226,7 @@ dependencies = [
|
||||
"arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lyon_path 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.88 (git+https://github.com/servo/serde?branch=deserialize_from_enums10)",
|
||||
"serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1575,7 +1575,7 @@ name = "serde"
|
||||
version = "1.0.88"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"serde_derive 1.0.88 (git+https://github.com/servo/serde?branch=deserialize_from_enums10)",
|
||||
"serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1589,7 +1589,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.88"
|
||||
source = "git+https://github.com/servo/serde?branch=deserialize_from_enums10#84b2795d2a7b5312125a99b1ef11c67fd8d17c35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -2028,7 +2028,6 @@ name = "webrender_api"
|
||||
version = "0.60.0"
|
||||
dependencies = [
|
||||
"app_units 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bincode 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"core-foundation 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -2040,7 +2039,7 @@ dependencies = [
|
||||
"peek-poke 0.2.0",
|
||||
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_bytes 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.88 (git+https://github.com/servo/serde?branch=deserialize_from_enums10)",
|
||||
"serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wr_malloc_size_of 0.0.1",
|
||||
]
|
||||
@ -2414,7 +2413,7 @@ dependencies = [
|
||||
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
"checksum serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)" = "9f301d728f2b94c9a7691c90f07b0b4e8a4517181d9461be94c04bddeb4bd850"
|
||||
"checksum serde_bytes 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)" = "adb6e51a6b3696b301bc221d785f898b4457c619b51d7ce195a6d20baecb37b3"
|
||||
"checksum serde_derive 1.0.88 (git+https://github.com/servo/serde?branch=deserialize_from_enums10)" = "<none>"
|
||||
"checksum serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)" = "beed18e6f5175aef3ba670e57c60ef3b1b74d250d962a26604bff4c80e970dd4"
|
||||
"checksum serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "f3ad6d546e765177cf3dded3c2e424a8040f870083a0e64064746b958ece9cb1"
|
||||
"checksum servo-fontconfig 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a088f8d775a5c5314aae09bd77340bc9c67d72b9a45258be34c83548b4814cd9"
|
||||
"checksum servo-fontconfig-sys 4.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "38b494f03009ee81914b0e7d387ad7c145cafcd69747c2ec89b0e17bb94f303a"
|
||||
|
@ -13,6 +13,3 @@ panic = "abort"
|
||||
|
||||
[profile.dev]
|
||||
panic = "abort"
|
||||
|
||||
[patch.crates-io]
|
||||
serde_derive = { git = "https://github.com/servo/serde", branch = "deserialize_from_enums10", feature="deserialize_in_place" }
|
||||
|
@ -16,7 +16,6 @@ display_list_stats = []
|
||||
|
||||
[dependencies]
|
||||
app_units = "0.7"
|
||||
bincode = "1.0"
|
||||
bitflags = "1.0"
|
||||
byteorder = "1.2.1"
|
||||
derive_more = "0.13"
|
||||
@ -24,7 +23,7 @@ ipc-channel = {version = "0.11.0", optional = true}
|
||||
euclid = { version = "0.19.9", features = ["serde"] }
|
||||
malloc_size_of_derive = "0.1"
|
||||
serde = { version = "=1.0.88", features = ["rc"] }
|
||||
serde_derive = { version = "=1.0.88", features = ["deserialize_in_place"] }
|
||||
serde_derive = "=1.0.88"
|
||||
serde_bytes = "0.10"
|
||||
time = "0.1"
|
||||
malloc_size_of = { version = "0.0.1", path = "../wr_malloc_size_of", package = "wr_malloc_size_of" }
|
||||
|
@ -2,7 +2,6 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use bincode;
|
||||
use euclid::SideOffsets2D;
|
||||
use peek_poke::{ensure_red_zone, peek_from_slice, poke_extend_vec};
|
||||
use peek_poke::{poke_inplace_slice, poke_into_vec, Poke};
|
||||
@ -11,10 +10,10 @@ use serde::de::Deserializer;
|
||||
#[cfg(feature = "serialize")]
|
||||
use serde::ser::{Serializer, SerializeSeq};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::io::{Read, stdout, Write};
|
||||
use std::io::{stdout, Write};
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::Range;
|
||||
use std::{io, mem, ptr, slice};
|
||||
use std::mem;
|
||||
use std::collections::HashMap;
|
||||
use time::precise_time_ns;
|
||||
// local imports
|
||||
@ -753,149 +752,6 @@ impl<'de> Deserialize<'de> for BuiltDisplayList {
|
||||
}
|
||||
}
|
||||
|
||||
// This is a replacement for bincode::serialize_into(&vec)
|
||||
// The default implementation Write for Vec will basically
|
||||
// call extend_from_slice(). Serde ends up calling that for every
|
||||
// field of a struct that we're serializing. extend_from_slice()
|
||||
// does not get inlined and thus we end up calling a generic memcpy()
|
||||
// implementation. If we instead reserve enough room for the serialized
|
||||
// struct in the Vec ahead of time we can rely on that and use
|
||||
// the following UnsafeVecWriter to write into the vec without
|
||||
// any checks. This writer assumes that size returned by the
|
||||
// serialize function will not change between calls to serialize_into:
|
||||
//
|
||||
// For example, the following struct will cause memory unsafety when
|
||||
// used with UnsafeVecWriter.
|
||||
//
|
||||
// struct S {
|
||||
// first: Cell<bool>,
|
||||
// }
|
||||
//
|
||||
// impl Serialize for S {
|
||||
// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
// where S: Serializer
|
||||
// {
|
||||
// if self.first.get() {
|
||||
// self.first.set(false);
|
||||
// ().serialize(serializer)
|
||||
// } else {
|
||||
// 0.serialize(serializer)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
|
||||
struct UnsafeVecWriter(*mut u8);
|
||||
|
||||
impl Write for UnsafeVecWriter {
|
||||
#[inline(always)]
|
||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||
unsafe {
|
||||
ptr::copy_nonoverlapping(buf.as_ptr(), self.0, buf.len());
|
||||
self.0 = self.0.add(buf.len());
|
||||
}
|
||||
Ok(buf.len())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
|
||||
unsafe {
|
||||
ptr::copy_nonoverlapping(buf.as_ptr(), self.0, buf.len());
|
||||
self.0 = self.0.add(buf.len());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn flush(&mut self) -> io::Result<()> { Ok(()) }
|
||||
}
|
||||
|
||||
struct SizeCounter(usize);
|
||||
|
||||
impl<'a> Write for SizeCounter {
|
||||
#[inline(always)]
|
||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||
self.0 += buf.len();
|
||||
Ok(buf.len())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
|
||||
self.0 += buf.len();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn flush(&mut self) -> io::Result<()> { Ok(()) }
|
||||
}
|
||||
|
||||
// This uses a (start, end) representation instead of (start, len) so that
|
||||
// only need to update a single field as we read through it. This
|
||||
// makes it easier for llvm to understand what's going on. (https://github.com/rust-lang/rust/issues/45068)
|
||||
// We update the slice only once we're done reading
|
||||
struct UnsafeReader<'a: 'b, 'b> {
|
||||
start: *const u8,
|
||||
end: *const u8,
|
||||
slice: &'b mut &'a [u8],
|
||||
}
|
||||
|
||||
impl<'a, 'b> UnsafeReader<'a, 'b> {
|
||||
#[inline(always)]
|
||||
fn new(buf: &'b mut &'a [u8]) -> UnsafeReader<'a, 'b> {
|
||||
unsafe {
|
||||
let end = buf.as_ptr().add(buf.len());
|
||||
let start = buf.as_ptr();
|
||||
UnsafeReader { start, end, slice: buf }
|
||||
}
|
||||
}
|
||||
|
||||
// This read implementation is significantly faster than the standard &[u8] one.
|
||||
//
|
||||
// First, it only supports reading exactly buf.len() bytes. This ensures that
|
||||
// the argument to memcpy is always buf.len() and will allow a constant buf.len()
|
||||
// to be propagated through to memcpy which LLVM will turn into explicit loads and
|
||||
// stores. The standard implementation does a len = min(slice.len(), buf.len())
|
||||
//
|
||||
// Second, we only need to adjust 'start' after reading and it's only adjusted by a
|
||||
// constant. This allows LLVM to avoid adjusting the length field after ever read
|
||||
// and lets it be aggregated into a single adjustment.
|
||||
#[inline(always)]
|
||||
fn read_internal(&mut self, buf: &mut [u8]) {
|
||||
// this is safe because we panic if start + buf.len() > end
|
||||
unsafe {
|
||||
assert!(self.start.add(buf.len()) <= self.end, "UnsafeReader: read past end of target");
|
||||
ptr::copy_nonoverlapping(self.start, buf.as_mut_ptr(), buf.len());
|
||||
self.start = self.start.add(buf.len());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> Drop for UnsafeReader<'a, 'b> {
|
||||
// this adjusts input slice so that it properly represents the amount that's left.
|
||||
#[inline(always)]
|
||||
fn drop(&mut self) {
|
||||
// this is safe because we know that start and end are contained inside the original slice
|
||||
unsafe {
|
||||
*self.slice = slice::from_raw_parts(self.start, (self.end as usize) - (self.start as usize));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> Read for UnsafeReader<'a, 'b> {
|
||||
// These methods were not being inlined and we need them to be so that the memcpy
|
||||
// is for a constant size
|
||||
#[inline(always)]
|
||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
self.read_internal(buf);
|
||||
Ok(buf.len())
|
||||
}
|
||||
#[inline(always)]
|
||||
fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
|
||||
self.read_internal(buf);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SaveState {
|
||||
dl_len: usize,
|
||||
|
@ -15,7 +15,6 @@
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(float_cmp, too_many_arguments, unreadable_literal))]
|
||||
|
||||
extern crate app_units;
|
||||
extern crate bincode;
|
||||
#[macro_use]
|
||||
extern crate bitflags;
|
||||
extern crate byteorder;
|
||||
|
@ -1 +1 @@
|
||||
{"files":{"Cargo.toml":"071ea0d1ef1e899f01b0e90383b7dfefdf1b23c733444c59815ce345e7833054","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"11f6eec1a694070311f8ff191c53e67b90bf1d5064f32d684a1b73b1c3264ac1","crates-io.md":"131dee2d4beaf83485aed22942b98815ef65af9bcfb65f02b5b90c59b8bc7b8b","src/bound.rs":"47b4018d54220862c2546589fe3cbccdd72c5d90438c265c258c1a2ee98e9210","src/de.rs":"09ba5a4cab60dfc713ea66f69d1989786a913e060f1ec6f9b701e83f37448931","src/dummy.rs":"413f639118681cecff6188e790c88636e34dd8e1b247bbbaa7b6a121b5cf6921","src/fragment.rs":"5819ac5b16f5945c05ce47c3370745f2e73deb415367ae6afbd8208867f611d2","src/internals/ast.rs":"64cd449a627a3489053407735f0d1de669272d879a75afc66051e323a1c1ebd4","src/internals/attr.rs":"f95eb8481822f4b5eca5e28483469c020d73335d60980cb20e1c28a073b90f52","src/internals/case.rs":"b2024f414f5d832bafa53b9ae7924b2d43a29175b19bb3da36f15c9071666558","src/internals/check.rs":"d101f08b2bd007602c4a7b3f6ae2d4cb9fbe0c179cde55809a666ed4a7043a12","src/internals/ctxt.rs":"ceb74c96802f89de896a30b774b49d4954d6c3344596cbbc1ff8fad2ac754fe1","src/internals/mod.rs":"8e363739bbfcd43bcaedd1746b2d17cebd5964167c145bd0db473f0ff4521edc","src/lib.rs":"fd6883d899ea98448aee074374388fdfd8792363928cc1ddd3812737c5921a76","src/pretend.rs":"ea5aa1b338038ce1791cef34fd20091abb062cd61c0384ac931d0069413a5302","src/ser.rs":"843b2a66a17511640c4e5ebd08e16b8f58f9772c7a8283e1bb2f043b302f21be","src/try.rs":"b9a10c8690d442a57fc7097d42c9a4f13034c7b4a30b7eb02d538fdbf8ae0a8d"},"package":null}
|
||||
{"files":{"Cargo.toml":"e32cf0f1999d39d32e222b28b26ccc431533204f6ae4f96afc55f0231900126b","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"11f6eec1a694070311f8ff191c53e67b90bf1d5064f32d684a1b73b1c3264ac1","crates-io.md":"131dee2d4beaf83485aed22942b98815ef65af9bcfb65f02b5b90c59b8bc7b8b","src/bound.rs":"346f20898b86432bad7ea86207b0b395d52fe804cb4b0f9805ba6f3ff58f9cd0","src/de.rs":"c7fba9a1206b11a17bd6445a9d6945f5171c7e81587f90aaf26732f50126dad7","src/dummy.rs":"413f639118681cecff6188e790c88636e34dd8e1b247bbbaa7b6a121b5cf6921","src/fragment.rs":"5819ac5b16f5945c05ce47c3370745f2e73deb415367ae6afbd8208867f611d2","src/internals/ast.rs":"b0a791275ea3d6f0e7b698e0758757dc6a4a5ce25ae45a9adfe70c1ac878fb34","src/internals/attr.rs":"f95eb8481822f4b5eca5e28483469c020d73335d60980cb20e1c28a073b90f52","src/internals/case.rs":"b2024f414f5d832bafa53b9ae7924b2d43a29175b19bb3da36f15c9071666558","src/internals/check.rs":"5beb3d32fcdf689dfce60eb4d5cf8f0167dcde3286e8075f8e40cb4aa714b8ad","src/internals/ctxt.rs":"ceb74c96802f89de896a30b774b49d4954d6c3344596cbbc1ff8fad2ac754fe1","src/internals/mod.rs":"8e363739bbfcd43bcaedd1746b2d17cebd5964167c145bd0db473f0ff4521edc","src/lib.rs":"fd6883d899ea98448aee074374388fdfd8792363928cc1ddd3812737c5921a76","src/pretend.rs":"24c7c4168cf176e77e718627ab81c1055481187d1551282f20416c01af895891","src/ser.rs":"1ee1499c317f5c8fadc21cb60ee9f114a748a17da4a52219ed03ec7eb3f894a8","src/try.rs":"b9a10c8690d442a57fc7097d42c9a4f13034c7b4a30b7eb02d538fdbf8ae0a8d"},"package":"beed18e6f5175aef3ba670e57c60ef3b1b74d250d962a26604bff4c80e970dd4"}
|
54
third_party/rust/serde_derive/Cargo.toml
vendored
54
third_party/rust/serde_derive/Cargo.toml
vendored
@ -1,32 +1,48 @@
|
||||
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
||||
#
|
||||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g. crates.io) dependencies
|
||||
#
|
||||
# If you believe there's an error in this file please file an
|
||||
# issue against the rust-lang/cargo repository. If you're
|
||||
# editing this file be aware that the upstream Cargo.toml
|
||||
# will likely look very different (and much more reasonable)
|
||||
|
||||
[package]
|
||||
name = "serde_derive"
|
||||
version = "1.0.88" # remember to update html_root_url
|
||||
version = "1.0.88"
|
||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||
license = "MIT/Apache-2.0"
|
||||
include = ["Cargo.toml", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
|
||||
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
||||
homepage = "https://serde.rs"
|
||||
repository = "https://github.com/serde-rs/serde"
|
||||
documentation = "https://serde.rs/derive.html"
|
||||
keywords = ["serde", "serialization", "no_std"]
|
||||
readme = "crates-io.md"
|
||||
include = ["Cargo.toml", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
|
||||
|
||||
[badges]
|
||||
travis-ci = { repository = "serde-rs/serde" }
|
||||
appveyor = { repository = "serde-rs/serde" }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
deserialize_in_place = []
|
||||
keywords = ["serde", "serialization", "no_std"]
|
||||
license = "MIT/Apache-2.0"
|
||||
repository = "https://github.com/serde-rs/serde"
|
||||
|
||||
[lib]
|
||||
name = "serde_derive"
|
||||
proc-macro = true
|
||||
[dependencies.proc-macro2]
|
||||
version = "0.4"
|
||||
|
||||
[dependencies]
|
||||
proc-macro2 = "0.4"
|
||||
quote = "0.6.3"
|
||||
syn = { version = "0.15.22", features = ["visit", "extra-traits"] }
|
||||
[dependencies.quote]
|
||||
version = "0.6.3"
|
||||
|
||||
[dev-dependencies]
|
||||
serde = { version = "1.0", path = "../serde" }
|
||||
[dependencies.syn]
|
||||
version = "0.15.22"
|
||||
features = ["visit"]
|
||||
[dev-dependencies.serde]
|
||||
version = "1.0"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
deserialize_in_place = []
|
||||
[badges.appveyor]
|
||||
repository = "serde-rs/serde"
|
||||
|
||||
[badges.travis-ci]
|
||||
repository = "serde-rs/serde"
|
||||
|
4
third_party/rust/serde_derive/src/bound.rs
vendored
4
third_party/rust/serde_derive/src/bound.rs
vendored
@ -64,7 +64,7 @@ pub fn with_where_predicates_from_variants(
|
||||
from_variant: fn(&attr::Variant) -> Option<&[syn::WherePredicate]>,
|
||||
) -> syn::Generics {
|
||||
let variants = match cont.data {
|
||||
Data::Enum(_, ref variants) => variants,
|
||||
Data::Enum(ref variants) => variants,
|
||||
Data::Struct(_, _) => {
|
||||
return generics.clone();
|
||||
}
|
||||
@ -161,7 +161,7 @@ pub fn with_bound(
|
||||
associated_type_usage: Vec::new(),
|
||||
};
|
||||
match cont.data {
|
||||
Data::Enum(_, ref variants) => {
|
||||
Data::Enum(ref variants) => {
|
||||
for variant in variants.iter() {
|
||||
let relevant_fields = variant
|
||||
.fields
|
||||
|
394
third_party/rust/serde_derive/src/de.rs
vendored
394
third_party/rust/serde_derive/src/de.rs
vendored
@ -11,10 +11,6 @@ use internals::ast::{Container, Data, Field, Style, Variant};
|
||||
use internals::{attr, Ctxt, Derive};
|
||||
use pretend;
|
||||
|
||||
#[cfg(feature = "deserialize_in_place")]
|
||||
use internals::ast::Repr;
|
||||
|
||||
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
pub fn expand_derive_deserialize(input: &syn::DeriveInput) -> Result<TokenStream, Vec<syn::Error>> {
|
||||
@ -99,7 +95,6 @@ fn precondition_no_de_lifetime(cx: &Ctxt, cont: &Container) {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Parameters {
|
||||
/// Name of the type the `derive` is on.
|
||||
local: syn::Ident,
|
||||
@ -214,7 +209,6 @@ fn requires_default(field: &attr::Field, _variant: Option<&attr::Variant>) -> bo
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
enum BorrowedLifetimes {
|
||||
Borrowed(BTreeSet<syn::Lifetime>),
|
||||
Static,
|
||||
@ -271,7 +265,7 @@ fn deserialize_body(cont: &Container, params: &Parameters) -> Fragment {
|
||||
deserialize_from(type_from)
|
||||
} else if let attr::Identifier::No = cont.attrs.identifier() {
|
||||
match cont.data {
|
||||
Data::Enum(_, ref variants) => deserialize_enum(params, variants, &cont.attrs),
|
||||
Data::Enum(ref variants) => deserialize_enum(params, variants, &cont.attrs),
|
||||
Data::Struct(Style::Struct, ref fields) => {
|
||||
deserialize_struct(None, params, fields, &cont.attrs, None, &Untagged::No)
|
||||
}
|
||||
@ -282,7 +276,7 @@ fn deserialize_body(cont: &Container, params: &Parameters) -> Fragment {
|
||||
}
|
||||
} else {
|
||||
match cont.data {
|
||||
Data::Enum(_, ref variants) => {
|
||||
Data::Enum(ref variants) => {
|
||||
deserialize_custom_identifier(params, variants, &cont.attrs)
|
||||
}
|
||||
Data::Struct(_, _) => unreachable!("checked in serde_derive_internals"),
|
||||
@ -319,14 +313,7 @@ fn deserialize_in_place_body(cont: &Container, params: &Parameters) -> Option<St
|
||||
Data::Struct(Style::Tuple, ref fields) | Data::Struct(Style::Newtype, ref fields) => {
|
||||
deserialize_tuple_in_place(None, params, fields, &cont.attrs, None)
|
||||
}
|
||||
Data::Enum(ref repr, ref variants) => {
|
||||
if let Some(x) = deserialize_enum_in_place(params, repr, variants, &cont.attrs) {
|
||||
x
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
Data::Struct(Style::Unit, _) => {
|
||||
Data::Enum(_) | Data::Struct(Style::Unit, _) => {
|
||||
return None;
|
||||
}
|
||||
};
|
||||
@ -354,7 +341,7 @@ fn deserialize_in_place_body(_cont: &Container, _params: &Parameters) -> Option<
|
||||
fn deserialize_transparent(cont: &Container, params: &Parameters) -> Fragment {
|
||||
let fields = match cont.data {
|
||||
Data::Struct(_, ref fields) => fields,
|
||||
Data::Enum(_, _) => unreachable!(),
|
||||
Data::Enum(_) => unreachable!(),
|
||||
};
|
||||
|
||||
let this = ¶ms.this;
|
||||
@ -554,28 +541,19 @@ fn deserialize_tuple_in_place(
|
||||
None
|
||||
};
|
||||
|
||||
let visit_seq = Stmts(deserialize_seq_in_place(params, fields, is_enum, cattrs, &expecting));
|
||||
let visit_seq = Stmts(deserialize_seq_in_place(params, fields, cattrs, &expecting));
|
||||
|
||||
let visitor_expr = if is_enum {
|
||||
quote! {
|
||||
__Visitor {
|
||||
place: this,
|
||||
lifetime: _serde::export::PhantomData,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
__Visitor {
|
||||
place: __place,
|
||||
lifetime: _serde::export::PhantomData,
|
||||
}
|
||||
let visitor_expr = quote! {
|
||||
__Visitor {
|
||||
place: __place,
|
||||
lifetime: _serde::export::PhantomData,
|
||||
}
|
||||
};
|
||||
|
||||
let dispatch = if let Some(deserializer) = deserializer {
|
||||
quote!(_serde::Deserializer::deserialize_tuple(#deserializer, #nfields, #visitor_expr))
|
||||
} else if is_enum {
|
||||
quote!(try!(_serde::de::VariantAccess::tuple_variant(__variant, #nfields, #visitor_expr)))
|
||||
quote!(_serde::de::VariantAccess::tuple_variant(__variant, #nfields, #visitor_expr))
|
||||
} else if nfields == 1 {
|
||||
let type_name = cattrs.name().deserialize_name();
|
||||
quote!(_serde::Deserializer::deserialize_newtype_struct(__deserializer, #type_name, #visitor_expr))
|
||||
@ -732,11 +710,9 @@ fn deserialize_seq(
|
||||
fn deserialize_seq_in_place(
|
||||
params: &Parameters,
|
||||
fields: &[Field],
|
||||
_increment_fields: bool, // FIXME: Not needed anymore?
|
||||
cattrs: &attr::Container,
|
||||
expecting: &str,
|
||||
) -> Fragment {
|
||||
// For enums there's a secret `tag` field at the start which we shouldn't touch,
|
||||
let deserialized_count = fields
|
||||
.iter()
|
||||
.filter(|field| !field.attrs.skip_deserializing())
|
||||
@ -1063,7 +1039,7 @@ fn deserialize_struct_in_place(
|
||||
None => format!("struct {}", params.type_name()),
|
||||
};
|
||||
|
||||
let visit_seq = Stmts(deserialize_seq_in_place(params, fields, false, cattrs, &expecting));
|
||||
let visit_seq = Stmts(deserialize_seq_in_place(params, fields, cattrs, &expecting));
|
||||
|
||||
let (field_visitor, fields_stmt, visit_map) =
|
||||
deserialize_struct_as_struct_in_place_visitor(params, fields, cattrs);
|
||||
@ -1164,19 +1140,6 @@ fn deserialize_enum(
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "deserialize_in_place")]
|
||||
fn deserialize_enum_in_place(
|
||||
params: &Parameters,
|
||||
repr: &Repr,
|
||||
variants: &[Variant],
|
||||
cattrs: &attr::Container,
|
||||
) -> Option<Fragment> {
|
||||
match *cattrs.tag() {
|
||||
attr::TagType::External => deserialize_externally_tagged_enum_in_place(params, repr, variants, cattrs),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn prepare_enum_variant_enum(
|
||||
variants: &[Variant],
|
||||
cattrs: &attr::Container,
|
||||
@ -1306,259 +1269,6 @@ fn deserialize_externally_tagged_enum(
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "deserialize_in_place")]
|
||||
fn deserialize_externally_tagged_enum_in_place(
|
||||
params: &Parameters,
|
||||
repr: &Repr,
|
||||
variants: &[Variant],
|
||||
cattrs: &attr::Container,
|
||||
) -> Option<Fragment> {
|
||||
let int_repr = repr.get_stable_rust_enum_layout().map(|int_repr| {
|
||||
let int_repr = Ident::new(int_repr, Span::call_site());
|
||||
quote!(#[repr(#int_repr)])
|
||||
});
|
||||
|
||||
let unit_variant = variants.iter().position(|variant| is_unit(variant));
|
||||
let non_unit_variant = variants.iter().enumerate().find(|&(_, variant)| !is_unit(variant));
|
||||
|
||||
// We need an int_repr, unit variant, and a non-unit variant to proceed
|
||||
if int_repr.is_none() || unit_variant.is_none() || non_unit_variant.is_none() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let unit_index = unit_variant.unwrap();
|
||||
let (non_unit_index, non_unit_variant) = non_unit_variant.unwrap();
|
||||
let int_repr = int_repr.unwrap();
|
||||
|
||||
let this = ¶ms.this;
|
||||
let (de_impl_generics, de_ty_generics, ty_generics, where_clause) = split_with_de_lifetime(params,);
|
||||
let delife = params.borrowed.de_lifetime();
|
||||
|
||||
let type_name = cattrs.name().deserialize_name();
|
||||
|
||||
let expecting = format!("enum {}", params.type_name());
|
||||
|
||||
let variant_names_idents: Vec<_> = variants
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|&(_, variant)| !variant.attrs.skip_deserializing())
|
||||
.map(|(i, variant)| {
|
||||
(
|
||||
variant.attrs.name().deserialize_name(),
|
||||
field_i(i),
|
||||
variant.attrs.aliases(),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
let variants_stmt = {
|
||||
let variant_names = variant_names_idents.iter().map(|&(ref name, _, _)| name);
|
||||
quote! {
|
||||
const VARIANTS: &'static [&'static str] = &[ #(#variant_names),* ];
|
||||
}
|
||||
};
|
||||
|
||||
let variant_visitor = Stmts(deserialize_generated_identifier(&variant_names_idents, cattrs, true, None),);
|
||||
|
||||
let non_unit_field = field_i(non_unit_index);
|
||||
let tag_access = match non_unit_variant.style {
|
||||
Style::Struct => {
|
||||
quote!(repr.#non_unit_field.tag)
|
||||
}
|
||||
Style::Tuple | Style::Newtype => {
|
||||
quote!(repr.#non_unit_field.0)
|
||||
}
|
||||
_ => unreachable!()
|
||||
};
|
||||
|
||||
let mut sub_params = params.clone();
|
||||
let variant_arms_from = variants
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|&(_, variant)| !variant.attrs.skip_deserializing())
|
||||
.map(
|
||||
|(i, variant)| {
|
||||
let variant_name = field_i(i);
|
||||
sub_params.this = syn::Path::from(variant_name.clone());
|
||||
|
||||
let this_decl = if is_unit(variant) {
|
||||
None
|
||||
} else {
|
||||
Some(quote!(let this = &mut repr.#variant_name;))
|
||||
};
|
||||
let block = Stmts(deserialize_externally_tagged_variant_in_place(&sub_params, variant, cattrs));
|
||||
quote! {
|
||||
(__Field::#variant_name, __variant) => {
|
||||
{
|
||||
#this_decl
|
||||
#block;
|
||||
}
|
||||
#tag_access = __Tag::#variant_name;
|
||||
_serde::export::Result::Ok(())
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
let all_skipped = variants
|
||||
.iter()
|
||||
.all(|variant| variant.attrs.skip_deserializing());
|
||||
|
||||
let match_variant_from = if all_skipped {
|
||||
// This is an empty enum like `enum Impossible {}` or an enum in which
|
||||
// all variants have `#[serde(skip_deserializing)]`.
|
||||
quote! {
|
||||
// FIXME: Once we drop support for Rust 1.15:
|
||||
// let _serde::export::Err(__err) = _serde::de::EnumAccess::variant::<__Field>(__data);
|
||||
// _serde::export::Err(__err)
|
||||
_serde::export::Result::map(
|
||||
_serde::de::EnumAccess::variant::<__Field>(__data),
|
||||
|(__impossible, _)| match __impossible {})
|
||||
}
|
||||
} else {
|
||||
let unit_field = field_i(unit_index);
|
||||
|
||||
quote! {
|
||||
unsafe {
|
||||
let repr = ::std::mem::transmute::<&mut #this #ty_generics, &mut __EnumRepr>(self.place);
|
||||
#tag_access = __Tag::#unit_field;
|
||||
match try!(_serde::de::EnumAccess::variant(__data)) {
|
||||
#(#variant_arms_from)*
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let repr_cases = variants
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(
|
||||
|(i, variant)| {
|
||||
if is_unit(&variant) {
|
||||
None
|
||||
} else {
|
||||
let variant_name = field_i(i);
|
||||
Some(quote!(#variant_name: #variant_name))
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
let tag_cases = variants
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(
|
||||
|(i, _variant)| {
|
||||
let variant_name = field_i(i);
|
||||
|
||||
quote!(#variant_name)
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
let repr_payloads = variants
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(
|
||||
|(i, variant)| {
|
||||
let variant_name = field_i(i);
|
||||
match variant.style {
|
||||
Style::Struct => {
|
||||
let fields = variant.fields.iter().enumerate().map(|(j, field)| {
|
||||
let field_name = field_i(j);
|
||||
let field_ty = field.ty;
|
||||
quote!(#field_name: #field_ty)
|
||||
});
|
||||
|
||||
let payload = quote! {
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
#[allow(non_camel_case_types)]
|
||||
struct #variant_name #ty_generics {
|
||||
tag: __Tag,
|
||||
#(#fields),*
|
||||
}
|
||||
};
|
||||
Some(payload)
|
||||
}
|
||||
Style::Tuple | Style::Newtype => {
|
||||
let fields = variant.fields.iter().map(|field| {
|
||||
let field_ty = field.ty;
|
||||
quote!(#field_ty)
|
||||
});
|
||||
|
||||
let payload = quote! {
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
#[allow(non_camel_case_types)]
|
||||
struct #variant_name #ty_generics (
|
||||
__Tag,
|
||||
#(#fields),*
|
||||
|
||||
);
|
||||
};
|
||||
Some(payload)
|
||||
}
|
||||
Style::Unit => None,
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
let raw_repr = quote! {
|
||||
#[repr(C)]
|
||||
#[allow(non_camel_case_types)]
|
||||
union __EnumRepr #ty_generics {
|
||||
#(#repr_cases),*
|
||||
}
|
||||
|
||||
#int_repr
|
||||
#[derive(Copy, Clone)]
|
||||
#[allow(non_camel_case_types)]
|
||||
enum __Tag {
|
||||
#(#tag_cases),*
|
||||
}
|
||||
|
||||
#(#repr_payloads)*
|
||||
};
|
||||
|
||||
let de_from_impl_generics = de_impl_generics.in_place();
|
||||
let de_from_ty_generics = de_ty_generics.in_place();
|
||||
let dest_life = place_lifetime();
|
||||
|
||||
Some(quote_block! {
|
||||
#variant_visitor
|
||||
|
||||
struct __Visitor #de_from_impl_generics #where_clause {
|
||||
place: &#dest_life mut #this #ty_generics,
|
||||
lifetime: _serde::export::PhantomData<&#delife ()>,
|
||||
}
|
||||
|
||||
impl #de_from_impl_generics _serde::de::Visitor<#delife> for __Visitor #de_from_ty_generics #where_clause {
|
||||
type Value = ();
|
||||
|
||||
fn expecting(&self, formatter: &mut _serde::export::Formatter) -> _serde::export::fmt::Result {
|
||||
_serde::export::Formatter::write_str(formatter, #expecting)
|
||||
}
|
||||
|
||||
fn visit_enum<__A>(self, __data: __A) -> _serde::export::Result<Self::Value, __A::Error>
|
||||
where __A: _serde::de::EnumAccess<#delife>
|
||||
{
|
||||
#raw_repr
|
||||
|
||||
#match_variant_from
|
||||
}
|
||||
}
|
||||
|
||||
#variants_stmt
|
||||
|
||||
_serde::Deserializer::deserialize_enum(__deserializer, #type_name, VARIANTS,
|
||||
__Visitor {
|
||||
place: __place,
|
||||
lifetime: _serde::export::PhantomData,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn deserialize_internally_tagged_enum(
|
||||
params: &Parameters,
|
||||
variants: &[Variant],
|
||||
@ -1657,6 +1367,13 @@ fn deserialize_adjacently_tagged_enum(
|
||||
}
|
||||
};
|
||||
|
||||
fn is_unit(variant: &Variant) -> bool {
|
||||
match variant.style {
|
||||
Style::Unit => true,
|
||||
Style::Struct | Style::Tuple | Style::Newtype => false,
|
||||
}
|
||||
}
|
||||
|
||||
let mut missing_content = quote! {
|
||||
_serde::export::Err(<__A::Error as _serde::de::Error>::missing_field(#content))
|
||||
};
|
||||
@ -1971,46 +1688,6 @@ fn deserialize_externally_tagged_variant(
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "deserialize_in_place")]
|
||||
fn deserialize_externally_tagged_variant_in_place(
|
||||
params: &Parameters,
|
||||
variant: &Variant,
|
||||
cattrs: &attr::Container,
|
||||
) -> Fragment {
|
||||
if let Some(_path) = variant.attrs.deserialize_with() {
|
||||
unimplemented!()
|
||||
/*
|
||||
let (wrapper, wrapper_ty, unwrap_fn) =
|
||||
wrap_deserialize_variant_with(params, &variant, path);
|
||||
return quote_block! {
|
||||
#wrapper
|
||||
_serde::export::Result::map(
|
||||
_serde::de::VariantAccess::newtype_variant::<#wrapper_ty>(__variant), #unwrap_fn)
|
||||
};
|
||||
*/
|
||||
}
|
||||
|
||||
let variant_ident = &variant.ident;
|
||||
|
||||
match variant.style {
|
||||
Style::Unit => {
|
||||
quote_block! {
|
||||
try!(_serde::de::VariantAccess::unit_variant(__variant));
|
||||
}
|
||||
}
|
||||
Style::Newtype => {
|
||||
deserialize_externally_tagged_newtype_variant_in_place(variant_ident, params, &variant.fields[0])
|
||||
}
|
||||
Style::Tuple => {
|
||||
deserialize_tuple_in_place(Some(variant_ident.clone()), params, &variant.fields, cattrs, None)
|
||||
}
|
||||
Style::Struct => {
|
||||
unimplemented!()
|
||||
// deserialize_struct(None, params, &variant.fields, cattrs, None, Untagged::No).0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn deserialize_internally_tagged_variant(
|
||||
params: &Parameters,
|
||||
variant: &Variant,
|
||||
@ -2135,34 +1812,6 @@ fn deserialize_externally_tagged_newtype_variant(
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "deserialize_in_place")]
|
||||
fn deserialize_externally_tagged_newtype_variant_in_place(
|
||||
_variant_ident: &syn::Ident,
|
||||
params: &Parameters,
|
||||
field: &Field,
|
||||
) -> Fragment {
|
||||
let _this = ¶ms.this;
|
||||
match field.attrs.deserialize_with() {
|
||||
None => {
|
||||
quote_expr! {
|
||||
try!(_serde::de::VariantAccess::newtype_variant_seed(__variant, _serde::private::de::InPlaceSeed(&mut this.1)));
|
||||
}
|
||||
}
|
||||
Some(_path) => {
|
||||
unimplemented!();
|
||||
/*
|
||||
let (wrapper, wrapper_ty) = wrap_deserialize_field_with(params, field.ty, path);
|
||||
quote_block! {
|
||||
#wrapper
|
||||
_serde::export::Result::map(
|
||||
_serde::de::VariantAccess::newtype_variant::<#wrapper_ty>(__variant),
|
||||
|__wrapper| #this::#variant_ident(__wrapper.value))
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn deserialize_untagged_newtype_variant(
|
||||
variant_ident: &syn::Ident,
|
||||
params: &Parameters,
|
||||
@ -3352,10 +3001,3 @@ fn split_with_de_lifetime(
|
||||
let (_, ty_generics, where_clause) = params.generics.split_for_impl();
|
||||
(de_impl_generics, de_ty_generics, ty_generics, where_clause)
|
||||
}
|
||||
|
||||
fn is_unit(variant: &Variant) -> bool {
|
||||
match variant.style {
|
||||
Style::Unit => true,
|
||||
Style::Struct | Style::Tuple | Style::Newtype => false,
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ pub struct Container<'a> {
|
||||
///
|
||||
/// Analagous to `syn::Data`.
|
||||
pub enum Data<'a> {
|
||||
Enum(Repr, Vec<Variant<'a>>),
|
||||
Enum(Vec<Variant<'a>>),
|
||||
Struct(Style, Vec<Field<'a>>),
|
||||
}
|
||||
|
||||
@ -46,12 +46,6 @@ pub struct Field<'a> {
|
||||
pub original: &'a syn::Field,
|
||||
}
|
||||
|
||||
pub struct Repr {
|
||||
pub int_repr: Option<&'static str>,
|
||||
pub c_repr: bool,
|
||||
pub other_repr: bool,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum Style {
|
||||
/// Named fields.
|
||||
@ -75,8 +69,7 @@ impl<'a> Container<'a> {
|
||||
|
||||
let mut data = match item.data {
|
||||
syn::Data::Enum(ref data) => {
|
||||
let (repr, variants) = enum_from_ast(cx, item, &data.variants, attrs.default());
|
||||
Data::Enum(repr, variants)
|
||||
Data::Enum(enum_from_ast(cx, &data.variants, attrs.default()))
|
||||
}
|
||||
syn::Data::Struct(ref data) => {
|
||||
let (style, fields) = struct_from_ast(cx, &data.fields, None, attrs.default());
|
||||
@ -90,7 +83,7 @@ impl<'a> Container<'a> {
|
||||
|
||||
let mut has_flatten = false;
|
||||
match data {
|
||||
Data::Enum(_, ref mut variants) => {
|
||||
Data::Enum(ref mut variants) => {
|
||||
for variant in variants {
|
||||
variant.attrs.rename_by_rules(attrs.rename_all_rules());
|
||||
for field in &mut variant.fields {
|
||||
@ -132,7 +125,7 @@ impl<'a> Container<'a> {
|
||||
impl<'a> Data<'a> {
|
||||
pub fn all_fields(&'a self) -> Box<Iterator<Item = &'a Field<'a>> + 'a> {
|
||||
match *self {
|
||||
Data::Enum(_, ref variants) => {
|
||||
Data::Enum(ref variants) => {
|
||||
Box::new(variants.iter().flat_map(|variant| variant.fields.iter()))
|
||||
}
|
||||
Data::Struct(_, ref fields) => Box::new(fields.iter()),
|
||||
@ -144,37 +137,16 @@ impl<'a> Data<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Repr {
|
||||
/// Gives the int type to use for the `repr(int)` enum layout
|
||||
pub fn get_stable_rust_enum_layout(&self) -> Option<&'static str> {
|
||||
if self.c_repr || self.other_repr {
|
||||
None
|
||||
} else {
|
||||
self.int_repr
|
||||
}
|
||||
}
|
||||
|
||||
/// Gives the int type to use for the `repr(C, int)` enum layout
|
||||
pub fn get_stable_c_enum_layout(&self) -> Option<&'static str> {
|
||||
if !self.c_repr && self.other_repr {
|
||||
None
|
||||
} else {
|
||||
self.int_repr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn enum_from_ast<'a>(
|
||||
cx: &Ctxt,
|
||||
item: &'a syn::DeriveInput,
|
||||
variants: &'a Punctuated<syn::Variant, Token![,]>,
|
||||
container_default: &attr::Default
|
||||
) -> (Repr, Vec<Variant<'a>>) {
|
||||
let variants = variants
|
||||
container_default: &attr::Default,
|
||||
) -> Vec<Variant<'a>> {
|
||||
variants
|
||||
.iter()
|
||||
.map(|variant| {
|
||||
let attrs = attr::Variant::from_ast(cx, variant);
|
||||
let (style, fields) =
|
||||
let (style, fields) =
|
||||
struct_from_ast(cx, &variant.fields, Some(&attrs), container_default);
|
||||
Variant {
|
||||
ident: variant.ident.clone(),
|
||||
@ -184,48 +156,7 @@ fn enum_from_ast<'a>(
|
||||
original: variant,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
// Compute repr info for enum optimizations
|
||||
static INT_TYPES: [&'static str; 12] = [
|
||||
"u8", "u16", "u32", "u64", "u128", "usize",
|
||||
"i8", "i16", "i32", "i64", "i128", "isize",
|
||||
];
|
||||
|
||||
let mut int_repr = None;
|
||||
let mut c_repr = false;
|
||||
let mut other_repr = false;
|
||||
|
||||
for attr in &item.attrs {
|
||||
if let Some(syn::Meta::List(ref list)) = attr.interpret_meta() {
|
||||
if list.ident == "repr" {
|
||||
// has_repr = true;
|
||||
for repr in &list.nested {
|
||||
if let syn::NestedMeta::Meta(syn::Meta::Word(ref repr)) = *repr {
|
||||
if repr == "C" {
|
||||
c_repr = true;
|
||||
} else if let Some(int_type) = INT_TYPES.iter().cloned().find(|int_type| repr == int_type) {
|
||||
if int_repr.is_some() {
|
||||
// This shouldn't happen, but we shouldn't crash if we see it.
|
||||
// So just treat the enum as having a mysterious other repr,
|
||||
// which makes us discard any attempt to optimize based on layout.
|
||||
other_repr = true;
|
||||
}
|
||||
int_repr = Some(int_type);
|
||||
} else {
|
||||
other_repr = true;
|
||||
}
|
||||
} else {
|
||||
panic!("impossible repr? {:?}", repr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let repr = Repr { int_repr, c_repr, other_repr };
|
||||
|
||||
(repr, variants)
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn struct_from_ast<'a>(
|
||||
|
@ -19,7 +19,7 @@ pub fn check(cx: &Ctxt, cont: &mut Container, derive: Derive) {
|
||||
/// attribute.
|
||||
fn check_getter(cx: &Ctxt, cont: &Container) {
|
||||
match cont.data {
|
||||
Data::Enum(_, _) => {
|
||||
Data::Enum(_) => {
|
||||
if cont.data.has_getter() {
|
||||
cx.error_spanned_by(
|
||||
cont.original,
|
||||
@ -42,7 +42,7 @@ fn check_getter(cx: &Ctxt, cont: &Container) {
|
||||
/// Flattening has some restrictions we can test.
|
||||
fn check_flatten(cx: &Ctxt, cont: &Container) {
|
||||
match cont.data {
|
||||
Data::Enum(_, ref variants) => {
|
||||
Data::Enum(ref variants) => {
|
||||
for variant in variants {
|
||||
for field in &variant.fields {
|
||||
check_flatten_field(cx, variant.style, field);
|
||||
@ -86,7 +86,7 @@ fn check_flatten_field(cx: &Ctxt, style: Style, field: &Field) {
|
||||
/// last variant may be a newtype variant which is an implicit "other" case.
|
||||
fn check_identifier(cx: &Ctxt, cont: &Container) {
|
||||
let variants = match cont.data {
|
||||
Data::Enum(_, ref variants) => variants,
|
||||
Data::Enum(ref variants) => variants,
|
||||
Data::Struct(_, _) => {
|
||||
return;
|
||||
}
|
||||
@ -170,7 +170,7 @@ fn check_identifier(cx: &Ctxt, cont: &Container) {
|
||||
/// (de)serialize_with.
|
||||
fn check_variant_skip_attrs(cx: &Ctxt, cont: &Container) {
|
||||
let variants = match cont.data {
|
||||
Data::Enum(_, ref variants) => variants,
|
||||
Data::Enum(ref variants) => variants,
|
||||
Data::Struct(_, _) => {
|
||||
return;
|
||||
}
|
||||
@ -252,7 +252,7 @@ fn check_variant_skip_attrs(cx: &Ctxt, cont: &Container) {
|
||||
/// the to-be-deserialized input.
|
||||
fn check_internal_tag_field_name_conflict(cx: &Ctxt, cont: &Container) {
|
||||
let variants = match cont.data {
|
||||
Data::Enum(_, ref variants) => variants,
|
||||
Data::Enum(ref variants) => variants,
|
||||
Data::Struct(_, _) => return,
|
||||
};
|
||||
|
||||
@ -338,7 +338,7 @@ fn check_transparent(cx: &Ctxt, cont: &mut Container, derive: Derive) {
|
||||
}
|
||||
|
||||
let fields = match cont.data {
|
||||
Data::Enum(_, _) => {
|
||||
Data::Enum(_) => {
|
||||
cx.error_spanned_by(
|
||||
cont.original,
|
||||
"#[serde(transparent)] is not allowed on an enum",
|
||||
|
4
third_party/rust/serde_derive/src/pretend.rs
vendored
4
third_party/rust/serde_derive/src/pretend.rs
vendored
@ -53,7 +53,7 @@ fn pretend_fields_used(cont: &Container) -> TokenStream {
|
||||
let (_, ty_generics, _) = cont.generics.split_for_impl();
|
||||
|
||||
let patterns = match cont.data {
|
||||
Data::Enum(_, ref variants) => variants
|
||||
Data::Enum(ref variants) => variants
|
||||
.iter()
|
||||
.filter_map(|variant| match variant.style {
|
||||
Style::Struct => {
|
||||
@ -94,7 +94,7 @@ fn pretend_fields_used(cont: &Container) -> TokenStream {
|
||||
//
|
||||
fn pretend_variants_used(cont: &Container) -> TokenStream {
|
||||
let variants = match cont.data {
|
||||
Data::Enum(_, ref variants) => variants,
|
||||
Data::Enum(ref variants) => variants,
|
||||
Data::Struct(_, _) => {
|
||||
return quote!();
|
||||
}
|
||||
|
4
third_party/rust/serde_derive/src/ser.rs
vendored
4
third_party/rust/serde_derive/src/ser.rs
vendored
@ -159,7 +159,7 @@ fn serialize_body(cont: &Container, params: &Parameters) -> Fragment {
|
||||
serialize_into(params, type_into)
|
||||
} else {
|
||||
match cont.data {
|
||||
Data::Enum(_, ref variants) => serialize_enum(params, variants, &cont.attrs),
|
||||
Data::Enum(ref variants) => serialize_enum(params, variants, &cont.attrs),
|
||||
Data::Struct(Style::Struct, ref fields) => {
|
||||
serialize_struct(params, fields, &cont.attrs)
|
||||
}
|
||||
@ -177,7 +177,7 @@ fn serialize_body(cont: &Container, params: &Parameters) -> Fragment {
|
||||
fn serialize_transparent(cont: &Container, params: &Parameters) -> Fragment {
|
||||
let fields = match cont.data {
|
||||
Data::Struct(_, ref fields) => fields,
|
||||
Data::Enum(_, _) => unreachable!(),
|
||||
Data::Enum(_) => unreachable!(),
|
||||
};
|
||||
|
||||
let self_var = ¶ms.self_var;
|
||||
|
Loading…
Reference in New Issue
Block a user