about summary refs log tree commit diff
path: root/compiler/rustc_metadata/src
AgeCommit message (Collapse)AuthorLines
2023-09-22Merge `ExternProviders` into the general `Providers` structOli Scherer-8/+8
2023-09-22Auto merge of #115920 - Zoxc:depkind-u16, r=cjgillotbors-2/+2
Move `DepKind` to `rustc_query_system` and define it as `u16` This moves the `DepKind` type to `rustc_query_system` where it's defined with an inner `u16` field. This decouples it from `rustc_middle` and is a step towards letting other crates define dep kinds. It also allows some type parameters to be removed. The `DepKind` trait is replaced with a `Deps` trait. That's used when some operations or information about dep kinds which is unavailable in `rustc_query_system` are still needed. r? `@cjgillot`
2023-09-21Record asyncness span in HIRMichael Goulet-4/+4
2023-09-21Move `DepKind` to `rustc_query_system` and define it as `u16`John Kåre Alsaker-2/+2
2023-09-20Auto merge of #115542 - saethlin:fileencoder-is-bufwriter, r=WaffleLapkinbors-2/+4
Simplify/Optimize FileEncoder FileEncoder is basically a BufWriter except that it exposes access to the not-written-to-yet region of the buffer so that some users can write directly to the buffer. This strategy is awesome because it lets us avoid calling memcpy for small copies, but the previous strategy was based on the writer accessing a `&mut [MaybeUninit<u8>; N]` and returning a `&[u8]` which is an API which currently mandates the use of unsafe code, making that interface in general not that appealing. So this PR cleans up the FileEncoder implementation and builds on that general idea of direct buffer access in order to prevent `memcpy` calls in a few key places when encoding the dep graph and rmeta tables. The interface used here is now 100% safe, but with the caveat that internally we need to avoid trusting the number of bytes that the provided function claims to have written. The original primary objective of this PR was to clean up the FileEncoder implementation so that the fix for the following issues would be easy to implement. The fix for these issues is to correctly update self.buffered even when writes fail, which I think it's easy to verify manually is now done, because all the FileEncoder methods are small. Fixes https://github.com/rust-lang/rust/issues/115298 Fixes https://github.com/rust-lang/rust/issues/114671 Fixes https://github.com/rust-lang/rust/issues/114045 Fixes https://github.com/rust-lang/rust/issues/108100 Fixes https://github.com/rust-lang/rust/issues/106787
2023-09-17Auto merge of #114750 - Enselic:metadata-dep-info, r=compiler-errorsbors-3/+1
Make `.rmeta` file in `dep-info` have correct name (`lib` prefix) Since `filename_for_metadata()` and `OutputFilenames::path(OutputType::Metadata)` had different logic for the name of the metadata file, the `.d` file contained a file name different from the actual name used. Share the logic to fix the out-of-sync name. Without this fix, the `.d` file contained dash-separated_something-extra.rmeta: dash-separated.rs instead of libdash_separated_something-extra.rmeta: dash-separated.rs which is the name of the file that is actually written by the compiler. Worth noting: It took me several iterations to get all tests to pass, so I am relatively confident that this PR does not break anything. Closes #68839
2023-09-13Auto merge of #115735 - bjorn3:better_list_crate_metadata, r=wesleywiserbors-18/+190
Extend rustc -Zls This makes it show a lot more things and thus a lot more useful.
2023-09-12Fix two typosbjorn3-1/+1
2023-09-10Reimplement FileEncoder with a small-write optimizationBen Kimock-2/+4
2023-09-10Auto merge of #115306 - tmiasko:encode-reachable-mir, r=cjgillotbors-12/+31
Encode only MIR reachable from other crates Only reachable items might participate in the code generation in the downstream crates. Omit redundant optimized MIR of unreachable items from a crate metadata. Additionally, include reachable closures in reachable set, so that unreachable closures can be omitted on the same basis.
2023-09-10Support listing all items in -Zlsbjorn3-10/+80
2023-09-10Show lib features in -Zls and allow configuring which things are shownbjorn3-70/+118
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-10Encode only MIR that can be used by other cratesTomasz Miąsko-12/+31
Only reachable items might participate in the code generation in the downstream crates. Omit redundant optimized MIR of unreachable items from a crate metadata. Additionally, include reachable closures in reachable set, so that unreachable closures can be omitted on the same basis.
2023-09-09Use `FreezeLock` for `CStore`John Kåre Alsaker-7/+7
2023-09-07Use `Freeze` for `SourceFile.external_src`John Kåre Alsaker-2/+2
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-03Make `.rmeta` file in `dep-info` have correct name (`lib` prefix)Martin Nordholts-3/+1
Since `filename_for_metadata()` and `OutputFilenames::path(OutputType::Metadata)` had different logic for the name of the metadata file, the `.d` file contained a file name different from the actual name used. Share the logic to fix the out-of-sync name. Closes 68839.
2023-09-02Auto merge of #115286 - saethlin:detangler, r=petrochenkovbors-12/+98
Skip rendering metadata strings from include_str!/include_bytes! The const rendering code in rustdoc completely ignores consts from expansions, but the compiler was rendering all consts. So some consts (namely those from `include_bytes!`) were rendered then ignored. Most of the diff here is from moving `print_const_expr` from rustdoc into `rustc_hir_pretty` so that it can be used in rustdoc and when building rmeta files.
2023-09-01Reuse const rendering from rustdoc in rmeta encodingBen Kimock-12/+98
2023-09-01Use `OnceLock` for `SingleCache`John Kåre Alsaker-2/+2
2023-08-30Auto merge of #113542 - saethlin:adaptive-tables, r=b-naberbors-47/+125
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-29Document in the code how this scheme worksBen Kimock-14/+25
2023-08-27Add a specialization for encoding byte arrays in rmetaBen Kimock-0/+7
2023-08-13Remove metadata_loader querybjorn3-5/+11
It is only used by CrateLoader. We can store the metadata loader in CStore instead which CrateLoader has access to.
2023-08-11rustc: Move `features` from `Session` to `GlobalCtxt`Vadim Petrochenkov-4/+7
Removes two pieces of mutable state. Follow up to #114622.
2023-08-09rustc: Move `crate_types` from `Session` to `GlobalCtxt`Vadim Petrochenkov-14/+18
Removes a piece of mutable state. Follow up to #114578.
2023-08-08Auto merge of #114578 - petrochenkov:noplugin, r=cjgillotbors-10/+11
rustc_interface: Dismantle `register_plugins` query It did three independent things: - Constructed `LintStore` - Prepared incremental directories and dep graph - Initialized some fields in `Session` The `LintStore` construction (now `passes::create_lint_store`) is more or less left in place. The incremental stuff is now moved into `fn dep_graph_future`. This helps us to start loading the dep graph a bit earlier. The `Session` field initialization is moved to tcx construction point. Now that tcx is constructed early these fields don't even need to live in `Session`, they can live in tcx instead and be initialized at its creation (see the FIXME). Three previously existing `rustc_interface` queries are de-querified (`register_plugins`, `dep_graph_future`, `dep_graph`) because they are only used locally in `fn global_ctxt` and their results don't need to be saved elsewhere. On the other hand, `crate_types` and `stable_crate_id` are querified. They are used from different places and their use is very similar to the existing `crate_name` query in this regard.
2023-08-07Store the laziness of type aliases in the DefKindLeón Orell Valerian Liehr-14/+14
2023-08-07rustc_interface: Dismantle `register_plugins` queryVadim Petrochenkov-10/+11
2023-08-04Rollup merge of #114253 - fmease:compute-variances-for-lazy-ty-aliases, ↵Matthias Krüger-3/+7
r=oli-obk Compute variances for lazy type aliases Fixes #114221. CC ``@oli-obk`` r? types
2023-08-03Auto merge of #113292 - MU001999:fix/issue-113222, r=Nilstriebbors-4/+14
Suggest `x build library` for a custom toolchain that fails to load `core` Fixes #113222 The nicer suggestion for dev-channel won't be emitted if `-Z ui-testing` enabled. IMO, this is acceptable for now.
2023-08-03Compute variances for lazy type aliasesLeón Orell Valerian Liehr-3/+7
2023-07-30Rollup merge of #113741 - compiler-errors:rpitit-projects-to-missing-opaque, ↵Jubilee-7/+1
r=spastorino Don't install default projection bound for return-position `impl Trait` in trait methods with no body This ensures that we never try to project to an opaque type in a trait method that has no body to infer its hidden type, which means we never later call `type_of` on that opaque. This is because opaque types try to reveal their hidden type when proving auto traits. I thought about this a lot, and I think this is a fix that's less likely to introduce other strange downstream ICEs than #113461. Fixes #113434 r? `@spastorino`
2023-07-30Don't install default projection bound for RPITITsMichael Goulet-7/+1
2023-07-30inline format!() args up to and including rustc_codegen_llvmMatthias Krüger-2/+2
2023-07-29Implement assumed_wf_types for RPITITs' implementationsMichael Goulet-0/+8
2023-07-25Auto merge of #113958 - lukas-code:doc-links, r=GuillaumeGomez,petrochenkovbors-5/+4
fix intra-doc links on nested `use` and `extern crate` items This PR fixes two rustdoc ICEs that happen if there are any intra-doc links on nested `use` or `extern crate` items, for example: ```rust /// Re-export [`fmt`] and [`io`]. pub use std::{fmt, io}; // "nested" use = use with braces /// Re-export [`std`]. pub extern crate std; ``` Nested use items were incorrectly considered private and therefore didn't have their intra-doc links resolved. I fixed this by always resolving intra-doc links for nested `use` items that are declared `pub`. <details> During AST->HIR lowering, nested `use` items are desugared like this: ```rust pub use std::{}; // "list stem" pub use std::fmt; pub use std::io; ``` Each of these HIR nodes has it's own effective visibility and the list stem is always considered private. To check the effective visibility of an AST node, the AST node is mapped to a HIR node with `Resolver::local_def_id`, which returns the (private) list stem for nested use items. </details> For `extern crate`, there was a hack in rustdoc that stored the `DefId` of the crate itself in the cleaned item, instead of the `DefId` of the `extern crate` item. This made rustdoc look at the resolved links of the extern crate's crate root instead of the `extern crate` item. I've removed this hack and instead translate the `DefId` in the appropriate places. As as side effect of fixing `extern crate`, i've turned ```rust #[doc(masked)] extern crate self as _; ``` into a no-op instead of hiding all trait impls. Proper verification for `doc(masked)` is included as a bonus. fixes https://github.com/rust-lang/rust/issues/113896
2023-07-23remove redundant clonesMatthias Krüger-2/+2
2023-07-22improve debuggabilityLukas Markeffsky-5/+4
2023-07-21Revert "Auto merge of #113166 - moulins:ref-niches-initial, r=oli-obk"David Tolnay-4/+1
This reverts commit 557359f92512ca88b62a602ebda291f17a953002, reversing changes made to 1e6c09a803fd543a98bfbe1624d697a55300a786.
2023-07-21add crate-local `-Z reference_niches` unstable flag (does nothing for now)Moulins-1/+4
2023-07-20Auto merge of #113695 - bjorn3:fix_rlib_cdylib_metadata_handling, ↵bors-24/+25
r=pnkfelix,petrochenkov Verify that all crate sources are in sync This ensures that rustc will not attempt to link against a cdylib as if it is a rust dylib when an rlib for the same crate is available. Previously rustc didn't actually check if any further formats of a crate which has been loaded are of the same version and if they are actually valid. This caused a cdylib to be interpreted as rust dylib as soon as the corresponding rlib was loaded. As cdylibs don't export any rust symbols, linking would fail if rustc decides to link against the cdylib rather than the rlib. Two crates depended on the previous behavior by separately compiling a test crate as both rlib and dylib. These have been changed to capture their original spirit to the best of my ability while still working when rustc verifies that all crates are in sync. It is unlikely that build systems depend on the current behavior and in any case we are taking a lot of measures to ensure that any change to either the source or the compilation options (including crate type) results in rustc rejecting it as incompatible. We merely didn't do this check here for now obsolete perf reasons. Fixes https://github.com/rust-lang/rust/issues/10786 Fixes https://github.com/rust-lang/rust/issues/82151 Fixes https://github.com/rust-lang/rust/issues/82972 Closes https://github.com/bevy-cheatbook/bevy-cheatbook/issues/114
2023-07-19Auto merge of #113865 - Dylan-DPC:rollup-pt960bk, r=Dylan-DPCbors-54/+49
Rollup of 7 pull requests Successful merges: - #113444 (add tests for alias bound preference) - #113716 (Add the `no-builtins` attribute to functions when `no_builtins` is applied at the crate level.) - #113754 (Simplify native_libs query) - #113765 (Make it clearer that edition functions are `>=`, not `==`) - #113774 (Improve error message when closing bracket interpreted as formatting fill character) - #113785 (Fix invalid display of inlined re-export when both local and foreign items are inlined) - #113803 (Fix inline_const with interpolated block) r? `@ghost` `@rustbot` modify labels: rollup
2023-07-19Rollup merge of #113754 - cjgillot:simplify-foreign, r=petrochenkovDylan DPC-54/+49
Simplify native_libs query Drive-by cleanup I saw while implementing https://github.com/rust-lang/rust/pull/113734
2023-07-19Fix review commentsbjorn3-5/+7
2023-07-19Don't compress dylib metadatabjorn3-12/+19
2023-07-19Verify that all crate sources are in syncbjorn3-13/+5
This ensures that rustc will not attempt to link against a cdylib as if it is a rust dylib when an rlib for the same crate is available. Previously rustc didn't actually check if any further formats of a crate which has been loaded are of the same version and if they are actually valid. This caused a cdylib to be interpreted as rust dylib as soon as the corresponding rlib was loaded. As cdylibs don't export any rust symbols, linking would fail if rustc decides to link against the cdylib rather than the rlib. Two crates depended on the previous behavior by separately compiling a test crate as both rlib and dylib. These have been changed to capture their original spirit to the best of my ability while still working when rustc verifies that all crates are in sync. It is unlikely that build systems depend on the current behavior and in any case we are taking a lot of measures to ensure that any change to either the source or the compilation options (including crate type) results in rustc rejecting it as incompatible. We merely didn't do this check here for now obsolete perf reasons.