coverage: Rename CodeRegion
to SourceRegion
LLVM uses the word "code" to refer to a particular kind of coverage mapping. This unrelated usage of the word is confusing, and makes it harder to introduce types whose names correspond to the LLVM classification of coverage kinds.
This commit is contained in:
parent
5e162a8f48
commit
46e1b5b6dd
5 changed files with 35 additions and 34 deletions
|
@ -13,7 +13,7 @@ use rustc_hir::intravisit::{walk_expr, Visitor};
|
|||
use rustc_middle::hir::map::Map;
|
||||
use rustc_middle::hir::nested_filter;
|
||||
use rustc_middle::mir::coverage::{
|
||||
CodeRegion, CoverageKind, DecisionInfo, FunctionCoverageInfo, Mapping, MappingKind,
|
||||
CoverageKind, DecisionInfo, FunctionCoverageInfo, Mapping, MappingKind, SourceRegion,
|
||||
};
|
||||
use rustc_middle::mir::{
|
||||
self, BasicBlock, BasicBlockData, SourceInfo, Statement, StatementKind, Terminator,
|
||||
|
@ -159,7 +159,7 @@ fn create_mappings<'tcx>(
|
|||
.expect("all BCBs with spans were given counters")
|
||||
.as_term()
|
||||
};
|
||||
let region_for_span = |span: Span| make_code_region(source_map, file_name, span, body_span);
|
||||
let region_for_span = |span: Span| make_source_region(source_map, file_name, span, body_span);
|
||||
|
||||
// Fully destructure the mappings struct to make sure we don't miss any kinds.
|
||||
let ExtractedMappings {
|
||||
|
@ -175,9 +175,9 @@ fn create_mappings<'tcx>(
|
|||
mappings.extend(code_mappings.iter().filter_map(
|
||||
// Ordinary code mappings are the simplest kind.
|
||||
|&mappings::CodeMapping { span, bcb }| {
|
||||
let code_region = region_for_span(span)?;
|
||||
let source_region = region_for_span(span)?;
|
||||
let kind = MappingKind::Code(term_for_bcb(bcb));
|
||||
Some(Mapping { kind, code_region })
|
||||
Some(Mapping { kind, source_region })
|
||||
},
|
||||
));
|
||||
|
||||
|
@ -186,29 +186,29 @@ fn create_mappings<'tcx>(
|
|||
let true_term = term_for_bcb(true_bcb);
|
||||
let false_term = term_for_bcb(false_bcb);
|
||||
let kind = MappingKind::Branch { true_term, false_term };
|
||||
let code_region = region_for_span(span)?;
|
||||
Some(Mapping { kind, code_region })
|
||||
let source_region = region_for_span(span)?;
|
||||
Some(Mapping { kind, source_region })
|
||||
},
|
||||
));
|
||||
|
||||
mappings.extend(mcdc_branches.iter().filter_map(
|
||||
|&mappings::MCDCBranch { span, true_bcb, false_bcb, condition_info, decision_depth: _ }| {
|
||||
let code_region = region_for_span(span)?;
|
||||
let source_region = region_for_span(span)?;
|
||||
let true_term = term_for_bcb(true_bcb);
|
||||
let false_term = term_for_bcb(false_bcb);
|
||||
let kind = match condition_info {
|
||||
Some(mcdc_params) => MappingKind::MCDCBranch { true_term, false_term, mcdc_params },
|
||||
None => MappingKind::Branch { true_term, false_term },
|
||||
};
|
||||
Some(Mapping { kind, code_region })
|
||||
Some(Mapping { kind, source_region })
|
||||
},
|
||||
));
|
||||
|
||||
mappings.extend(mcdc_decisions.iter().filter_map(
|
||||
|&mappings::MCDCDecision { span, bitmap_idx, num_conditions, .. }| {
|
||||
let code_region = region_for_span(span)?;
|
||||
let source_region = region_for_span(span)?;
|
||||
let kind = MappingKind::MCDCDecision(DecisionInfo { bitmap_idx, num_conditions });
|
||||
Some(Mapping { kind, code_region })
|
||||
Some(Mapping { kind, source_region })
|
||||
},
|
||||
));
|
||||
|
||||
|
@ -363,12 +363,12 @@ fn inject_statement(mir_body: &mut mir::Body<'_>, counter_kind: CoverageKind, bb
|
|||
/// or other expansions), and if it does happen then skipping a span or function is
|
||||
/// better than an ICE or `llvm-cov` failure that the user might have no way to avoid.
|
||||
#[instrument(level = "debug", skip(source_map))]
|
||||
fn make_code_region(
|
||||
fn make_source_region(
|
||||
source_map: &SourceMap,
|
||||
file_name: Symbol,
|
||||
span: Span,
|
||||
body_span: Span,
|
||||
) -> Option<CodeRegion> {
|
||||
) -> Option<SourceRegion> {
|
||||
let lo = span.lo();
|
||||
let hi = span.hi();
|
||||
|
||||
|
@ -418,7 +418,7 @@ fn make_code_region(
|
|||
start_line = source_map.doctest_offset_line(&file.name, start_line);
|
||||
end_line = source_map.doctest_offset_line(&file.name, end_line);
|
||||
|
||||
check_code_region(CodeRegion {
|
||||
check_source_region(SourceRegion {
|
||||
file_name,
|
||||
start_line: start_line as u32,
|
||||
start_col: start_col as u32,
|
||||
|
@ -427,12 +427,12 @@ fn make_code_region(
|
|||
})
|
||||
}
|
||||
|
||||
/// If `llvm-cov` sees a code region that is improperly ordered (end < start),
|
||||
/// If `llvm-cov` sees a source region that is improperly ordered (end < start),
|
||||
/// it will immediately exit with a fatal error. To prevent that from happening,
|
||||
/// discard regions that are improperly ordered, or might be interpreted in a
|
||||
/// way that makes them improperly ordered.
|
||||
fn check_code_region(code_region: CodeRegion) -> Option<CodeRegion> {
|
||||
let CodeRegion { file_name: _, start_line, start_col, end_line, end_col } = code_region;
|
||||
fn check_source_region(source_region: SourceRegion) -> Option<SourceRegion> {
|
||||
let SourceRegion { file_name: _, start_line, start_col, end_line, end_col } = source_region;
|
||||
|
||||
// Line/column coordinates are supposed to be 1-based. If we ever emit
|
||||
// coordinates of 0, `llvm-cov` might misinterpret them.
|
||||
|
@ -445,17 +445,17 @@ fn check_code_region(code_region: CodeRegion) -> Option<CodeRegion> {
|
|||
let is_ordered = (start_line, start_col) <= (end_line, end_col);
|
||||
|
||||
if all_nonzero && end_col_has_high_bit_unset && is_ordered {
|
||||
Some(code_region)
|
||||
Some(source_region)
|
||||
} else {
|
||||
debug!(
|
||||
?code_region,
|
||||
?source_region,
|
||||
?all_nonzero,
|
||||
?end_col_has_high_bit_unset,
|
||||
?is_ordered,
|
||||
"Skipping code region that would be misinterpreted or rejected by LLVM"
|
||||
"Skipping source region that would be misinterpreted or rejected by LLVM"
|
||||
);
|
||||
// If this happens in a debug build, ICE to make it easier to notice.
|
||||
debug_assert!(false, "Improper code region: {code_region:?}");
|
||||
debug_assert!(false, "Improper source region: {source_region:?}");
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue