diff --git a/Cargo.lock b/Cargo.lock index 0ff7a6d..74a24bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -150,9 +150,9 @@ checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" [[package]] name = "bitflags" -version = "2.8.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" +checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" [[package]] name = "bitvec" @@ -199,9 +199,9 @@ checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" [[package]] name = "cairo-annotations" -version = "0.2.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e6d7624764c83e33a4eb0d581cc126232d42c878a187ffa6372bea038dc9ee6" +checksum = "b6e8925548bb02e41cb71b0aa523744694d63a834cbd9d8a84e4a3646ae678f7" dependencies = [ "cairo-lang-sierra", "cairo-lang-sierra-to-casm", @@ -465,9 +465,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.30" +version = "4.5.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92b7b18d71fad5313a1e320fa9897994228ce274b60faa4d694fe0ea89cd9e6d" +checksum = "027bb0d98429ae334a8698531da7077bdf906419543a35a55c2cb1b66437d767" dependencies = [ "clap_builder", "clap_derive", @@ -475,9 +475,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.30" +version = "4.5.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a35db2071778a7344791a4fb4f95308b5673d219dee3ae348b86642574ecc90c" +checksum = "5589e0cba072e0f3d23791efac0fd8627b49c829c196a492e88168e6a669d863" dependencies = [ "anstream", "anstyle", @@ -511,9 +511,9 @@ checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" [[package]] name = "console" -version = "0.15.10" +version = "0.15.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea3c6ecd8059b57859df5c69830340ed3c41d30e3da0c1cbed90a96ac853041b" +checksum = "054ccb5b10f9f2cbf51eb355ca1d05c2d279ce1804688d0db74b4733a5aeafd8" dependencies = [ "encode_unicode", "libc", @@ -726,9 +726,9 @@ checksum = "feeef44e73baff3a26d371801df019877a9866a8c493d315ab00177843314f35" [[package]] name = "either" -version = "1.13.0" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" +checksum = "b7914353092ddf589ad78f25c5c1c21b7f80b0ff8621e7c814c3485b5306da9d" [[package]] name = "ena" @@ -826,9 +826,9 @@ dependencies = [ [[package]] name = "globset" -version = "0.4.15" +version = "0.4.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15f1ce686646e7f1e19bf7d5533fe443a45dbfb990e00629110797578b42fb19" +checksum = "54a1028dfc5f5df5da8a56a73e6c153c9a9708ec57232470703592a3f18e49f5" dependencies = [ "aho-corasick", "bstr", @@ -1103,9 +1103,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.169" +version = "0.2.170" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" +checksum = "875b3680cb2f8f71bdcf9a30f38d48282f5d3c95cbf9b3fa57269bb5d5c06828" [[package]] name = "libredox" @@ -1157,9 +1157,9 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "microlp" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edaa5264bc1f7668bc12e10757f8f529a526656c796cc2106cf2be10c5b8d483" +checksum = "51d1790c73b93164ff65868f63164497cb32339458a9297e17e212d91df62258" dependencies = [ "log", "sprs", @@ -1354,9 +1354,9 @@ dependencies = [ [[package]] name = "portable-atomic" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "280dc24453071f1b63954171985a0b0d30058d287960968b9b2aca264c8d4ee6" +checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e" [[package]] name = "portable-atomic-util" @@ -1579,22 +1579,22 @@ dependencies = [ [[package]] name = "scarb-metadata" -version = "1.13.0" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a8b71f63999dbb6d269fbc6fd61310016ab3a160fb13e52a6511a2b904359f0" +checksum = "f580d215bb85d42e9a1489aa869cae7878aff343384b73e235753334e8fb72b4" dependencies = [ "camino", "semver", "serde", "serde_json", - "thiserror 1.0.69", + "thiserror 2.0.11", ] [[package]] name = "schemars" -version = "0.8.21" +version = "0.8.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92" +checksum = "3fbf2ae1b8bc8e02df939598064d22402220cd5bbcca1c76f7d6a310974d5615" dependencies = [ "dyn-clone", "indexmap 1.9.3", @@ -1605,9 +1605,9 @@ dependencies = [ [[package]] name = "schemars_derive" -version = "0.8.21" +version = "0.8.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e" +checksum = "32e265784ad618884abaea0600a9adf15393368d840e0222d101a072f3f7534d" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 13e1fed..7c1d914 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,19 +14,19 @@ edition = "2024" cairo-lang-sierra = "2.10.1" cairo-lang-sierra-to-casm = "2.10.1" cairo-lang-starknet-classes = "2.10.1" -cairo-annotations = "0.2.2" +cairo-annotations = "0.3.0" anyhow = "1.0.96" assert_fs = "1.1.2" camino = "1.1.9" -clap = { version = "4.5.30", features = ["derive"] } +clap = { version = "4.5.31", features = ["derive"] } criterion = "0.5" -console = "0.15.10" +console = "0.15.11" itertools = "0.14.0" ignore = "0.4.23" serde = "1.0.218" serde_json = "1.0.139" -scarb-metadata = "1.13.0" +scarb-metadata = "1.14.0" snapbox = "0.6.21" semver = "1.0.25" indoc = "2.0.5" diff --git a/crates/cairo-coverage-core/src/build/filter/ignore_matcher.rs b/crates/cairo-coverage-core/src/build/filter/ignore_matcher.rs index deca11e..e3b8d9b 100644 --- a/crates/cairo-coverage-core/src/build/filter/ignore_matcher.rs +++ b/crates/cairo-coverage-core/src/build/filter/ignore_matcher.rs @@ -1,4 +1,3 @@ -use crate::build::filter::statement_category_filter::VIRTUAL_FILE_REGEX; use anyhow::{Error, Result}; use camino::{Utf8Path, Utf8PathBuf}; use ignore::Match; @@ -34,7 +33,7 @@ pub struct CairoCoverageIgnoreMatcher(Gitignore); impl CairoCoverageIgnoreMatcher { /// Check if the given path is ignored by the [`CAIRO_COVERAGE_IGNORE`] file. pub fn is_ignored(&self, path: &str) -> bool { - let path: Utf8PathBuf = VIRTUAL_FILE_REGEX.replace_all(path, "").to_string().into(); + let path: Utf8PathBuf = path.to_string().into(); let result = self.0.matched(&path, path.is_dir()); matches!(result, Match::Ignore(_)) } diff --git a/crates/cairo-coverage-core/src/build/filter/statement_category_filter.rs b/crates/cairo-coverage-core/src/build/filter/statement_category_filter.rs index a6c5e00..967e703 100644 --- a/crates/cairo-coverage-core/src/build/filter/statement_category_filter.rs +++ b/crates/cairo-coverage-core/src/build/filter/statement_category_filter.rs @@ -3,17 +3,10 @@ use crate::build::filter::ignore_matcher::CairoCoverageIgnoreMatcher; use crate::build::filter::libfuncs; use crate::build::filter::libfuncs::NOT_RELIABLE_LIBFUNCS; use crate::loading::enriched_program::EnrichedProgram; -use cairo_annotations::annotations::coverage::SourceFileFullPath; use cairo_annotations::annotations::profiler::FunctionName; use cairo_lang_sierra::program::StatementIdx; use camino::Utf8PathBuf; -use regex::Regex; use std::collections::{HashMap, HashSet}; -use std::sync::LazyLock; - -/// Regex to match virtual files like `/path/to/project/lib.cairo[array_inline_macro][assert_macro]` -/// where `array_inline_macro` and `assert_macro` is a virtual file. -pub static VIRTUAL_FILE_REGEX: LazyLock = LazyLock::new(|| Regex::new(r"\[.*?]").unwrap()); /// Statement category filter that is used to filter out statements that should not be included in the coverage report. /// `included_components` and `ignore_matcher` are references to reduce the amount of data that needs to be copied. @@ -57,23 +50,20 @@ impl StatementCategoryFilter<'_> { &self, idx: StatementIdx, function_name: &FunctionName, - source_file_full_path: &SourceFileFullPath, + source_file_full_path: &str, + is_macro: bool, ) -> bool { - self.is_allowed_macro(function_name, source_file_full_path) + self.is_allowed_macro(function_name, is_macro) && self.is_user_function(source_file_full_path) && self.is_reliable_libfunc(idx) && self.is_not_ignored(source_file_full_path) } - fn is_allowed_macro( - &self, - function_name: &FunctionName, - source_file_full_path: &SourceFileFullPath, - ) -> bool { + fn is_allowed_macro(&self, function_name: &FunctionName, is_macro: bool) -> bool { if self.test_functions.contains(function_name) { self.included_components .contains(&IncludedComponent::TestFunctions) - } else if VIRTUAL_FILE_REGEX.is_match(&source_file_full_path.0) { + } else if is_macro { self.included_components .contains(&IncludedComponent::Macros) } else { @@ -81,8 +71,8 @@ impl StatementCategoryFilter<'_> { } } - fn is_user_function(&self, source_file_full_path: &SourceFileFullPath) -> bool { - source_file_full_path.0.contains(&self.user_project_path) + fn is_user_function(&self, source_file_full_path: &str) -> bool { + source_file_full_path.contains(&self.user_project_path) } fn is_reliable_libfunc(&self, idx: StatementIdx) -> bool { @@ -92,7 +82,7 @@ impl StatementCategoryFilter<'_> { .is_some_and(|libfunc_name| NOT_RELIABLE_LIBFUNCS.contains(libfunc_name)) } - fn is_not_ignored(&self, source_file_full_path: &SourceFileFullPath) -> bool { - !self.ignore_matcher.is_ignored(&source_file_full_path.0) + fn is_not_ignored(&self, source_file_full_path: &str) -> bool { + !self.ignore_matcher.is_ignored(source_file_full_path) } } diff --git a/crates/cairo-coverage-core/src/build/statement_information.rs b/crates/cairo-coverage-core/src/build/statement_information.rs index 7ea4dd3..81c87fb 100644 --- a/crates/cairo-coverage-core/src/build/statement_information.rs +++ b/crates/cairo-coverage-core/src/build/statement_information.rs @@ -1,6 +1,4 @@ -use crate::build::filter::statement_category_filter::{ - StatementCategoryFilter, VIRTUAL_FILE_REGEX, -}; +use crate::build::filter::statement_category_filter::StatementCategoryFilter; use cairo_annotations::annotations::coverage::{ CodeLocation, CoverageAnnotationsV1, LineNumber, SourceCodeSpan, SourceFileFullPath, VersionedCoverageAnnotations, @@ -26,16 +24,6 @@ pub struct StatementInformation { pub line_range: LineRange, } -impl StatementInformation { - pub fn remove_virtual_file_prefix(&mut self) { - self.source_file_full_path = SourceFileFullPath( - VIRTUAL_FILE_REGEX - .replace_all(&self.source_file_full_path.0, "") - .to_string(), - ); - } -} - #[derive(Deserialize, Clone, Eq, PartialEq)] pub struct LineRange { /// Line number is 1-based @@ -93,24 +81,18 @@ fn get_statement_information( function_names: Vec, filter: &StatementCategoryFilter, ) -> Option { - code_locations - .into_iter() - .zip(function_names) - .find(|(CodeLocation(source_file_full_path, _), function_name)| { - filter.should_include(idx, function_name, source_file_full_path) - }) - .map( - |(CodeLocation(source_file_full_path, line_range), function_name)| { - StatementInformation { + code_locations.into_iter().zip(function_names).find_map( + |(CodeLocation(source_file_full_path, line_range, is_macro), function_name)| { + let (path, marking) = source_file_full_path.remove_virtual_file_markings(); + let is_macro = is_macro.unwrap_or(!marking.is_empty()); + filter + .should_include(idx, &function_name, path, is_macro) + .then(|| StatementInformation { function_name, - source_file_full_path, + source_file_full_path: SourceFileFullPath(path.to_string()), line_range: line_range.into(), idx, - } - }, - ) - .map(|mut statement_origin| { - statement_origin.remove_virtual_file_prefix(); - statement_origin - }) + }) + }, + ) }