about summary refs log tree commit diff
path: root/compiler/rustc_serialize/src/opaque.rs
AgeCommit message (Collapse)AuthorLines
2025-06-21Add a few inline directives in rustc_serialize.Camille GILLOT-0/+2
2025-04-22Add index to the dep graph format and encode via `MemEncoder`John Kåre Alsaker-0/+2
2025-04-10Bump `FileEncoder` buffer size to 64 kBJohn Kåre Alsaker-1/+1
2025-03-20Convert `rustc_serialize` integration tests to unit tests.Nicholas Nethercote-0/+3
Because (a) the vast majority of compiler tests are unit tests, and (b) this works better with `unused_crate_dependencies`.
2025-02-23rename sub_ptr 😅bendn-3/+3
2024-10-07Fix used_underscore_binding in rustc_serializeMichal Piotrowski-3/+3
2024-09-02chore: Fix typos in 'compiler' (batch 2)Alexander Cyon-1/+1
2024-07-29Reformat `use` declarations.Nicholas Nethercote-4/+3
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-02chore: remove duplicate wordshattizai-1/+1
2024-05-21PR feedbackBen Kimock-5/+5
2024-05-21Add a footer in FileEncoder and check for it in MemDecoderBen Kimock-5/+11
2024-04-13Add add/sub methods that only panic with debug assertions to rustcNilstrieb-3/+7
This mitigates the perf impact of enabling overflow checks on rustc. The change to use overflow checks will be done in a later PR.
2023-11-22Call FileEncoder::finish in rmeta encodingBen Kimock-7/+36
2023-09-22Open the FileEncoder file for reading and writingBen Kimock-1/+6
2023-09-20PR feedbackBen Kimock-32/+54
2023-09-10Reimplement FileEncoder with a small-write optimizationBen Kimock-196/+74
2023-09-04Use a specialized varint + bitpacking scheme for DepGraph encodingBen Kimock-1/+1
2023-05-15Fix the `FileEncoder` buffer size.Nicholas Nethercote-33/+11
It allows a variable size, but in practice we always use the default of 8192 bytes. This commit fixes it to that size, which makes things slightly faster because the size can be hard-wired in generated code. The commit also: - Rearranges some buffer capacity checks so they're all in the same form (`x > BUFSIZE`). - Removes some buffer capacity assertions and comments about them. With an 8192 byte buffer, we're not in any danger of overflowing a `usize`.
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-10/+10
So they match the order in the `Decoder` trait.
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-76/+0
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-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-36/+119
2023-04-06Remove f32 & f64 from MemDecoder/MemEncoderScott McMurray-36/+0
2022-12-10compiler: remove unnecessary imports and qualified pathsKaDiWa-1/+0
2022-11-29rename `{max=>largest}_max_leb128_len`Maybe Waffle-3/+3
2022-11-29Replace a macro with a functionMaybe Waffle-5/+5
2022-11-27Prefer doc comments over `//`-comments in compilerMaybe Waffle-13/+13
2022-09-20add comment explaining read permissionsSikkema, Isaac-0/+2
2022-08-25use `File::options()` instead of `File::create()`Sikkema, Isaac-1/+1
2022-07-02use BufReader for counting zero bytesYoshiki Matsuda-0/+4
2022-06-16Move `finish` out of the `Encoder` trait.Nicholas Nethercote-17/+11
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-11/+17
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-17/+11
This simplifies things, but requires making `CacheEncoder` non-generic.
2022-06-08Use delayed error handling for `Encodable` and `Encoder` infallible.Nicholas Nethercote-110/+130
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-03Remove emit_unitbjorn3-10/+0
It doesn't do anything for all encoders
2022-02-22Delete Decoder::read_unitMark Rousskov-5/+0
2022-02-22Provide copy-free access to raw Decoder bytesMark Rousskov-13/+6
2022-02-22Provide raw &str access from DecoderMark Rousskov-3/+2
2022-01-31Remove two unnecessary transmutes from opaque Encoder and Decoderbjorn3-4/+3
2022-01-22Address review comments.Nicholas Nethercote-2/+1
2022-01-22Make `Decodable` and `Decoder` infallible.Nicholas Nethercote-48/+41
`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.