Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b95232d

Browse files
authoredNov 10, 2024
Rollup merge of #132675 - Zalathar:empty-spans, r=jieyouxu
coverage: Restrict empty-span expansion to only cover `{` and `}` Coverage instrumentation has some tricky code for converting a coverage-relevant `Span` into a set of start/end line/byte-column coordinates that will be embedded in the CGU's coverage metadata. A big part of this complexity is special code for handling empty spans, which are expanded into non-empty spans (if possible) because LLVM's coverage reporter does not handle empty spans well. This PR simplifies that code by restricting it to only apply in two specific situations: when the character after the empty span is `{`, or the character before the empty span is `}`. (As an added benefit, this means that the expanded spans no longer extend awkwardly beyond the end of a physical line, which was common under the previous implementation.) Along the way, this PR also removes some unhelpful code for dealing with function source code spread across multiple files. Functions currently can't have coverage spans in multiple files, and if that ever changes (e.g. to properly support expansion regions) then this code will need to be completely overhauled anyway.
2 parents c22887b + 925dfc8 commit b95232d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+320
-305
lines changed
 

‎compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use rustc_middle::mir::coverage::{CounterId, CovTerm, ExpressionId, SourceRegion};
22

3+
use crate::coverageinfo::mapgen::LocalFileId;
4+
35
/// Must match the layout of `LLVMRustCounterKind`.
46
#[derive(Copy, Clone, Debug)]
57
#[repr(C)]
@@ -137,8 +139,12 @@ pub(crate) struct CoverageSpan {
137139
}
138140

139141
impl CoverageSpan {
140-
pub(crate) fn from_source_region(file_id: u32, code_region: &SourceRegion) -> Self {
141-
let &SourceRegion { file_name: _, start_line, start_col, end_line, end_col } = code_region;
142+
pub(crate) fn from_source_region(
143+
local_file_id: LocalFileId,
144+
code_region: &SourceRegion,
145+
) -> Self {
146+
let file_id = local_file_id.as_u32();
147+
let &SourceRegion { start_line, start_col, end_line, end_col } = code_region;
142148
// Internally, LLVM uses the high bit of `end_col` to distinguish between
143149
// code regions and gap regions, so it can't be used by the column number.
144150
assert!(end_col & (1u32 << 31) == 0, "high bit of `end_col` must be unset: {end_col:#X}");

‎compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc_middle::mir::coverage::{
66
SourceRegion,
77
};
88
use rustc_middle::ty::Instance;
9-
use rustc_span::Symbol;
109
use tracing::{debug, instrument};
1110

1211
use crate::coverageinfo::ffi::{Counter, CounterExpression, ExprKind};
@@ -180,7 +179,7 @@ impl<'tcx> FunctionCoverageCollector<'tcx> {
180179
}
181180

182181
pub(crate) struct FunctionCoverage<'tcx> {
183-
function_coverage_info: &'tcx FunctionCoverageInfo,
182+
pub(crate) function_coverage_info: &'tcx FunctionCoverageInfo,
184183
is_used: bool,
185184

186185
counters_seen: BitSet<CounterId>,
@@ -199,11 +198,6 @@ impl<'tcx> FunctionCoverage<'tcx> {
199198
if self.is_used { self.function_coverage_info.function_source_hash } else { 0 }
200199
}
201200

202-
/// Returns an iterator over all filenames used by this function's mappings.
203-
pub(crate) fn all_file_names(&self) -> impl Iterator<Item = Symbol> + Captures<'_> {
204-
self.function_coverage_info.mappings.iter().map(|mapping| mapping.source_region.file_name)
205-
}
206-
207201
/// Convert this function's coverage expression data into a form that can be
208202
/// passed through FFI to LLVM.
209203
pub(crate) fn counter_expressions(

0 commit comments

Comments
 (0)
Please sign in to comment.