From 17d40c6057c88f4c432b0d7bac88e1b84cb7e67f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:03:36 +0200 Subject: Adding upstream version 1.65.0+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_serialize/Cargo.toml | 1 + compiler/rustc_serialize/src/collection_impls.rs | 20 +++++++++++++---- compiler/rustc_serialize/src/lib.rs | 5 ++++- compiler/rustc_serialize/src/serialize.rs | 28 ++++++++++++++---------- 4 files changed, 37 insertions(+), 17 deletions(-) (limited to 'compiler/rustc_serialize') diff --git a/compiler/rustc_serialize/Cargo.toml b/compiler/rustc_serialize/Cargo.toml index dbc5c1519..3b0b3144f 100644 --- a/compiler/rustc_serialize/Cargo.toml +++ b/compiler/rustc_serialize/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] indexmap = "1.9.1" smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } +thin-vec = "0.2.8" [dev-dependencies] rustc_macros = { path = "../rustc_macros" } diff --git a/compiler/rustc_serialize/src/collection_impls.rs b/compiler/rustc_serialize/src/collection_impls.rs index 5e53f0b10..8f8c50411 100644 --- a/compiler/rustc_serialize/src/collection_impls.rs +++ b/compiler/rustc_serialize/src/collection_impls.rs @@ -1,13 +1,12 @@ //! Implementations of serialization for structures found in liballoc -use std::hash::{BuildHasher, Hash}; - use crate::{Decodable, Decoder, Encodable, Encoder}; +use smallvec::{Array, SmallVec}; use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, LinkedList, VecDeque}; +use std::hash::{BuildHasher, Hash}; use std::rc::Rc; use std::sync::Arc; - -use smallvec::{Array, SmallVec}; +use thin_vec::ThinVec; impl>> Encodable for SmallVec { fn encode(&self, s: &mut S) { @@ -23,6 +22,19 @@ impl>> Decodable for SmallVec { } } +impl> Encodable for ThinVec { + fn encode(&self, s: &mut S) { + self.as_slice().encode(s); + } +} + +impl> Decodable for ThinVec { + fn decode(d: &mut D) -> ThinVec { + let len = d.read_usize(); + (0..len).map(|_| Decodable::decode(d)).collect() + } +} + impl> Encodable for LinkedList { fn encode(&self, s: &mut S) { s.emit_usize(self.len()); diff --git a/compiler/rustc_serialize/src/lib.rs b/compiler/rustc_serialize/src/lib.rs index e606f4273..fa9c7bd54 100644 --- a/compiler/rustc_serialize/src/lib.rs +++ b/compiler/rustc_serialize/src/lib.rs @@ -14,10 +14,13 @@ Core encoding and decoding interfaces. #![feature(min_specialization)] #![feature(core_intrinsics)] #![feature(maybe_uninit_slice)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(new_uninit)] +#![feature(allocator_api)] #![cfg_attr(test, feature(test))] #![allow(rustc::internal)] +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] pub use self::serialize::{Decodable, Decoder, Encodable, Encoder}; diff --git a/compiler/rustc_serialize/src/serialize.rs b/compiler/rustc_serialize/src/serialize.rs index 36585b8d7..751b209f1 100644 --- a/compiler/rustc_serialize/src/serialize.rs +++ b/compiler/rustc_serialize/src/serialize.rs @@ -4,6 +4,7 @@ Core encoding and decoding interfaces. */ +use std::alloc::Allocator; use std::borrow::Cow; use std::cell::{Cell, RefCell}; use std::marker::PhantomData; @@ -229,9 +230,9 @@ impl Decodable for PhantomData { } } -impl> Decodable for Box<[T]> { - fn decode(d: &mut D) -> Box<[T]> { - let v: Vec = Decodable::decode(d); +impl> Decodable for Box<[T], A> { + fn decode(d: &mut D) -> Box<[T], A> { + let v: Vec = Decodable::decode(d); v.into_boxed_slice() } } @@ -264,16 +265,17 @@ impl> Encodable for Vec { } } -impl> Decodable for Vec { - default fn decode(d: &mut D) -> Vec { +impl, A: Allocator + Default> Decodable for Vec { + default fn decode(d: &mut D) -> Vec { let len = d.read_usize(); + let allocator = A::default(); // SAFETY: we set the capacity in advance, only write elements, and // only set the length at the end once the writing has succeeded. - let mut vec = Vec::with_capacity(len); + let mut vec = Vec::with_capacity_in(len, allocator); unsafe { let ptr: *mut T = vec.as_mut_ptr(); for i in 0..len { - std::ptr::write(ptr.offset(i as isize), Decodable::decode(d)); + std::ptr::write(ptr.add(i), Decodable::decode(d)); } vec.set_len(len); } @@ -457,13 +459,15 @@ impl> Decodable for Arc { } } -impl> Encodable for Box { +impl, A: Allocator + Default> Encodable for Box { fn encode(&self, s: &mut S) { - (**self).encode(s); + (**self).encode(s) } } -impl> Decodable for Box { - fn decode(d: &mut D) -> Box { - Box::new(Decodable::decode(d)) + +impl> Decodable for Box { + fn decode(d: &mut D) -> Box { + let allocator = A::default(); + Box::new_in(Decodable::decode(d), allocator) } } -- cgit v1.2.3