From fc5e41ff59a8153363aaaeca91d9a275e4afc7cb Mon Sep 17 00:00:00 2001 From: Karol Sewilo Date: Mon, 7 Oct 2024 13:23:23 +0200 Subject: [PATCH 1/2] Delete trace data commit-id:2eecc7d9 --- Cargo.lock | 197 ++++++++++-------- Cargo.toml | 2 +- crates/cairo-coverage/Cargo.toml | 2 +- .../src/data_loader/loaded_data.rs | 8 +- .../src/input/unique_executed_sierra_ids.rs | 2 +- 5 files changed, 123 insertions(+), 88 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 03a122b..7212f28 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -122,9 +122,9 @@ checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "bit-set" @@ -184,12 +184,28 @@ version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" +[[package]] +name = "cairo-annotations" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b27bd803ae8b063e8fba0ee9a94af33b4881582d9a337e271d6be882313aa5cd" +dependencies = [ + "cairo-lang-sierra", + "cairo-lang-sierra-to-casm", + "camino", + "derive_more", + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "cairo-coverage" version = "0.2.0" dependencies = [ "anyhow", "assert_fs", + "cairo-annotations", "cairo-lang-sierra", "cairo-lang-sierra-to-casm", "cairo-lang-starknet-classes", @@ -202,14 +218,13 @@ dependencies = [ "serde", "serde_json", "snapbox", - "trace-data", ] [[package]] name = "cairo-lang-casm" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60a4b4ca8473c25d1e760c83c2a49d953197556f82f6feb636004d3b6d6cc4a7" +checksum = "fd4d6659539ace9649c8e8a7434e51b0c50a7a700111d0a2b967dde220ddff49" dependencies = [ "cairo-lang-utils", "indoc", @@ -221,9 +236,9 @@ dependencies = [ [[package]] name = "cairo-lang-eq-solver" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0cd844e568f51e39729e8ac18bd27ada2e2b6dc9138f8c81adad48456480681" +checksum = "33a416c5871960fb4823160ebef2abc51e0c1b86fef1e97a1ebb2e5f3c3795d3" dependencies = [ "cairo-lang-utils", "good_lp", @@ -231,9 +246,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "891488c1a3184ce91679f5bdb63015a1d24769a48bd07e5d51a1779d0031dfbe" +checksum = "424f55450494e959c1ae26c52a71075767a90f76e3ecca6e81056dd7517e8ba0" dependencies = [ "anyhow", "cairo-lang-utils", @@ -258,9 +273,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-ap-change" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea7752cd48c86b2cde8603b753a6df4da086dacd16a73d288854d5f040b51171" +checksum = "053dd520e0b9d1c1078d93ea69045f6f334c3d41b4b75db183ab33e32cfd8570" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -274,9 +289,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-gas" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "340892a09c9421414b2ac45b03c705f16e2bd737e4559dfd98ee1d20718dec9e" +checksum = "9a73227867377efc62ebb893cddaa88df3940bf2be5dbdc2f0b00f9edf69288e" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -290,9 +305,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-to-casm" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c22ff7e8113a46a907f82f191096c96935cc48247e3079971ddf536ccc2f4f8" +checksum = "7162fb3c93960dfc6d8005b65064e518e3f1ed6102e8981b42ea41879c331184" dependencies = [ "assert_matches", "cairo-lang-casm", @@ -311,9 +326,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-type-size" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bf41941776e7410a8853a8e2a116292fc24d219df1989a92ffe5ab0e98037eb" +checksum = "a51b80c117e2b05a6d300f2e2247892cc99e42e950e79f6085e6ed6cbcb44d12" dependencies = [ "cairo-lang-sierra", "cairo-lang-utils", @@ -321,9 +336,9 @@ dependencies = [ [[package]] name = "cairo-lang-starknet-classes" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "482b8f9d7f8cc7140f1260ee71f3308a66d15bd228a06281067ca3f8f4410db2" +checksum = "832fd9072ddf4204ca6d227c0238929349f10146bd066a98025d51ac15d27fad" dependencies = [ "cairo-lang-casm", "cairo-lang-sierra", @@ -344,12 +359,12 @@ dependencies = [ [[package]] name = "cairo-lang-utils" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73104609a7d865e4cd1de9cbf4e750683d076b6d0233bf81be511df274a26916" +checksum = "8bfc6372538143afad658c853a35bdc9f5210c5cb54e0c8f04ab78e268139466" dependencies = [ "hashbrown 0.14.5", - "indexmap 2.5.0", + "indexmap 2.6.0", "itertools 0.12.1", "num-bigint", "num-traits 0.2.19", @@ -374,9 +389,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.5.18" +version = "4.5.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0956a43b323ac1afaffc053ed5c4b7c1f1800bacd1683c353aabbb752515dd3" +checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" dependencies = [ "clap_builder", "clap_derive", @@ -384,9 +399,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.18" +version = "4.5.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d72166dd41634086d5803a47eb71ae740e61d84709c36f3c34110173db3961b" +checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" dependencies = [ "anstream", "anstyle", @@ -403,7 +418,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -494,6 +509,27 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "derive_more" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", + "unicode-xid", +] + [[package]] name = "derived-deref" version = "2.1.0" @@ -502,7 +538,7 @@ checksum = "805ef2023ccd65425743a91ecd11fc020979a0b01921db3104fb606d18a7b43e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -681,6 +717,12 @@ dependencies = [ "serde", ] +[[package]] +name = "hashbrown" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" + [[package]] name = "heck" version = "0.4.1" @@ -733,12 +775,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown 0.14.5", + "hashbrown 0.15.0", "serde", ] @@ -829,9 +871,9 @@ dependencies = [ [[package]] name = "lambdaworks-crypto" -version = "0.7.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fb5d4f22241504f7c7b8d2c3a7d7835d7c07117f10bff2a7d96a9ef6ef217c3" +checksum = "bbc2a4da0d9e52ccfe6306801a112e81a8fc0c76aa3e4449fefeda7fef72bb34" dependencies = [ "lambdaworks-math", "serde", @@ -841,9 +883,9 @@ dependencies = [ [[package]] name = "lambdaworks-math" -version = "0.7.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "358e172628e713b80a530a59654154bfc45783a6ed70ea284839800cebdf8f97" +checksum = "d1bd2632acbd9957afc5aeec07ad39f078ae38656654043bf16e046fa2730e23" dependencies = [ "serde", "serde_json", @@ -857,9 +899,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.158" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libredox" @@ -993,9 +1035,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.20.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ea5043e58958ee56f3e15a90aee535795cd7dfd319846288d93c5b57d85cbe" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "oorandom" @@ -1059,7 +1101,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", - "indexmap 2.5.0", + "indexmap 2.6.0", ] [[package]] @@ -1127,9 +1169,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" dependencies = [ "unicode-ident", ] @@ -1157,9 +1199,9 @@ checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" [[package]] name = "redox_syscall" -version = "0.5.4" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ "bitflags", ] @@ -1210,7 +1252,7 @@ version = "0.17.0-pre.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719825638c59fd26a55412a24561c7c5bcf54364c88b9a7a04ba08a6eafaba8d" dependencies = [ - "indexmap 2.5.0", + "indexmap 2.6.0", "lock_api", "oorandom", "parking_lot", @@ -1230,7 +1272,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1295,7 +1337,7 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1321,7 +1363,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1332,7 +1374,7 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1397,9 +1439,9 @@ dependencies = [ [[package]] name = "snapbox" -version = "0.6.17" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "840b73eb3148bc3cbc10ebe00ec9bc6d96033e658d022c4adcbf3f35596fd64a" +checksum = "7ba434818a8a9b1b106404288d6bd75a94348aae8fc9a518b211b609a36a54bc" dependencies = [ "anstream", "anstyle", @@ -1436,9 +1478,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "starknet-types-core" -version = "0.1.5" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce6bacf0ba19bc721e518bc4bf389ff13daa8a7c5db5fd320600473b8aa9fcbd" +checksum = "fa1b9e01ccb217ab6d475c5cda05dbb22c30029f7bb52b192a010a00d77a3d74" dependencies = [ "lambdaworks-crypto", "lambdaworks-math", @@ -1481,9 +1523,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.77" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", @@ -1498,9 +1540,9 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tempfile" -version = "3.12.0" +version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" dependencies = [ "cfg-if", "fastrand", @@ -1528,22 +1570,22 @@ checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" [[package]] name = "thiserror" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1563,24 +1605,15 @@ checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" [[package]] name = "toml_edit" -version = "0.22.20" +version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ - "indexmap 2.5.0", + "indexmap 2.6.0", "toml_datetime", "winnow", ] -[[package]] -name = "trace-data" -version = "0.5.0" -source = "git+https://github.com/software-mansion/cairo-profiler/?tag=v0.6.0#f55e35953f36ef7b09cb4b96394978a8fe7f5dff" -dependencies = [ - "camino", - "serde", -] - [[package]] name = "tracing" version = "0.1.40" @@ -1600,7 +1633,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1614,9 +1647,9 @@ dependencies = [ [[package]] name = "triomphe" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6631e42e10b40c0690bf92f404ebcfe6e1fdb480391d15f17cc8e96eeed5369" +checksum = "ef8f7726da4807b58ea5c96fdc122f80702030edc33b35aff9190a51148ccc85" dependencies = [ "serde", "stable_deref_trait", @@ -1642,9 +1675,9 @@ checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" [[package]] name = "unicode-xid" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "229730647fbc343e3a80e463c1db7f78f3855d3f3739bee0dda773c9a037c90a" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" [[package]] name = "utf8parse" @@ -1789,9 +1822,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.18" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" dependencies = [ "memchr", ] @@ -1822,5 +1855,5 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] diff --git a/Cargo.toml b/Cargo.toml index 31f6f24..604d615 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ anyhow = "1.0.88" assert_fs = "1.1.2" camino = "1.1.9" clap = { version = "4.5.18", features = ["derive"] } +cairo-annotations = "0.1.0" cairo-lang-sierra = "2.8.2" cairo-lang-sierra-to-casm = "2.8.2" cairo-lang-starknet-classes = "2.8.2" @@ -23,4 +24,3 @@ serde_json = "1.0.128" snapbox = "0.6.17" indoc = "2.0.5" regex = "1.11.0" -trace-data = { git = "https://github.com/software-mansion/cairo-profiler/", tag = "v0.6.0" } diff --git a/crates/cairo-coverage/Cargo.toml b/crates/cairo-coverage/Cargo.toml index e210ed5..118239b 100644 --- a/crates/cairo-coverage/Cargo.toml +++ b/crates/cairo-coverage/Cargo.toml @@ -6,6 +6,7 @@ edition.workspace = true [dependencies] anyhow.workspace = true camino.workspace = true +cairo-annotations.workspace = true cairo-lang-sierra.workspace = true cairo-lang-sierra-to-casm.workspace = true cairo-lang-starknet-classes.workspace = true @@ -14,7 +15,6 @@ derived-deref.workspace = true itertools.workspace = true serde.workspace = true serde_json.workspace = true -trace-data.workspace = true regex.workspace = true indoc.workspace = true diff --git a/crates/cairo-coverage/src/data_loader/loaded_data.rs b/crates/cairo-coverage/src/data_loader/loaded_data.rs index 474eda4..cd029eb 100644 --- a/crates/cairo-coverage/src/data_loader/loaded_data.rs +++ b/crates/cairo-coverage/src/data_loader/loaded_data.rs @@ -1,5 +1,8 @@ use crate::data_loader::sierra_program::{GetDebugInfos, SierraProgram}; use anyhow::{Context, Result}; +use cairo_annotations::trace_data::{ + CallTraceNode, CallTraceV1, CasmLevelInfo, VersionedCallTrace, +}; use cairo_lang_sierra::debug_info::DebugInfo; use cairo_lang_sierra_to_casm::compiler::CairoProgramDebugInfo; use camino::Utf8PathBuf; @@ -7,7 +10,6 @@ use derived_deref::Deref; use serde::de::DeserializeOwned; use std::collections::HashMap; use std::fs; -use trace_data::{CallTrace, CallTraceNode, CasmLevelInfo}; #[derive(Deref)] pub struct LoadedDataMap(HashMap); @@ -63,8 +65,8 @@ impl LoadedDataMap { } } -fn load_nested_traces(call_trace: CallTrace) -> Vec { - fn load_recursively(call_trace: CallTrace, acc: &mut Vec) { +fn load_nested_traces(VersionedCallTrace::V1(call_trace): VersionedCallTrace) -> Vec { + fn load_recursively(call_trace: CallTraceV1, acc: &mut Vec) { acc.push(call_trace.clone()); for call_trace_node in call_trace.nested_calls { if let CallTraceNode::EntryPointCall(nested_call_trace) = call_trace_node { diff --git a/crates/cairo-coverage/src/input/unique_executed_sierra_ids.rs b/crates/cairo-coverage/src/input/unique_executed_sierra_ids.rs index 23fd5b0..edfc0be 100644 --- a/crates/cairo-coverage/src/input/unique_executed_sierra_ids.rs +++ b/crates/cairo-coverage/src/input/unique_executed_sierra_ids.rs @@ -1,11 +1,11 @@ use crate::input::SierraToCairoMap; use crate::merge::MergeOwned; +use cairo_annotations::trace_data::CasmLevelInfo; use cairo_lang_sierra::program::StatementIdx; use cairo_lang_sierra_to_casm::compiler::CairoProgramDebugInfo; use derived_deref::Deref; use itertools::Itertools; use std::collections::HashMap; -use trace_data::CasmLevelInfo; #[derive(Deref)] pub struct UniqueExecutedSierraIds(HashMap); From dae923f5a66b5c0f5dc3c8732d0aaf9d72f3fa13 Mon Sep 17 00:00:00 2001 From: ksew1 <95349104+ksew1@users.noreply.github.com> Date: Wed, 16 Oct 2024 04:58:40 -0700 Subject: [PATCH 2/2] Use map_pcs_to_sierra_statement_ids (#76) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Stack**: - #78 - #77 - #76 ⬅ - #75 ⚠️ *Part of a stack created by [spr](https://github.com/ejoffe/spr). Do not merge manually using the UI - doing so may have unexpected results.* --- .../src/coverage_data/function.rs | 33 ++--- crates/cairo-coverage/src/data_loader/mod.rs | 2 - .../cairo-coverage/src/data_loader/types.rs | 50 -------- .../src/input/sierra_to_cairo_map.rs | 116 ++++++++++-------- .../src/input/statement_category_filter.rs | 10 +- .../src/input/unique_executed_sierra_ids.rs | 34 ++--- crates/cairo-coverage/src/output/lcov.rs | 42 ++++--- crates/cairo-coverage/src/types.rs | 3 - 8 files changed, 119 insertions(+), 171 deletions(-) delete mode 100644 crates/cairo-coverage/src/data_loader/types.rs diff --git a/crates/cairo-coverage/src/coverage_data/function.rs b/crates/cairo-coverage/src/coverage_data/function.rs index a9c95de..280cdf6 100644 --- a/crates/cairo-coverage/src/coverage_data/function.rs +++ b/crates/cairo-coverage/src/coverage_data/function.rs @@ -1,10 +1,11 @@ -use crate::data_loader::LineRange; use crate::input::{InputData, SierraToCairoMap}; -use crate::types::{FileLocation, FunctionName, HitCount, LineNumber}; +use crate::types::HitCount; +use cairo_annotations::annotations::coverage::{LineNumber, SourceFileFullPath}; +use cairo_annotations::annotations::profiler::FunctionName; use itertools::Itertools; use std::collections::HashMap; -pub type FilesCoverageData = HashMap; +pub type FilesCoverageData = HashMap; pub fn create_files_coverage_data_with_hits(input_data: &InputData) -> FilesCoverageData { input_data @@ -15,7 +16,7 @@ pub fn create_files_coverage_data_with_hits(input_data: &InputData) -> FilesCove create_files_coverage_data(&input_data.sierra_to_cairo_map), |mut files_coverage_data, (id, statement_origin)| { if let Some(function_details) = files_coverage_data - .get_mut(&statement_origin.file_location) + .get_mut(&statement_origin.source_file_full_path) .and_then(|functions| functions.get_mut(&statement_origin.function_name)) { function_details.register_hit( @@ -33,13 +34,11 @@ fn create_files_coverage_data(sierra_to_cairo_map: &SierraToCairoMap) -> FilesCo .values() .cloned() .fold(HashMap::new(), |mut acc, origin| { - acc.entry(origin.file_location) + acc.entry(origin.source_file_full_path) .or_default() .entry(origin.function_name) - .and_modify(|function_details: &mut FunctionCoverageData| { - function_details.register_line(&origin.line_range); - }) - .or_insert(origin.line_range.into()); + .or_default() + .register_line(&origin.line_range); acc }) } @@ -95,27 +94,19 @@ impl FunctionCoverageDataOps for FunctionCoverageData { } } -impl From for FunctionCoverageData { - fn from(line_range: LineRange) -> Self { - let mut function_coverage_data = FunctionCoverageData::new(); - function_coverage_data.register_line(&line_range); - function_coverage_data - } -} - trait Register { - fn register_line>(&mut self, lines: T); - fn register_hit>(&mut self, lines: T, times: HitCount); + fn register_line(&mut self, lines: impl IntoIterator); + fn register_hit(&mut self, lines: impl IntoIterator, times: HitCount); } impl Register for FunctionCoverageData { - fn register_line>(&mut self, lines: T) { + fn register_line(&mut self, lines: impl IntoIterator) { for line in lines { self.entry(line).or_default(); } } - fn register_hit>(&mut self, lines: T, times: HitCount) { + fn register_hit(&mut self, lines: impl IntoIterator, times: HitCount) { for line in lines { *self.entry(line).or_default() += times; } diff --git a/crates/cairo-coverage/src/data_loader/mod.rs b/crates/cairo-coverage/src/data_loader/mod.rs index f9615e4..534fff5 100644 --- a/crates/cairo-coverage/src/data_loader/mod.rs +++ b/crates/cairo-coverage/src/data_loader/mod.rs @@ -1,6 +1,4 @@ mod loaded_data; mod sierra_program; -mod types; pub use loaded_data::{LoadedData, LoadedDataMap}; -pub use types::{CodeLocation, CoverageAnnotations, LineRange, ProfilerAnnotations}; diff --git a/crates/cairo-coverage/src/data_loader/types.rs b/crates/cairo-coverage/src/data_loader/types.rs deleted file mode 100644 index adc17ea..0000000 --- a/crates/cairo-coverage/src/data_loader/types.rs +++ /dev/null @@ -1,50 +0,0 @@ -use crate::types::{FileLocation, FunctionName, LineNumber}; -use cairo_lang_sierra::program::StatementIdx; -use serde::Deserialize; -use std::collections::HashMap; -use std::ops::RangeInclusive; - -pub type CodeLocation = (FileLocation, LineRange); - -#[derive(Deserialize, Clone, Eq, PartialEq)] -pub struct LineRange { - pub start: Position, - pub end: Position, -} - -impl LineRange { - pub fn move_by_1(&self) -> LineRange { - LineRange { - start: Position { - line: self.start.line + 1, - }, - end: Position { - line: self.end.line + 1, - }, - } - } -} - -impl IntoIterator for &LineRange { - type Item = LineNumber; - type IntoIter = RangeInclusive; - - fn into_iter(self) -> Self::IntoIter { - self.start.line..=self.end.line - } -} - -#[derive(Deserialize, Clone, Eq, PartialEq)] -pub struct Position { - pub line: LineNumber, -} - -#[derive(Deserialize)] -pub struct CoverageAnnotations { - pub statements_code_locations: HashMap>, -} - -#[derive(Deserialize)] -pub struct ProfilerAnnotations { - pub statements_functions: HashMap>, -} diff --git a/crates/cairo-coverage/src/input/sierra_to_cairo_map.rs b/crates/cairo-coverage/src/input/sierra_to_cairo_map.rs index d9f5b28..22b7870 100644 --- a/crates/cairo-coverage/src/input/sierra_to_cairo_map.rs +++ b/crates/cairo-coverage/src/input/sierra_to_cairo_map.rs @@ -1,13 +1,32 @@ -use crate::data_loader::{CodeLocation, CoverageAnnotations, LineRange, ProfilerAnnotations}; use crate::input::statement_category_filter::{StatementCategoryFilter, VIRTUAL_FILE_REGEX}; -use crate::types::{FileLocation, FunctionName}; use anyhow::{Context, Result}; -use cairo_lang_sierra::debug_info::{Annotations, DebugInfo}; +use cairo_annotations::annotations::coverage::{ + CodeLocation, CoverageAnnotationsV1, LineNumber, SourceCodeSpan, SourceFileFullPath, + VersionedCoverageAnnotations, +}; +use cairo_annotations::annotations::profiler::{ + FunctionName, ProfilerAnnotationsV1, VersionedProfilerAnnotations, +}; +use cairo_annotations::annotations::TryFromDebugInfo; +use cairo_lang_sierra::debug_info::DebugInfo; use cairo_lang_sierra::program::StatementIdx; use derived_deref::Deref; -use indoc::formatdoc; -use serde::de::DeserializeOwned; +use indoc::indoc; +use serde::Deserialize; use std::collections::HashMap; +use std::iter; +use std::ops::RangeInclusive; + +const RECOMMENDED_CAIRO_PROFILE_TOML: &str = indoc! { + r#" + Perhaps you are missing the following entries in Scarb.toml: + + [profile.dev.cairo] + unstable-add-statements-functions-debug-info = true + unstable-add-statements-code-locations-debug-info = true + inlining-strategy = "avoid" + "# +}; #[derive(Deref)] pub struct SierraToCairoMap(HashMap); @@ -15,15 +34,44 @@ pub struct SierraToCairoMap(HashMap); #[derive(Clone, Eq, PartialEq)] pub struct StatementOrigin { pub function_name: FunctionName, - pub file_location: FileLocation, + pub source_file_full_path: SourceFileFullPath, pub line_range: LineRange, } impl StatementOrigin { pub fn remove_virtual_file_prefix(&mut self) { - self.file_location = VIRTUAL_FILE_REGEX - .replace_all(&self.file_location, "") - .to_string(); + 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 + pub start: LineNumber, + /// Line number is 1-based + pub end: LineNumber, +} + +impl From<&SourceCodeSpan> for LineRange { + fn from(span: &SourceCodeSpan) -> Self { + // `SourceCodeSpan` is 0-based, so we need to add 1 to the line numbers + Self { + start: span.start.line + LineNumber(1), + end: span.end.line + LineNumber(1), + } + } +} + +impl IntoIterator for &LineRange { + type Item = LineNumber; + type IntoIter = iter::Map, fn(usize) -> LineNumber>; + + fn into_iter(self) -> Self::IntoIter { + (self.start.0..=self.end.0).map(LineNumber) } } @@ -31,13 +79,15 @@ pub fn create_sierra_to_cairo_map( debug_info: &DebugInfo, filter: &StatementCategoryFilter, ) -> Result { - let CoverageAnnotations { + let VersionedCoverageAnnotations::V1(CoverageAnnotationsV1 { statements_code_locations, - } = CoverageAnnotations::get_namespace(&debug_info.annotations)?; + }) = VersionedCoverageAnnotations::try_from_debug_info(debug_info) + .context(RECOMMENDED_CAIRO_PROFILE_TOML)?; - let ProfilerAnnotations { + let VersionedProfilerAnnotations::V1(ProfilerAnnotationsV1 { statements_functions, - } = ProfilerAnnotations::get_namespace(&debug_info.annotations)?; + }) = VersionedProfilerAnnotations::try_from_debug_info(debug_info) + .context(RECOMMENDED_CAIRO_PROFILE_TOML)?; Ok(SierraToCairoMap( statements_code_locations @@ -63,10 +113,10 @@ fn find_statement_origin( .iter() .zip(function_names) .map( - |((file_location, line_range), function_name)| StatementOrigin { + |(CodeLocation(source_file_full_path, line_range), function_name)| StatementOrigin { function_name: function_name.clone(), - file_location: file_location.clone(), - line_range: line_range.move_by_1(), + source_file_full_path: source_file_full_path.clone(), + line_range: line_range.into(), }, ) .find(|statement_origin| filter.should_include(statement_origin)) @@ -75,37 +125,3 @@ fn find_statement_origin( statement_origin }) } - -trait Namespace { - const NAMESPACE: &'static str; - - fn get_namespace(annotations: &Annotations) -> Result { - annotations - .get(Self::NAMESPACE) - .cloned() - .context(formatdoc! { - r#"Expected key: {} but was missing. - - Perhaps you are missing the following entries in Scarb.toml: - - [profile.dev.cairo] - unstable-add-statements-functions-debug-info = true - unstable-add-statements-code-locations-debug-info = true - inlining-strategy= "avoid" - "#, - Self::NAMESPACE, - }) - .and_then(|value| { - serde_json::from_value(value) - .context(format!("Failed to deserialize at key: {}", Self::NAMESPACE)) - }) - } -} - -impl Namespace for CoverageAnnotations { - const NAMESPACE: &'static str = "github.com/software-mansion/cairo-coverage"; -} - -impl Namespace for ProfilerAnnotations { - const NAMESPACE: &'static str = "github.com/software-mansion/cairo-profiler"; -} diff --git a/crates/cairo-coverage/src/input/statement_category_filter.rs b/crates/cairo-coverage/src/input/statement_category_filter.rs index 6cc0920..edeb4a3 100644 --- a/crates/cairo-coverage/src/input/statement_category_filter.rs +++ b/crates/cairo-coverage/src/input/statement_category_filter.rs @@ -1,6 +1,8 @@ use crate::cli::IncludedComponent; use crate::data_loader::LoadedData; use crate::input::sierra_to_cairo_map::StatementOrigin; +use cairo_annotations::annotations::coverage::SourceFileFullPath; +use cairo_annotations::annotations::profiler::FunctionName; use camino::Utf8PathBuf; use regex::Regex; use std::collections::HashSet; @@ -72,8 +74,8 @@ impl StatementCategoryFilter { fn get_categories_for_statement( &self, StatementOrigin { - function_name, - file_location, + function_name: FunctionName(function_name), + source_file_full_path: SourceFileFullPath(source_file_full_path), .. }: &StatementOrigin, ) -> HashSet { @@ -81,11 +83,11 @@ impl StatementCategoryFilter { if self.test_functions.contains(function_name) { labels.insert(StatementCategory::TestFunction); - } else if VIRTUAL_FILE_REGEX.is_match(file_location) { + } else if VIRTUAL_FILE_REGEX.is_match(source_file_full_path) { labels.insert(StatementCategory::Macro); } - if file_location.contains(&self.user_project_path) { + if source_file_full_path.contains(&self.user_project_path) { labels.insert(StatementCategory::UserFunction); } else { labels.insert(StatementCategory::NonUserFunction); diff --git a/crates/cairo-coverage/src/input/unique_executed_sierra_ids.rs b/crates/cairo-coverage/src/input/unique_executed_sierra_ids.rs index edfc0be..f55f9b5 100644 --- a/crates/cairo-coverage/src/input/unique_executed_sierra_ids.rs +++ b/crates/cairo-coverage/src/input/unique_executed_sierra_ids.rs @@ -1,5 +1,6 @@ use crate::input::SierraToCairoMap; use crate::merge::MergeOwned; +use cairo_annotations::map_pcs_to_sierra_statement_ids; use cairo_annotations::trace_data::CasmLevelInfo; use cairo_lang_sierra::program::StatementIdx; use cairo_lang_sierra_to_casm::compiler::CairoProgramDebugInfo; @@ -22,34 +23,17 @@ impl UniqueExecutedSierraIds { casm_level_info: &CasmLevelInfo, sierra_to_cairo_map: &SierraToCairoMap, ) -> Self { - let CasmLevelInfo { - run_with_call_header, - vm_trace, - } = &casm_level_info; - - let real_minimal_pc = run_with_call_header - .then(|| vm_trace.last().map_or(1, |trace| trace.pc + 1)) - .unwrap_or(1); - - let iter = vm_trace - .iter() - .map(|step| step.pc) - .filter(|pc| pc >= &real_minimal_pc) - .map(|pc| { - let real_pc_code_offset = pc - real_minimal_pc; - casm_debug_info - .sierra_statement_info - .partition_point(|debug_info| debug_info.start_offset <= real_pc_code_offset) - - 1 - }) - .map(StatementIdx); - - squash_idx_pointing_to_same_statement(iter, sierra_to_cairo_map) + squash_idx_pointing_to_same_statement( + map_pcs_to_sierra_statement_ids(casm_debug_info, casm_level_info) + .into_iter() + .filter_map(Option::from), + sierra_to_cairo_map, + ) } } -fn squash_idx_pointing_to_same_statement>( - iter: I, +fn squash_idx_pointing_to_same_statement( + iter: impl Iterator, sierra_to_cairo_map: &SierraToCairoMap, ) -> UniqueExecutedSierraIds { UniqueExecutedSierraIds( diff --git a/crates/cairo-coverage/src/output/lcov.rs b/crates/cairo-coverage/src/output/lcov.rs index e5fc17d..3bd280d 100644 --- a/crates/cairo-coverage/src/output/lcov.rs +++ b/crates/cairo-coverage/src/output/lcov.rs @@ -2,13 +2,16 @@ use crate::coverage_data::{ FileCoverageData, FileCoverageDataOps, FilesCoverageData, FunctionCoverageData, FunctionCoverageDataOps, }; -use crate::types::{FileLocation, FunctionName, HitCount, LineNumber}; +use crate::types::HitCount; +use cairo_annotations::annotations::coverage::{LineNumber, SourceFileFullPath}; +use cairo_annotations::annotations::profiler::FunctionName; use derived_deref::Deref; +use itertools::Itertools; use std::fmt; use std::fmt::Display; #[derive(Deref)] -pub struct LcovFormat(Vec<(FileLocation, LcovData)>); +pub struct LcovFormat(Vec<(SourceFileFullPath, LcovData)>); pub struct LcovData { lines: Vec<(LineNumber, HitCount)>, @@ -26,24 +29,31 @@ struct LcovDetails { impl From for LcovFormat { fn from(files_coverage_data: FilesCoverageData) -> Self { - let mut list: Vec<_> = files_coverage_data - .iter() - .map(|(file_location, file_coverage_data)| { - (file_location.to_owned(), file_coverage_data.into()) - }) - .collect(); - list.sort_by_key(|(file_location, _)| file_location.to_owned()); - Self(list) + Self( + files_coverage_data + .iter() + .map(|(source_file_full_path, file_coverage_data)| { + (source_file_full_path.to_owned(), file_coverage_data.into()) + }) + .sorted_by( + |(source_file_full_path, _), (other_source_file_full_path, _)| { + source_file_full_path.cmp(other_source_file_full_path) + }, + ) + .collect(), + ) } } impl From<&FileCoverageData> for LcovData { fn from(file_coverage_data: &FileCoverageData) -> Self { - let mut lines: Vec<_> = file_coverage_data.lines().into_iter().collect(); - lines.sort_unstable(); + let lines = file_coverage_data.lines().into_iter().sorted().collect(); - let mut functions: Vec<_> = file_coverage_data.iter().map(LcovDetails::from).collect(); - functions.sort(); + let functions = file_coverage_data + .iter() + .map(LcovDetails::from) + .sorted() + .collect(); let file_hit_count = file_coverage_data.file_hit_count(); let unique_file_hit_count = file_coverage_data.unique_file_hit_count(); @@ -69,9 +79,9 @@ impl From<(&FunctionName, &FunctionCoverageData)> for LcovDetails { impl Display for LcovFormat { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - for (file_location, functions) in self.iter() { + for (source_file_full_path, functions) in self.iter() { writeln!(f, "TN:")?; - writeln!(f, "SF:{file_location}")?; + writeln!(f, "SF:{source_file_full_path}")?; write!(f, "{functions}")?; } Ok(()) diff --git a/crates/cairo-coverage/src/types.rs b/crates/cairo-coverage/src/types.rs index 4762b65..5c0ec24 100644 --- a/crates/cairo-coverage/src/types.rs +++ b/crates/cairo-coverage/src/types.rs @@ -1,4 +1 @@ -pub type FileLocation = String; -pub type FunctionName = String; -pub type LineNumber = usize; pub type HitCount = usize;