From 1c335e570952e0ceeb13b89a67ab9056f74d14e6 Mon Sep 17 00:00:00 2001 From: James Wilson Date: Thu, 14 Aug 2025 10:58:02 +0100 Subject: [PATCH] constants.mod, and Display for CaseIdx to use it --- crates/compiler/src/constants.rs | 4 ++++ crates/compiler/src/lib.rs | 2 ++ crates/compiler/src/revive_resolc.rs | 3 ++- crates/compiler/src/solc.rs | 4 +--- crates/core/src/main.rs | 4 ++-- crates/format/src/case.rs | 6 ++++++ 6 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 crates/compiler/src/constants.rs diff --git a/crates/compiler/src/constants.rs b/crates/compiler/src/constants.rs new file mode 100644 index 0000000..0abd722 --- /dev/null +++ b/crates/compiler/src/constants.rs @@ -0,0 +1,4 @@ +use semver::Version; + +/// This is the first version of solc that supports the `--via-ir` flag / "viaIR" input JSON. +pub const VERSION_SUPPORTING_VIA_IR: Version = Version::new(0, 8, 13); \ No newline at end of file diff --git a/crates/compiler/src/lib.rs b/crates/compiler/src/lib.rs index 9d35476..f7a66c2 100644 --- a/crates/compiler/src/lib.rs +++ b/crates/compiler/src/lib.rs @@ -3,6 +3,8 @@ //! - Polkadot revive resolc compiler //! - Polkadot revive Wasm compiler +mod constants; + use std::{ collections::HashMap, fs::read_to_string, diff --git a/crates/compiler/src/revive_resolc.rs b/crates/compiler/src/revive_resolc.rs index 8209a48..d542e40 100644 --- a/crates/compiler/src/revive_resolc.rs +++ b/crates/compiler/src/revive_resolc.rs @@ -15,6 +15,7 @@ use revive_solc_json_interface::{ }; use crate::{CompilerInput, CompilerOutput, ModeOptimizerSetting, ModePipeline, SolidityCompiler}; +use super::constants::VERSION_SUPPORTING_VIA_IR; use alloy::json_abi::JsonAbi; use anyhow::Context; @@ -246,7 +247,7 @@ impl SolidityCompiler for Resolc { // We only support the Y (IE compile via Yul IR) mode here, which also means that we can // only use solc version 0.8.13 and above. We must always compile via Yul IR as resolc // needs this to translate to LLVM IR and then RISCV. - pipeline == ModePipeline::Y && compiler_version >= &Version::new(0, 8, 13) + pipeline == ModePipeline::Y && compiler_version >= &VERSION_SUPPORTING_VIA_IR } } diff --git a/crates/compiler/src/solc.rs b/crates/compiler/src/solc.rs index 993bf0d..c8df146 100644 --- a/crates/compiler/src/solc.rs +++ b/crates/compiler/src/solc.rs @@ -11,6 +11,7 @@ use revive_dt_config::Arguments; use revive_dt_solc_binaries::download_solc; use crate::{CompilerInput, CompilerOutput, ModeOptimizerSetting, ModePipeline, SolidityCompiler}; +use super::constants::VERSION_SUPPORTING_VIA_IR; use anyhow::Context; use foundry_compilers_artifacts::{ @@ -23,9 +24,6 @@ use foundry_compilers_artifacts::{ use semver::Version; use tokio::{io::AsyncWriteExt, process::Command as AsyncCommand}; -/// This is the first version of solc that supports the `--via-ir` flag / "viaIR" input JSON. -const VERSION_SUPPORTING_VIA_IR: Version = Version::new(0, 8, 13); - #[derive(Debug)] pub struct Solc { solc_path: PathBuf, diff --git a/crates/core/src/main.rs b/crates/core/src/main.rs index 3d854ca..5ad9a50 100644 --- a/crates/core/src/main.rs +++ b/crates/core/src/main.rs @@ -56,7 +56,7 @@ struct Test { metadata: Metadata, path: PathBuf, mode: Mode, - case_idx: usize, + case_idx: CaseIdx, case: Case, } @@ -231,7 +231,7 @@ where metadata: metadata.clone(), path: metadata_file_path.to_path_buf(), mode: solc_mode, - case_idx, + case_idx: case_idx.into(), case: case.clone(), } }) diff --git a/crates/format/src/case.rs b/crates/format/src/case.rs index 9a7d577..77c5d46 100644 --- a/crates/format/src/case.rs +++ b/crates/format/src/case.rs @@ -67,3 +67,9 @@ define_wrapper_type!( #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct CaseIdx(usize); ); + +impl std::fmt::Display for CaseIdx { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.0) + } +} \ No newline at end of file