coverage: Don't store function_source_hash
in BcbCounter::Counter
This shows one small benefit of separating `BcbCounter` from `CoverageKind`. The function source hash will be the same for all counters within a function, so instead of passing it through `CoverageCounters` and storing it in every counter, we can just supply it during the final conversion to `CoverageKind`.
This commit is contained in:
parent
fbab055e77
commit
72f4c78dc6
3 changed files with 9 additions and 12 deletions
|
@ -20,7 +20,7 @@ use std::fmt::{self, Debug};
|
||||||
/// BCB node or BCB edge.
|
/// BCB node or BCB edge.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(super) enum BcbCounter {
|
pub(super) enum BcbCounter {
|
||||||
Counter { function_source_hash: u64, id: CounterId },
|
Counter { id: CounterId },
|
||||||
Expression { id: ExpressionId, lhs: Operand, op: Op, rhs: Operand },
|
Expression { id: ExpressionId, lhs: Operand, op: Op, rhs: Operand },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,6 @@ impl Debug for BcbCounter {
|
||||||
/// Generates and stores coverage counter and coverage expression information
|
/// Generates and stores coverage counter and coverage expression information
|
||||||
/// associated with nodes/edges in the BCB graph.
|
/// associated with nodes/edges in the BCB graph.
|
||||||
pub(super) struct CoverageCounters {
|
pub(super) struct CoverageCounters {
|
||||||
function_source_hash: u64,
|
|
||||||
next_counter_id: CounterId,
|
next_counter_id: CounterId,
|
||||||
next_expression_id: ExpressionId,
|
next_expression_id: ExpressionId,
|
||||||
|
|
||||||
|
@ -81,11 +80,10 @@ pub(super) struct CoverageCounters {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CoverageCounters {
|
impl CoverageCounters {
|
||||||
pub(super) fn new(function_source_hash: u64, basic_coverage_blocks: &CoverageGraph) -> Self {
|
pub(super) fn new(basic_coverage_blocks: &CoverageGraph) -> Self {
|
||||||
let num_bcbs = basic_coverage_blocks.num_nodes();
|
let num_bcbs = basic_coverage_blocks.num_nodes();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
function_source_hash,
|
|
||||||
next_counter_id: CounterId::START,
|
next_counter_id: CounterId::START,
|
||||||
next_expression_id: ExpressionId::START,
|
next_expression_id: ExpressionId::START,
|
||||||
|
|
||||||
|
@ -119,10 +117,7 @@ impl CoverageCounters {
|
||||||
where
|
where
|
||||||
F: Fn() -> Option<String>,
|
F: Fn() -> Option<String>,
|
||||||
{
|
{
|
||||||
let counter = BcbCounter::Counter {
|
let counter = BcbCounter::Counter { id: self.next_counter() };
|
||||||
function_source_hash: self.function_source_hash,
|
|
||||||
id: self.next_counter(),
|
|
||||||
};
|
|
||||||
if self.debug_counters.is_enabled() {
|
if self.debug_counters.is_enabled() {
|
||||||
self.debug_counters.add_counter(&counter, (debug_block_label_fn)());
|
self.debug_counters.add_counter(&counter, (debug_block_label_fn)());
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,6 +106,7 @@ struct Instrumentor<'a, 'tcx> {
|
||||||
source_file: Lrc<SourceFile>,
|
source_file: Lrc<SourceFile>,
|
||||||
fn_sig_span: Span,
|
fn_sig_span: Span,
|
||||||
body_span: Span,
|
body_span: Span,
|
||||||
|
function_source_hash: u64,
|
||||||
basic_coverage_blocks: CoverageGraph,
|
basic_coverage_blocks: CoverageGraph,
|
||||||
coverage_counters: CoverageCounters,
|
coverage_counters: CoverageCounters,
|
||||||
}
|
}
|
||||||
|
@ -137,7 +138,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
|
||||||
|
|
||||||
let function_source_hash = hash_mir_source(tcx, hir_body);
|
let function_source_hash = hash_mir_source(tcx, hir_body);
|
||||||
let basic_coverage_blocks = CoverageGraph::from_mir(mir_body);
|
let basic_coverage_blocks = CoverageGraph::from_mir(mir_body);
|
||||||
let coverage_counters = CoverageCounters::new(function_source_hash, &basic_coverage_blocks);
|
let coverage_counters = CoverageCounters::new(&basic_coverage_blocks);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
pass_name,
|
pass_name,
|
||||||
|
@ -146,6 +147,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
|
||||||
source_file,
|
source_file,
|
||||||
fn_sig_span,
|
fn_sig_span,
|
||||||
body_span,
|
body_span,
|
||||||
|
function_source_hash,
|
||||||
basic_coverage_blocks,
|
basic_coverage_blocks,
|
||||||
coverage_counters,
|
coverage_counters,
|
||||||
}
|
}
|
||||||
|
@ -435,8 +437,8 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
|
||||||
|
|
||||||
fn make_mir_coverage_kind(&self, counter_kind: &BcbCounter) -> CoverageKind {
|
fn make_mir_coverage_kind(&self, counter_kind: &BcbCounter) -> CoverageKind {
|
||||||
match *counter_kind {
|
match *counter_kind {
|
||||||
BcbCounter::Counter { function_source_hash, id } => {
|
BcbCounter::Counter { id } => {
|
||||||
CoverageKind::Counter { function_source_hash, id }
|
CoverageKind::Counter { function_source_hash: self.function_source_hash, id }
|
||||||
}
|
}
|
||||||
BcbCounter::Expression { id, lhs, op, rhs } => {
|
BcbCounter::Expression { id, lhs, op, rhs } => {
|
||||||
CoverageKind::Expression { id, lhs, op, rhs }
|
CoverageKind::Expression { id, lhs, op, rhs }
|
||||||
|
|
|
@ -674,7 +674,7 @@ fn test_make_bcb_counters() {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut coverage_counters = counters::CoverageCounters::new(0, &basic_coverage_blocks);
|
let mut coverage_counters = counters::CoverageCounters::new(&basic_coverage_blocks);
|
||||||
coverage_counters
|
coverage_counters
|
||||||
.make_bcb_counters(&mut basic_coverage_blocks, &coverage_spans)
|
.make_bcb_counters(&mut basic_coverage_blocks, &coverage_spans)
|
||||||
.expect("should be Ok");
|
.expect("should be Ok");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue