about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/mir/coverage.rs
AgeCommit message (Collapse)AuthorLines
2025-08-06coverage: Remove all unstable support for MC/DC instrumentationZalathar-85/+0
2025-03-18coverage: Don't store a body span in `FunctionCoverageInfo`Zalathar-1/+0
2025-02-06coverage: Remove the old code for simplifying counters after MIR optsZalathar-31/+1
2025-02-06coverage: Defer part of counter-creation until codegenZalathar-26/+44
2025-02-06coverage: Store BCB node IDs in mappings, and resolve them in codegenZalathar-23/+28
Even though the coverage graph itself is no longer available during codegen, its nodes can still be used as opaque IDs.
2025-01-24Exclude `mir::coverage` types from TypeFoldable/TypeVisitableZalathar-14/+14
These types are unlikely to ever contain type information in the foreseeable future, so excluding them from TypeFoldable/TypeVisitable avoids some unhelpful derive boilerplate.
2025-01-18coverage: Remove `BcbCounter` and `BcbExpression`Zalathar-6/+2
Making these separate types from `CovTerm` and `Expression` was historically very helpful, but now that most of the counter-creation work is handled by `node_flow` they are no longer needed.
2025-01-11rename `BitSet` to `DenseBitSet`Rémy Rakic-3/+3
This should make it clearer that this bitset is dense, with the advantages and disadvantages that it entails.
2024-12-19coverage: Store coverage source regions as `Span` until codegenZalathar-17/+1
2024-12-08coverage: Use a query to find counters/expressions that must be zeroZalathar-1/+12
This query (`coverage_ids_info`) already determines which counter/expression IDs are unused, so it only takes a little extra effort to also determine which counters/expressions must have a value of zero.
2024-12-08coverage: Move `CoverageIdsInfo` into `mir::coverage`Zalathar-0/+28
2024-11-30coverage: Allow niches in counter/expression IDsZalathar-2/+0
There is unlikely to be any practical difference between a counter limit of 2^32 and a counter limit of (2^32 - 256).
2024-11-29Revert "Rollup merge of #133418 - Zalathar:spans, r=jieyouxu"Zalathar-1/+17
This reverts commit adf9b5fcd1de43eaf0a779e10612caee8b47bede, reversing changes made to af1ca153d4aed5ffe22445273aa388a8d3f8f4ae. Reverting due to <https://github.com/rust-lang/rust/issues/133606>.
2024-11-24coverage: Store coverage source regions as `Span` until codegenZalathar-17/+1
2024-11-08coverage: Remove unhelpful code for handling multiple files per functionZalathar-7/+4
Functions currently can't have mappings in multiple files, and if that ever changes (e.g. to properly support expansion regions), this code will need to be completely overhauled anyway.
2024-10-08coverage. Adapt to mcdc mapping formats introduced by llvm 19zhuyunxing-18/+11
2024-10-08coverage. MCDC ConditionId start from 0 to keep with llvm 19zhuyunxing-13/+3
2024-08-28coverage: Rename `CodeRegion` to `SourceRegion`Zalathar-3/+3
LLVM uses the word "code" to refer to a particular kind of coverage mapping. This unrelated usage of the word is confusing, and makes it harder to introduce types whose names correspond to the LLVM classification of coverage kinds.
2024-07-29Reformat `use` declarations.Nicholas Nethercote-2/+2
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-15coverage: Restrict `ExpressionUsed` simplification to `Code` mappingsZalathar-13/+0
In the future, branch and MC/DC mappings might have expressions that don't correspond to any single point in the control-flow graph. That makes it trickier to keep track of which expressions should expect an `ExpressionUsed` node. We therefore sidestep that complexity by only performing `ExpressionUsed` simplification for expressions associated directly with ordinary `Code` mappings.
2024-07-05coverage: Rename `mir::coverage::BranchInfo` to `CoverageInfoHi`Zalathar-3/+8
This opens the door to collecting and storing coverage information that is unrelated to branch coverage or MC/DC.
2024-05-30coverage: Rename MC/DC `conditions_num` to `num_conditions`Zalathar-2/+2
This value represents a quantity of conditions, not an ID, so the new spelling is more appropriate.
2024-05-20Rollup merge of #125106 - Zalathar:expressions, r=davidtwcoMatthias Krüger-2/+2
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-14coverage: Remove confusing comments from `CoverageKind`Zalathar-6/+0
These comments appear to be inspired by the similar comments on `CounterIncrement` and `ExpressionUsed`. But those comments refer to specific simplification steps performed during coverage codegen, and there is no corresponding step for the MC/DC coverage statements. If these statements do not survive optimization, they will simply not participate in code generation, just like any other statement.
2024-05-14coverage: Memoize newly-created counter expressionsZalathar-2/+2
This currently has no effect, but is expected to be useful when expanding support for branch coverage and MC/DC coverage.
2024-05-01coverage: Replace `max_decision_depth` with `num_condition_bitmaps`Zalathar-1/+1
This clearly distinguishes individual decision-depth indices from the total number of condition bitmaps to allocate.
2024-04-30Rollup merge of #124511 - nnethercote:rm-extern-crates, r=fee1-deadMatthias Krüger-1/+1
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-29mcdc-coverage: Get decision_depth from THIR loweringDorian Péron-0/+3
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-6/+14
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-29Remove `extern crate rustc_macros` from `rustc_middle`.Nicholas Nethercote-1/+1
2024-04-22coverage: Detach MC/DC branch spans from regular branch spansZalathar-1/+3
MC/DC's reliance on the existing branch coverage types is making it much harder to improve branch coverage.
2024-04-19coverage. Generate Mappings of decisions and conditions for MC/DCzhuyunxing-3/+101
2024-04-04coverage: Remove useless constantsZalathar-8/+0
2024-04-03rustc_index: Add a `ZERO` constant to index typesVadim Petrochenkov-2/+2
It is commonly used.
2024-03-22coverage: Clean up marker statements that aren't needed laterZalathar-3/+2
Some of the marker statements used by coverage are added during MIR building for use by the InstrumentCoverage pass (during analysis), and are not needed afterwards.
2024-03-14coverage: Include recorded branch info in coverage instrumentationZalathar-1/+8
2024-03-14coverage: Data structures for recording branch info during MIR buildingZalathar-2/+21
2024-03-13coverage: Add `CoverageKind::BlockMarker`Zalathar-0/+16
2024-01-11coverage: Add enums to accommodate other kinds of coverage mappingsZalathar-8/+26
2023-12-08coverage: Add `CoverageKind::SpanMarker` for including extra spans in MIRZalathar-0/+8
There are cases where coverage instrumentation wants to show a span for some syntax element, but there is no MIR node that naturally carries that span, so the instrumentor can't see it. MIR building can now use this new kind of coverage statement to deliberately include those spans in MIR, attached to a dummy statement that has no other effect.
2023-11-22Replace `no_ord_impl` with `orderable`.Nicholas Nethercote-0/+2
Similar to the previous commit, this replaces `newtype_index`'s opt-out `no_ord_impl` attribute with the opt-in `orderable` attribute.
2023-11-22Replace `custom_encodable` with `encodable`.Nicholas Nethercote-0/+2
By default, `newtype_index!` types get a default `Encodable`/`Decodable` impl. You can opt out of this with `custom_encodable`. Opting out is the opposite to how Rust normally works with autogenerated (derived) impls. This commit inverts the behaviour, replacing `custom_encodable` with `encodable` which opts into the default `Encodable`/`Decodable` impl. Only 23 of the 59 `newtype_index!` occurrences need `encodable`. Even better, there were eight crates with a dependency on `rustc_serialize` just from unused default `Encodable`/`Decodable` impls. This commit removes that dependency from those eight crates.
2023-10-18coverage: Explicitly note that counter/expression IDs are function-localZalathar-0/+10
2023-10-18coverage: Store expression data in function coverage infoZalathar-20/+21
Even though expression details are now stored in the info structure, we still need to inject `ExpressionUsed` statements into MIR, because if one is missing during codegen then we know that it was optimized out and we can remap all of its associated code regions to zero.
2023-10-18coverage: Store all of a function's mappings in function coverage infoZalathar-8/+10
Previously, mappings were attached to individual coverage statements in MIR. That necessitated special handling in MIR optimizations to avoid deleting those statements, since otherwise codegen would be unable to reassemble the original list of mappings. With this change, a function's list of mappings is now attached to its MIR body, and survives intact even if individual statements are deleted by optimizations.
2023-10-18coverage: Collect a function's coverage mappings into a single listZalathar-0/+14
This is an intermediate step towards being able to store all of a function's mappings in function coverage info.
2023-10-18coverage: Rename `Operand` to `CovTerm`Zalathar-7/+9
Later patches in this PR will use `CovTerm` to represent things that are not expression operands.
2023-10-18coverage: Store the number of counters/expressions in function coverage infoZalathar-0/+2
Coverage codegen can now allocate arrays based on the number of counters/expressions originally used by the instrumentor. The existing query that inspects coverage statements is still used for determining the number of counters passed to `llvm.instrprof.increment`. If some high-numbered counters were removed by MIR optimizations, the instrumented binary can potentially use less memory and disk space at runtime.
2023-10-18coverage: Attach an optional `FunctionCoverageInfo` to `mir::Body`Zalathar-2/+10
This allows coverage information to be attached to the function as a whole when appropriate, instead of being smuggled through coverage statements in the function's basic blocks. As an example, this patch moves the `function_source_hash` value out of individual `CoverageKind::Counter` statements and into the per-function info. When synthesizing unused functions for coverage purposes, the absence of this info is taken to indicate that a function was not eligible for coverage and should not be synthesized.
2023-10-03coverage: Remove `next_id` methods from counter/expression IDsZalathar-10/+0
When these methods were originally written, I wasn't aware that `newtype_index!` already supports addition with ordinary numbers, without needing to unwrap and re-wrap.