about summary refs log tree commit diff
path: root/compiler/rustc_session/src
AgeCommit message (Collapse)AuthorLines
2024-05-29Rollup merge of #124320 - Urgau:print-check-cfg, r=petrochenkov许杰友 Jieyou Xu (Joe)-1/+13
Add `--print=check-cfg` to get the expected configs This PR adds a new `--print` variant `check-cfg` to get the expected configs. Details and rational can be found on the MCP: https://github.com/rust-lang/compiler-team/issues/743 ``@rustbot`` label +F-check-cfg +S-waiting-on-MCP r? ``@petrochenkov``
2024-05-03Add -Zfixed-x18Alice Ryhl-0/+2
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2024-04-30Rollup merge of #124511 - nnethercote:rm-extern-crates, r=fee1-deadMatthias Krüger-10/+10
Remove many `#[macro_use] extern crate foo` items This requires the addition of more `use` items, which often make the code more verbose. But they also make the code easier to read, because `#[macro_use]` obscures where macros are defined. r? `@fee1-dead`
2024-04-30Remove `extern crate tracing` from numerous crates.Nicholas Nethercote-7/+4
2024-04-29coverage: Replace boolean options with a `CoverageLevel` enumZalathar-18/+30
2024-04-29Remove `extern crate rustc_macros` from numerous crates.Nicholas Nethercote-3/+6
2024-04-25debuginfo: Stabilize `-Z debug-macros`, `-Z collapse-macro-debuginfo` and ↵Vadim Petrochenkov-7/+15
`#[collapse_debuginfo]` `-Z debug-macros` is "stabilized" by enabling it by default and removing. `-Z collapse-macro-debuginfo` is stabilized as `-C collapse-macro-debuginfo`. It now supports all typical boolean values (`parse_opt_bool`) in addition to just yes/no. Default value of `collapse_debuginfo` was changed from `false` to `external` (i.e. collapsed if external, not collapsed if local). `#[collapse_debuginfo]` attribute without a value is no longer supported to avoid guessing the default.
2024-04-25Add `--print=check-cfg` to get the expected configsUrgau-1/+13
2024-04-25Rollup merge of #124324 - nnethercote:minor-ast-cleanups, r=estebankMatthias Krüger-10/+6
Minor AST cleanups r? ``@estebank``
2024-04-25Rollup merge of #124333 - Urgau:better-bad-print, r=fmeaseMatthias Krüger-3/+6
Improve diagnostic for unknown `--print` request This PR improves the diagnostic when encountering a unknown `--print` request. It also moves the run-make test to a simple UI test.
2024-04-24Improve diagnostic for unknown --print requestUrgau-3/+6
2024-04-24Whitespace fixes.Nicholas Nethercote-10/+6
2024-04-23Auto merge of #123126 - oli-obk:feed_crate_num, r=davidtwcobors-2/+5
Enable `CrateNum` query feeding via `TyCtxt` Instead of having a magic function that violates some `TyCtxtFeed` invariants, add a `create_def` equivalent for `CrateNum`s. Note that this still isn't tracked by the query system (unlike `create_def`), and that feeding most `CrateNum` queries for crates other than the local one will likely cause performance regressions. These things should be attempted on their own separately, but this PR should stand on its own
2024-04-23Mark @RUSTC_BUILTIN search path usage as unstableLukas Wirth-1/+16
2024-04-22Stabilize generic `NonZero`.Markus Reiter-1/+0
2024-04-20Rollup merge of #123409 - ZhuUx:master, r=oli-obkMatthias Krüger-10/+18
Implement Modified Condition/Decision Coverage This is an implementation based on llvm backend support (>= 18) by `@evodius96` and branch coverage support by `@Zalathar.` ### Major changes: * Add -Zcoverage-options=mcdc as switch. Now coverage options accept either `no-branch`, `branch`, or `mcdc`. `mcdc` also enables `branch` because it is essential to work. * Add coverage mapping for MCDCBranch and MCDCDecision. Note that MCDCParameter evolves from llvm 18 to llvm 19. The mapping in rust side mainly references to 19 and is casted to 18 types in llvm wrapper. * Add wrapper for mcdc instrinc functions from llvm. And inject associated statements to mir. * Add BcbMappingKind::Decision, I'm not sure is it proper but can't find a better way temporarily. * Let coverage-dump support parsing MCDCBranch and MCDCDecision from llvm ir. * Add simple tests to check whether mcdc works. * Same as clang, currently rustc does not generate instrument for decision with more than 6 condtions or only 1 condition due to considerations of resource. ### Implementation Details 1. To get information about conditions and decisions, `MCDCState` in `BranchInfoBuilder` is used during hir lowering to mir. For expressions with logical op we call `Builder::visit_coverage_branch_operation` to record its sub conditions, generate condition ids for them and save their spans (to construct the span of whole decision). This process mainly references to the implementation in clang and is described in comments over `MCDCState::record_conditions`. Also true marks and false marks introduced by branch coverage are used to detect where the decision evaluation ends: the next id of the condition == 0. 2. Once the `MCDCState::decision_stack` popped all recorded conditions, we can ensure that the decision is checked over and push it into `decision_spans`. We do not manually insert decision span to avoid complexity from then_else_break in nested if scopes. 3. When constructing CoverageSpans, add condition info to BcbMappingKind::Branch and decision info to BcbMappingKind::Decision. If the branch mapping has non-zero condition id it will be transformed to MCDCBranch mapping and insert `CondBitmapUpdate` statements to its evaluated blocks. While decision bcb mapping will insert `TestVectorBitmapUpdate` in all its end blocks. ### Usage ```bash echo "[build]\nprofiler=true" >> config.toml ./x build --stage 1 ./x test tests/coverage/mcdc_if.rs ``` to build the compiler and run tests. ```shell export PATH=path/to/llvm-build:$PATH rustup toolchain link mcdc build/host/stage1 cargo +mcdc rustc --bin foo -- -Cinstrument-coverage -Zcoverage-options=mcdc cd target/debug LLVM_PROFILE_FILE="foo.profraw" ./foo llvm-profdata merge -sparse foo.profraw -o foo.profdata llvm-cov show ./foo -instr-profile=foo.profdata --show-mcdc ``` to check "foo" code. ### Problems to solve For now decision mapping will insert statements to its all end blocks, which may be optimized by inserting a final block of the decision. To do this we must also trace the evaluated value at each end of the decision and join them separately. This implementation is not heavily tested so there should be some unrevealed issues. We are going to check our rust products in the next. Please let me know if you had any suggestions or comments.
2024-04-19Move `stable_crate_ids` from `CrateStore` to `Untracked`Oli Scherer-2/+5
This way it's like `Definitions`, which creates `DefId`s by interning `DefPathData`s, but for interning stable crate hashes
2024-04-19Auto merge of #117919 - daxpedda:wasm-c-abi, r=wesleywiserbors-2/+17
Introduce perma-unstable `wasm-c-abi` flag Now that `wasm-bindgen` v0.2.88 supports the spec-compliant C ABI, the idea is to switch to that in a future version of Rust. In the meantime it would be good to let people test and play around with it. This PR introduces a new perma-unstable `-Zwasm-c-abi` compiler flag, which switches to the new spec-compliant C ABI when targeting `wasm32-unknown-unknown`. Alternatively, we could also stabilize this and then deprecate it when we switch. I will leave this to the Rust maintainers to decide. This is a companion PR to #117918, but they could be merged independently. MCP: https://github.com/rust-lang/compiler-team/issues/703 Tracking issue: https://github.com/rust-lang/rust/issues/122532
2024-04-19coverage. Add coverage-options=mcdc as gate for MC/DC instrumentzhuyunxing-10/+18
2024-04-18Ensure `[rust] debuginfo-level-std` doesn't change core's MIRScott McMurray-0/+3
2024-04-16Rollup merge of #122811 - nnethercote:mv-SourceMap-init, r=WaffleLapkinGuillaume Gomez-28/+18
Move `SourceMap` initialization So it happens at the same time as `SessionGlobals` initialization, rather than shortly afterward. r? `@WaffleLapkin`
2024-04-16Rollup merge of #123501 - Urgau:stabilize-check-cfg, r=petrochenkovMatthias Krüger-2/+2
Stabilize checking of cfgs at compile-time: `--check-cfg` option This PR stabilize the `--check-cfg` CLI option of `rustc` (and `rustdoc`) :tada:. In particular this PR does two things: 1. it makes the `--check-cfg` option stable 2. and it moves the documentation to the stable books FCP: https://github.com/rust-lang/rust/issues/82450#issuecomment-1965328542 Resolves #82450 ``@rustbot`` labels +S-blocked +F-check-cfg r? ``@petrochenkov``
2024-04-16Rollup merge of #121694 - davidtwco:stabilize-relro-level, r=Mark-SimulacrumGuillaume Gomez-3/+3
sess: stabilize `-Zrelro-level` as `-Crelro-level` Stabilise `-Zrelro-level` as `-Crelro-level`. There's no tracking issue for this flag to close.
2024-04-16Move `initialize_checked_jobserver`.Nicholas Nethercote-10/+4
Currently it's a method on `EarlyDiagCtxt`, which is not the right place for it at all -- `EarlyDiagCtxt` is used to issue diagnostics, but shouldn't be doing any of the actual checking. This commit moves it into a standalone function that takes an `EarlyDiagCtxt` as an argument, which is more sensible. This does require adding `EarlyDiagCtxt::early_struct_warn`, so a warning can be returned and then modified with a note. (And that likely explains why somebody put `initialize_checked_jobserver` into `EarlyDiagCtxt` in the first place.)
2024-04-16Construct `SourceMap` at the same time as `SessionGlobals`.Nicholas Nethercote-18/+14
Currently `SourceMap` is constructed slightly later than `SessionGlobals`, and inserted. This commit changes things so they are done at the same time. Benefits: - `SessionGlobals::source_map` changes from `Lock<Option<Lrc<SourceMap>>>` to `Option<Lrc<SourceMap>>`. It's still optional, but mutability isn't required because it's initialized at construction. - `set_source_map` is removed, simplifying `run_compiler`, which is good because that's a critical function and it's nice to make it simpler. This requires moving things around a bit, so the necessary inputs are available when `SessionGlobals` is created, in particular the `loader` and `hash_kind`, which are no longer computed by `build_session`. These inputs are captured by the new `SourceMapInputs` type, which is threaded through various places.
2024-04-15Move --check-cfg documentation to stable booksUrgau-1/+1
2024-04-15Stabilize checking of cfgs at compile-time: --check-cfg optionUrgau-1/+1
2024-04-14Stabilize --json unused-externs(-silent)Jeremy Fitzhardinge-7/+0
Implement https://github.com/rust-lang/compiler-team/issues/674
2024-04-13Auto merge of #123854 - petrochenkov:searchdirs2, r=lqdbors-5/+0
linker: Remove laziness and caching from native search directory walks It shouldn't be necessary for performance now. Follow up to https://github.com/rust-lang/rust/pull/123827.
2024-04-13Auto merge of #123656 - lqd:linker-features, r=petrochenkovbors-1/+63
Linker flavors next steps: linker features This is my understanding of the first step towards `@petrochenkov's` vision for the future of linker flavors, described in https://github.com/rust-lang/rust/pull/119906#issuecomment-1895693162 and the discussion that followed. To summarize: having `Cc` and `Lld` embedded in linker flavors creates tension about naming, and a combinatorial explosion of flavors for each new linker feature we'd want to use. Linker features are an extension mechanism that is complementary to principal flavors, with benefits described in #119906. The most immediate use of this flag would be to turn self-contained linking on and off via features instead of flavors. For example, `-Clinker-features=+/-lld` would toggle using lld instead of selecting a precise flavor, and would be "generic" and work cross-platform (whereas linker flavors are currently more tied to targets). Under this scheme, MCP510 is expected to be `-Clink-self-contained=+linker -Zlinker-features=+lld -Zunstable-options` (though for the time being, the original flags using lld-cc flavors still work). I purposefully didn't add or document CLI support for `+/-cc`, as it would be a noop right now. I only expect that we'd initially want to stabilize `+/-lld` to begin with. r? `@petrochenkov` You had requested that minimal churn would be done to the 230 target specs and this does none yet: the linker features are inferred from the flavor since they're currently isomorphic. We of course expect this to change sooner rather than later. In the future, we can allow targets to define linker features independently from their flavor, and remove the cc and lld components from the flavors to use the features instead, this actually doesn't need to block stabilization, as we discussed. (Best reviewed per commit)
2024-04-12linker: Remove laziness and caching from native search directory walksVadim Petrochenkov-5/+0
It shouldn't be necessary for performance now.
2024-04-12add `-Z linker-features` to toggle lld on the CLIRémy Rakic-1/+63
but don't expose `+/-cc` yet
2024-04-12linker: Avoid some allocations in search directory iterationVadim Petrochenkov-2/+2
2024-04-09Auto merge of #123099 - oli-obk:span_tcx, r=petrochenkovbors-18/+0
Replace some `CrateStore` trait methods with hooks. Just like with the `CrateStore` trait, this avoids the cyclic definition issues with `CStore` being defined after TyCtxt, but needing to be used in TyCtxt.
2024-04-06Put checks that detect UB under their own flag below debug_assertionsBen Kimock-0/+13
2024-04-05Move cfg and check-cfg configuration in it's own module and add docsUrgau-342/+379
2024-04-03Remove MIR unsafe checkMatthew Jasper-2/+0
This also remove safety information from MIR.
2024-03-30Rollup merge of #123200 - maurer:kcfi-abort, r=compiler-errorsMatthias Krüger-0/+9
KCFI: Require -C panic=abort While the KCFI scheme is not incompatible with unwinding, LLVM's `invoke` instruction does not currently support KCFI bundles. While it likely will in the near future, we won't be able to assume that in Rust for a while. We encountered this problem while [turning on closure support](https://github.com/rust-lang/rust/pull/123106#issuecomment-2027436640). r? ``@workingjubilee``
2024-03-29KCFI: Require -C panic=abortMatthew Maurer-0/+9
While the KCFI scheme is not incompatible with unwinding, LLVM's `invoke` instruction does not currently support KCFI bundles. While it likely will in the near future, we won't be able to assume that in Rust for a while.
2024-03-29Auto merge of #123194 - matthiaskrgr:rollup-vhdc8hw, r=matthiaskrgrbors-5/+7
Rollup of 4 pull requests Successful merges: - #123176 (Normalize the result of `Fields::ty_with_args`) - #123186 (copy any file from stage0/lib to stage0-sysroot/lib) - #123187 (Forward port 1.77.1 release notes) - #123188 (compiler: fix few unused_peekable and needless_pass_by_ref_mut clippy lints) r? `@ghost` `@rustbot` modify labels: rollup
2024-03-28Replace Session should_remap_filepaths with filename_display_preferenceUrgau-3/+14
2024-03-28Introduce `FileNameMapping::to_real_filename` and use it everywhereUrgau-9/+3
2024-03-28Make local_crate_source_file return a RealFileNameUrgau-7/+3
so it can be remapped (or not) by callers
2024-03-28Replace `RemapFileNameExt::for_codegen` with explicit callsUrgau-24/+5
2024-03-28Simplify trim-paths feature by merging all debuginfo options togetherUrgau-51/+10
2024-03-28compiler: fix few needless_pass_by_ref_mut clippy lintsklensy-2/+2
warning: this argument is a mutable reference, but not used mutably --> compiler\rustc_session\src\config.rs:2013:16 | 2013 | early_dcx: &mut EarlyDiagCtxt, | ^^^^^^^^^^^^^^^^^^ help: consider changing to: `&EarlyDiagCtxt` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut warning: this argument is a mutable reference, but not used mutably --> compiler\rustc_ast_passes\src\ast_validation.rs:1555:11 | 1555 | this: &mut AstValidator<'_>, | ^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&AstValidator<'_>` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut warning: this argument is a mutable reference, but not used mutably --> compiler\rustc_infer\src\infer\snapshot\fudge.rs:16:12 | 16 | table: &mut UnificationTable<'_, 'tcx, T>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&UnificationTable<'_, 'tcx, T>` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut warning: this argument is a mutable reference, but not used mutably --> compiler\rustc_expand\src\expand.rs:961:13 | 961 | parser: &mut Parser<'a>, | ^^^^^^^^^^^^^^^ help: consider changing to: `&Parser<'a>` | = warning: changing this function will impact semver compatibility = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut
2024-03-28compiler: fix some clippy needless_pass_by_ref_mutklensy-2/+4
warning: this argument is a mutable reference, but not used mutably --> compiler\rustc_session\src\config.rs:2111:20 | 2111 | unstable_opts: &mut UnstableOptions, | ^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&UnstableOptions` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut
2024-03-28compiler: fix unused_peekable clippy lintklensy-1/+1
warning: `peek` never called on `Peekable` iterator --> compiler\rustc_session\src\utils.rs:130:13 | 130 | let mut args = std::env::args_os().map(|arg| arg.to_string_lossy().to_string()).peekable(); | ^^^^ | = help: consider removing the call to `peekable` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_peekable warning: `peek` never called on `Peekable` iterator --> compiler\rustc_trait_selection\src\traits\error_reporting\suggestions.rs:4934:17 | 4934 | let mut bounds = pred.bounds.iter().peekable(); | ^^^^^^ | = help: consider removing the call to `peekable` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_peekable
2024-03-27Make `def_path_hash_to_def_id` a hookOli Scherer-3/+0
2024-03-27Move `CrateStore::expn_hash_to_expn_id` to a hookOli Scherer-9/+0