about summary refs log tree commit diff
path: root/compiler/rustc_serialize/tests
AgeCommit message (Collapse)AuthorLines
2025-03-20Convert `rustc_serialize` integration tests to unit tests.Nicholas Nethercote-396/+0
Because (a) the vast majority of compiler tests are unit tests, and (b) this works better with `unused_crate_dependencies`.
2025-03-20Use `-Wunused_crate_dependencies` for compiler crates.Nicholas Nethercote-0/+5
It's very useful. There are some false positives involving integration tests in `rustc_pattern_analysis` and `rustc_serialize`. There is also a false positive involving `rustc_driver_impl`'s `rustc_randomized_layouts` feature. And I removed a `rustc_span` mention in a doc comment in `rustc_log` because it wasn't integral to the comment but caused a dev-dependency.
2025-03-15Use {Decodable,Encodable}_NoContext in type_irMichael Goulet-7/+7
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-2/+2
2024-07-29Reformat `use` declarations.Nicholas Nethercote-4/+4
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-05-21PR feedbackBen Kimock-2/+3
2024-05-21Add a footer in FileEncoder and check for it in MemDecoderBen Kimock-5/+10
2023-12-31Avoid specialization for the Span Encodable and Decodable implsbjorn3-8/+8
2023-09-10Reimplement FileEncoder with a small-write optimizationBen Kimock-8/+6
2023-05-02Remove `MemEncoder`.Nicholas Nethercote-8/+11
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-05-02Move some `Encodable`/`Decodable` tests.Nicholas Nethercote-0/+39
Round-trip encoding/decoding of many types is tested in `compiler/rustc_serialize/tests/opaque.rs`. There is also a small amount of encoding/decoding testing in three files in `tests/ui-fulldeps`. There is no obvious reason why these three files are necessary. They were originally added in 2014. Maybe it wasn't possible for a proc macro to run in a unit test back then? This commit just moves the testing from those three files into the unit test.
2023-04-23Rewrite MemDecoder around pointers not a sliceBen Kimock-6/+7
2023-04-06Remove f32 & f64 from MemDecoder/MemEncoderScott McMurray-28/+4
2022-06-16Move `finish` out of the `Encoder` trait.Nicholas Nethercote-2/+2
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-4/+6
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-2/+2
2022-06-10Revert b983e42936feab29f6333e9835913afc6b4a394e.Nicholas Nethercote-6/+4
2022-06-08Rename `rustc_serialize::opaque::Encoder` as `MemEncoder`.Nicholas Nethercote-4/+6
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-2/+2
This simplifies things, but requires making `CacheEncoder` non-generic.
2022-06-08Use delayed error handling for `Encodable` and `Encoder` infallible.Nicholas Nethercote-4/+3
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-1/+1
It's not necessary.
2022-06-03Remove json support from rustc_serializebjorn3-978/+0
2022-02-20Remove support for JSON deserialization to RustMark Rousskov-303/+8
This is no longer used by the compiler itself, and removing this support opens the door to massively simplifying the Decodable/Decoder API by dropping the self-describing deserialization support (necessary for JSON).
2022-01-22Make `Decodable` and `Decoder` infallible.Nicholas Nethercote-103/+107
`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.
2022-01-07Modify the buffer position directly when reading leb128 values.Nicholas Nethercote-4/+2
It's a small but clear performance win.
2021-06-14Use the now available implementation of `IntoIterator` for arraysLeSeulArtichaut-1/+1
2021-03-24Revert "Revert stabilizing integer::BITS."Mara Bos-1/+0
2021-02-03Revert stabilizing integer::BITS.Mara Bos-0/+1
2021-01-31stabilize int_bits_constAshley Mannix-1/+0
2021-01-11rustc_serialize: fix incorrect signed LEB128 decodingTyson Nottingham-16/+44
The signed LEB128 decoding function used a hardcoded constant of 64 instead of the number of bits in the type of integer being decoded, which resulted in incorrect results for some inputs. Fix this, make the decoding more consistent with the unsigned version, and increase the LEB128 encoding and decoding test coverage.
2021-01-11Serialize incr comp structures to file via fixed-size bufferTyson Nottingham-15/+36
Reduce a large memory spike that happens during serialization by writing the incr comp structures to file by way of a fixed-size buffer, rather than an unbounded vector. Effort was made to keep the instruction count close to that of the previous implementation. However, buffered writing to a file inherently has more overhead than writing to a vector, because each write may result in a handleable error. To reduce this overhead, arrangements are made so that each LEB128-encoded integer can be written to the buffer with only one capacity and error check. Higher-level optimizations in which entire composite structures can be written with one capacity and error check are possible, but would require much more work. The performance is mostly on par with the previous implementation, with small to moderate instruction count regressions. The memory reduction is significant, however, so it seems like a worth-while trade-off.
2020-08-30mv compiler to compiler/mark-0/+1590