Skip to content

Commit

Permalink
coverage: Prepare to split spans.rs into two files
Browse files Browse the repository at this point in the history
  • Loading branch information
Zalathar committed Apr 30, 2024
1 parent 7823bf0 commit 18e9b81
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_mir_transform/src/coverage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pub mod query;
mod counters;
mod graph;
mod spans;

#[cfg(test)]
mod tests;

Expand Down
50 changes: 26 additions & 24 deletions compiler/rustc_mir_transform/src/coverage/spans.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::collections::BTreeSet;

use rustc_data_structures::graph::DirectedGraph;
use rustc_index::bit_set::BitSet;
use rustc_middle::mir;
use rustc_middle::mir::coverage::ConditionInfo;
use rustc_span::{BytePos, Span};
use std::collections::BTreeSet;

use crate::coverage::graph::{BasicCoverageBlock, CoverageGraph, START_BCB};
use crate::coverage::spans::from_mir::SpanFromMir;
use crate::coverage::spans::from_mir::{extract_branch_pairs, extract_mcdc_mappings, SpanFromMir};
use crate::coverage::ExtractedHirInfo;

mod from_mir;
Expand Down Expand Up @@ -91,28 +92,11 @@ pub(super) fn generate_coverage_spans(
mappings.push(BcbMapping { kind: BcbMappingKind::Code(START_BCB), span });
}
} else {
let sorted_spans = from_mir::mir_to_initial_sorted_coverage_spans(
mir_body,
hir_info,
basic_coverage_blocks,
);
let coverage_spans = SpansRefiner::refine_sorted_spans(sorted_spans);
mappings.extend(coverage_spans.into_iter().map(|RefinedCovspan { bcb, span, .. }| {
// Each span produced by the generator represents an ordinary code region.
BcbMapping { kind: BcbMappingKind::Code(bcb), span }
}));

branch_pairs.extend(from_mir::extract_branch_pairs(
mir_body,
hir_info,
basic_coverage_blocks,
));

mappings.extend(from_mir::extract_mcdc_mappings(
mir_body,
hir_info.body_span,
basic_coverage_blocks,
));
extract_refined_covspans(mir_body, hir_info, basic_coverage_blocks, &mut mappings);

branch_pairs.extend(extract_branch_pairs(mir_body, hir_info, basic_coverage_blocks));

mappings.extend(extract_mcdc_mappings(mir_body, hir_info.body_span, basic_coverage_blocks));
}

if mappings.is_empty() && branch_pairs.is_empty() {
Expand Down Expand Up @@ -149,6 +133,24 @@ pub(super) fn generate_coverage_spans(
Some(CoverageSpans { bcb_has_mappings, mappings, branch_pairs, test_vector_bitmap_bytes })
}

#[allow(unused_imports)] // Remove this line during the actual split.
pub(super) use from_mir::unexpand_into_body_span_with_visible_macro;

pub(super) fn extract_refined_covspans(
mir_body: &mir::Body<'_>,
hir_info: &ExtractedHirInfo,
basic_coverage_blocks: &CoverageGraph,
mappings: &mut impl Extend<BcbMapping>,
) {
let sorted_spans =
from_mir::mir_to_initial_sorted_coverage_spans(mir_body, hir_info, basic_coverage_blocks);
let coverage_spans = SpansRefiner::refine_sorted_spans(sorted_spans);
mappings.extend(coverage_spans.into_iter().map(|RefinedCovspan { bcb, span, .. }| {
// Each span produced by the generator represents an ordinary code region.
BcbMapping { kind: BcbMappingKind::Code(bcb), span }
}));
}

#[derive(Debug)]
struct CurrCovspan {
span: Span,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ fn filtered_terminator_span(terminator: &Terminator<'_>) -> Option<Span> {
///
/// [^1]Expansions result from Rust syntax including macros, syntactic sugar,
/// etc.).
fn unexpand_into_body_span_with_visible_macro(
pub(crate) fn unexpand_into_body_span_with_visible_macro(
original_span: Span,
body_span: Span,
) -> Option<(Span, Option<Symbol>)> {
Expand Down

0 comments on commit 18e9b81

Please sign in to comment.