@@ -2,7 +2,9 @@ use crate::coverageinfo::ffi::{Counter, CounterExpression, ExprKind};
2
2
3
3
use rustc_data_structures:: fx:: FxIndexSet ;
4
4
use rustc_index:: IndexVec ;
5
- use rustc_middle:: mir:: coverage:: { CodeRegion , CounterId , ExpressionId , Op , Operand } ;
5
+ use rustc_middle:: mir:: coverage:: {
6
+ CodeRegion , CounterId , ExpressionId , FunctionCoverageInfo , Op , Operand ,
7
+ } ;
6
8
use rustc_middle:: ty:: Instance ;
7
9
use rustc_middle:: ty:: TyCtxt ;
8
10
@@ -27,8 +29,8 @@ pub struct Expression {
27
29
/// line."
28
30
#[ derive( Debug ) ]
29
31
pub struct FunctionCoverage < ' tcx > {
30
- instance : Instance < ' tcx > ,
31
- source_hash : u64 ,
32
+ /// Coverage info that was attached to this function by the instrumentor.
33
+ function_coverage_info : & ' tcx FunctionCoverageInfo ,
32
34
is_used : bool ,
33
35
counters : IndexVec < CounterId , Option < Vec < CodeRegion > > > ,
34
36
expressions : IndexVec < ExpressionId , Option < Expression > > ,
@@ -37,24 +39,36 @@ pub struct FunctionCoverage<'tcx> {
37
39
38
40
impl < ' tcx > FunctionCoverage < ' tcx > {
39
41
/// Creates a new set of coverage data for a used (called) function.
40
- pub fn new ( tcx : TyCtxt < ' tcx > , instance : Instance < ' tcx > ) -> Self {
41
- Self :: create ( tcx, instance, true )
42
+ pub fn new (
43
+ tcx : TyCtxt < ' tcx > ,
44
+ instance : Instance < ' tcx > ,
45
+ function_coverage_info : & ' tcx FunctionCoverageInfo ,
46
+ ) -> Self {
47
+ Self :: create ( tcx, instance, function_coverage_info, true )
42
48
}
43
49
44
50
/// Creates a new set of coverage data for an unused (never called) function.
45
- pub fn unused ( tcx : TyCtxt < ' tcx > , instance : Instance < ' tcx > ) -> Self {
46
- Self :: create ( tcx, instance, false )
51
+ pub fn unused (
52
+ tcx : TyCtxt < ' tcx > ,
53
+ instance : Instance < ' tcx > ,
54
+ function_coverage_info : & ' tcx FunctionCoverageInfo ,
55
+ ) -> Self {
56
+ Self :: create ( tcx, instance, function_coverage_info, false )
47
57
}
48
58
49
- fn create ( tcx : TyCtxt < ' tcx > , instance : Instance < ' tcx > , is_used : bool ) -> Self {
59
+ fn create (
60
+ tcx : TyCtxt < ' tcx > ,
61
+ instance : Instance < ' tcx > ,
62
+ function_coverage_info : & ' tcx FunctionCoverageInfo ,
63
+ is_used : bool ,
64
+ ) -> Self {
50
65
let coverageinfo = tcx. coverageinfo ( instance. def ) ;
51
66
debug ! (
52
67
"FunctionCoverage::create(instance={:?}) has coverageinfo={:?}. is_used={}" ,
53
68
instance, coverageinfo, is_used
54
69
) ;
55
70
Self {
56
- instance,
57
- source_hash : 0 , // will be set with the first `add_counter()`
71
+ function_coverage_info,
58
72
is_used,
59
73
counters : IndexVec :: from_elem_n ( None , coverageinfo. num_counters as usize ) ,
60
74
expressions : IndexVec :: from_elem_n ( None , coverageinfo. num_expressions as usize ) ,
@@ -67,16 +81,6 @@ impl<'tcx> FunctionCoverage<'tcx> {
67
81
self . is_used
68
82
}
69
83
70
- /// Sets the function source hash value. If called multiple times for the same function, all
71
- /// calls should have the same hash value.
72
- pub fn set_function_source_hash ( & mut self , source_hash : u64 ) {
73
- if self . source_hash == 0 {
74
- self . source_hash = source_hash;
75
- } else {
76
- debug_assert_eq ! ( source_hash, self . source_hash) ;
77
- }
78
- }
79
-
80
84
/// Adds code regions to be counted by an injected counter intrinsic.
81
85
#[ instrument( level = "debug" , skip( self ) ) ]
82
86
pub ( crate ) fn add_counter ( & mut self , id : CounterId , code_regions : & [ CodeRegion ] ) {
@@ -195,7 +199,7 @@ impl<'tcx> FunctionCoverage<'tcx> {
195
199
/// Return the source hash, generated from the HIR node structure, and used to indicate whether
196
200
/// or not the source code structure changed between different compilations.
197
201
pub fn source_hash ( & self ) -> u64 {
198
- self . source_hash
202
+ if self . is_used { self . function_coverage_info . function_source_hash } else { 0 }
199
203
}
200
204
201
205
/// Generate an array of CounterExpressions, and an iterator over all `Counter`s and their
@@ -204,12 +208,6 @@ impl<'tcx> FunctionCoverage<'tcx> {
204
208
pub fn get_expressions_and_counter_regions (
205
209
& self ,
206
210
) -> ( Vec < CounterExpression > , impl Iterator < Item = ( Counter , & CodeRegion ) > ) {
207
- assert ! (
208
- self . source_hash != 0 || !self . is_used,
209
- "No counters provided the source_hash for used function: {:?}" ,
210
- self . instance
211
- ) ;
212
-
213
211
let counter_expressions = self . counter_expressions ( ) ;
214
212
// Expression IDs are indices into `self.expressions`, and on the LLVM
215
213
// side they will be treated as indices into `counter_expressions`, so
0 commit comments