about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2023-09-10 16:35:37 +1000
committerZalathar <Zalathar@users.noreply.github.com>2023-10-18 21:20:29 +1100
commitc479bc7f3b8bb0441bef0634b0a60cfdd1ac0914 (patch)
tree09af7843a45c2cf0c61c9ec411bbcb7225e86557 /compiler/rustc_mir_transform/src
parent6d7160ce97f4bbbd44991a7325077e08214e0ce2 (diff)
downloadrust-c479bc7f3b8bb0441bef0634b0a60cfdd1ac0914.tar.gz
rust-c479bc7f3b8bb0441bef0634b0a60cfdd1ac0914.zip
coverage: Attach an optional `FunctionCoverageInfo` to `mir::Body`
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.
Diffstat (limited to 'compiler/rustc_mir_transform/src')
-rw-r--r--compiler/rustc_mir_transform/src/coverage/mod.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/compiler/rustc_mir_transform/src/coverage/mod.rs b/compiler/rustc_mir_transform/src/coverage/mod.rs
index abf13519e9e..1ce6ecc3bb5 100644
--- a/compiler/rustc_mir_transform/src/coverage/mod.rs
+++ b/compiler/rustc_mir_transform/src/coverage/mod.rs
@@ -211,6 +211,10 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
                 self.make_mir_coverage_kind(intermediate_expression),
             );
         }
+
+        self.mir_body.function_coverage_info = Some(Box::new(FunctionCoverageInfo {
+            function_source_hash: self.function_source_hash,
+        }));
     }
 
     /// Injects a single [`StatementKind::Coverage`] for each BCB that has one
@@ -323,9 +327,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
 
     fn make_mir_coverage_kind(&self, counter_kind: &BcbCounter) -> CoverageKind {
         match *counter_kind {
-            BcbCounter::Counter { id } => {
-                CoverageKind::Counter { function_source_hash: self.function_source_hash, id }
-            }
+            BcbCounter::Counter { id } => CoverageKind::Counter { id },
             BcbCounter::Expression { id, lhs, op, rhs } => {
                 CoverageKind::Expression { id, lhs, op, rhs }
             }