rust-lang / rust-lang/rust

Known limitations of branch coverage instrumentation

Open
#124,118 9 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-code-coverage T-compiler
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

Branch coverage is known to support these branching language constructs:

  • if and while
    • Includes if let and let-chains
    • Treats nested || and && as separate branches
    • while desugars to if before MIR building, so we support it as a consequence of supporting if
  • Standalone || and && expressions
    • Nested || and && are treated as separate branches
    • The final operand is not a branch, but can be optionally treated as one via #125756
  • let-else statements
  • Match arm guards
    • These also desugar to if expressions before MIR building
      • This also means that we naturally support if let guards
    • But their presence makes it more complicated to instrument match arms, as described below

Branch coverage is known to not yet support these branching language constructs:

  • Individual arms and or-patterns in match expressions
    • We need to be sure to support (or gracefully not support) all four combinations of:
      • Arms with/without guards
        • The guards themselves are already supported (as indicated above), but their presence also complicates how we instrument the enclosing match arm, and other match arms in the same match
        • Note that the combination of guards and or-patterns results in particularly complex control-flow, because if a guard fails then we keep searching for other or-pattern matches in the same arm
      • Arms with/without or-patterns, including arbitrary nesting
    • #124154
      • This draft does not support or-patterns, and might not be able to support them without substantial changes (requiring a different approach)
      • This draft uses complex counter expressions to work around not being able to instrument all the appropriate points in the control-flow graph directly; this ties back into concerns about or-patterns
  • The try ? operator (which conditionally returns)
    • This is desugared to a match expression, so once we support those, supporting ? should mostly be a matter of expansion-span bookkeeping
  • .await expressions (which implicitly “return” when the enclosing future is dropped)
    • This can probably be excluded from any MVP of branch coverage, unless it turns out to be unexpectedly easy after supporting ?
    • But some users will presumably want this in the long run
  • Any of the above branching constructs that are introduced by macro expansion
    • The current implementation discards any branch span that isn't “directly visible” in the function body

Relevant PR links:

  • #122322
  • #124223
  • #124154

(Rewritten on 2024-07-11; see edit history for the old text.)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the relevant PRs #122322, #124223, and #124154, then compare their approaches with the unsupported constructs listed here. The issue names no files or tests, and completion would require deciding which limitations to address and defining support for them.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, testing-qa
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.