about summary refs log tree commit diff
path: root/compiler/rustc_metadata
AgeCommit message (Collapse)AuthorLines
2021-03-26Fix #83045 by moving some crate loading verification code to a better place.Michael Woerister-3/+8
2021-03-25Auto merge of #83307 - richkadel:cov-unused-functions-1.1, r=tmandrybors-1/+1
coverage bug fixes and optimization support Adjusted LLVM codegen for code compiled with `-Zinstrument-coverage` to address multiple, somewhat related issues. Fixed a significant flaw in prior coverage solution: Every counter generated a new counter variable, but there should have only been one counter variable per function. This appears to have bloated .profraw files significantly. (For a small program, it increased the size by about 40%. I have not tested large programs, but there is anecdotal evidence that profraw files were way too large. This is a good fix, regardless, but hopefully it also addresses related issues. Fixes: #82144 Invalid LLVM coverage data produced when compiled with -C opt-level=1 Existing tests now work up to at least `opt-level=3`. This required a detailed analysis of the LLVM IR, comparisons with Clang C++ LLVM IR when compiled with coverage, and a lot of trial and error with codegen adjustments. The biggest hurdle was figuring out how to continue to support coverage results for unused functions and generics. Rust's coverage results have three advantages over Clang's coverage results: 1. Rust's coverage map does not include any overlapping code regions, making coverage counting unambiguous. 2. Rust generates coverage results (showing zero counts) for all unused functions, including generics. (Clang does not generate coverage for uninstantiated template functions.) 3. Rust's unused functions produce minimal stubbed functions in LLVM IR, sufficient for including in the coverage results; while Clang must generate the complete LLVM IR for each unused function, even though it will never be called. This PR removes the previous hack of attempting to inject coverage into some other existing function instance, and generates dedicated instances for each unused function. This change, and a few other adjustments (similar to what is required for `-C link-dead-code`, but with lower impact), makes it possible to support LLVM optimizations. Fixes: #79651 Coverage report: "Unexecuted instantiation:..." for a generic function from multiple crates Fixed by removing the aforementioned hack. Some "Unexecuted instantiation" notices are unavoidable, as explained in the `used_crate.rs` test, but `-Zinstrument-coverage` has new options to back off support for either unused generics, or all unused functions, which avoids the notice, at the cost of less coverage of unused functions. Fixes: #82875 Invalid LLVM coverage data produced with crate brotli_decompressor Fixed by disabling the LLVM function attribute that forces inlining, if `-Z instrument-coverage` is enabled. This attribute is applied to Rust functions with `#[inline(always)], and in some cases, the forced inlining breaks coverage instrumentation and reports. FYI: `@wesleywiser` r? `@tmandry`
2021-03-23Update with commentskadmin-1/+0
2021-03-23Update with commentskadmin-2/+2
A bunch of nits fixed, and a new test for pretty printing the AST.
2021-03-23Add query for const_param_defaultkadmin-8/+15
2021-03-23Some refactoringvarkor-2/+5
2021-03-22Auto merge of #79278 - mark-i-m:stabilize-or-pattern, r=nikomatsakisbors-1/+1
Stabilize or_patterns (RFC 2535, 2530, 2175) closes #54883 This PR stabilizes the or_patterns feature in Rust 1.53. This is blocked on the following (in order): - [x] The crater run in https://github.com/rust-lang/rust/pull/78935#issuecomment-731564021 - [x] The resolution of the unresolved questions and a second crater run (https://github.com/rust-lang/rust/pull/78935#issuecomment-735412705) - It looks like we will need to pursue some sort of edition-based transition for `:pat`. - [x] Nomination and discussion by T-lang - [x] Implement new behavior for `:pat` based on consensus (https://github.com/rust-lang/rust/pull/80100). - [ ] An FCP on stabilization EDIT: Stabilization report is in https://github.com/rust-lang/rust/pull/79278#issuecomment-772815177
2021-03-22Auto merge of #83273 - cjgillot:endecode, r=michaelwoeristerbors-17/+5
Simplify encoder and decoder Extracted from https://github.com/rust-lang/rust/pull/83036 and https://github.com/rust-lang/rust/pull/82780.
2021-03-19stabilize or_patternsmark-1/+1
2021-03-19coverage bug fixes and optimization supportRich Kadel-1/+1
Adjusted LLVM codegen for code compiled with `-Zinstrument-coverage` to address multiple, somewhat related issues. Fixed a significant flaw in prior coverage solution: Every counter generated a new counter variable, but there should have only been one counter variable per function. This appears to have bloated .profraw files significantly. (For a small program, it increased the size by about 40%. I have not tested large programs, but there is anecdotal evidence that profraw files were way too large. This is a good fix, regardless, but hopefully it also addresses related issues. Fixes: #82144 Invalid LLVM coverage data produced when compiled with -C opt-level=1 Existing tests now work up to at least `opt-level=3`. This required a detailed analysis of the LLVM IR, comparisons with Clang C++ LLVM IR when compiled with coverage, and a lot of trial and error with codegen adjustments. The biggest hurdle was figuring out how to continue to support coverage results for unused functions and generics. Rust's coverage results have three advantages over Clang's coverage results: 1. Rust's coverage map does not include any overlapping code regions, making coverage counting unambiguous. 2. Rust generates coverage results (showing zero counts) for all unused functions, including generics. (Clang does not generate coverage for uninstantiated template functions.) 3. Rust's unused functions produce minimal stubbed functions in LLVM IR, sufficient for including in the coverage results; while Clang must generate the complete LLVM IR for each unused function, even though it will never be called. This PR removes the previous hack of attempting to inject coverage into some other existing function instance, and generates dedicated instances for each unused function. This change, and a few other adjustments (similar to what is required for `-C link-dead-code`, but with lower impact), makes it possible to support LLVM optimizations. Fixes: #79651 Coverage report: "Unexecuted instantiation:..." for a generic function from multiple crates Fixed by removing the aforementioned hack. Some "Unexecuted instantiation" notices are unavoidable, as explained in the `used_crate.rs` test, but `-Zinstrument-coverage` has new options to back off support for either unused generics, or all unused functions, which avoids the notice, at the cost of less coverage of unused functions. Fixes: #82875 Invalid LLVM coverage data produced with crate brotli_decompressor Fixed by disabling the LLVM function attribute that forces inlining, if `-Z instrument-coverage` is enabled. This attribute is applied to Rust functions with `#[inline(always)], and in some cases, the forced inlining breaks coverage instrumentation and reports.
2021-03-19Remove FingerprintEncoder/Decoder.Camille GILLOT-14/+0
2021-03-19Move raw bytes handling to Encoder/Decoder.Camille GILLOT-3/+5
2021-03-19Rollup merge of #83236 - cjgillot:memmap, r=joshtriplettDylan DPC-3/+3
Upgrade memmap to memmap2 memmap is no longer maintained. memmap2 is a fork that is still maintained. https://rustsec.org/advisories/RUSTSEC-2020-0077.html The remaining use of memmap is through measureme.
2021-03-18Upgrade memmap to memmap2 in other crates.Camille GILLOT-3/+3
2021-03-17Iterate for super_predicates.Camille GILLOT-11/+3
2021-03-16Filter generics.Camille GILLOT-6/+43
2021-03-16Iterate on inferred_outlives.Camille GILLOT-32/+4
2021-03-16Iterate on explicit_predicates.Camille GILLOT-15/+1
2021-03-16Iterate on generics_of.Camille GILLOT-15/+2
2021-03-16Iterate on variances_of.Camille GILLOT-19/+39
2021-03-13Iterate on crate_inherent_impls for metadata.Camille GILLOT-14/+11
2021-03-09Remove hir::Item::attrs.Camille GILLOT-2/+5
2021-03-09Remove hir::Crate::attrs.Camille GILLOT-1/+1
2021-03-07Auto merge of #81635 - michaelwoerister:structured_def_path_hash, r=pnkfelixbors-3/+43
Let a portion of DefPathHash uniquely identify the DefPath's crate. This allows to directly map from a `DefPathHash` to the crate it originates from, without constructing side tables to do that mapping -- something that is useful for incremental compilation where we deal with `DefPathHash` instead of `DefId` a lot. It also allows to reliably and cheaply check for `DefPathHash` collisions which allows the compiler to gracefully abort compilation instead of running into a subsequent ICE at some random place in the code. The following new piece of documentation describes the most interesting aspects of the changes: ```rust /// A `DefPathHash` is a fixed-size representation of a `DefPath` that is /// stable across crate and compilation session boundaries. It consists of two /// separate 64-bit hashes. The first uniquely identifies the crate this /// `DefPathHash` originates from (see [StableCrateId]), and the second /// uniquely identifies the corresponding `DefPath` within that crate. Together /// they form a unique identifier within an entire crate graph. /// /// There is a very small chance of hash collisions, which would mean that two /// different `DefPath`s map to the same `DefPathHash`. Proceeding compilation /// with such a hash collision would very probably lead to an ICE and, in the /// worst case, to a silent mis-compilation. The compiler therefore actively /// and exhaustively checks for such hash collisions and aborts compilation if /// it finds one. /// /// `DefPathHash` uses 64-bit hashes for both the crate-id part and the /// crate-internal part, even though it is likely that there are many more /// `LocalDefId`s in a single crate than there are individual crates in a crate /// graph. Since we use the same number of bits in both cases, the collision /// probability for the crate-local part will be quite a bit higher (though /// still very small). /// /// This imbalance is not by accident: A hash collision in the /// crate-local part of a `DefPathHash` will be detected and reported while /// compiling the crate in question. Such a collision does not depend on /// outside factors and can be easily fixed by the crate maintainer (e.g. by /// renaming the item in question or by bumping the crate version in a harmless /// way). /// /// A collision between crate-id hashes on the other hand is harder to fix /// because it depends on the set of crates in the entire crate graph of a /// compilation session. Again, using the same crate with a different version /// number would fix the issue with a high probability -- but that might be /// easier said then done if the crates in questions are dependencies of /// third-party crates. /// /// That being said, given a high quality hash function, the collision /// probabilities in question are very small. For example, for a big crate like /// `rustc_middle` (with ~50000 `LocalDefId`s as of the time of writing) there /// is a probability of roughly 1 in 14,750,000,000 of a crate-internal /// collision occurring. For a big crate graph with 1000 crates in it, there is /// a probability of 1 in 36,890,000,000,000 of a `StableCrateId` collision. ``` Given the probabilities involved I hope that no one will ever actually see the error messages. Nonetheless, I'd be glad about some feedback on how to improve them. Should we create a GH issue describing the problem and possible solutions to point to? Or a page in the rustc book? r? `@pnkfelix` (feel free to re-assign)
2021-02-23Add #[rustc_legacy_const_generics]Amanieu d'Antras-0/+4
2021-02-18Print -Ztime-passes (and misc stats/logs) on stderr, not stdout.Eduard-Mihai Burtescu-17/+17
2021-02-16Auto merge of #81611 - cjgillot:meowner, r=estebankbors-33/+25
Only store a LocalDefId in some HIR nodes Some HIR nodes are guaranteed to be HIR owners: Item, TraitItem, ImplItem, ForeignItem and MacroDef. As a consequence, we do not need to store the `HirId`'s `local_id`, and we can directly store a `LocalDefId`. This allows to avoid a bit of the dance with `tcx.hir().local_def_id` and `tcx.hir().local_def_id_to_hir_id` mappings.
2021-02-16avoid full-slicing slicesMatthias Krüger-1/+1
If we already have a slice, there is no need to get another full-range slice from that, just use the original. clippy::redundant_slicing
2021-02-15Only store a LocalDefId in hir::MacroDef.Camille GILLOT-1/+1
2021-02-15Only store a LocalDefId in hir::ForeignItem.Camille GILLOT-10/+6
2021-02-15Only store a LocalDefId in hir::Item.Camille GILLOT-22/+18
Items are guaranteed to be HIR owner.
2021-02-14bumped smallvec depsklensy-1/+1
2021-02-08Rollup merge of #81861 - tmiasko:mir-bytes, r=wesleywiserMara Bos-1/+6
Show MIR bytes separately in -Zmeta-stats output The size of serialized MIR is substantial enough to deserve its own category.
2021-02-07Add `--extern-loc` to augment unused crate dependency diagnosticsJeremy Fitzhardinge-4/+23
This allows a build system to indicate a location in its own dependency specification files (eg Cargo's `Cargo.toml`) which can be reported along side any unused crate dependency. This supports several types of location: - 'json' - provide some json-structured data, which is included in the json diagnostics in a `tool_metadata` field - 'raw' - emit the provided string into the output. This also appears as a json string in `tool_metadata`. If no `--extern-location` is explicitly provided then a default json entry of the form `"tool_metadata":{"name":<cratename>,"path":<cratepath>}` is emitted.
2021-02-07Show MIR bytes separately in -Zmeta-stats outputTomasz Miąsko-1/+6
2021-02-05Auto merge of #81215 - cjgillot:defkey-mir, r=oli-obkbors-215/+103
Encode MIR metadata by iterating on DefId instead of traversing the HIR tree Split out of https://github.com/rust-lang/rust/pull/80347. This part only traverses `mir_keys` and encodes MIR according to the def kind. r? `@oli-obk`
2021-02-04Encode less consts.Camille GILLOT-7/+16
2021-02-03Address review.Camille GILLOT-6/+2
2021-02-02Let a portion of DefPathHash uniquely identify the DefPath's crate.Michael Woerister-3/+43
This allows to directly map from a DefPathHash to the crate it originates from, without constructing side tables to do that mapping. It also allows to reliably and cheaply check for DefPathHash collisions.
2021-01-29Pre-canoncalize ExternLocation::ExactPathsRyan Levick-13/+21
2021-01-26Check for rmeta crates when getting existing crates from cacheRyan Levick-2/+3
2021-01-24Sort mir_keys to ensure consistent diagnostic order.Camille GILLOT-5/+18
2021-01-24Review comment.Camille GILLOT-0/+5
2021-01-24Refactor MIR metadata emission.Camille GILLOT-215/+43
2021-01-24Introduce should_encode_mir.Camille GILLOT-0/+37
2021-01-23Fix proc macro crate encoding.Camille GILLOT-2/+9
2021-01-23Filter stability.Camille GILLOT-3/+40
2021-01-23Iterate on deprecation.Camille GILLOT-10/+1
2021-01-23Iterate on const_stability.Camille GILLOT-4/+1
2021-01-23Iterate on stability.Camille GILLOT-14/+2