mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-19 19:23:10 +00:00
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
@ -20,7 +20,7 @@ use std::fmt::{self, Debug};
|
||||
/// BCB node or BCB edge.
|
||||
#[derive(Clone)]
|
||||
pub(super) enum BcbCounter {
|
||||
Counter { function_source_hash: u64, id: CounterId },
|
||||
Counter { id: CounterId },
|
||||
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
|
||||
/// associated with nodes/edges in the BCB graph.
|
||||
pub(super) struct CoverageCounters {
|
||||
function_source_hash: u64,
|
||||
next_counter_id: CounterId,
|
||||
next_expression_id: ExpressionId,
|
||||
|
||||
@ -81,11 +80,10 @@ pub(super) struct 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();
|
||||
|
||||
Self {
|
||||
function_source_hash,
|
||||
next_counter_id: CounterId::START,
|
||||
next_expression_id: ExpressionId::START,
|
||||
|
||||
@ -119,10 +117,7 @@ impl CoverageCounters {
|
||||
where
|
||||
F: Fn() -> Option<String>,
|
||||
{
|
||||
let counter = BcbCounter::Counter {
|
||||
function_source_hash: self.function_source_hash,
|
||||
id: self.next_counter(),
|
||||
};
|
||||
let counter = BcbCounter::Counter { id: self.next_counter() };
|
||||
if self.debug_counters.is_enabled() {
|
||||
self.debug_counters.add_counter(&counter, (debug_block_label_fn)());
|
||||
}
|
||||
|
@ -106,6 +106,7 @@ struct Instrumentor<'a, 'tcx> {
|
||||
source_file: Lrc<SourceFile>,
|
||||
fn_sig_span: Span,
|
||||
body_span: Span,
|
||||
function_source_hash: u64,
|
||||
basic_coverage_blocks: CoverageGraph,
|
||||
coverage_counters: CoverageCounters,
|
||||
}
|
||||
@ -137,7 +138,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
|
||||
|
||||
let function_source_hash = hash_mir_source(tcx, hir_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 {
|
||||
pass_name,
|
||||
@ -146,6 +147,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
|
||||
source_file,
|
||||
fn_sig_span,
|
||||
body_span,
|
||||
function_source_hash,
|
||||
basic_coverage_blocks,
|
||||
coverage_counters,
|
||||
}
|
||||
@ -435,8 +437,8 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
|
||||
|
||||
fn make_mir_coverage_kind(&self, counter_kind: &BcbCounter) -> CoverageKind {
|
||||
match *counter_kind {
|
||||
BcbCounter::Counter { function_source_hash, id } => {
|
||||
CoverageKind::Counter { function_source_hash, id }
|
||||
BcbCounter::Counter { id } => {
|
||||
CoverageKind::Counter { function_source_hash: self.function_source_hash, id }
|
||||
}
|
||||
BcbCounter::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
|
||||
.make_bcb_counters(&mut basic_coverage_blocks, &coverage_spans)
|
||||
.expect("should be Ok");
|
||||
|
Loading…
Reference in New Issue
Block a user