Skip to content

Commit d909b22

Browse files
committed
refactor coverage.rs
1 parent de228ce commit d909b22

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

move-mutator/src/coverage.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fn compute_function_covered_spans(
109109

110110
// Calculate covered locations for this specific function
111111
let covered_ir_locs: Vec<IrLoc> = match &function_def.code {
112-
None => vec![], // Native functions have no covered locations to track
112+
None => vec![],
113113
Some(code_unit) => match module_map.function_maps.get(&fn_name) {
114114
None => vec![], // Function has no coverage data - no covered locations
115115
Some(function_coverage) => {
@@ -120,7 +120,6 @@ fn compute_function_covered_spans(
120120
function_def_idx,
121121
code_offset as CodeOffset,
122122
) {
123-
// If execution count > 0, it's covered
124123
if function_coverage
125124
.get(&(code_offset as u64))
126125
.unwrap_or(&0)
@@ -136,14 +135,13 @@ fn compute_function_covered_spans(
136135
})
137136
.collect();
138137

139-
minimize_ir_locations(covered_locs)
138+
minimize_locations(covered_locs)
140139
},
141140
},
142141
};
143142

144143
// Only include functions that have covered locations
145144
if !covered_ir_locs.is_empty() {
146-
// Convert IrLoc to Span for easier comparison with move_model::Loc.span()
147145
let covered_spans: Vec<Span> = covered_ir_locs
148146
.into_iter()
149147
.map(|ir_loc| Span::new(ir_loc.start(), ir_loc.end()))
@@ -159,8 +157,9 @@ fn compute_function_covered_spans(
159157
function_covered_map
160158
}
161159

162-
/// Helper function to minimize IR locations by merging overlapping/adjacent ones
163-
fn minimize_ir_locations(mut locs: Vec<IrLoc>) -> Vec<IrLoc> {
160+
/// Given a list of locations, merge overlapping and abutting locations.
161+
/// Taken from aptos-core third-party/move/tools/move-coverage/src/source_coverage.rs
162+
fn minimize_locations(mut locs: Vec<IrLoc>) -> Vec<IrLoc> {
164163
locs.sort();
165164
let mut result = vec![];
166165
let mut locs_iter = locs.into_iter();

0 commit comments

Comments
 (0)