Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[move] Update source coverage gathering so we don't include any duplicate source spans #20183

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions external-crates/move/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions external-crates/move/crates/move-coverage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ move-ir-types.workspace = true
move-binary-format.workspace = true
move-bytecode-source-map.workspace = true
move-abstract-interpreter.workspace = true
indexmap.workspace = true

[features]
default = []
19 changes: 11 additions & 8 deletions external-crates/move/crates/move-coverage/src/source_coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use crate::coverage_map::CoverageMap;
use codespan::{Files, Span};
use colored::*;
use indexmap::IndexSet;
use move_binary_format::{
file_format::{CodeOffset, FunctionDefinitionIndex},
CompiledModule,
Expand Down Expand Up @@ -34,7 +35,7 @@ pub struct SourceCoverageBuilder<'a> {
source_map: &'a SourceMap,
}

#[derive(Debug, Serialize, Eq, PartialEq, Ord, PartialOrd)]
#[derive(Debug, Serialize, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum AbstractSegment {
Bounded { start: u32, end: u32 },
BoundedRight { end: u32 },
Expand Down Expand Up @@ -150,7 +151,7 @@ impl<'a> SourceCoverageBuilder<'a> {
let end_line = end_loc.line.0;
let segments = uncovered_segments
.entry(start_line)
.or_insert_with(Vec::new);
.or_insert_with(IndexSet::new);
if start_line == end_line {
let segment = AbstractSegment::Bounded {
start: start_loc.column.0,
Expand All @@ -159,18 +160,20 @@ impl<'a> SourceCoverageBuilder<'a> {
// TODO: There is some issue with the source map where we have multiple spans
// from different functions. This can be seen in the source map for `Roles.move`
if !segments.contains(&segment) {
segments.push(segment);
segments.insert(segment);
}
} else {
segments.push(AbstractSegment::BoundedLeft {
segments.insert(AbstractSegment::BoundedLeft {
start: start_loc.column.0,
});
for i in start_line + 1..end_line {
let segment = uncovered_segments.entry(i).or_insert_with(Vec::new);
segment.push(AbstractSegment::BoundedLeft { start: 0 });
let segment = uncovered_segments.entry(i).or_insert_with(IndexSet::new);
segment.insert(AbstractSegment::BoundedLeft { start: 0 });
}
let last_segment = uncovered_segments.entry(end_line).or_insert_with(Vec::new);
last_segment.push(AbstractSegment::BoundedRight {
let last_segment = uncovered_segments
.entry(end_line)
.or_insert_with(IndexSet::new);
last_segment.insert(AbstractSegment::BoundedRight {
end: end_loc.column.0,
});
}
Expand Down
Loading