about summary refs log tree commit diff
path: root/compiler/rustc_session/src
AgeCommit message (Collapse)AuthorLines
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
2024-03-27Start replacing `CStore` trait methods with hooks.Oli Scherer-6/+0
This also avoids the cyclic definition issues with CrateStore being defined after TyCtxt, but needing to be used in TyCtxt.
2024-03-25Replace implementation with @RUSTC_BUILTIN prefix substitution varLukas Wirth-14/+8
2024-03-25Make sysroot mandatory for rustdocLukas Wirth-14/+4
2024-03-25Implement `-L builtin:$path`Lukas Wirth-6/+33
2024-03-25Rollup merge of #122842 - pacak:explicit_name, r=michaelwoeristerMatthias Krüger-0/+5
Don't emit an error about failing to produce a file with a specific name if user never gave an explicit name Fixes #122509 You can ask `rustc` to produce some intermediate results with `--emit foo`, this operation comes in two flavors: `--emit asm` and `--emit asm=foo.s`. First one produces one or more `.s` files without any name guarantees, second one renames it into `foo.s`. Second version only works when compiler produces a single file - for asm files this means using a single compilation unit for example. In case compilation produced more than a single file `rustc` runs following check to emit some warnings: ```rust if crate_output.outputs.contains_key(&output_type) { // 2) Multiple codegen units, with `--emit foo=some_name`. We have // no good solution for this case, so warn the user. sess.dcx().emit_warn(errors::IgnoringEmitPath { extension }); } else if crate_output.single_output_file.is_some() { // 3) Multiple codegen units, with `-o some_name`. We have // no good solution for this case, so warn the user. sess.dcx().emit_warn(errors::IgnoringOutput { extension }); } else { // 4) Multiple codegen units, but no explicit name. We // just leave the `foo.0.x` files in place. // (We don't have to do any work in this case.) } ``` Comment in the final `else` branch implies that if user didn't ask for a specific name - there's no need to emit warnings. However because of the internal representation of `crate_output.outputs` - this doesn't work as expected: if user asked to produce an asm file without giving it an implicit name it will contain `Some(None)`. To fix the problem new code actually checks if user gave an explicit name. I think this was an original intentional behavior, at least comments imply that.
2024-03-24Rollup merge of #122737 - ytmimi:conditionally_ignore_fatal_diagnostic, ↵Matthias Krüger-1/+6
r=davidtwco conditionally ignore fatal diagnostic in the SilentEmitter This change is primarily meant to allow rustfmt to ignore all diagnostics when using the `SilentEmitter`. Back in #121301 the `SilentEmitter` was shared between rustc and rustfmt. This changed rustfmt's behavior from ignoring all diagnostic to emitting fatal diagnostics, which lead to https://github.com/rust-lang/rustfmt/issues/6109. These changes allow rustfmt to maintain its previous behaviour when using the `SilentEmitter`, while allowing rustc code to still emit fatal diagnostics.
2024-03-22-Zprint-type-sizes: print the types of awaitees and unnamed coroutine locals.Kevin Reid-4/+14
This should assist comprehending the size of coroutines. In particular, whenever a future is suspended while awaiting another future, the latter is given the special name `__awaitee`, and now the type of the awaited future will be printed, allowing identifying caller/callee — er, I mean, poller/pollee — relationships. It would be possible to include the type name in more cases, but I thought that that might be overly verbose (`print-type-sizes` is already a lot of text) and ordinary named fields or variables are easier for readers to discover the types of.
2024-03-22Don't emit an error about failing to produce a file with a specific nameMichael Baikov-0/+5
If user never gave an explicit name
2024-03-21Rename some `target_cfg` variables as `target`.Nicholas Nethercote-5/+4
Because the underlying type is called `Target`. (There is also a separate type called `TargetCfg`.)
2024-03-21Remove `CodegenBackend::target_override`.Nicholas Nethercote-27/+18
Backend and target selection is a mess: the target can override the backend (via `Target::default_codegen_backend`), *and* the backend can override the target (via `CodegenBackend::target_override`). The code that handles this is ugly. It calls `build_target_config` twice, once before getting the backend and once again afterward. It also must check that both overrides aren't triggering at the same time. This commit removes the latter override. It's used in rust-gpu but @eddyb said via Zulip that removing it would be ok. This simplifies the code greatly, and will allow some nice follow-up refactorings.
2024-03-20Rollup merge of #122748 - nnethercote:rustc_session-pub, r=jackh726Matthias Krüger-132/+130
Reduce `pub` usage in `rustc_session`. In particular, almost none of the errors in `errors.rs` are used outside the crate. r? `@jackh726`
2024-03-20Reduce `pub` usage in `rustc_session`.Nicholas Nethercote-132/+130
In particular, almost none of the errors in `errors.rs` are used outside the crate.