about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform
AgeCommit message (Collapse)AuthorLines
2024-06-04Auto merge of #122597 - pacak:master, r=bjorn3bors-0/+3
Show files produced by `--emit foo` in json artifact notifications Right now it is possible to ask `rustc` to save some intermediate representation into one or more files with `--emit=foo`, but figuring out what exactly was produced is difficult. This pull request adds information about `llvm_ir` and `asm` intermediate files into notifications produced by `--json=artifacts`. Related discussion: https://internals.rust-lang.org/t/easier-access-to-files-generated-by-emit-foo/20477 Motivation - `cargo-show-asm` parses those intermediate files and presents them in a user friendly way, but right now I have to apply some dirty hacks. Hacks make behavior confusing: https://github.com/hintron/computer-enhance/issues/35 This pull request introduces a new behavior: now `rustc` will emit a new artifact notification for every artifact type user asked to `--emit`, for example for `--emit asm` those will include all the `.s` files. Most users won't notice this behavior, to be affected by it all of the following must hold: - user must use `rustc` binary directly (when `cargo` invokes `rustc` - it consumes artifact notifications and doesn't emit anything) - user must specify both `--emit xxx` and `--json artifacts` - user must refuse to handle unknown artifact types - user must disable incremental compilation (or deal with it better than cargo does, or use a workaround like `save-temps`) in order not to hit #88829 / #89149
2024-06-03Opt-in diagnostics reporting to avoid doing extra work in the new solverMichael Goulet-1/+1
2024-06-03Reformat `mir!` macro invocations to use braces.Nicholas Nethercote-2/+2
The `mir!` macro has multiple parts: - An optional return type annotation. - A sequence of zero or more local declarations. - A mandatory starting anonymous basic block, which is brace-delimited. - A sequence of zero of more additional named basic blocks. Some `mir!` invocations use braces with a "block" style, like so: ``` mir! { let _unit: (); { let non_copy = S(42); let ptr = std::ptr::addr_of_mut!(non_copy); // Inside `callee`, the first argument and `*ptr` are basically // aliasing places! Call(_unit = callee(Move(*ptr), ptr), ReturnTo(after_call), UnwindContinue()) } after_call = { Return() } } ``` Some invocations use parens with a "block" style, like so: ``` mir!( let x: [i32; 2]; let one: i32; { x = [42, 43]; one = 1; x = [one, 2]; RET = Move(x); Return() } ) ``` And some invocations uses parens with a "tighter" style, like so: ``` mir!({ SetDiscriminant(*b, 0); Return() }) ``` This last style is generally used for cases where just the mandatory starting basic block is present. Its braces are placed next to the parens. This commit changes all `mir!` invocations to use braces with a "block" style. Why? - Consistency is good. - The contents of the invocation is a block of code, so it's odd to use parens. They are more normally used for function-like macros. - Most importantly, the next commit will enable rustfmt for `tests/mir-opt/`. rustfmt is more aggressive about formatting macros that use parens than macros that use braces. Without this commit's changes, rustfmt would break a couple of `mir!` macro invocations that use braces within `tests/mir-opt` by inserting an extraneous comma. E.g.: ``` mir!(type RET = (i32, bool);, { // extraneous comma after ';' RET.0 = 1; RET.1 = true; Return() }) ``` Switching those `mir!` invocations to use braces avoids that problem, resulting in this, which is nicer to read as well as being valid syntax: ``` mir! { type RET = (i32, bool); { RET.0 = 1; RET.1 = true; Return() } } ```
2024-06-01Add some more specific checks to the MIR validatorScott McMurray-7/+94
None of the `PointerCoercion`s had any, so while there's probably more that could be done here, hopefully these are better than the previous nothing.
2024-06-01Uplift TypeRelation and RelateMichael Goulet-4/+6
2024-06-01Auto merge of #125821 - Luv-Ray:issue#121126, r=fee1-deadbors-2/+6
Check index `value <= 0xFFFF_FF00` <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r​? <reviewer name> --> fixes #121126 check `idx <= FieldIdx::MAX_AS_U32` before calling `FieldIdx::from_u32` to avoid panic.
2024-06-01check index `value <= 0xFFFF_FF00`Luv-Ray-2/+6
2024-05-31Rollup merge of #125796 - scottmcm:more-inst-simplify, r=oli-obkMatthias Krüger-1/+1
Also InstSimplify `&raw*` We do this for `&*` and `&mut*` already; might as well do it for raw pointers too. r? mir-opt
2024-05-31Auto merge of #124662 - zetanumbers:needs_async_drop, r=oli-obkbors-6/+31
Implement `needs_async_drop` in rustc and optimize async drop glue This PR expands on #121801 and implements `Ty::needs_async_drop` which works almost exactly the same as `Ty::needs_drop`, which is needed for #123948. Also made compiler's async drop code to look more like compiler's regular drop code, which enabled me to write an optimization where types which do not use `AsyncDrop` can simply forward async drop glue to `drop_in_place`. This made size of the async block from the [async_drop test](https://github.com/zetanumbers/rust/blob/67980dd6fb11917d23d01a19c2cf4cfc3978aac8/tests/ui/async-await/async-drop.rs) to decrease by 12%.
2024-05-30Also InstSimplify `&raw*`Scott McMurray-1/+1
We do this for `&*` and `&mut*` already; might as well do it for raw pointers too.
2024-05-31Revert "Auto merge of #115105 - cjgillot:dest-prop-default, r=oli-obk"Camille GILLOT-2/+239
This reverts commit cfb730450f847bb622243eaaab15e77e58d91767, reversing changes made to 91c0823ee63e793d990bb9fed898dc95b5d6db51.
2024-05-30Auto merge of #115105 - cjgillot:dest-prop-default, r=oli-obkbors-239/+2
Enable DestinationPropagation by default. ~~Based on https://github.com/rust-lang/rust/pull/115291.~~ This PR proposes to enable the destination propagation pass by default. This pass is meant to reduce the amount of copies present in MIR. At the same time, this PR removes the `RenameReturnPlace` pass, as it is currently unsound. `DestinationPropagation` is not limited to `_0`, but does not handle borrowed locals.
2024-05-30Rollup merge of #125754 - Zalathar:conditions-num, r=lqdMatthias Krüger-6/+6
coverage: Rename MC/DC `conditions_num` to `num_conditions` Updated version of #124571, without the other changes that were split out into #125108 and #125700. This value represents a quantity of conditions, not an ID, so the new spelling is more appropriate. Some of the code touched by this PR could perhaps use some other changes, but I would prefer to keep this PR as a simple renaming and avoid scope creep. `@rustbot` label +A-code-coverage
2024-05-30coverage: Rename MC/DC `conditions_num` to `num_conditions`Zalathar-6/+6
This value represents a quantity of conditions, not an ID, so the new spelling is more appropriate.
2024-05-29Enable DestinationPropagation by default.Camille GILLOT-239/+2
2024-05-29Make `body_owned_by` return the body directly.Oli Scherer-1/+2
Almost all callers want this anyway, and now we can use it to also return fed bodies
2024-05-29Optimize async drop glue for some old typesDaria Sukhonina-6/+31
2024-05-29Rollup merge of #124251 - scottmcm:unop-ptr-metadata, r=oli-obk许杰友 Jieyou Xu (Joe)-1/+28
Add an intrinsic for `ptr::metadata` The follow-up to #123840, so we can remove `PtrComponents` and `PtrRepr` from libcore entirely (well, after a bootstrap update). As discussed in <https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/.60ptr_metadata.60.20in.20MIR/near/435637808>, this introduces `UnOp::PtrMetadata` taking a raw pointer and returning the associated metadata value. By no longer going through a `union`, this should also help future PRs better optimize pointer operations. r? ``@oli-obk``
2024-05-28Add an intrinsic for `ptr::metadata`Scott McMurray-1/+28
2024-05-28Rollup merge of #125637 - nnethercote:rustfmt-fixes, r=GuillaumeGomezMatthias Krüger-5/+3
rustfmt fixes The `rmake.rs` entries in `rustfmt.toml` are causing major problems for `x fmt`. This PR removes them and does some minor related cleanups. r? ``@GuillaumeGomez``
2024-05-28Cache whether a body has inline constsOli Scherer-1/+4
2024-05-28Create const block DefIds in typeck instead of ast loweringOli Scherer-0/+6
2024-05-28Use the HIR instead of mir_keys for determining whether something will have ↵Oli Scherer-1/+1
a MIR body.
2024-05-28Don't format `tests/run-make/*/rmake.rs`.Nicholas Nethercote-5/+3
It's reasonable to want to, but in the current implementation this causes multiple problems. - All the `rmake.rs` files are formatted every time even when they haven't changed. This is because they get whitelisted unconditionally in the `OverrideBuilder`, before the changed files get added. - The way `OverrideBuilder` works, if any files gets whitelisted then no unmentioned files will get traversed. This is surprising, and means that the `rmake.rs` entries broke the use of explicit paths to `x fmt`, and also broke `GITHUB_ACTIONS=true git check --fmt`. The commit removes the `rmake.rs` entries, fixes the formatting of a couple of files that were misformatted (not previously caught due to the `GITHUB_ACTIONS` breakage), and bans `!`-prefixed entries in `rustfmt.toml` because they cause all these problems.
2024-05-27Rollup merge of #125616 - RalfJung:mir-validate-downcast-projection, ↵Matthias Krüger-3/+23
r=compiler-errors MIR validation: ensure that downcast projection is followed by field projection Cc https://github.com/rust-lang/rust/issues/120369
2024-05-27MIR validation: ensure that downcast projection is followed by field projectionRalf Jung-3/+23
2024-05-27Auto merge of #125602 - RalfJung:interpret-mir-lifetime, r=oli-obkbors-12/+11
interpret: get rid of 'mir lifetime I realized our MIR bodies are actually at lifetime `'tcx`, so we don't need to carry around this other lifetime everywhere. r? `@oli-obk`
2024-05-27Auto merge of #125410 - fmease:adj-lint-diag-api, r=nnethercotebors-14/+8
[perf] Delay the construction of early lint diag structs Attacks some of the perf regressions from https://github.com/rust-lang/rust/pull/124417#issuecomment-2123700666. See individual commits for details. The first three commits are not strictly necessary. However, the 2nd one (06bc4fc67145e3a7be9b5a2cf2b5968cef36e587, *Remove `LintDiagnostic::msg`*) makes the main change way nicer to implement. It's also pretty sweet on its own if I may say so myself.
2024-05-27interpret: get rid of 'mir lifetime everywhereRalf Jung-12/+11
2024-05-26Avoid a `FieldIdx::from_usize` in InstSimplifyScott McMurray-5/+4
2024-05-26Rollup merge of #125508 - scottmcm:fix-125506, r=NilstriebMatthias Krüger-0/+5
Stop SRoA'ing `DynMetadata` in MIR Fixes #125506
2024-05-25Stop SRoA'ing `DynMetadata` in MIRScott McMurray-0/+5
2024-05-24compiler: unnest rustc_const_eval::check_constsJubilee Young-2/+2
2024-05-24compiler: const_eval/transform/validate.rs -> mir_transform/validate.rsJubilee Young-2/+1409
2024-05-23Remove `LintDiagnostic::msg`León Orell Valerian Liehr-14/+8
* instead simply set the primary message inside the lint decorator functions * it used to be this way before [#]101986 which introduced `msg` to prevent good path delayed bugs (which no longer exist) from firing under certain circumstances when lints were suppressed / silenced * this is no longer necessary for various reasons I presume * it shaves off complexity and makes further changes easier to implement
2024-05-21interpret: make overflowing binops just normal binopsRalf Jung-51/+66
2024-05-20Rollup merge of #125173 - scottmcm:never-checked, r=davidtwcoMatthias Krüger-52/+38
Remove `Rvalue::CheckedBinaryOp` Zulip conversation: <https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/intrinsics.20vs.20binop.2Funop/near/438729996> cc `@RalfJung` While it's a draft, r? ghost
2024-05-20Rollup merge of #125106 - Zalathar:expressions, r=davidtwcoMatthias Krüger-5/+80
coverage: Memoize and simplify counter expressions When creating coverage counter expressions as part of coverage instrumentation, we often end up creating obviously-redundant expressions like `c1 + (c0 - c1)`, which is equivalent to just `c0`. To avoid doing so, this PR checks when we would create an expression matching one of 5 patterns, and uses the simplified form instead: - `(a - b) + b` → `a`. - `(a + b) - b` → `a`. - `(a + b) - a` → `b`. - `a + (b - a)` → `b`. - `a - (a - b)` → `b`. Of all the different ways to combine 3 operands and 2 operators, these are the patterns that allow simplification. (Some of those patterns currently don't occur in practice, but are included anyway for completeness, to avoid having to add them later as branch coverage and MC/DC coverage support expands.) --- This PR also adds memoization for newly-created (or newly-simplified) counter expressions, to avoid creating duplicates. This currently makes no difference to the final mappings, but is expected to be useful for MC/DC coverage of match expressions, as proposed by https://github.com/rust-lang/rust/pull/124278#issuecomment-2106754753.
2024-05-17Remove `Rvalue::CheckedBinaryOp`Scott McMurray-52/+38
2024-05-17Rename Unsafe to SafetySantiago Pastorino-2/+2
2024-05-14coverage: `CoverageIdsInfo::mcdc_bitmap_bytes` is never neededZalathar-11/+1
This code for recalculating `mcdc_bitmap_bytes` doesn't provide any benefit, because its result won't have changed from the value in `FunctionCoverageInfo` that was computed during the MIR instrumentation pass.
2024-05-14coverage: Simplify counter expressions using simple algebraZalathar-0/+37
Some of these cases currently don't occur in practice, but are included for completeness, and to avoid having to add them later as branch coverage and MC/DC coverage start building more complex expressions.
2024-05-14coverage: Memoize newly-created counter expressionsZalathar-3/+21
This currently has no effect, but is expected to be useful when expanding support for branch coverage and MC/DC coverage.
2024-05-14coverage: Store expression operands as `BcbCounter`Zalathar-4/+24
2024-05-13Auto merge of #125076 - compiler-errors:alias-term, r=lcnrbors-2/+1
Split out `ty::AliasTerm` from `ty::AliasTy` Splitting out `AliasTerm` (for use in project and normalizes goals) and `AliasTy` (for use in `ty::Alias`) r? lcnr
2024-05-13split out AliasTy -> AliasTermMichael Goulet-2/+1
2024-05-13Remove `extern crate rustc_middle` from `rustc_mir_transform`.Nicholas Nethercote-2/+31
2024-05-10Rollup merge of #124957 - compiler-errors:builtin-deref, r=michaelwoeristerMatthias Krüger-9/+9
Make `Ty::builtin_deref` just return a `Ty` Nowhere in the compiler are we using the mutability part of the `TyAndMut` that we used to return.
2024-05-10Rollup merge of #124615 - Zalathar:extracted-mappings, r=davidtwcoMatthias Krüger-107/+118
coverage: Further simplify extraction of mapping info from MIR This is another round of rearrangement and simplification that builds on top of the changes made to mapping-extraction by #124603. The overall theme is to take the computation of `bcb_has_mappings` and `test_vector_bitmap_bytes` out of the main body of `generate_coverage_spans`, which then lets us perform a few other small changes that had previously been held up by the need to work around those computations.
2024-05-09Make builtin_deref just return a TyMichael Goulet-9/+9