Implement resolc end-to-end compilation benchmarks (#406)

# Description

Closes [#403](https://github.com/paritytech/revive/issues/403)

Adds compilation time benchmarks for resolc end-to-end.

The benchmarks can be run from the root via:

```sh
make bench-resolc
```

HTML reports will be generated under `target/criterion`, and a summary
of the results at
[crates/resolc/BENCHMARKS_M4PRO.md](https://github.com/paritytech/revive/blob/lj/compilation-benchmarks/crates/resolc/BENCHMARKS_M4PRO.md)
(currently from running on a Mac M4 Pro).
This commit is contained in:
LJ
2025-11-19 12:16:07 +01:00
committed by GitHub
parent e78f3cc419
commit ad61b6e3c9
24 changed files with 668 additions and 193 deletions
+1
View File
@@ -3,6 +3,7 @@
target-llvm
*.dot
.vscode/
.zed/
.DS_Store
/*.sol
/*.yul
Generated
+2
View File
@@ -8962,10 +8962,12 @@ version = "0.5.0"
dependencies = [
"anyhow",
"clap",
"criterion",
"git2",
"hex",
"inkwell",
"libc",
"log",
"mimalloc",
"normpath",
"once_cell",
+6 -1
View File
@@ -20,6 +20,7 @@
bench \
bench-pvm \
bench-evm \
bench-resolc \
clean
install: install-bin install-npm
@@ -66,7 +67,7 @@ test-integration: install-bin
cargo test --package revive-integration
test-resolc: install
cargo test --package resolc
cargo test --package resolc --benches
test-workspace: install
cargo test --workspace --exclude revive-llvm-builder
@@ -90,6 +91,10 @@ bench-evm: install-bin
cargo criterion --bench execute --features bench-evm --message-format=json \
| criterion-table > crates/benchmarks/EVM.md
bench-resolc: test-resolc
cargo criterion --package resolc --bench compile --message-format=json \
| criterion-table > crates/resolc/BENCHMARKS_M4PRO.md
clean:
cargo clean ; \
revive-llvm clean ; \
+2 -3
View File
@@ -4,7 +4,7 @@
- [Benchmark Results](#benchmark-results)
- [Baseline](#baseline)
- [OddPorduct](#oddporduct)
- [OddProduct](#oddproduct)
- [TriangleNumber](#trianglenumber)
- [FibonacciRecursive](#fibonaccirecursive)
- [FibonacciIterative](#fibonacciiterative)
@@ -19,7 +19,7 @@
|:--------|:-------------------------|:-------------------------------- |
| **`0`** | `10.08 us` (✅ **1.00x**) | `10.32 us` (✅ **1.02x slower**) |
### OddPorduct
### OddProduct
| | `EVM` | `PVMInterpreter` |
|:-------------|:--------------------------|:-------------------------------- |
@@ -70,4 +70,3 @@
---
Made with [criterion-table](https://github.com/nu11ptr/criterion-table)
+1 -1
View File
@@ -57,7 +57,7 @@ fn bench_baseline(c: &mut Criterion) {
}
fn bench_odd_product(c: &mut Criterion) {
let group = group(c, "OddPorduct");
let group = group(c, "OddProduct");
let parameters = &[10_000, 100_000, 300000];
bench(group, parameters, parameters, Contract::odd_product);
+53
View File
@@ -0,0 +1,53 @@
# Benchmarks
## Table of Contents
- [Benchmark Results](#benchmark-results)
- [Empty](#empty)
- [Dependency](#dependency)
- [LargeDivRem](#largedivrem)
- [Memset (`--yul`)](#memset-(`--yul`))
- [Return (`--yul`)](#return-(`--yul`))
- [Multiple Contracts (`--standard-json`)](#multiple-contracts-(`--standard-json`))
## Benchmark Results
### Empty
| | `resolc` | `solc` |
|:-------|:-------------------------|:------------------------------- |
| | `62.77 ms` (✅ **1.00x**) | `9.63 ms` (🚀 **6.52x faster**) |
### Dependency
| | `resolc` | `solc` |
|:-------|:--------------------------|:-------------------------------- |
| | `142.28 ms` (✅ **1.00x**) | `57.57 ms` (🚀 **2.47x faster**) |
### LargeDivRem
| | `resolc` | `solc` |
|:-------|:--------------------------|:-------------------------------- |
| | `110.80 ms` (✅ **1.00x**) | `20.96 ms` (🚀 **5.29x faster**) |
### Memset (`--yul`)
| | `resolc` | `solc` |
|:-------|:-------------------------|:------------------------------- |
| | `58.39 ms` (✅ **1.00x**) | `8.84 ms` (🚀 **6.61x faster**) |
### Return (`--yul`)
| | `resolc` | `solc` |
|:-------|:-------------------------|:------------------------------- |
| | `52.83 ms` (✅ **1.00x**) | `8.04 ms` (🚀 **6.57x faster**) |
### Multiple Contracts (`--standard-json`)
| | `resolc` | `solc` |
|:-------|:-----------------------|:--------------------------------- |
| | `1.52 s` (✅ **1.00x**) | `623.91 ms` (🚀 **2.44x faster**) |
---
Made with [criterion-table](https://github.com/nu11ptr/criterion-table)
+5
View File
@@ -22,6 +22,7 @@ anyhow = { workspace = true }
clap = { workspace = true }
hex = { workspace = true }
inkwell = { workspace = true }
log = { workspace = true }
once_cell = { workspace = true }
path-slash = { workspace = true }
rayon = { workspace = true, optional = true }
@@ -47,9 +48,13 @@ inkwell = { workspace = true, features = ["target-riscv", "llvm18-1-no-llvm-link
git2 = { workspace = true, default-features = false }
[dev-dependencies]
criterion = { workspace = true }
tempfile = { workspace = true }
[features]
parallel = ["rayon", "revive-solc-json-interface/parallel"]
default = ["parallel"]
[[bench]]
name = "compile"
harness = false
+177
View File
@@ -0,0 +1,177 @@
//! The `resolc` compilation benchmarks.
//! The tests mimicking the commands run by these benchmarks exist in `src/tests/cli/bin.rs`.
use std::time::Duration;
use criterion::{
criterion_group, criterion_main,
measurement::{Measurement, WallTime},
BenchmarkGroup, Criterion,
};
use resolc::{
self,
cli_utils::{
absolute_path, execute_command, ResolcOptSettings, SolcOptSettings, SOLIDITY_CONTRACT_PATH,
SOLIDITY_DEPENDENCY_CONTRACT_PATH, SOLIDITY_LARGE_DIV_REM_CONTRACT_PATH,
STANDARD_JSON_CONTRACTS_PATH, YUL_MEMSET_CONTRACT_PATH, YUL_RETURN_CONTRACT_PATH,
},
SolcCompiler,
};
/// The function under test executes the `resolc` executable.
fn execute_resolc(arguments: &[&str], stdin_file_path: Option<&str>) {
execute_command(resolc::DEFAULT_EXECUTABLE_NAME, arguments, stdin_file_path);
}
/// The function under test executes the `solc` executable.
fn execute_solc(arguments: &[&str], stdin_file_path: Option<&str>) {
execute_command(
SolcCompiler::DEFAULT_EXECUTABLE_NAME,
arguments,
stdin_file_path,
);
}
fn group<'error, M>(c: &'error mut Criterion<M>, group_name: &str) -> BenchmarkGroup<'error, M>
where
M: Measurement,
{
c.benchmark_group(group_name)
}
fn bench(
mut group: BenchmarkGroup<'_, WallTime>,
resolc_arguments: &[&str],
solc_arguments: &[&str],
stdin_file_path: Option<&str>,
) {
group.bench_function("resolc", |b| {
b.iter(|| execute_resolc(resolc_arguments, stdin_file_path));
});
group.bench_function("solc", |b| {
b.iter(|| execute_solc(solc_arguments, stdin_file_path));
});
group.finish();
}
fn bench_empty(c: &mut Criterion) {
let mut group = group(c, "Empty");
group
.sample_size(100)
.measurement_time(Duration::from_secs(8));
let path = absolute_path(SOLIDITY_CONTRACT_PATH);
let resolc_arguments = &[&path, "--bin", ResolcOptSettings::PERFORMANCE];
let solc_arguments = &[
&path,
"--bin",
"--via-ir",
"--optimize",
"--optimize-runs",
SolcOptSettings::PERFORMANCE,
];
bench(group, resolc_arguments, solc_arguments, None);
}
fn bench_dependency(c: &mut Criterion) {
let mut group = group(c, "Dependency");
group
.sample_size(50)
.measurement_time(Duration::from_secs(9));
let path = absolute_path(SOLIDITY_DEPENDENCY_CONTRACT_PATH);
let resolc_arguments = &[&path, "--bin", ResolcOptSettings::PERFORMANCE];
let solc_arguments = &[
&path,
"--bin",
"--via-ir",
"--optimize",
"--optimize-runs",
SolcOptSettings::PERFORMANCE,
];
bench(group, resolc_arguments, solc_arguments, None);
}
fn bench_large_div_rem(c: &mut Criterion) {
let mut group = group(c, "LargeDivRem");
group
.sample_size(45)
.measurement_time(Duration::from_secs(9));
let path = absolute_path(SOLIDITY_LARGE_DIV_REM_CONTRACT_PATH);
let resolc_arguments = &[&path, "--bin", ResolcOptSettings::PERFORMANCE];
let solc_arguments = &[
&path,
"--bin",
"--via-ir",
"--optimize",
"--optimize-runs",
SolcOptSettings::PERFORMANCE,
];
bench(group, resolc_arguments, solc_arguments, None);
}
fn bench_memset(c: &mut Criterion) {
let mut group = group(c, "Memset (`--yul`)");
group
.sample_size(100)
.measurement_time(Duration::from_secs(7));
let path = absolute_path(YUL_MEMSET_CONTRACT_PATH);
let resolc_arguments = &[&path, "--yul", "--bin", ResolcOptSettings::PERFORMANCE];
let solc_arguments = &[
&path,
"--strict-assembly",
"--bin",
"--optimize",
"--optimize-runs",
SolcOptSettings::PERFORMANCE,
];
bench(group, resolc_arguments, solc_arguments, None);
}
fn bench_return(c: &mut Criterion) {
let mut group = group(c, "Return (`--yul`)");
group
.sample_size(100)
.measurement_time(Duration::from_secs(6));
let path = absolute_path(YUL_RETURN_CONTRACT_PATH);
let resolc_arguments = &[&path, "--yul", "--bin", ResolcOptSettings::PERFORMANCE];
let solc_arguments = &[
&path,
"--strict-assembly",
"--bin",
"--optimize",
"--optimize-runs",
SolcOptSettings::PERFORMANCE,
];
bench(group, resolc_arguments, solc_arguments, None);
}
fn bench_standard_json_contracts(c: &mut Criterion) {
let mut group = group(c, "Multiple Contracts (`--standard-json`)");
group
.sample_size(20)
.measurement_time(Duration::from_secs(35));
let path = absolute_path(STANDARD_JSON_CONTRACTS_PATH);
let resolc_arguments = &["--standard-json"];
let solc_arguments = &["--standard-json"];
bench(group, resolc_arguments, solc_arguments, Some(&path));
}
criterion_group!(
name = benches;
config = Criterion::default();
targets =
bench_empty,
bench_dependency,
bench_large_div_rem,
bench_memset,
bench_return,
bench_standard_json_contracts,
);
criterion_main!(benches);
@@ -2,6 +2,7 @@
use std::{
fs::File,
path::PathBuf,
process::{Command, Stdio},
};
@@ -10,13 +11,18 @@ use crate::SolcCompiler;
/// The simple Solidity contract test fixture path.
pub const SOLIDITY_CONTRACT_PATH: &str = "src/tests/data/solidity/contract.sol";
/// The dependency Solidity contract test fixture path.
pub const DEPENDENCY_CONTRACT_PATH: &str = "src/tests/data/solidity/dependency.sol";
pub const SOLIDITY_DEPENDENCY_CONTRACT_PATH: &str = "src/tests/data/solidity/dependency.sol";
/// The simple Solidity contract containing i256 divisions and remains
/// that should be compiled correctly.
pub const SOLIDITY_LARGE_DIV_REM_CONTRACT_PATH: &str = "src/tests/data/solidity/large_div_rem.sol";
/// The simple YUL contract test fixture path.
pub const YUL_CONTRACT_PATH: &str = "src/tests/data/yul/contract.yul";
/// The memeset YUL contract test fixture path.
pub const YUL_MEMSET_CONTRACT_PATH: &str = "src/tests/data/yul/memset.yul";
/// The return YUL contract test fixture path.
pub const YUL_RETURN_CONTRACT_PATH: &str = "src/tests/data/yul/return.yul";
/// The standard JSON contracts test fixture path.
pub const STANDARD_JSON_CONTRACTS_PATH: &str =
"src/tests/data/standard_json/solidity_contracts.json";
@@ -28,16 +34,30 @@ pub const STANDARD_JSON_CONTRACTS_PATH: &str =
pub const STANDARD_JSON_NO_EVM_CODEGEN_PATH: &str =
"src/tests/data/standard_json/no_evm_codegen.json";
/// The simple Solidity contract containing i256 divisions and remains that should be compiled
/// correctly
pub const SOLIDITY_LARGE_DIV_REM_CONTRACT_PATH: &str = "src/tests/data/solidity/large_div_rem.sol";
/// The `resolc` YUL mode flag.
pub const RESOLC_YUL_FLAG: &str = "--yul";
/// The `--yul` option was deprecated in Solidity 0.8.27 in favor of `--strict-assembly`.
/// See section `--strict-assembly vs. --yul` in https://soliditylang.org/blog/2024/09/04/solidity-0.8.27-release-announcement/
/// See section `--strict-assembly vs. --yul` in the [release announcement](https://soliditylang.org/blog/2024/09/04/solidity-0.8.27-release-announcement/).
pub const SOLC_YUL_FLAG: &str = "--strict-assembly";
/// Common `resolc` CLI optimization settings.
pub struct ResolcOptSettings;
impl ResolcOptSettings {
pub const NONE: &'static str = "-O0";
pub const PERFORMANCE: &'static str = "-O3";
pub const SIZE: &'static str = "-Oz";
}
/// Common `solc` CLI optimization settings for `--optimize-runs`.
pub struct SolcOptSettings;
impl SolcOptSettings {
pub const NONE: &'static str = "0";
pub const PERFORMANCE: &'static str = "20000";
pub const SIZE: &'static str = "1";
}
/// The result of executing a command.
pub struct CommandResult {
/// The data written to `stdout`.
@@ -50,18 +70,22 @@ pub struct CommandResult {
pub code: i32,
}
/// Executes the `resolc` command with the given `arguments`.
pub fn execute_resolc(arguments: &[&str]) -> CommandResult {
execute_command("resolc", arguments, None)
}
/// Executes the `resolc` command with the given `arguments` and file path passed to `stdin`.
pub fn execute_resolc_with_stdin_input(arguments: &[&str], stdin_file_path: &str) -> CommandResult {
execute_command("resolc", arguments, Some(stdin_file_path))
}
/// Executes the `solc` command with the given `arguments`.
pub fn execute_solc(arguments: &[&str]) -> CommandResult {
execute_command(SolcCompiler::DEFAULT_EXECUTABLE_NAME, arguments, None)
}
/// Executes the `solc` command with the given `arguments` and file path passed to `stdin`.
pub fn execute_solc_with_stdin_input(arguments: &[&str], stdin_file_path: &str) -> CommandResult {
execute_command(
SolcCompiler::DEFAULT_EXECUTABLE_NAME,
@@ -70,12 +94,13 @@ pub fn execute_solc_with_stdin_input(arguments: &[&str], stdin_file_path: &str)
)
}
fn execute_command(
/// Executes the `command` with the given `arguments` and optional file path passed to `stdin`.
pub fn execute_command(
command: &str,
arguments: &[&str],
stdin_file_path: Option<&str>,
) -> CommandResult {
println!(
log::trace!(
"executing command: '{command} {}{}'",
arguments.join(" "),
stdin_file_path
@@ -103,10 +128,12 @@ fn execute_command(
}
}
/// Asserts that the exit codes of executing `solc` and `resolc` are equal.
pub fn assert_equal_exit_codes(solc_result: &CommandResult, resolc_result: &CommandResult) {
assert_eq!(solc_result.code, resolc_result.code,);
}
/// Asserts that the command terminated successfully with a `0` exit code.
pub fn assert_command_success(result: &CommandResult, error_message_prefix: &str) {
assert!(
result.success,
@@ -117,6 +144,7 @@ pub fn assert_command_success(result: &CommandResult, error_message_prefix: &str
);
}
/// Asserts that the command terminated with an error and a non-`0` exit code.
pub fn assert_command_failure(result: &CommandResult, error_message_prefix: &str) {
assert!(
!result.success,
@@ -125,3 +153,15 @@ pub fn assert_command_failure(result: &CommandResult, error_message_prefix: &str
result.code
);
}
/// Gets the absolute path of a file. The `relative_path` must
/// be relative to the `resolc` crate.
/// Panics if the path does not exist or is not an accessible file.
pub fn absolute_path(relative_path: &str) -> String {
let absolute_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(relative_path);
if !absolute_path.is_file() {
panic!("expected a file at `{}`", absolute_path.display());
}
absolute_path.to_string_lossy().into_owned()
}
+2
View File
@@ -55,6 +55,8 @@ pub use self::solc::LAST_SUPPORTED_VERSION as SolcLastSupportedVersion;
pub use self::version::Version as ResolcVersion;
pub(crate) mod build;
#[cfg(not(target_os = "emscripten"))]
pub mod cli_utils;
pub(crate) mod r#const;
pub(crate) mod linker;
pub(crate) mod missing_libraries;
+13 -10
View File
@@ -1,14 +1,17 @@
//! The tests for running resolc with asm option.
use crate::tests::cli::utils;
use crate::cli_utils::{
assert_command_failure, assert_command_success, assert_equal_exit_codes, execute_resolc,
execute_solc, SOLIDITY_CONTRACT_PATH,
};
const ASM_OPTION: &str = "--asm";
#[test]
fn runs_with_valid_input_file() {
let arguments = &[utils::SOLIDITY_CONTRACT_PATH, ASM_OPTION];
let resolc_result = utils::execute_resolc(arguments);
utils::assert_command_success(&resolc_result, "Providing a valid input file");
let arguments = &[SOLIDITY_CONTRACT_PATH, ASM_OPTION];
let resolc_result = execute_resolc(arguments);
assert_command_success(&resolc_result, "Providing a valid input file");
for pattern in &["deploy", "call", "seal_return"] {
assert!(
@@ -17,19 +20,19 @@ fn runs_with_valid_input_file() {
);
}
let solc_result = utils::execute_solc(arguments);
utils::assert_equal_exit_codes(&solc_result, &resolc_result);
let solc_result = execute_solc(arguments);
assert_equal_exit_codes(&solc_result, &resolc_result);
}
#[test]
fn fails_without_input_file() {
let arguments = &[ASM_OPTION];
let resolc_result = utils::execute_resolc(arguments);
utils::assert_command_failure(&resolc_result, "Omitting an input file");
let resolc_result = execute_resolc(arguments);
assert_command_failure(&resolc_result, "Omitting an input file");
let output = resolc_result.stderr.to_lowercase();
assert!(output.contains("no input sources specified"));
let solc_result = utils::execute_solc(arguments);
utils::assert_equal_exit_codes(&solc_result, &resolc_result);
let solc_result = execute_solc(arguments);
assert_equal_exit_codes(&solc_result, &resolc_result);
}
+188
View File
@@ -0,0 +1,188 @@
//! The tests for running `resolc` with bin option.
use crate::{
cli_utils::{
absolute_path, assert_command_success, execute_command, CommandResult, ResolcOptSettings,
SolcOptSettings, SOLIDITY_CONTRACT_PATH, STANDARD_JSON_CONTRACTS_PATH,
YUL_MEMSET_CONTRACT_PATH,
},
SolcCompiler,
};
/// The starting hex value of a PVM blob (encoding of `"PVM"`).
const PVM_BLOB_START: &str = "50564d";
/// The starting hex value of an EVM blob compiled from Solidity.
const EVM_BLOB_START_FROM_SOLIDITY: &str = "6080";
/// The starting hex value of an EVM blob compiled from Yul.
/// (Blobs compiled from Yul do not have consistent starting hex values.)
const EVM_BLOB_START_FROM_YUL: &str = "";
/// Asserts that the `resolc` output contains a PVM blob.
fn assert_pvm_blob(result: &CommandResult) {
assert_binary_blob(result, "Binary:\n", PVM_BLOB_START);
}
/// Asserts that the `solc` output from compiling Solidity contains an EVM blob.
fn assert_evm_blob_from_solidity(result: &CommandResult) {
assert_binary_blob(result, "Binary:\n", EVM_BLOB_START_FROM_SOLIDITY);
}
/// Asserts that the `solc` output from compiling Yul contains an EVM blob.
fn assert_evm_blob_from_yul(result: &CommandResult) {
assert_binary_blob(result, "Binary representation:\n", EVM_BLOB_START_FROM_YUL);
}
/// Asserts that the `resolc` output of compiling Solidity from JSON input contains a PVM blob.
/// - `result`: The result of running the command.
/// - `file_name`: The file name of the contract to verify the existence of a PVM blob for (corresponds to the name specified as a `source` in the JSON input).
/// - `contract_name`: The name of the contract to verify the existence of a PVM blob for.
fn assert_pvm_blob_from_json(result: &CommandResult, file_name: &str, contract_name: &str) {
assert_binary_blob_from_json(result, file_name, contract_name, PVM_BLOB_START);
}
/// Asserts that the `solc` output of compiling Solidity from JSON input contains an EVM blob.
/// - `result`: The result of running the command.
/// - `file_name`: The file name of the contract to verify the existence of an EVM blob for (corresponds to the name specified as a `source` in the JSON input).
/// - `contract_name`: The name of the contract to verify the existence of an EVM blob for.
fn assert_evm_blob_from_json(result: &CommandResult, file_name: &str, contract_name: &str) {
assert_binary_blob_from_json(
result,
file_name,
contract_name,
EVM_BLOB_START_FROM_SOLIDITY,
);
}
/// Asserts that the output of a compilation contains a binary blob.
/// - `result`: The result of running the command.
/// - `blob_prefix`: The `stdout` message immediately preceding the binary blob representation.
/// - `blob_start`: The starting hex value of the binary blob.
fn assert_binary_blob(result: &CommandResult, blob_prefix: &str, blob_start: &str) {
assert_command_success(result, "Executing the command");
let is_blob = result
.stdout
.split(blob_prefix)
.collect::<Vec<&str>>()
.get(1)
.is_some_and(|blob| blob.starts_with(blob_start));
assert!(
is_blob,
"expected a binary blob starting with `{blob_start}`",
);
}
/// Asserts that the output of compiling Solidity from JSON input contains a binary blob.
/// - `result`: The result of running the command.
/// - `file_name`: The file name of the contract to verify the existence of a binary blob for (corresponds to the name specified as a `source` in the JSON input).
/// - `contract_name`: The name of the contract to verify the existence of a binary blob for.
/// - `blob_start`: The starting hex value of the binary blob.
///
/// See [output description](https://docs.soliditylang.org/en/latest/using-the-compiler.html#output-description)
/// for more details on the JSON output format.
fn assert_binary_blob_from_json(
result: &CommandResult,
file_name: &str,
contract_name: &str,
blob_start: &str,
) {
assert_command_success(result, "Executing the command with stdin JSON input");
let parsed_output: serde_json::Value =
serde_json::from_str(&result.stdout).expect("expected valid JSON output");
let contract = &parsed_output["contracts"][file_name][contract_name];
let errors = contract["errors"].as_array();
assert!(
errors.is_none(),
"errors found for JSON-provided contract `{contract_name}` in `{file_name}`: {}",
get_first_json_error(errors.unwrap()),
);
let blob = contract["evm"]["bytecode"]["object"]
.as_str()
.unwrap_or_else(|| {
panic!(
"expected a binary blob for JSON-provided contract `{contract_name}` in `{file_name}`",
)
});
assert!(
blob.starts_with(blob_start),
"expected a binary blob starting with `{blob_start}`",
);
}
/// Gets the first error message reported when compiling from JSON input.
///
/// See [output description](https://docs.soliditylang.org/en/latest/using-the-compiler.html#output-description)
/// for more details on the JSON output format.
fn get_first_json_error(errors: &[serde_json::Value]) -> &str {
errors.first().unwrap()["message"].as_str().unwrap()
}
/// This test mimics the command used in the `resolc` benchmarks when compiling Solidity.
#[test]
fn compiles_solidity_to_binary_blob() {
let path = absolute_path(SOLIDITY_CONTRACT_PATH);
let resolc_arguments = &[&path, "--bin", ResolcOptSettings::PERFORMANCE];
let solc_arguments = &[
&path,
"--bin",
"--via-ir",
"--optimize",
"--optimize-runs",
SolcOptSettings::PERFORMANCE,
];
let resolc_result = execute_command(crate::DEFAULT_EXECUTABLE_NAME, resolc_arguments, None);
assert_pvm_blob(&resolc_result);
let solc_result = execute_command(SolcCompiler::DEFAULT_EXECUTABLE_NAME, solc_arguments, None);
assert_evm_blob_from_solidity(&solc_result);
}
/// This test mimics the command used in the `resolc` benchmarks when compiling Yul.
#[test]
fn compiles_yul_to_binary_blob() {
let path = absolute_path(YUL_MEMSET_CONTRACT_PATH);
let resolc_arguments = &[&path, "--yul", "--bin", ResolcOptSettings::PERFORMANCE];
let solc_arguments = &[
&path,
"--strict-assembly",
"--bin",
"--optimize",
"--optimize-runs",
SolcOptSettings::PERFORMANCE,
];
let resolc_result = execute_command(crate::DEFAULT_EXECUTABLE_NAME, resolc_arguments, None);
assert_pvm_blob(&resolc_result);
let solc_result = execute_command(SolcCompiler::DEFAULT_EXECUTABLE_NAME, solc_arguments, None);
assert_evm_blob_from_yul(&solc_result);
}
/// This test mimics the command used in the `resolc` benchmarks when compiling Solidity via standard JSON input.
#[test]
fn compiles_json_to_binary_blob() {
let path = absolute_path(STANDARD_JSON_CONTRACTS_PATH);
let resolc_arguments = &["--standard-json"];
let solc_arguments = &["--standard-json"];
let resolc_result = execute_command(
crate::DEFAULT_EXECUTABLE_NAME,
resolc_arguments,
Some(&path),
);
assert_pvm_blob_from_json(&resolc_result, "src/Counter.sol", "Counter");
let solc_result = execute_command(
SolcCompiler::DEFAULT_EXECUTABLE_NAME,
solc_arguments,
Some(&path),
);
assert_evm_blob_from_json(&solc_result, "src/Counter.sol", "Counter");
}
+32 -33
View File
@@ -2,7 +2,10 @@
use revive_solc_json_interface::CombinedJsonInvalidSelectorMessage;
use crate::tests::cli::utils;
use crate::cli_utils::{
assert_command_failure, assert_equal_exit_codes, execute_resolc, execute_solc,
SOLIDITY_CONTRACT_PATH, YUL_CONTRACT_PATH,
};
const JSON_OPTION: &str = "--combined-json";
const JSON_ARGUMENTS: &[&str] = &[
@@ -21,8 +24,8 @@ const JSON_ARGUMENTS: &[&str] = &[
#[test]
fn runs_with_valid_json_argument() {
for json_argument in JSON_ARGUMENTS {
let arguments = &[utils::SOLIDITY_CONTRACT_PATH, JSON_OPTION, json_argument];
let resolc_result = utils::execute_resolc(arguments);
let arguments = &[SOLIDITY_CONTRACT_PATH, JSON_OPTION, json_argument];
let resolc_result = execute_resolc(arguments);
assert!(
resolc_result.success,
"Providing the `{json_argument}` argument should succeed with exit code {}, got {}.\nDetails: {}",
@@ -36,86 +39,82 @@ fn runs_with_valid_json_argument() {
"Expected the output to contain a `contracts` field when using the `{json_argument}` argument."
);
let solc_result = utils::execute_solc(arguments);
utils::assert_equal_exit_codes(&solc_result, &resolc_result);
let solc_result = execute_solc(arguments);
assert_equal_exit_codes(&solc_result, &resolc_result);
}
}
#[test]
fn fails_with_invalid_json_argument() {
let arguments = &[
utils::SOLIDITY_CONTRACT_PATH,
JSON_OPTION,
"invalid-argument",
];
let resolc_result = utils::execute_resolc(arguments);
utils::assert_command_failure(&resolc_result, "Providing an invalid json argument");
let arguments = &[SOLIDITY_CONTRACT_PATH, JSON_OPTION, "invalid-argument"];
let resolc_result = execute_resolc(arguments);
assert_command_failure(&resolc_result, "Providing an invalid json argument");
assert!(resolc_result
.stderr
.contains(CombinedJsonInvalidSelectorMessage));
let solc_result = utils::execute_solc(arguments);
utils::assert_equal_exit_codes(&solc_result, &resolc_result);
let solc_result = execute_solc(arguments);
assert_equal_exit_codes(&solc_result, &resolc_result);
}
#[test]
fn fails_with_multiple_json_arguments() {
let arguments = &[
utils::SOLIDITY_CONTRACT_PATH,
SOLIDITY_CONTRACT_PATH,
JSON_OPTION,
JSON_ARGUMENTS[0],
JSON_ARGUMENTS[1],
];
let resolc_result = utils::execute_resolc(arguments);
utils::assert_command_failure(&resolc_result, "Providing multiple json arguments");
let resolc_result = execute_resolc(arguments);
assert_command_failure(&resolc_result, "Providing multiple json arguments");
assert!(resolc_result
.stderr
.contains(&format!("Error: \"{}\" is not found.", JSON_ARGUMENTS[1])),);
let solc_result = utils::execute_solc(arguments);
utils::assert_equal_exit_codes(&solc_result, &resolc_result);
let solc_result = execute_solc(arguments);
assert_equal_exit_codes(&solc_result, &resolc_result);
}
#[test]
fn fails_without_json_argument() {
let arguments = &[utils::SOLIDITY_CONTRACT_PATH, JSON_OPTION];
let resolc_result = utils::execute_resolc(arguments);
utils::assert_command_failure(&resolc_result, "Omitting a JSON argument");
let arguments = &[SOLIDITY_CONTRACT_PATH, JSON_OPTION];
let resolc_result = execute_resolc(arguments);
assert_command_failure(&resolc_result, "Omitting a JSON argument");
assert!(resolc_result.stderr.contains(
"a value is required for '--combined-json <COMBINED_JSON>' but none was supplied"
));
let solc_result = utils::execute_solc(arguments);
utils::assert_equal_exit_codes(&solc_result, &resolc_result);
let solc_result = execute_solc(arguments);
assert_equal_exit_codes(&solc_result, &resolc_result);
}
#[test]
fn fails_without_solidity_input_file() {
let arguments = &[JSON_OPTION, JSON_ARGUMENTS[0]];
let resolc_result = utils::execute_resolc(arguments);
utils::assert_command_failure(&resolc_result, "Omitting a Solidity input file");
let resolc_result = execute_resolc(arguments);
assert_command_failure(&resolc_result, "Omitting a Solidity input file");
assert!(resolc_result.stderr.contains("Error: No input files given"),);
let solc_result = utils::execute_solc(arguments);
utils::assert_equal_exit_codes(&solc_result, &resolc_result);
let solc_result = execute_solc(arguments);
assert_equal_exit_codes(&solc_result, &resolc_result);
}
#[test]
fn fails_with_yul_input_file() {
for json_argument in JSON_ARGUMENTS {
let arguments = &[utils::YUL_CONTRACT_PATH, JSON_OPTION, json_argument];
let resolc_result = utils::execute_resolc(arguments);
utils::assert_command_failure(&resolc_result, "Providing a Yul input file");
let arguments = &[YUL_CONTRACT_PATH, JSON_OPTION, json_argument];
let resolc_result = execute_resolc(arguments);
assert_command_failure(&resolc_result, "Providing a Yul input file");
assert!(resolc_result
.stderr
.contains("Error: Expected identifier but got 'StringLiteral'"));
let solc_result = utils::execute_solc(arguments);
utils::assert_equal_exit_codes(&solc_result, &resolc_result);
let solc_result = execute_solc(arguments);
assert_equal_exit_codes(&solc_result, &resolc_result);
}
}
+3 -3
View File
@@ -1,4 +1,4 @@
use crate::tests::cli::utils::{assert_command_success, execute_resolc, DEPENDENCY_CONTRACT_PATH};
use crate::cli_utils::{assert_command_success, execute_resolc, SOLIDITY_DEPENDENCY_CONTRACT_PATH};
/// Test deploy time linking a contract with unresolved factory dependencies.
#[test]
@@ -6,7 +6,7 @@ fn deploy_time_linking_works() {
let temp_dir = tempfile::TempDir::new().unwrap();
let output_directory = temp_dir.path().to_path_buf();
let source_path = temp_dir.path().to_path_buf().join("dependency.sol");
std::fs::copy(DEPENDENCY_CONTRACT_PATH, &source_path).unwrap();
std::fs::copy(SOLIDITY_DEPENDENCY_CONTRACT_PATH, &source_path).unwrap();
assert_command_success(
&execute_resolc(&[
@@ -58,7 +58,7 @@ fn deploy_time_linking_works() {
#[test]
fn emits_unlinked_binary_warning() {
let output = execute_resolc(&[DEPENDENCY_CONTRACT_PATH, "--bin"]);
let output = execute_resolc(&[SOLIDITY_DEPENDENCY_CONTRACT_PATH, "--bin"]);
assert_command_success(&output, "Missing libraries should compile fine");
assert!(output.stderr.contains("is unlinked"));
}
@@ -1,4 +1,4 @@
use crate::tests::cli::utils::{
use crate::cli_utils::{
assert_command_success, execute_resolc, RESOLC_YUL_FLAG, YUL_CONTRACT_PATH,
};
+1 -1
View File
@@ -1,6 +1,7 @@
//! The `resolc` CLI tests.
mod asm;
mod bin;
mod combined_json;
mod linker;
mod llvm_arguments;
@@ -8,5 +9,4 @@ mod optimization;
mod output_dir;
mod standard_json;
mod usage;
mod utils;
mod yul;
+4 -4
View File
@@ -1,7 +1,7 @@
//! The tests for running resolc with explicit optimization.
use crate::tests::cli::utils::{
self, assert_command_failure, assert_command_success, assert_equal_exit_codes, execute_resolc,
use crate::cli_utils::{
assert_command_failure, assert_command_success, assert_equal_exit_codes, execute_resolc,
execute_solc, RESOLC_YUL_FLAG, SOLIDITY_CONTRACT_PATH, SOLIDITY_LARGE_DIV_REM_CONTRACT_PATH,
YUL_MEMSET_CONTRACT_PATH,
};
@@ -13,7 +13,7 @@ fn runs_with_valid_level() {
for level in LEVELS {
let optimization_argument = format!("-O{level}");
let arguments = &[YUL_MEMSET_CONTRACT_PATH, "--yul", &optimization_argument];
let resolc_result = utils::execute_resolc(arguments);
let resolc_result = execute_resolc(arguments);
assert!(
resolc_result.success,
"Providing the level `{optimization_argument}` should succeed with exit code {}, got {}.\nDetails: {}",
@@ -63,7 +63,7 @@ fn test_large_div_rem_expansion() {
for level in LEVELS {
let optimization_argument = format!("-O{level}");
let arguments = &[SOLIDITY_LARGE_DIV_REM_CONTRACT_PATH, &optimization_argument];
let resolc_result = utils::execute_resolc(arguments);
let resolc_result = execute_resolc(arguments);
assert!(
resolc_result.success,
"Providing the level `{optimization_argument}` should succeed with exit code {}, got {}.\nDetails: {}",
+15 -13
View File
@@ -4,7 +4,9 @@ use std::path::Path;
use tempfile::tempdir;
use crate::tests::cli::utils;
use crate::cli_utils::{
assert_command_success, execute_resolc, CommandResult, SOLIDITY_CONTRACT_PATH,
};
const OUTPUT_BIN_FILE_PATH: &str = "contract.sol:C.pvm";
const OUTPUT_ASM_FILE_PATH: &str = "contract.sol:C.pvmasm";
@@ -13,11 +15,11 @@ const OUTPUT_LLVM_UNOPTIMIZED_FILE_PATH: &str =
"src_tests_data_solidity_contract.sol.C.unoptimized.ll";
fn assert_valid_output_file(
result: &utils::CommandResult,
result: &CommandResult,
debug_output_directory: &Path,
output_file_name: &str,
) {
utils::assert_command_success(result, "Providing an output directory");
assert_command_success(result, "Providing an output directory");
assert!(result.stderr.contains("Compiler run successful"),);
@@ -37,7 +39,7 @@ fn assert_valid_output_file(
fn writes_to_file() {
let temp_dir = tempdir().unwrap();
let arguments = &[
utils::SOLIDITY_CONTRACT_PATH,
SOLIDITY_CONTRACT_PATH,
"--overwrite",
"-O3",
"--bin",
@@ -45,7 +47,7 @@ fn writes_to_file() {
"--output-dir",
temp_dir.path().to_str().unwrap(),
];
let result = utils::execute_resolc(arguments);
let result = execute_resolc(arguments);
assert_valid_output_file(&result, temp_dir.path(), OUTPUT_BIN_FILE_PATH);
assert_valid_output_file(&result, temp_dir.path(), OUTPUT_ASM_FILE_PATH);
}
@@ -54,7 +56,7 @@ fn writes_to_file() {
fn writes_debug_info_to_file_unoptimized() {
let temp_dir = tempdir().unwrap();
let arguments = &[
utils::SOLIDITY_CONTRACT_PATH,
SOLIDITY_CONTRACT_PATH,
"-g",
"--disable-solc-optimizer",
"--overwrite",
@@ -63,7 +65,7 @@ fn writes_debug_info_to_file_unoptimized() {
"--output-dir",
temp_dir.path().to_str().unwrap(),
];
let result = utils::execute_resolc(arguments);
let result = execute_resolc(arguments);
assert_valid_output_file(&result, temp_dir.path(), OUTPUT_BIN_FILE_PATH);
assert_valid_output_file(&result, temp_dir.path(), OUTPUT_ASM_FILE_PATH);
}
@@ -72,7 +74,7 @@ fn writes_debug_info_to_file_unoptimized() {
fn writes_debug_info_to_file_optimized() {
let temp_dir = tempdir().unwrap();
let arguments = &[
utils::SOLIDITY_CONTRACT_PATH,
SOLIDITY_CONTRACT_PATH,
"-g",
"--overwrite",
"--bin",
@@ -80,7 +82,7 @@ fn writes_debug_info_to_file_optimized() {
"--output-dir",
temp_dir.path().to_str().unwrap(),
];
let result = utils::execute_resolc(arguments);
let result = execute_resolc(arguments);
assert_valid_output_file(&result, temp_dir.path(), OUTPUT_BIN_FILE_PATH);
assert_valid_output_file(&result, temp_dir.path(), OUTPUT_ASM_FILE_PATH);
}
@@ -89,14 +91,14 @@ fn writes_debug_info_to_file_optimized() {
fn writes_llvm_debug_info_to_file_unoptimized() {
let temp_dir = tempdir().unwrap();
let arguments = &[
utils::SOLIDITY_CONTRACT_PATH,
SOLIDITY_CONTRACT_PATH,
"-g",
"--disable-solc-optimizer",
"--overwrite",
"--debug-output-dir",
temp_dir.path().to_str().unwrap(),
];
let result = utils::execute_resolc(arguments);
let result = execute_resolc(arguments);
assert_valid_output_file(&result, temp_dir.path(), OUTPUT_LLVM_UNOPTIMIZED_FILE_PATH);
}
@@ -104,12 +106,12 @@ fn writes_llvm_debug_info_to_file_unoptimized() {
fn writes_llvm_debug_info_to_file_optimized() {
let temp_dir = tempdir().unwrap();
let arguments = &[
utils::SOLIDITY_CONTRACT_PATH,
SOLIDITY_CONTRACT_PATH,
"-g",
"--overwrite",
"--debug-output-dir",
temp_dir.path().to_str().unwrap(),
];
let result = utils::execute_resolc(arguments);
let result = execute_resolc(arguments);
assert_valid_output_file(&result, temp_dir.path(), OUTPUT_LLVM_OPTIMIZED_FILE_PATH);
}
+1 -1
View File
@@ -2,7 +2,7 @@
use revive_solc_json_interface::SolcStandardJsonOutput;
use crate::tests::cli::utils::{
use crate::cli_utils::{
assert_command_success, assert_equal_exit_codes, execute_resolc_with_stdin_input,
execute_solc_with_stdin_input, STANDARD_JSON_CONTRACTS_PATH, STANDARD_JSON_NO_EVM_CODEGEN_PATH,
};
+12 -9
View File
@@ -1,26 +1,29 @@
//! The tests for running resolc when expecting usage output.
use crate::tests::cli::utils;
use crate::cli_utils::{
assert_command_failure, assert_command_success, assert_equal_exit_codes, execute_resolc,
execute_solc,
};
#[test]
fn shows_usage_with_help() {
let arguments = &["--help"];
let resolc_result = utils::execute_resolc(arguments);
utils::assert_command_success(&resolc_result, "Providing the `--help` option");
let resolc_result = execute_resolc(arguments);
assert_command_success(&resolc_result, "Providing the `--help` option");
assert!(resolc_result.stdout.contains("Usage: resolc"));
let solc_result = utils::execute_solc(arguments);
utils::assert_equal_exit_codes(&solc_result, &resolc_result);
let solc_result = execute_solc(arguments);
assert_equal_exit_codes(&solc_result, &resolc_result);
}
#[test]
fn fails_without_options() {
let resolc_result = utils::execute_resolc(&[]);
utils::assert_command_failure(&resolc_result, "Omitting options");
let resolc_result = execute_resolc(&[]);
assert_command_failure(&resolc_result, "Omitting options");
assert!(resolc_result.stderr.contains("Usage: resolc"));
let solc_result = utils::execute_solc(&[]);
utils::assert_equal_exit_codes(&solc_result, &resolc_result);
let solc_result = execute_solc(&[]);
assert_equal_exit_codes(&solc_result, &resolc_result);
}
+1 -1
View File
@@ -1,6 +1,6 @@
//! The tests for running resolc with yul option.
use crate::tests::cli::utils::{
use crate::cli_utils::{
assert_command_success, assert_equal_exit_codes, execute_resolc, execute_solc, RESOLC_YUL_FLAG,
SOLC_YUL_FLAG, YUL_CONTRACT_PATH,
};
File diff suppressed because one or more lines are too long
@@ -2,9 +2,7 @@
"language": "Yul",
"sources": {
"Test": {
"urls": [
"src/tests/data/yul/Test.yul"
]
"urls": ["src/tests/data/yul/return.yul"]
}
},
"settings": {