about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform
AgeCommit message (Collapse)AuthorLines
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
2024-05-08Simplify `use crate::rustc_foo::bar` occurrences.Nicholas Nethercote-1/+1
They can just be written as `use rustc_foo::bar`, which is far more standard. (I didn't even know that a `crate::` prefix was valid.)
2024-05-06coverage: Tidy imports in `rustc_mir_transform::coverage`Zalathar-7/+8
2024-05-06coverage: Rename `CoverageSpans` to `ExtractedMappings`Zalathar-21/+27
2024-05-06coverage: Destructure the mappings struct to make sure we don't miss anyZalathar-4/+13
2024-05-06coverage: Don't recompute the number of test vector bitmap bytesZalathar-33/+12
The code in `extract_mcdc_mappings` that allocates these bytes already knows how many are needed in total, so there's no need to immediately recompute that value in the calling function.
2024-05-06coverage: Make the special case for async functions exit earlyZalathar-18/+21
2024-05-06coverage: Separately compute the set of BCBs with counter mappingsZalathar-46/+59
2024-05-04coverage: Rename `BcbBranchPair` to `mappings::BranchPair`Zalathar-7/+7
This makes it consistent with the other mapping structs introduced by this PR.
2024-05-04coverage: Flatten `BcbMappingKind` into `mappings::CodeMapping`Zalathar-32/+20
Now that branch and MC/DC mappings have been split out into separate types and vectors, this enum is no longer needed, since it only represents ordinary "code" regions. (We can revisit this decision if we ever add support for other region kinds, such as skipped regions or expansion regions. But at that point, we might just add new structs/vectors for those kinds as well.)
2024-05-04coverage: Extract helper `region_for_span`Zalathar-4/+5
2024-05-04coverage: Split out MC/DC branches from `BcbMappingKind`Zalathar-80/+72
2024-05-04coverage: Split out MC/DC decisions from `BcbMappingKind`Zalathar-51/+71
2024-05-03Auto merge of #123602 - cjgillot:gvn-borrowed, r=oli-obkbors-42/+78
Account for immutably borrowed locals in MIR copy-prop and GVN For the most part, we consider that immutably borrowed `Freeze` locals still fulfill SSA conditions. As the borrow is immutable, any use of the local will have the value given by the single assignment, and there can be no surprise. This allows copy-prop to merge a non-borrowed local with a borrowed local. We chose to keep copy-classes heads unborrowed, as those may be easier to optimize in later passes. This also allows to GVN the value behind an immutable borrow. If a SSA local is borrowed, dereferencing that borrow is equivalent to copying the local's value: re-executing the assignment between the borrow and the dereference would be UB. r? `@ghost` for perf
2024-05-03Rollup merge of #124555 - Zalathar:init-coverage, r=nnethercoteMatthias Krüger-3/+3
coverage: Clean up creation of MC/DC condition bitmaps This PR improves the code for creating and initializing [MC/DC](https://en.wikipedia.org/wiki/Modified_condition/decision_coverage) condition bitmap variables, as introduced by #123409 and modified by #124255. - The condition bitmap variables are now created eagerly at the start of per-function codegen, via a new `init_coverage` method in `CoverageInfoBuilderMethods`. This avoids having to retroactively create the bitmaps while doing codegen for an individual coverage statement. - As a result, we can now create and initialize those bitmaps using existing safe APIs, instead of having to perform our own unsafe call to `llvm::LLVMBuildAlloca`. - This PR also tweaks the way we count the number of condition bitmaps needed, by tracking the total number of bitmaps needed (max depth + 1), instead of only tracking the maximum depth. This reduces the potential for subtle off-by-one confusion.
2024-05-02Rollup merge of #124624 - WaffleLapkin:old_unit, r=fmeaseMatthias Krüger-1/+1
Use `tcx.types.unit` instead of `Ty::new_unit(tcx)` I don't think there is any need for the function, given that we can just access the `.types`, similarly to all other primitives?
2024-05-02Inline & delete `Ty::new_unit`, since it's just a field accessWaffle Lapkin-1/+1
2024-05-01Step bootstrap cfgsMark Rousskov-1/+0
2024-05-01coverage: Replace `max_decision_depth` with `num_condition_bitmaps`Zalathar-3/+3
This clearly distinguishes individual decision-depth indices from the total number of condition bitmaps to allocate.
2024-04-30Auto merge of #124558 - matthiaskrgr:rollup-axi1bxu, r=matthiaskrgrbors-29/+18
Rollup of 3 pull requests Successful merges: - #123247 (Mention Both HRTB and Generic Lifetime Param in `E0637` documentation) - #124511 (Remove many `#[macro_use] extern crate foo` items) - #124550 (Remove redundant union check in `KnownPanicsLint` const prop) r? `@ghost` `@rustbot` modify labels: rollup
2024-04-30Remove redundant union check in `KnownPanicsLint const propGurinder Singh-29/+18
because we are already marking unions `NoPropagation` in `CanConstProp::check()`. That is enough to prevent any attempts at const propagating unions and this second check is not needed. Also improve a comment in `CanConstProp::check()`
2024-04-30coverage: Split off `mappings.rs` from `spans.rs` and `from_mir.rs`Zalathar-275/+283
2024-04-30coverage: Prepare to split `spans.rs` into two filesZalathar-26/+30
2024-04-29Rollup merge of #124504 - gurry:123710-union-ICE, r=oli-obk许杰友 Jieyou Xu (Joe)-7/+13
Mark unions non-const-propagatable in `KnownPanicsLint` without calling layout Fixes #123710 The ICE occurs during the layout calculation of the union `InvalidTag` in #123710 because the following assert fails:https://github.com/rust-lang/rust/blob/5fe8b697e729b6eb64841a3905e57da1b47f4ca3/compiler/rustc_abi/src/layout.rs#L289-L292 The layout calculation is invoked by `KnownPanicsLint` when it is trying to figure out which locals it can const prop. Since `KnownPanicsLint` is never actually going to const props unions thanks to PR https://github.com/rust-lang/rust/pull/121628 there's no point calling layout to check if it can. So in this fix I skip the call to layout and just mark the local non-const propagatable if it is a union.
2024-04-29Auto merge of #124255 - RenjiSann:renji/mcdc-nested-expressions, r=Zalatharbors-24/+57
MCDC coverage: support nested decision coverage #123409 provided the initial MCDC coverage implementation. As referenced in #124144, it does not currently support "nested" decisions, like the following example : ```rust fn nested_if_in_condition(a: bool, b: bool, c: bool) { if a && if b || c { true } else { false } { say("yes"); } else { say("no"); } } ``` Note that there is an if-expression (`if b || c ...`) embedded inside a boolean expression in the decision of an outer if-expression. This PR proposes a workaround for this cases, by introducing a Decision context stack, and by handing several `temporary condition bitmaps` instead of just one. When instrumenting boolean expressions, if the current node is a leaf condition (i.e. not a `||`/`&&` logical operator nor a `!` not operator), we insert a new decision context, such that if there are more boolean expressions inside the condition, they are handled as separate expressions. On the codegen LLVM side, we allocate as many `temp_cond_bitmap`s as necessary to handle the maximum encountered decision depth.
2024-04-29mcdc-coverage: Get decision_depth from THIR loweringDorian Péron-0/+11
Use decision context stack to handle nested decisions: - Introduce MCDCDecisionCtx - Use a stack of MCDCDecisionCtx to handle nested decisions
2024-04-29mcdc-coverage: Add decision_depth field in structsDorian Péron-24/+46
Add decision_depth field to TVBitmapUpdate/CondBitmapUpdate statements Add decision_depth field to BcbMappingKinds MCDCBranch and MCDCDecision Add decision_depth field to MCDCBranchSpan and MCDCDecisionSpan
2024-04-29Prohibit const prop of unions in `KnownPanicsLint`Gurinder Singh-7/+13
as they have a potential to ICE during layout calculation