about summary refs log tree commit diff
path: root/compiler/rustc_metadata/src/creader.rs
AgeCommit message (Collapse)AuthorLines
2025-08-21-Zsanitize and -Zsanitizer-cfi-normalize-integers flags are now target ↵Andrew Zhogin-5/+13
modifiers with custom consistency check function
2025-08-15Detect missing `derive` on unresolved attribute even when not importedEsteban Küber-0/+5
``` error: cannot find attribute `sede` in this scope --> $DIR/missing-derive-3.rs:20:7 | LL | #[sede(untagged)] | ^^^^ | help: the derive macros `Deserialize` and `Serialize` accept the similarly named `serde` attribute | LL | #[serde(untagged)] | + error: cannot find attribute `serde` in this scope --> $DIR/missing-derive-3.rs:14:7 | LL | #[serde(untagged)] | ^^^^^ | note: `serde` is imported here, but it is a crate, not an attribute --> $DIR/missing-derive-3.rs:4:1 | LL | extern crate serde; | ^^^^^^^^^^^^^^^^^^^ help: `serde` is an attribute that can be used by the derive macros `Deserialize` and `Serialize`, you might be missing a `derive` attribute | LL + #[derive(Deserialize, Serialize)] LL | enum B { | ```
2025-07-28Support multiple crate versions in --extern-html-root-urlKornel-0/+8
2025-07-28Save names of used extern cratesKornel-0/+15
Tracks association between `self.sess.opts.externs` (aliases in `--extern alias=rlib`) and resolved `CrateNum` Intended to allow Rustdoc match the aliases in `--extern-html-root-url` Force-injected extern crates aren't included, since they're meant for the linker only
2025-07-28Avoid redundant lookup in CrateLoader::existing_matchKornel-1/+1
2025-07-18inline CrateLoader inside of CStoreLorrensP-2158466-137/+149
2025-07-03Make most CrateLocator fields privatebjorn3-21/+7
This ensures they don't get out of sync
2025-07-03Have a separate code path for -Zdual-proc-macrobjorn3-41/+56
This makes it clearer when the locator and when crate_rejections is updated
2025-07-03Pass CrateRejections separately from CrateLocatorbjorn3-25/+39
This allows all CrateLocator methods to take &self.
2025-06-24Stop handling explicit dependencies on the panic runtimebjorn3-14/+7
You shouldn't ever need to explicitly depend on it. And we weren't checking that the panic runtime used the correct panic strategy either.
2025-06-24Remove dependency injection for the panic runtimebjorn3-70/+3
This used to be necessary for a correct linker order, but ever since the introduction of symbols.o adding the symbols in question to symbols.o would work just as well. We do still add dependencies on the panic runtime to the local crate, but not for #![needs_panic_runtime] crates. This also removes the runtime-depends-on-needs-runtime test. inject_dependency_if used to emit this error, but with symbols.o it is no longer important that there is no dependency and in fact it may be nice to have panic_abort and panic_unwind directly depend on libstd in the future for calling std::process::abort().
2025-06-01Auto merge of #141730 - osiewicz:collect-crate-deps-postorder-use-indexset, ↵bors-8/+10
r=nnethercote cstore: Use IndexSet as backing store for postorder dependencies `<rustc_metadata::creader::CStore>::push_dependencies_in_postorder` showed up in new benchmarks from https://github.com/rust-lang/rustc-perf/pull/2143, hence I gave it a shot to remove an obvious O(n) there. r? nnethercote
2025-05-29Erase return type of crate_dependencies_in_reverse_postorderPiotr Osiewicz-4/+5
2025-05-29cstore: Use IndexSet as backing store for postorder dependenciesPiotr Osiewicz-5/+6
<rustc_metadata::creader::CStore>::push_dependencies_in_postorder showed up in new benchmarks from https://github.com/rust-lang/rustc-perf/pull/2143, hence I gave it a shot to remove an obvious O(n) there.
2025-05-27Do not get proc_macro from the sysroot in rustcbjorn3-1/+1
With the stage0 refactor the proc_macro version found in the sysroot will no longer always match the proc_macro version that proc-macros get compiled with by the rustc executable that uses this proc_macro. This will cause problems as soon as the ABI of the bridge gets changed to implement new features or change the way existing features work. To fix this, this commit changes rustc crates to depend directly on the local version of proc_macro which will also be used in the sysroot that rustc will build.
2025-05-19Warning added when dependency crate has async drop types, and the feature is ↵Andrew Zhogin-0/+21
disabled
2025-05-04Initial support for dynamically linked cratesBryanskiy-1/+4
2025-04-03Make LevelAndSource a structOli Scherer-1/+1
2025-04-01Move `ast::Item::ident` into `ast::ItemKind`.Nicholas Nethercote-7/+5
`ast::Item` has an `ident` field. - It's always non-empty for these item kinds: `ExternCrate`, `Static`, `Const`, `Fn`, `Mod`, `TyAlias`, `Enum`, `Struct`, `Union`, `Trait`, `TraitAlias`, `MacroDef`, `Delegation`. - It's always empty for these item kinds: `Use`, `ForeignMod`, `GlobalAsm`, `Impl`, `MacCall`, `DelegationMac`. There is a similar story for `AssocItemKind` and `ForeignItemKind`. Some sites that handle items check for an empty ident, some don't. This is a very C-like way of doing things, but this is Rust, we have sum types, we can do this properly and never forget to check for the exceptional case and never YOLO possibly empty identifiers (or possibly dummy spans) around and hope that things will work out. The commit is large but it's mostly obvious plumbing work. Some notable things. - `ast::Item` got 8 bytes bigger. This could be avoided by boxing the fields within some of the `ast::ItemKind` variants (specifically: `Struct`, `Union`, `Enum`). I might do that in a follow-up; this commit is big enough already. - For the visitors: `FnKind` no longer needs an `ident` field because the `Fn` within how has one. - In the parser, the `ItemInfo` typedef is no longer needed. It was used in various places to return an `Ident` alongside an `ItemKind`, but now the `Ident` (if present) is within the `ItemKind`. - In a few places I renamed identifier variables called `name` (or `foo_name`) as `ident` (or `foo_ident`), to better match the type, and because `name` is normally used for `Symbol`s. It's confusing to see something like `foo_name.name`.
2025-04-01Factor out some shared code.Nicholas Nethercote-32/+14
`global_allocator_spans` and `alloc_error_handler_span` are identical except for `name`.
2025-03-17Target modifiers fix for bool flags without valueAndrew Zhogin-18/+51
2025-02-23Rollup merge of #135501 - tgross35:stdlib-dependencies-private, r=bjorn3Matthias Krüger-39/+136
Inject `compiler_builtins` during postprocessing and ensure it is made private Follow up of https://github.com/rust-lang/rust/pull/135278 Do the following: * Inject `compiler_builtins` during postprocessing, rather than injecting `extern crate compiler_builtins as _` into the AST * Do not make dependencies of `std` private by default (this was added in #135278) * Make sure sysroot crates correctly mark their dependencies private/public * Ensure that marking a dependency private makes its dependents private by default as well, unless otherwise specified * Do the `compiler_builtins` update that has been blocked on this There is more detail in the commit messages. This includes the changes I was working on in https://github.com/rust-lang/rust/pull/136226. try-job: test-various try-job: x86_64-msvc-1 try-job: x86_64-msvc-2 try-job: i686-mingw-1 try-job: i686-mingw-2
2025-02-21If the parent dependency is private, treat dependents as privateTrevor Gross-5/+26
Currently, marking a dependency private does not automatically make all its child dependencies private. Resolve this by making its children private by default as well. This also resolves some FIXMEs for tests that are intended to fail but previously passed. [1]: https://github.com/rust-lang/rust/pull/135501#issuecomment-2620242419
2025-02-21Partially revert ed63539282 ("Mark dependencies ... private by default")Trevor Gross-17/+1
Remove the portion of ed63539282 that automatically sets crates private based on whether they are dependencies of `std`. Instead, this is controlled by dependency configuration in `Cargo.toml`.
2025-02-21Inject `compiler_builtins` during postprocessing rather than via ASTTrevor Gross-0/+38
`compiler_builtins` is currently injected as `extern crate compiler_builtins as _`. This has made gating via diagnostics difficult because it appears in the crate graph as a non-private dependency, and there isn't an easy way to differentiate between the injected AST and user-specified `extern crate compiler_builtins`. Resolve this by injecting `compiler_builtins` during postprocessing rather than early in the AST. Most of the time this isn't even needed because it shows up in `std` or `core`'s crate graph, but injection is still needed to ensure `#![no_core]` works correctly. A similar change was attempted at [1] but this encountered errors building `proc_macro` and `rustc-std-workspace-std`. Similar failures showed up while working on this patch, which were traced back to `compiler_builtins` showing up in the graph twice (once via dependency and once via injection). This is resolved by not injecting if a `#![compiler_builtins]` crate already exists. [1]: https://github.com/rust-lang/rust/pull/113634
2025-02-21Always allow reusing cratenum in CrateLoader::loadbjorn3-21/+9
The only case where can_reuse_cratenum could have been false in the past are rustc plugins, support for which has been removed over a year ago now. Nowadays the only case where locator.tuple is not target_triple is when loading a proc macro, in which case we also set can_reuse_cratenum to true. As such it is always true and we can remove some dead code.
2025-02-20Improve debugging for metadata structuresTrevor Gross-1/+2
I had to do a lot of debug by printing; having these `Debug` traits in place made it easier. Additionally, add some more information to existing `info!` statements.
2025-02-20Track where crate dependencies come from in `creader`Trevor Gross-20/+73
Introduce an enum that represents the different possible sources for dependencies, and use them where possible. This will enable more fine grained control and provides better context than passing the `dep_root` tuple. Use this to ensure that injected crates always show up as private by default.
2025-02-08Rustfmtbjorn3-13/+19
2025-02-02Target modifiers (special marked options) are recorded in metainfo and ↵Andrew Zhogin-2/+95
compared to be equal in different crates
2025-01-23Make the wasm_c_abi future compat warning a hard errorbjorn3-6/+1
This is the next step in getting rid of the broken C abi for wasm32-unknown-unknown.
2025-01-19Manual cleanup of some `is_{or_none|some_and}` usagesYotam Ofek-1/+2
2025-01-19Run `clippy --fix` for `unnecessary_map_or` lintYotam Ofek-1/+1
2025-01-14Mark dependencies of the standard library as private by defaultTrevor Gross-19/+47
In order to avoid diagnostics suggesting stdlib-private dependencies, make everything that is a direct dependency of any `std` crates private by default. Note that this will be overridden, if the same crate is public elsewhere in the crate graph then that overrides the private default. It may also be feasible to do this in the library crate, marking `std`'s dependencies private via Cargo. However, given that the feature is still rather unstable, doing this within the compiler seems more straightforward. Fixes: https://github.com/rust-lang/rust/issues/135232 [1]
2025-01-14rustc_metadata: Rename `root` to `dep_root`Trevor Gross-20/+29
Currently `root` or `crate_root` is used to refer to an instance of `CrateRoot` (representation of a crate's serialized metadata), but the name `root` sometimes also refers to a `CratePath` representing a "root" node in the dependency graph. In order to disambiguate, rename all instances of the latter to `dep_root`.
2025-01-08update cfg(bootstrap)Pietro Albini-1/+1
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-2/+1
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-12-15Add hir::AttributeJonathan Dönszelmann-1/+8
2024-11-28Replace `Symbol::intern` calls with preinterned symbolsclubby789-4/+5
2024-11-27Auto merge of #133369 - Zalathar:profiler-builtins-no-core, r=jieyouxubors-9/+5
Allow injecting a profiler runtime into `#![no_core]` crates An alternative to #133300, allowing `-Cinstrument-coverage` to be used with `-Zbuild-std`. The incompatibility between `profiler_builtins` and `#![no_core]` crates appears to have been caused by profiler_builtins depending on core, and therefore conflicting with core (or minicore). But that's a false dependency, because the profiler doesn't contain any actual Rust code. So we can just mark the profiler itself as `#![no_core]`, and remove the incompatibility error. --- For context, the error was originally added by #79958.
2024-11-25use ReadCache for archive loadingHenry Jiang-1/+1
2024-11-24Allow injecting a profiler runtime into `#![no_core]` cratesZalathar-6/+2
Now that the profiler runtime is itself `#![no_core]`, it can be a dependency of other no_core crates, including core.
2024-11-24Rollup merge of #133300 - Enselic:build-std-instrument-coverage, r=jieyouxuMatthias Krüger-2/+2
inject_panic_runtime(): Avoid double negation for 'any non rlib' <details> <summary>This PR originally did more things .Click to expand to see.</summary> By not trying to inject a profiler runtime when only building an rlib. This logic already exists for the panic runtime. This makes RUSTFLAGS="-Cinstrument-coverage" cargo build -Zbuild-std=std,profiler_builtins work. Note that you probably also need `RUST_COMPILER_RT_FOR_PROFILER=$src/llvm-project/compiler-rt` in your environment. cc #79401 # Demonstration Before this fix you get these errors: ```console $ rm -rf target ; RUST_COMPILER_RT_FOR_PROFILER=/home/martin/src/llvm-project/compiler-rt RUSTFLAGS="-Cinstrument-coverage" cargo +nightly build --release -Zbuild-std=std,profiler_builtins error: `profiler_builtins` crate (required by compiler options) is not compatible with crate attribute `#![no_core]` error[E0152]: found duplicate lang item `manually_drop` = note: first definition in `core` loaded from /home/martin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-d453bab70303062c.rlib = note: second definition in the local crate (`core`) ``` With the fix the build succeeds: ```console $ rm -rf target ; RUST_COMPILER_RT_FOR_PROFILER=/home/martin/src/llvm-project/compiler-rt RUSTFLAGS="-Cinstrument-coverage" cargo +stage1 build --release -Zbuild-std=std,profiler_builtins Finished `release` profile [optimized] target(s) in 45.57s ``` And we can check code coverage. My example program looks like this: ```rs fn main() { if std::env::args_os().nth(1) == Some("write-file".into()) { std::fs::write("hello.txt", "Hello, world!").unwrap(); } else { println!("Hello, world!"); } } ``` when the program prints to stdout: ``` $ LLVM_PROFILE_FILE=stdout.profraw ./target/release/hello-world Hello, world! ``` we can see that `fs::write()` is not being used (note the `0`'s): ```console $ /home/martin/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata merge -sparse stdout.profraw -o stdout.profdata $ /home/martin/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-cov show target/release/hello-world --sources /home/martin/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/std/src/fs.rs --instr-profile stdout.profdata --color | grep -A 3 'pub fn write(&mut self, write: b ool) -> &mut Self {' 1357| 0| pub fn write(&mut self, write: bool) -> &mut Self { 1358| 0| self.0.write(write); 1359| 0| self 1360| 0| } ``` but when we print to a file: ```console $ LLVM_PROFILE_FILE=file.profraw ./target/release/hello-world write-file ``` the code coverage shows `fs::write()` as being used (note the `1`'s): ```console $ /home/martin/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata merge -sparse file.profraw -o file.profdata $ /home/martin/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-cov show target/release/hello-world --sources /home/martin/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/std/src/fs.rs --instr-profile file.profdata --color | grep -A 3 'pub fn write(&mut self, write: bool) -> &mut Self {' 1357| 1| pub fn write(&mut self, write: bool) -> &mut Self { 1358| 1| self.0.write(write); 1359| 1| self 1360| 1| } ``` </summary>
2024-11-24Clarify logic for whether a profiler runtime is neededZalathar-3/+3
2024-11-21inject_panic_runtime(): Avoid double negation for 'any non rlib'Martin Nordholts-2/+2
2024-11-21aix: fix archive formatHenry Jiang-2/+49
fmt fix cfg for windows remove unused imports address comments update libc to 0.2.164 fmt remove unused imports
2024-11-15rustc_metadata: Preprocess search paths for better performancePiotr Osiewicz-1/+2
Over in Zed we've noticed that loading crates for a large-ish workspace can take almost 200ms. We've pinned it down to how rustc searches for paths, as it performs a linear search over the list of candidate paths. In our case the candidate list had about 20k entries which we had to iterate over for each dependency being loaded. This commit introduces a simple FilesIndex that's just a sorted Vec under the hood. Since crates are looked up by both prefix and suffix, we perform a range search on said Vec (which constraints the search space based on prefix) and follow up with a linear scan of entries with matching suffixes. FilesIndex is also pre-filtered before any queries are performed using available target information; query prefixes/sufixes are based on the target we are compiling for, so we can remove entries that can never match up front. Overall, this commit brings down build time for us in dev scenarios by about 6%. 100ms might not seem like much, but this is a constant cost that each of our workspace crates has to pay, even when said crate is miniscule.
2024-11-02Rename target triple to target tuple in many places in the compilerNoratrieb-3/+3
This changes the naming to the new naming, used by `--print target-tuple`. It does not change all locations, but many.
2024-10-31Remove support for `-Zprofile` (gcov-style coverage instrumentation)Zalathar-3/+1
2024-10-26expand: Stop using artificial `ast::Item` for macros loaded from metadataVadim Petrochenkov-2/+2