about summary refs log tree commit diff
path: root/compiler/rustc_serialize/src
AgeCommit message (Collapse)AuthorLines
2023-05-04Factor out more repeated code in `{write,read}_leb128!`.Nicholas Nethercote-95/+44
Make them generate the entire function, not just the function body.
2023-05-04Rename `file_encoder_write_leb128!`.Nicholas Nethercote-9/+9
`MemEncoder` was recently removed, leaving `FileEncoder` as the only encoder. So this prefix is no longer needed, and `write_leb128!` matches the existing `read_leb128!`.
2023-05-04Reorder some `MemDecoder` methods.Nicholas Nethercote-12/+12
So they match the order in the `Decoder` trait.
2023-05-04Remove a low value comment.Nicholas Nethercote-4/+0
2023-05-02Remove `MemEncoder`.Nicholas Nethercote-125/+4
It's only used in tests. Which is bad, because it means that `FileEncoder` is used in the compiler but isn't used in tests! `tests/opaque.rs` now tests encoding/decoding round-trips via file. Because this is slower than memory, this commit also adjusts the `u16`/`i16` tests so they are more like the `u32`/`i32` tests, i.e. they don't test every possible value.
2023-04-28Remove `MemDecoder::read_byte`.Nicholas Nethercote-14/+9
It's just a synonym for `read_u8`.
2023-04-28Add some provided methods to `Encoder`/`Decoder`.Nicholas Nethercote-84/+56
The methods for `i8`, `bool`, `char`, `str` are the same for all impls, because they layered on top of other methods.
2023-04-28Remove a low-value assertion.Nicholas Nethercote-7/+2
Checking that `read_raw_bytes(len)` changes the position by `len` is a reasonable thing for a test, but isn't much use in just one of the zillion `Decodable` impls.
2023-04-28Add a comment explaining the lack of `Decoder::read_enum_variant`.Nicholas Nethercote-0/+5
Because I was wondering about it, and this may save a future person from also wondering.
2023-04-28Remove `MemDecoder::read_raw_bytes_inherent`.Nicholas Nethercote-19/+11
It's unnecessary. Note that `MemDecoder::read_raw_bytes` how has a `&'a [u8]` return type, the same as what `read_raw_bytes_inherent` had.
2023-04-23Rewrite MemDecoder around pointers not a sliceBen Kimock-44/+130
2023-04-06Remove f32 & f64 from MemDecoder/MemEncoderScott McMurray-42/+10
2023-02-25Emit the enum discriminant separately for the Encodable macroJohn Kåre Alsaker-12/+0
2023-02-20Remove old FIXME that no longer appliesDeadbeef-5/+0
it looks like Encodable was fallible at some point, but that was changed which means that this FIXME is no longer applicable
2022-12-10compiler: remove unnecessary imports and qualified pathsKaDiWa-1/+0
2022-11-29rename `{max=>largest}_max_leb128_len`Maybe Waffle-6/+6
2022-11-29Replace a macro with a functionMaybe Waffle-16/+13
2022-11-27Prefer doc comments over `//`-comments in compilerMaybe Waffle-14/+14
2022-09-26remove cfg(bootstrap)Pietro Albini-1/+0
2022-09-20Rollup merge of #101014 - ↵Michael Howell-1/+3
isikkema:fix-zmeta-stats-file-encoder-no-read-perms, r=isikkema Fix -Zmeta-stats ICE by giving `FileEncoder` file read permissions Fixes #101001 As far as I can tell, #101001 is caused because the file is being created with write-only permissions here: https://github.com/rust-lang/rust/blob/master/compiler/rustc_serialize/src/opaque.rs#L196 but it is trying to be read here: https://github.com/rust-lang/rust/blob/master/compiler/rustc_metadata/src/rmeta/encoder.rs#L780 This PR attempts to fix this by creating/opening the file with the same permissions as `File::create()` with the addition of read.
2022-09-20add comment explaining read permissionsSikkema, Isaac-0/+2
2022-09-15Only enable the let_else feature on bootstrapest31-1/+1
On later stages, the feature is already stable. Result of running: rg -l "feature.let_else" compiler/ src/librustdoc/ library/ | xargs sed -s -i "s#\\[feature.let_else#\\[cfg_attr\\(bootstrap, feature\\(let_else\\)#"
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-08-25use `File::options()` instead of `File::create()`Sikkema, Isaac-1/+1
2022-08-25Adding support for rustc_serialize encode and decode for Box and Vec that ↵Ellen Arteca-11/+16
use a custom allocator
2022-08-21Rollup merge of #100822 - WaffleLapkin:no_offset_question_mark, r=scottmcmMatthias Krüger-1/+1
Replace most uses of `pointer::offset` with `add` and `sub` As PR title says, it replaces `pointer::offset` in compiler and standard library with `pointer::add` and `pointer::sub`. This generally makes code cleaner, easier to grasp and removes (or, well, hides) integer casts. This is generally trivially correct, `.offset(-constant)` is just `.sub(constant)`, `.offset(usized as isize)` is just `.add(usized)`, etc. However in some cases we need to be careful with signs of things. r? ````@scottmcm```` _split off from #100746_
2022-08-21Replace most uses of `pointer::offset` with `add` and `sub`Maybe Waffle-1/+1
2022-08-18Add diagnostic translation lints to crates that don't emit them5225225-0/+2
2022-07-02use BufReader for counting zero bytesYoshiki Matsuda-0/+4
2022-06-16Move `finish` out of the `Encoder` trait.Nicholas Nethercote-26/+14
This simplifies things, but requires making `CacheEncoder` non-generic. (This was previously merged as commit 4 in #94732 and then was reverted in #97905 because it caused a perf regression.)
2022-06-14Rename rustc_serialize::opaque::Encoder as MemEncoder.Nicholas Nethercote-26/+26
This avoids the name clash with `rustc_serialize::Encoder` (a trait), and allows lots qualifiers to be removed and imports to be simplified (e.g. fewer `as` imports). (This was previously merged as commit 5 in #94732 and then was reverted in #97905 because of a perf regression caused by commit 4 in #94732.)
2022-06-10Revert dc08bc51f2c58a0f5f815a07f9bb3d671153b5a1.Nicholas Nethercote-14/+26
2022-06-10Revert b983e42936feab29f6333e9835913afc6b4a394e.Nicholas Nethercote-26/+26
2022-06-08Rename `rustc_serialize::opaque::Encoder` as `MemEncoder`.Nicholas Nethercote-26/+26
This avoids the name clash with `rustc_serialize::Encoder` (a trait), and allows lots qualifiers to be removed and imports to be simplified (e.g. fewer `as` imports).
2022-06-08Move `finish` out of the `Encoder` trait.Nicholas Nethercote-26/+14
This simplifies things, but requires making `CacheEncoder` non-generic.
2022-06-08Use delayed error handling for `Encodable` and `Encoder` infallible.Nicholas Nethercote-224/+246
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-08Don't pass in a vector to `Encoder::new`.Nicholas Nethercote-2/+2
It's not necessary.
2022-06-03Fully stabilize NLLJack Huey-1/+0
2022-06-03Remove emit_unitbjorn3-15/+4
It doesn't do anything for all encoders
2022-06-03Inline many methods of Encoderbjorn3-178/+59
They aren't overridden anyway
2022-06-03Remove all names from Encoderbjorn3-60/+33
They aren't used anymore now that the json format has been removed
2022-06-03Remove json support from rustc_serializebjorn3-2517/+0
2022-05-13Cache more queries on disk.Camille GILLOT-16/+9
2022-04-18Remove unused macro rulesest31-1/+0
2022-04-05errors: implement fallback diagnostic translationDavid Wood-0/+14
This commit updates the signatures of all diagnostic functions to accept types that can be converted into a `DiagnosticMessage`. This enables existing diagnostic calls to continue to work as before and Fluent identifiers to be provided. The `SessionDiagnostic` derive just generates normal diagnostic calls, so these APIs had to be modified to accept Fluent identifiers. In addition, loading of the "fallback" Fluent bundle, which contains the built-in English messages, has been implemented. Each diagnostic now has "arguments" which correspond to variables in the Fluent messages (necessary to render a Fluent message) but no API for adding arguments has been added yet. Therefore, diagnostics (that do not require interpolation) can be converted to use Fluent identifiers and will be output as before.
2022-04-03Replace every Vec in Target(Options) with it's Cow equivalentLoïc BRANSTETT-0/+9
2022-04-03Replace every `String` in Target(Options) with `Cow<'static, str>`Loïc BRANSTETT-0/+7
2022-02-22Delete Decoder::read_unitMark Rousskov-11/+2
2022-02-22Provide copy-free access to raw Decoder bytesMark Rousskov-14/+7
2022-02-22Provide raw &str access from DecoderMark Rousskov-5/+4