Struct rustc_codegen_ssa::coverageinfo::map::FunctionCoverage
source · [−]pub struct FunctionCoverage<'tcx> {
instance: Instance<'tcx>,
source_hash: u64,
is_used: bool,
counters: IndexVec<CounterValueReference, Option<CodeRegion>>,
expressions: IndexVec<InjectedExpressionIndex, Option<Expression>>,
unreachable_regions: Vec<CodeRegion>,
}
Expand description
Collects all of the coverage regions associated with (a) injected counters, (b) counter
expressions (additions or subtraction), and (c) unreachable regions (always counted as zero),
for a given Function. Counters and counter expressions have non-overlapping id
s because they
can both be operands in an expression. This struct also stores the function_source_hash
,
computed during instrumentation, and forwarded with counters.
Note, it may be important to understand LLVM’s definitions of unreachable
regions versus “gap
regions” (or “gap areas”). A gap region is a code region within a counted region (either counter
or expression), but the line or lines in the gap region are not executable (such as lines with
only whitespace or comments). According to LLVM Code Coverage Mapping documentation, “A count
for a gap area is only used as the line execution count if there are no other regions on a
line.”
Fields
instance: Instance<'tcx>
source_hash: u64
is_used: bool
counters: IndexVec<CounterValueReference, Option<CodeRegion>>
expressions: IndexVec<InjectedExpressionIndex, Option<Expression>>
unreachable_regions: Vec<CodeRegion>
Implementations
sourceimpl<'tcx> FunctionCoverage<'tcx>
impl<'tcx> FunctionCoverage<'tcx>
sourcepub fn new(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> Self
pub fn new(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> Self
Creates a new set of coverage data for a used (called) function.
sourcepub fn unused(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> Self
pub fn unused(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> Self
Creates a new set of coverage data for an unused (never called) function.
fn create(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>, is_used: bool) -> Self
sourcepub fn is_used(&self) -> bool
pub fn is_used(&self) -> bool
Returns true for a used (called) function, and false for an unused function.
sourcepub fn set_function_source_hash(&mut self, source_hash: u64)
pub fn set_function_source_hash(&mut self, source_hash: u64)
Sets the function source hash value. If called multiple times for the same function, all calls should have the same hash value.
sourcepub fn add_counter(&mut self, id: CounterValueReference, region: CodeRegion)
pub fn add_counter(&mut self, id: CounterValueReference, region: CodeRegion)
Adds a code region to be counted by an injected counter intrinsic.
sourcepub fn add_counter_expression(
&mut self,
expression_id: InjectedExpressionId,
lhs: ExpressionOperandId,
op: Op,
rhs: ExpressionOperandId,
region: Option<CodeRegion>
)
pub fn add_counter_expression(
&mut self,
expression_id: InjectedExpressionId,
lhs: ExpressionOperandId,
op: Op,
rhs: ExpressionOperandId,
region: Option<CodeRegion>
)
Both counters and “counter expressions” (or simply, “expressions”) can be operands in other
expressions. Expression IDs start from u32::MAX
and go down, so the range of expression
IDs will not overlap with the range of counter IDs. Counters and expressions can be added in
any order, and expressions can still be assigned contiguous (though descending) IDs, without
knowing what the last counter ID will be.
When storing the expression data in the expressions
vector in the FunctionCoverage
struct, its vector index is computed, from the given expression ID, by subtracting from
u32::MAX
.
Since the expression operands (lhs
and rhs
) can reference either counters or
expressions, an operand that references an expression also uses its original ID, descending
from u32::MAX
. Theses operands are translated only during code generation, after all
counters and expressions have been added.
sourcepub fn add_unreachable_region(&mut self, region: CodeRegion)
pub fn add_unreachable_region(&mut self, region: CodeRegion)
Add a region that will be marked as “unreachable”, with a constant “zero counter”.
sourcepub fn source_hash(&self) -> u64
pub fn source_hash(&self) -> u64
Return the source hash, generated from the HIR node structure, and used to indicate whether or not the source code structure changed between different compilations.
sourcepub fn get_expressions_and_counter_regions(
&self
) -> (Vec<CounterExpression>, impl Iterator<Item = (Counter, &CodeRegion)>)
pub fn get_expressions_and_counter_regions(
&self
) -> (Vec<CounterExpression>, impl Iterator<Item = (Counter, &CodeRegion)>)
Generate an array of CounterExpressions, and an iterator over all Counter
s and their
associated Regions
(from which the LLVM-specific CoverageMapGenerator
will create
CounterMappingRegion
s.
fn counter_regions(&self) -> impl Iterator<Item = (Counter, &CodeRegion)>
fn expressions_with_regions(
&self
) -> (Vec<CounterExpression>, impl Iterator<Item = (Counter, &CodeRegion)>)
fn unreachable_regions(&self) -> impl Iterator<Item = (Counter, &CodeRegion)>
fn expression_index(
&self,
id_descending_from_max: u32
) -> InjectedExpressionIndex
Trait Implementations
Auto Trait Implementations
impl<'tcx> !RefUnwindSafe for FunctionCoverage<'tcx>
impl<'tcx> Send for FunctionCoverage<'tcx>
impl<'tcx> Sync for FunctionCoverage<'tcx>
impl<'tcx> Unpin for FunctionCoverage<'tcx>
impl<'tcx> !UnwindSafe for FunctionCoverage<'tcx>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Layout
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.
Size: 120 bytes