about summary refs log tree commit diff
path: root/compiler/rustc_metadata/src
AgeCommit message (Collapse)AuthorLines
2025-01-08update cfg(bootstrap)Pietro Albini-2/+2
2024-12-31Convert some Into impls into From implsMichael Goulet-3/+3
2024-12-20Review commentsbjorn3-0/+7
2024-12-19Update commentsbjorn3-8/+7
2024-12-19Make DependencyList an IndexVecbjorn3-45/+58
2024-12-18Auto merge of #134243 - nnethercote:re-export-more-rustc_span, r=jieyouxubors-13/+8
Re-export more `rustc_span::symbol` things from `rustc_span`. `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 to `rustc_span::`. This is a 300+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one. r? `@jieyouxu`
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-13/+8
`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-17Rollup merge of #133265 - the8472:extract-if-ranges, r=cuviperMatthias Krüger-1/+1
Add a range argument to vec.extract_if tracking issue: #43244 This adds the range argument requested in https://github.com/rust-lang/rust/issues/43244#issuecomment-2486160659
2024-12-16update uses of extract_if in the compilerThe 8472-1/+1
2024-12-16rename rustc_attr to rustc_attr_parsing and create rustc_attr_data_structuresJonathan Dönszelmann-3/+3
2024-12-16split attributesJonathan Dönszelmann-10/+13
2024-12-15Add hir::AttributeJonathan Dönszelmann-7/+14
2024-12-14Rollup merge of #134251 - bjorn3:various_cleanups2, r=oli-obkMatthias Krüger-5/+2
A bunch of cleanups (part 2) Just like https://github.com/rust-lang/rust/pull/133567 these were all found while looking at the respective code, but are not blocking any other changes I want to make in the short term.
2024-12-13Make dependency_formats an FxIndexMap rather than a list of tuplesbjorn3-5/+2
It is treated as a map already. This is using FxIndexMap rather than UnordMap because the latter doesn't provide an api to pick a single value iff all values are equal, which each_linked_rlib depends on.
2024-12-12Move impl constness into impl trait headerOli Scherer-6/+2
2024-12-11Require the `constness` query to only be invoked on things that can have ↵Oli Scherer-2/+3
constness
2024-12-09Support x-crate default fieldsEsteban Küber-1/+13
2024-12-09Introduce `default_field_values` featureEsteban Küber-0/+1
Initial implementation of `#[feature(default_field_values]`, proposed in https://github.com/rust-lang/rfcs/pull/3681. Support default fields in enum struct variant Allow default values in an enum struct variant definition: ```rust pub enum Bar { Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Allow using `..` without a base on an enum struct variant ```rust Bar::Foo { .. } ``` `#[derive(Default)]` doesn't account for these as it is still gating `#[default]` only being allowed on unit variants. Support `#[derive(Default)]` on enum struct variants with all defaulted fields ```rust pub enum Bar { #[default] Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Check for missing fields in typeck instead of mir_build. Expand test with `const` param case (needs `generic_const_exprs` enabled). Properly instantiate MIR const The following works: ```rust struct S<A> { a: Vec<A> = Vec::new(), } S::<i32> { .. } ``` Add lint for default fields that will always fail const-eval We *allow* this to happen for API writers that might want to rely on users' getting a compile error when using the default field, different to the error that they would get when the field isn't default. We could change this to *always* error instead of being a lint, if we wanted. This will *not* catch errors for partially evaluated consts, like when the expression relies on a const parameter. Suggestions when encountering `Foo { .. }` without `#[feature(default_field_values)]`: - Suggest adding a base expression if there are missing fields. - Suggest enabling the feature if all the missing fields have optional values. - Suggest removing `..` if there are no missing fields.
2024-12-06Remove polymorphizationBen Kimock-6/+0
2024-12-04Remove some noisy tracingOli Scherer-3/+0
2024-12-03Rollup merge of #133779 - BoxyUwU:array_const_arg_infer_hir_id, ↵Matthias Krüger-4/+8
r=compiler-errors Use correct `hir_id` for array const arg infers Fixes #133771 `self.next_id()` results in the `DefId` for the const argument, created from the hack introduced by #133468, having no `HirId` associated with it. This then results in an ICE in metadata encoding. Fixing this then results in *another* ICE where `encode_defs` was not skipping encoding `type_of` and other queries for `DefId`s when they correspond to a `ConstArgKind::Infer` node. This only reproduces with a library crate as metadata is not encoded for binaries, and apparently we had 0 tests for `generic_arg_infer` for array lengths in a library crate so this was not caught :< cc #133589 `@voidc` r? `@compiler-errors` `@lcnr`
2024-12-03Rollup merge of #133545 - clubby789:symbol-intern-lit, r=jieyouxuMatthias Krüger-4/+6
Lint against Symbol::intern on a string literal Disabled in tests where this doesn't make much sense
2024-12-03Use correct `hir_id` for array const arg infersBoxy-4/+8
2024-11-30Rollup merge of #132750 - daltenty:daltenty/libs, r=jieyouxu许杰友 Jieyou Xu (Joe)-0/+4
[AIX] handle libunwind native_libs AIX should follow a similar path here to other libunwind platforms, with regards to system vs in-tree libunwind and the native lib search directories. Having the right native lib search directories here is also required to get the correct default library search paths, due to some quirks of the AIX linker.
2024-11-29Add a commentDavid Tenty-0/+3
2024-11-28Replace `Symbol::intern` calls with preinterned symbolsclubby789-4/+6
2024-11-28always create `DefId`s when lowering anon-constslcnr-0/+14
2024-11-27Auto merge of #133369 - Zalathar:profiler-builtins-no-core, r=jieyouxubors-13/+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-10/+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-23Auto merge of #132915 - veluca93:unsafe-fields, r=jswrennbors-0/+18
Implement the unsafe-fields RFC. RFC: rust-lang/rfcs#3458 Tracking: - https://github.com/rust-lang/rust/issues/132922 r? jswrenn
2024-11-21Auto merge of #132362 - mustartt:aix-dylib-detection, r=jieyouxubors-3/+53
[AIX] change system dynamic library format Historically on AIX, almost all dynamic libraries are distributed in `.a` Big Archive Format which can consists of both static and shared objects in the same archive (e.g. `libc++abi.a(libc++abi.so.1)`). During the initial porting process, the dynamic libraries are kept as `.a` to simplify the migration, but semantically having an XCOFF object under the archive extension is wrong. For crate type `cdylib` we want to be able to distribute the libraries as archives as well. We are migrating to archives with the following format: ``` $ ar -t lib<name>.a lib<name>.so ``` where each archive contains a single member that is a shared XCOFF object that can be loaded.
2024-11-21Implement the unsafe-fields RFC.Luca Versari-0/+18
Co-Authored-By: Jacob Pratt <jacob@jhpratt.dev>
2024-11-21inject_panic_runtime(): Avoid double negation for 'any non rlib'Martin Nordholts-2/+2
2024-11-21aix: fix archive formatHenry Jiang-3/+53
fmt fix cfg for windows remove unused imports address comments update libc to 0.2.164 fmt remove unused imports
2024-11-19Implement ~const opaquesMichael Goulet-0/+4
2024-11-19Rename implied_const_bounds to explicit_implied_const_boundsMichael Goulet-6/+6
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-2/+2
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
2024-11-15rustc_metadata: Preprocess search paths for better performancePiotr Osiewicz-43/+48
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-07Rollup merge of #132131 - celinval:smir-crate-defs, r=compiler-errorsJubilee-0/+1
[StableMIR] API to retrieve definitions from crates Add functions to retrieve function definitions and static items from all crates (local and external). For external crates, we're still missing items from trait implementation and primitives. r? ````@compiler-errors:```` Do you know what is the best way to retrieve the associated items for primitives and trait implementations for external crates? Thanks!
2024-11-07[AIX] handle libunwind native_libsDavid Tenty-0/+1
AIX should follow a similar path here to other libunwind platforms, with regards to system vs in-tree libunwind and the native lib search directories
2024-11-07[StableMIR] API to retrieve definitions from cratesCelina G. Val-0/+1
Add functions to retrieve function definitions and static items from all crates (local and external). For external crates, add a query to retrieve the number of defs in a foreign crate.
2024-11-04ty::KContainer -> ty::AssocItemContainer::KMichael Goulet-7/+7
2024-11-03compiler: Directly use rustc_abi in metadata and middleJubilee Young-11/+15
Stop reexporting ReprOptions from middle::ty
2024-11-02Rename target triple to target tuple in many places in the compilerNoratrieb-17/+17
This changes the naming to the new naming, used by `--print target-tuple`. It does not change all locations, but many.
2024-11-02Rollup merge of #131829 - Zalathar:goodbye-zprofile, r=chenyukangGuillaume Gomez-3/+1
Remove support for `-Zprofile` (gcov-style coverage instrumentation) Tracking issue: #42524 MCP: https://github.com/rust-lang/compiler-team/issues/798 --- This PR removes the unstable `-Zprofile` flag, which enables ”gcov-style” coverage instrumentation, along with its associated `-Zprofile-emit` configuration flag. (The profile flag predates and is almost entirely separate from the stable `-Cinstrument-coverage` flag.) Notably, the `-Zprofile` flag: - Is largely untested in-tree, having only one run-make test that does not check whether its output is correct or useful. - Has no known maintainer. - Has seen no push towards stabilization. - Has at least one severe regression reported in 2022 that apparently remains unaddressed. - #100125 - Is confusingly named, since it appears to be more about coverage than performance profiling, and has nothing to do with PGO. - Is fundamentally limited by relying on counters auto-inserted by LLVM, with no knowledge of Rust beyond debuginfo.
2024-10-31Remove support for decompressing dylib metadatabjorn3-25/+4
We haven't been compressing dylib metadata for a while now. Removing decompression support will regress error messages about an incompatible rustc version being used, but dylibs are pretty rare anyway.
2024-10-31Auto merge of #131186 - compiler-errors:precise-capturing-borrowck, r=estebankbors-9/+4
Try to point out when edition 2024 lifetime capture rules cause borrowck issues Lifetime capture rules in 2024 are modified to capture more lifetimes, which sometimes lead to some non-local borrowck errors. This PR attempts to link these back together with a useful note pointing out the capture rule changes. This is not a blocking concern, but I'd appreciate feedback (though, again, I'd like to stress that I don't want to block this PR on this): I'm worried about this note drowning in the sea of other diagnostics that borrowck emits. I was tempted to change the level of the note to `.span_warn` just so it would show up in a different color. Thoughts? Fixes #130545 Opening as a draft first since it's stacked on #131183. r? `@ghost`