Skip to content

Commit 5f3c3f7

Browse files
grandizzyklkvrzerosnacksDaniPopes
authored
feat: add support for preprocessing sources (#252)
Implements a preprocessor allowing us to skip recompiling tests on non-interface source file changes. See the companion Foundry PR foundry-rs/foundry#10010 for benchmarks and more details. Supersedes #198: - uses solar AST instead solang-parser to compute interface representation - uses solar HIR instead of solc AST to find bytecode dependencies - handles more edge cases, like deploying with salt/value Closes #197. ### TODO - [x] use solar HIR (deps to review and include paradigmxyz/solar#210) - [x] unit tests - [x] opt-in caching changes - [x] autodetect mocks - [x] figure out how to parse when building from different dir - [x] additional testing (tested with uniswap v4-core and simpler projects) ### Depends on - [x] merge solar PR (paradigmxyz/solar#210) - [x] solar release --------- Co-authored-by: Arsenii Kulikov <[email protected]> Co-authored-by: zerosnacks <[email protected]> Co-authored-by: DaniPopes <[email protected]>
1 parent 846f863 commit 5f3c3f7

File tree

28 files changed

+720
-149
lines changed

28 files changed

+720
-149
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77

88
env:
99
CARGO_TERM_COLOR: always
10+
RUST_BACKTRACE: full
1011

1112
concurrency:
1213
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
/target
33
/Cargo.lock
44

5-
cache/
5+
/cache
6+
test-data/**/cache/
67

78
.vscode
89
/.envrc
@@ -12,4 +13,4 @@ cache/
1213
devenv.local.nix
1314
.direnv
1415
.pre-commit-config.yaml
15-
.lock
16+
.lock

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ manual-string-new = "warn"
2222
uninlined-format-args = "warn"
2323
use-self = "warn"
2424
redundant-clone = "warn"
25-
# until <https://github.com/rust-lang/rust-clippy/issues/13885> is fixed
26-
literal-string-with-formatting-args = "allow"
25+
26+
result-large-err = "allow"
27+
large-enum-variant = "allow"
2728

2829
[workspace.lints.rust]
2930
rust-2018-idioms = "warn"
@@ -54,7 +55,8 @@ semver = { version = "1.0", features = ["serde"] }
5455
serde = { version = "1", features = ["derive", "rc"] }
5556
serde_json = "1.0"
5657
similar-asserts = "1"
57-
solar-parse = { version = "=0.1.1", default-features = false }
58+
solar-parse = { version = "=0.1.2", default-features = false }
59+
solar-sema = { version = "=0.1.2", default-features = false }
5860
svm = { package = "svm-rs", version = "0.5", default-features = false }
5961
tempfile = "3.9"
6062
thiserror = "2"

crates/artifacts/solc/src/ast/misc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{fmt, fmt::Write, str::FromStr};
44
/// Represents the source location of a node: `<start byte>:<length>:<source index>`.
55
///
66
/// The `start`, `length` and `index` can be -1 which is represented as `None`
7-
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
7+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
88
pub struct SourceLocation {
99
pub start: Option<usize>,
1010
pub length: Option<usize>,

crates/artifacts/solc/src/sources.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,13 @@ impl Source {
198198
/// Generate a non-cryptographically secure checksum of the file's content.
199199
#[cfg(feature = "checksum")]
200200
pub fn content_hash(&self) -> String {
201-
alloy_primitives::hex::encode(<md5::Md5 as md5::Digest>::digest(self.content.as_bytes()))
201+
Self::content_hash_of(&self.content)
202+
}
203+
204+
/// Generate a non-cryptographically secure checksum of the given source.
205+
#[cfg(feature = "checksum")]
206+
pub fn content_hash_of(src: &str) -> String {
207+
alloy_primitives::hex::encode(<md5::Md5 as md5::Digest>::digest(src))
202208
}
203209
}
204210

crates/compilers/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ thiserror.workspace = true
3333
path-slash.workspace = true
3434
yansi.workspace = true
3535
solar-parse.workspace = true
36+
solar-sema.workspace = true
3637
futures-util = { workspace = true, optional = true }
3738
tokio = { workspace = true, optional = true }
3839

0 commit comments

Comments
 (0)