summary refs log tree commit diff
path: root/compiler/rustc_metadata/src/rmeta/decoder.rs
AgeCommit message (Collapse)AuthorLines
2024-01-17Improved collapse_debuginfo attribute, added command-line flag (no|external|yes)Andrew Zhogin-0/+1
2024-01-06Auto merge of #119478 - bjorn3:no_serialize_specialization, r=wesleywiserbors-70/+59
Avoid specialization in the metadata serialization code With the exception of a perf-only specialization for byte slices and byte vectors. This uses the same trick of introducing a new trait and having the Encodable and Decodable derives add a bound to it as used for TyEncoder/TyDecoder. The new code is clearer about which encoder/decoder uses which impl and it reduces the dependency of rustc on specialization, making it easier to remove support for specialization entirely or turn it into a construct that is only allowed for perf optimizations if we decide to do this.
2024-01-04cstore: Remove unnecessary locking from `CrateMetadata`Vadim Petrochenkov-20/+19
2023-12-31Avoid specialization for AttrId deserializationbjorn3-6/+3
2023-12-31Remove almost all uses of specialization from the metadata encoding codebjorn3-57/+49
2023-12-31Avoid specialization for the Span Encodable and Decodable implsbjorn3-9/+9
2023-12-29Shrink span encoding furtherMark Rousskov-21/+19
Spans are now stored in a more compact form which cuts down on at least 1 byte per span (indirect/direct encoding) and at most 3 bytes per span (indirect/direct encoding, context byte, length byte). As a result, libcore metadata shrinks by 1.5MB.
2023-12-27Support relative offsets when encoding spansMark Rousskov-1/+9
The relative offset is often smaller than the absolute offset, and with the LEB128 encoding, this ends up cutting the overall metadata size considerably (~1.5 megabytes on libcore). We can support both relative and absolute encodings essentially for free since we already take a full byte to differentiate between direct and indirect encodings (so an extra variant is quite cheap).
2023-12-24Auto merge of #119139 - michaelwoerister:cleanup-stable-source-file-id, ↵bors-2/+2
r=cjgillot Unify SourceFile::name_hash and StableSourceFileId This PR adapts the existing `StableSourceFileId` type so that it can be used instead of the `name_hash` field of `SourceFile`. This simplifies a few things that were kind of duplicated before. The PR should also fix issues https://github.com/rust-lang/rust/issues/112700 and https://github.com/rust-lang/rust/issues/115835, but I was not able to reproduce these issues in a regression test. As far as I can tell, the root cause of these issues is that the id of the originating crate is not hashed in the `HashStable` impl of `Span` and thus cache entries that should have been considered invalidated were loaded. After this PR, the `stable_id` field of `SourceFile` includes information about the originating crate, so that ICE should not occur anymore.
2023-12-24Auto merge of #119265 - Mark-Simulacrum:remove-cache, r=cjgillotbors-22/+8
Remove metadata decoding DefPathHash cache My expectation is that this cache is largely useless. Decoding a DefPathHash from metadata is essentially a pair of memory loads - there's no heavyweight processing involved. Caching it behind a HashMap just adds extra cost and incurs hashing overheads for the indices. Based on https://github.com/rust-lang/rust/pull/119238.
2023-12-24Auto merge of #119238 - Mark-Simulacrum:def-hash-efficiency, r=cjgillotbors-3/+11
Skip duplicate stable crate ID encoding into metadata Instead, we store just the local crate hash as a bare u64. On decoding, we recombine it with the crate's stable crate ID stored separately in metadata. The end result is that we save ~8 bytes/DefIndex in metadata size. One key detail here is that we no longer distinguish in encoded metadata between present and non-present DefPathHashes. It used to be highly likely we could distinguish as we used DefPathHash::default(), an all-zero representation. However in theory even that is fallible as nothing strictly prevents the StableCrateId from being zero. In review it was pointed out that we should never have a missing hash for a DefIndex anyway, so this shouldn't matter.
2023-12-23Remove metadata decoding DefPathHash cacheMark Rousskov-22/+8
This cache is largely useless. Decoding a DefPathHash from metadata is essentially a pair of memory loads - there's no heavyweight processing involved. Caching it behind a HashMap just adds extra cost and incurs hashing overheads.
2023-12-23Specialize DefPathHash table to skip crate IDsMark Rousskov-3/+11
Instead, we store just the local crate hash as a bare u64. On decoding, we recombine it with the crate's stable crate ID stored separately in metadata. The end result is that we save ~8 bytes/DefIndex in metadata size. One key detail here is that we no longer distinguish in encoded metadata between present and non-present DefPathHashes. It used to be highly likely we could distinguish as we used DefPathHash::default(), an all-zero representation. However in theory even that is fallible as nothing strictly prevents the StableCrateId from being zero.
2023-12-23Auto merge of #119225 - Mark-Simulacrum:remove-option, r=compiler-errorsbors-1/+1
Avoid redundant Option for cross_crate_inlinable
2023-12-22Avoid redundant Option for cross_crate_inlinableMark Rousskov-1/+1
2023-12-19Unify SourceFile::name_hash and StableSourceFileIdMichael Woerister-2/+2
2023-12-18Replace some instances of FxHashMap/FxHashSet with stable alternatives ↵Michael Woerister-2/+2
(mostly in rustc_hir and rustc_ast_lowering) Part of https://github.com/rust-lang/compiler-team/issues/533
2023-12-11Auto merge of #118344 - saethlin:rmeta-header-pos, r=WaffleLapkinbors-14/+11
Use a u64 for the rmeta root position Waffle noticed this in https://github.com/rust-lang/rust/pull/117301#discussion_r1405410174 We've upgraded the other file offsets to u64, and this one only costs 4 bytes per file. Also the way the truncation was being done before was extremely easy to miss, I sure missed it! It's not clear to me if not having this change effectively made the other upgrades from u32 to u64 ineffective, but we can have it now. r? `@WaffleLapkin`
2023-12-10Apply suggestions from code reviewBen Kimock-2/+1
Co-authored-by: Waffle Maybe <waffle.lapkin@gmail.com>
2023-12-10remove redundant importssurechen-19/+9
detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR.
2023-11-28Use a u64 for the rmeta root positionBen Kimock-13/+11
2023-11-25rustc: Make `def_kind` mandatory for all `DefId`sVadim Petrochenkov-9/+6
2023-11-20Store feature stability un-splitMichael Goulet-12/+8
2023-11-20Unify defined_lib_features and lib_features queriesMichael Goulet-3/+15
2023-10-20s/generator/coroutine/Oli Scherer-1/+1
2023-10-17Automatically enable cross-crate inlining for small functionsBen Kimock-0/+4
2023-10-13Format all the let chains in compilerMichael Goulet-5/+10
2023-09-23Enable drop_tracking_mir by default.Camille GILLOT-19/+0
2023-09-22Merge `ExternProviders` into the general `Providers` structOli Scherer-1/+0
2023-09-12Fix two typosbjorn3-1/+1
2023-09-10Support listing all items in -Zlsbjorn3-10/+80
2023-09-10Show lib features in -Zls and allow configuring which things are shownbjorn3-69/+116
2023-09-10List all defined and required lang items in -Zlsbjorn3-0/+20
2023-09-10List more crate metadata in -Zlsbjorn3-4/+38
2023-09-03Register the file while computing its start position.Camille GILLOT-1/+1
2023-09-03Use relative positions inside a SourceFile.Camille GILLOT-13/+11
2023-09-01Use `OnceLock` for `SingleCache`John Kåre Alsaker-2/+2
2023-08-30Auto merge of #113542 - saethlin:adaptive-tables, r=b-naberbors-3/+11
Adapt table sizes to the contents This is an implementation of https://github.com/rust-lang/compiler-team/issues/666 The objective of this PR is to permit the rmeta format to accommodate larger crates that need offsets larger than a `u32` can store without compromising performance for crates that do not need such range. The second commit is a number of tiny optimization opportunities I noticed while looking at perf recordings of the first commit. The rmeta tables need to have fixed-size elements to permit lazy random access. But the size only needs to be fixed _per table_, not per element type. This PR adds another `usize` to the table header which indicates the table element size. As each element of a table is set, we keep track of the widest encoded table value, then don't bother encoding all the unused trailing bytes on each value. When decoding table elements, we copy them to a full-width array if they are not already full-width. `LazyArray` needs some special treatment. Most other values that are encoded in tables are indexes or offsets, and those tend to be small so we get to drop a lot of zero bytes off the end. But `LazyArray` encodes _two_ small values in a fixed-width table element: A position of the table and the length of the table. The treatment described above could trim zero bytes off the table length, but any nonzero length shields the position bytes from the optimization. To improve this, we interleave the bytes of position and length. This change is responsible for about half of the crate metadata win on many crates. Fixes https://github.com/rust-lang/rust/issues/112934 (probably) Fixes https://github.com/rust-lang/rust/issues/103607
2023-08-11rustc: Move `features` from `Session` to `GlobalCtxt`Vadim Petrochenkov-1/+3
Removes two pieces of mutable state. Follow up to #114622.
2023-07-19Encode shorthands for spans in metadata.Camille GILLOT-3/+18
2023-07-14Micro-optimizeBen Kimock-0/+7
2023-07-13Adapt table sizes to the contentsBen Kimock-3/+4
2023-07-12Re-format let-else per rustfmt updateMark Rousskov-8/+16
2023-06-26Migrate predicates_of and caller_bounds to ClauseMichael Goulet-6/+0
2023-06-22Migrate item_bounds to ty::ClauseMichael Goulet-2/+8
2023-06-01Remember names of `cfg`-ed out items to mention them in diagnosticsNilstrieb-0/+9
`#[cfg]`s are frequently used to gate crate content behind cargo features. This can lead to very confusing errors when features are missing. For example, `serde` doesn't have the `derive` feature by default. Therefore, `serde::Serialize` fails to resolve with a generic error, even though the macro is present in the docs. This commit adds a list of all stripped item names to metadata. This is filled during macro expansion and then, through a fed query, persisted in metadata. The downstream resolver can then access the metadata to look at possible candidates for mentioning in the errors. This slightly increases metadata (800k->809k for the feature-heavy windows crate), but not enough to really matter.
2023-05-31Auto merge of #111076 - ↵bors-7/+14
notriddle:notriddle/silence-private-dep-trait-impl-suggestions, r=cjgillot diagnostics: exclude indirect private deps from trait impl suggest Fixes #88696
2023-05-30Rollup merge of #112060 - lcnr:early-binder, r=jackh726Nilstrieb-1/+1
`EarlyBinder::new` -> `EarlyBinder::bind` for consistency with `Binder::bind`. it may make sense to also add `EarlyBinder::dummy` in places where we know that no parameters exist, but I left that out of this PR. r? `@jackh726` `@kylematsuda`
2023-05-29EarlyBinder::new -> EarlyBinder::bindlcnr-1/+1
2023-05-29Auto merge of #111329 - jyn514:metadata-ice, r=bjorn3bors-13/+20
Load only the crate header for `locator::crate_matches` Previously, we used the following info to determine whether to load the crate: 1. The METADATA_HEADER, which includes a METADATA_VERSION constant 2. The embedded rustc version 3. Various metadata in the `CrateRoot`, including the SVH This worked ok most of the time. Unfortunately, when building locally the rustc version is always the same because `omit-git-hash` is on by default. That meant that we depended only on 1 and 3, and we are not very good about bumping METADATA_VERSION (it's currently at 7) so in practice we were only depending on 3. `CrateRoot` is a very large struct and changes somewhat regularly, so this led to a steady stream of crashes from trying to load it. Change the logic to add an intermediate step between 2 and 3: introduce a new `CrateHeader` struct that contains only the minimum info needed to decide whether the crate should be loaded or not. That avoids having to load all of `CrateRoot`, which in practice means we should crash much less often. Note that this works because the SVH should be different between any two dependencies, even if the compiler has changed, because we use `-Zbinary-dep-depinfo` in bootstrap. See https://github.com/rust-lang/rust/pull/111329#issuecomment-1538303474 for more details about how the original crash happened.