Skip to content

Commit

Permalink
chore: use merge_spans from aptos-core
Browse files Browse the repository at this point in the history
We recently merged a PR in aptos-core to improve their `merge_span`
function, and now we can use their implememntation:
aptos-labs/aptos-core#15120
  • Loading branch information
Rqnsom committed Nov 15, 2024
1 parent 9df44d9 commit 6189dbb
Showing 1 changed file with 1 addition and 25 deletions.
26 changes: 1 addition & 25 deletions move-mutator/src/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use move_command_line_common::files::FileHash;
use move_compiler::compiled_unit::{CompiledUnit, NamedCompiledModule};
use move_coverage::{
coverage_map::CoverageMap,
source_coverage::{FunctionSourceCoverage, SourceCoverageBuilder},
source_coverage::{merge_spans, FunctionSourceCoverage, SourceCoverageBuilder},
};
use move_model::model::Loc;
use move_package::BuildConfig;
Expand Down Expand Up @@ -158,30 +158,6 @@ impl UncoveredSpans {
}
}

// There is a similar function in aptos-core with the same name, but that one doesn't merge
// spans that are next to each other (e.g. spans (0..5] and (5..10]) - but that is not
// noticeable in their usage for the coverage, so nobody noticed this. We can make an update
// there maybe and then use a more efficient `merge_spans` function from aptos-core repo.
/// Efficiently merge spans.
fn merge_spans(file_hash: FileHash, cov: FunctionSourceCoverage) -> Vec<Span> {
let mut spans = cov
.uncovered_locations
.iter()
.filter(|loc| loc.file_hash() == file_hash)
.map(|loc| Span::new(loc.start(), loc.end()))
.collect::<Vec<_>>();
spans.sort();
spans.windows(2).fold(vec![], |mut acc, spans| {
let [curr, next] = spans else { return acc };
if curr.end() >= next.start() {
acc.push(curr.merge(*next));
} else {
acc.push(*curr);
}
acc
})
}

/// Remove all whitespaces between spans and merge spans again.
fn merge_spans_after_removing_whitespaces(mut spans: Vec<Span>, source_code: &str) -> Vec<Span> {
if spans.is_empty() {
Expand Down

0 comments on commit 6189dbb

Please sign in to comment.