Commit Graph

140 Commits

Author SHA1 Message Date
Ben Kimock
fbaa24ee35 Call FileEncoder::finish in rmeta encoding 2023-11-22 22:49:22 -05:00
Mark Rousskov
db3e2bacb6 Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
Nicholas Nethercote
8ff624a9f2 Clean up rustc_*/Cargo.toml.
- Sort dependencies and features sections.
- Add `tidy` markers to the sorted sections so they stay sorted.
- Remove empty `[lib`] sections.
- Remove "See more keys..." comments.

Excluded files:
- rustc_codegen_{cranelift,gcc}, because they're external.
- rustc_lexer, because it has external use.
- stable_mir, because it has external use.
2023-10-30 08:46:02 +11:00
Michael Howell
c6e6ecb1af rustdoc: remove rust logo from non-Rust crates 2023-10-08 20:17:53 -07:00
Nicholas Nethercote
ad8271dd56 Use collect to decode Vec.
It's hyper-optimized, we don't need our own unsafe code here.

This requires getting rid of all the `Allocator` stuff, which isn't
needed anyway.
2023-10-06 10:30:03 +11:00
Nicholas Nethercote
1d71971973 Streamline some Encodable impls.
Making them consistent with similar impls.
2023-10-06 10:30:03 +11:00
Nicholas Nethercote
2db1d59830 Use collect for decoding more collection types. 2023-10-06 10:30:03 +11:00
Nicholas Nethercote
5f69ca62f2 rustc_serialize: merge collection_impls.rs into serialize.rs.
`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-06 10:30:01 +11:00
Nicholas Nethercote
f703475b4e Remove unused serialization support for LinkedList. 2023-10-06 09:13:54 +11:00
Nicholas Nethercote
3ee67475b2 rustc_serialize: Remove unneeded feature decls.
I.e. `maybe_uninit_slice` and `new_uninit`.

Also sort the remaining features and remove an ugly, low-value comment.
2023-10-06 09:13:54 +11:00
Ben Kimock
09960e0319 Open the FileEncoder file for reading and writing 2023-09-22 16:13:25 -04:00
Ben Kimock
6cee6b0bde PR feedback 2023-09-20 16:49:13 -04:00
Ben Kimock
01e9798148 Reimplement FileEncoder with a small-write optimization 2023-09-10 23:37:51 -04:00
Ben Kimock
94fe18f84b Use a specialized varint + bitpacking scheme for DepGraph encoding 2023-09-04 12:16:50 -04:00
Josh Stone
d9b1fa93c4 Upgrade to indexmap 2.0.0
The new version was already added to the tree as an indirect dependency
in #113046, but now our direct dependents are using it too.
2023-07-03 13:51:54 -07:00
Nicholas Nethercote
f2df861c7f Fix the FileEncoder buffer size.
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-15 08:59:11 +10:00
Nicholas Nethercote
723ca2a33d Factor out more repeated code in {write,read}_leb128!.
Make them generate the entire function, not just the function body.
2023-05-04 13:52:14 +10:00
Nicholas Nethercote
4ac959a3c0 Rename file_encoder_write_leb128!.
`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-04 13:51:20 +10:00
Nicholas Nethercote
58002faca0 Reorder some MemDecoder methods.
So they match the order in the `Decoder` trait.
2023-05-04 13:11:51 +10:00
Nicholas Nethercote
b71ce293e8 Remove a low value comment. 2023-05-04 10:42:42 +10:00
Nicholas Nethercote
ebee3f8515 Remove MemEncoder.
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-02 12:02:32 +10:00
Nicholas Nethercote
8d359e4385 Move some Encodable/Decodable tests.
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-05-02 12:02:32 +10:00
Nicholas Nethercote
a676dfa888 Remove MemDecoder::read_byte.
It's just a synonym for `read_u8`.
2023-04-28 18:34:55 +10:00
Nicholas Nethercote
7a16d25365 Add some provided methods to Encoder/Decoder.
The methods for `i8`, `bool`, `char`, `str` are the same for all impls,
because they layered on top of other methods.
2023-04-28 18:34:54 +10:00
Nicholas Nethercote
fa133f5354 Remove a low-value assertion.
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-28 18:34:52 +10:00
Nicholas Nethercote
37c9e45186 Add a comment explaining the lack of Decoder::read_enum_variant.
Because I was wondering about it, and this may save a future person from
also wondering.
2023-04-28 09:51:00 +10:00
Nicholas Nethercote
b51deba9ac Remove MemDecoder::read_raw_bytes_inherent.
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-28 09:50:21 +10:00
Ben Kimock
1f67ba61a9 Rewrite MemDecoder around pointers not a slice 2023-04-23 17:25:11 -04:00
Scott McMurray
5cb23e4a43 Remove f32 & f64 from MemDecoder/MemEncoder 2023-04-06 00:54:07 -07:00
John Kåre Alsaker
27c44d2e28 Update indexmap and rayon crates 2023-03-25 02:12:13 +01:00
John Kåre Alsaker
7de205ea3a Emit the enum discriminant separately for the Encodable macro 2023-02-25 01:04:56 +01:00
bors
3fee48c161 Auto merge of #104754 - nnethercote:more-ThinVec-in-ast, r=the8472
Use `ThinVec` more in the AST

r? `@ghost`
2023-02-21 07:02:57 +00:00
Nicholas Nethercote
06228d6e93 Upgrade thin-vec from 0.2.9 to 0.2.12.
Because 0.2.10 added supports for `ThinVec::splice`, and 0.2.12 is the
latest release.
2023-02-21 11:51:55 +11:00
Deadbeef
255eb217e9 Remove old FIXME that no longer applies
it looks like Encodable was fallible at some point, but that was changed
which means that this FIXME is no longer applicable
2023-02-20 06:26:28 +00:00
KaDiWa
9bc69925cb
compiler: remove unnecessary imports and qualified paths 2022-12-10 18:45:34 +01:00
Maybe Waffle
8c0951511b rename {max=>largest}_max_leb128_len 2022-11-29 17:58:09 +00:00
Maybe Waffle
050cee48f8 Replace a macro with a function 2022-11-29 11:52:48 +00:00
Maybe Waffle
1d42936b18 Prefer doc comments over //-comments in compiler 2022-11-27 11:19:04 +00:00
Michael Howell
03968a802c rustdoc: use ThinVec for cleaned generics 2022-11-02 16:17:22 -07:00
Pietro Albini
3975d55d98
remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
Michael Howell
3f377d3f96
Rollup merge of #101014 - 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-20 10:12:57 -07:00
Sikkema, Isaac
a2cb8a4949 add comment explaining read permissions 2022-09-20 10:06:50 -04:00
est31
173eb6f407 Only enable the let_else feature on bootstrap
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-09-15 21:06:45 +02:00
Nicholas Nethercote
b38106b6d8 Replace rustc_data_structures::thin_vec::ThinVec with thin_vec::ThinVec.
`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-29 15:42:13 +10:00
Sikkema, Isaac
06139e57d5 use File::options() instead of File::create() 2022-08-25 18:00:45 -04:00
Ellen Arteca
258d3672f0 Adding support for rustc_serialize encode and decode for Box and Vec that use a custom allocator 2022-08-25 20:19:49 +00:00
Matthias Krüger
a45f69f27d
Rollup merge of #100822 - WaffleLapkin:no_offset_question_mark, r=scottmcm
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-21 16:54:07 +02:00
Maybe Waffle
e4720e1cf2 Replace most uses of pointer::offset with add and sub 2022-08-21 02:21:41 +04:00
5225225
09ea9f0a87 Add diagnostic translation lints to crates that don't emit them 2022-08-18 19:29:02 +01:00
Josh Stone
daa7c14a44 Upgrade indexmap and thorin-dwp to use hashbrown 0.12
This removes the last dependencies on hashbrown 0.11.
2022-07-17 07:05:58 -07:00