pub struct FunctionCoverage<'tcx> {
    instance: Instance<'tcx>,
    source_hash: u64,
    is_used: bool,
    counters: IndexVec<CounterId, Option<Vec<CodeRegion>>>,
    expressions: IndexVec<ExpressionId, 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. 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<CounterId, Option<Vec<CodeRegion>>>§expressions: IndexVec<ExpressionId, Option<Expression>>§unreachable_regions: Vec<CodeRegion>

Implementations§

source§

impl<'tcx> FunctionCoverage<'tcx>

source

pub fn new(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> Self

Creates a new set of coverage data for a used (called) function.

source

pub fn unused(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> Self

Creates a new set of coverage data for an unused (never called) function.

source

fn create(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>, is_used: bool) -> Self

source

pub fn is_used(&self) -> bool

Returns true for a used (called) function, and false for an unused function.

source

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.

source

pub(crate) fn add_counter(&mut self, id: CounterId, code_regions: &[CodeRegion])

Adds code regions to be counted by an injected counter intrinsic.

source

pub(crate) fn add_counter_expression( &mut self, expression_id: ExpressionId, lhs: Operand, op: Op, rhs: Operand, code_regions: &[CodeRegion] )

Adds information about a coverage expression, along with zero or more code regions mapped to that expression.

Both counters and “counter expressions” (or simply, “expressions”) can be operands in other expressions. These are tracked as separate variants of Operand, so there is no ambiguity between operands that are counter IDs and operands that are expression IDs.

source

pub(crate) fn add_unreachable_regions(&mut self, code_regions: &[CodeRegion])

Adds regions that will be marked as “unreachable”, with a constant “zero counter”.

source

pub(crate) fn simplify_expressions(&mut self)

Perform some simplifications to make the final coverage mappings slightly smaller.

This method mainly exists to preserve the simplifications that were already being performed by the Rust-side expression renumbering, so that the resulting coverage mappings don’t get worse.

source

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.

source

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 Counters and their associated Regions (from which the LLVM-specific CoverageMapGenerator will create CounterMappingRegions.

source

fn counter_regions(&self) -> impl Iterator<Item = (Counter, &CodeRegion)>

source

fn counter_expressions(&self) -> Vec<CounterExpression>

Convert this function’s coverage expression data into a form that can be passed through FFI to LLVM.

source

fn expression_regions(&self) -> Vec<(Counter, &CodeRegion)>

source

fn unreachable_regions(&self) -> impl Iterator<Item = (Counter, &CodeRegion)>

Trait Implementations§

source§

impl<'tcx> Debug for FunctionCoverage<'tcx>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

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