about summary refs log tree commit diff
path: root/compiler/rustc_serialize/src/collection_impls.rs
AgeCommit message (Collapse)AuthorLines
2023-10-06rustc_serialize: merge `collection_impls.rs` into `serialize.rs`.Nicholas Nethercote-263/+0
`serialize.rs` has the `Encodable`/`Decodable` impls for lots of basic types, including `Vec`. `collection_impls` has it for lots of collection types. The distinction isn't really meaningful, and it's simpler to have them all in a single file.
2023-10-06Remove unused serialization support for `LinkedList`.Nicholas Nethercote-17/+1
2022-08-29Replace `rustc_data_structures::thin_vec::ThinVec` with `thin_vec::ThinVec`.Nicholas Nethercote-4/+16
`rustc_data_structures::thin_vec::ThinVec` looks like this: ``` pub struct ThinVec<T>(Option<Box<Vec<T>>>); ``` It's just a zero word if the vector is empty, but requires two allocations if it is non-empty. So it's only usable in cases where the vector is empty most of the time. This commit removes it in favour of `thin_vec::ThinVec`, which is also word-sized, but stores the length and capacity in the same allocation as the elements. It's good in a wider variety of situation, e.g. in enum variants where the vector is usually/always non-empty. The commit also: - Sorts some `Cargo.toml` dependency lists, to make additions easier. - Sorts some `use` item lists, to make additions easier. - Changes `clean_trait_ref_with_bindings` to take a `ThinVec<TypeBinding>` rather than a `&[TypeBinding]`, because this avoid some unnecessary allocations.
2022-06-08Use delayed error handling for `Encodable` and `Encoder` infallible.Nicholas Nethercote-41/+33
There are two impls of the `Encoder` trait: `opaque::Encoder` and `opaque::FileEncoder`. The former encodes into memory and is infallible, the latter writes to file and is fallible. Currently, standard `Result`/`?`/`unwrap` error handling is used, but this is a bit verbose and has non-trivial cost, which is annoying given how rare failures are (especially in the infallible `opaque::Encoder` case). This commit changes how `Encoder` fallibility is handled. All the `emit_*` methods are now infallible. `opaque::Encoder` requires no great changes for this. `opaque::FileEncoder` now implements a delayed error handling strategy. If a failure occurs, it records this via the `res` field, and all subsequent encoding operations are skipped if `res` indicates an error has occurred. Once encoding is complete, the new `finish` method is called, which returns a `Result`. In other words, there is now a single `Result`-producing method instead of many of them. This has very little effect on how any file errors are reported if `opaque::FileEncoder` has any failures. Much of this commit is boring mechanical changes, removing `Result` return values and `?` or `unwrap` from expressions. The more interesting parts are as follows. - serialize.rs: The `Encoder` trait gains an `Ok` associated type. The `into_inner` method is changed into `finish`, which returns `Result<Vec<u8>, !>`. - opaque.rs: The `FileEncoder` adopts the delayed error handling strategy. Its `Ok` type is a `usize`, returning the number of bytes written, replacing previous uses of `FileEncoder::position`. - Various methods that take an encoder now consume it, rather than being passed a mutable reference, e.g. `serialize_query_result_cache`.
2022-06-03Inline many methods of Encoderbjorn3-51/+43
They aren't overridden anyway
2022-06-03Remove all names from Encoderbjorn3-16/+16
They aren't used anymore now that the json format has been removed
2022-05-13Cache more queries on disk.Camille GILLOT-10/+0
2022-02-20Delete Decoder::read_mapMark Rousskov-29/+26
2022-02-20Delete Decoder::read_seqMark Rousskov-26/+26
2022-02-20Delete Decoder::read_map_elt_valMark Rousskov-3/+3
2022-02-20Delete Decoder::read_map_elt_keyMark Rousskov-3/+3
2022-02-20Delete Decoder::read_seq_eltMark Rousskov-6/+6
2022-01-22Make `Decodable` and `Decoder` infallible.Nicholas Nethercote-52/+33
`Decoder` has two impls: - opaque: this impl is already partly infallible, i.e. in some places it currently panics on failure (e.g. if the input is too short, or on a bad `Result` discriminant), and in some places it returns an error (e.g. on a bad `Option` discriminant). The number of places where either happens is surprisingly small, just because the binary representation has very little redundancy and a lot of input reading can occur even on malformed data. - json: this impl is fully fallible, but it's only used (a) for the `.rlink` file production, and there's a `FIXME` comment suggesting it should change to a binary format, and (b) in a few tests in non-fundamental ways. Indeed #85993 is open to remove it entirely. And the top-level places in the compiler that call into decoding just abort on error anyway. So the fallibility is providing little value, and getting rid of it leads to some non-trivial performance improvements. Much of this commit is pretty boring and mechanical. Some notes about a few interesting parts: - The commit removes `Decoder::{Error,error}`. - `InternIteratorElement::intern_with`: the impl for `T` now has the same optimization for small counts that the impl for `Result<T, E>` has, because it's now much hotter. - Decodable impls for SmallVec, LinkedList, VecDeque now all use `collect`, which is nice; the one for `Vec` uses unsafe code, because that gave better perf on some benchmarks.
2021-06-01Remove unused functions and arguments from rustc_serializebjorn3-24/+24
2021-01-01rustc_serialize: specialize opaque decoding of some u8 sequencesTyson Nottingham-14/+4
2021-01-01rustc_serialize: specialize opaque encoding of some u8 sequencesTyson Nottingham-18/+6
2020-08-30mv compiler to compiler/mark-0/+337