|
1 | 1 | use super::{ |
2 | | - CompilationError, Compiler, CompilerInput, CompilerOutput, CompilerSettings, CompilerVersion, |
3 | | - Language, ParsedSource, |
| 2 | + restrictions::CompilerSettingsRestrictions, CompilationError, Compiler, CompilerInput, |
| 3 | + CompilerOutput, CompilerSettings, CompilerVersion, Language, ParsedSource, |
4 | 4 | }; |
5 | | -use crate::{resolver::parse::SolData, CompilerSettingsRestrictions}; |
| 5 | +use crate::resolver::parse::SolData; |
6 | 6 | pub use foundry_compilers_artifacts::SolcLanguage; |
7 | 7 | use foundry_compilers_artifacts::{ |
8 | 8 | error::SourceLocation, |
9 | 9 | output_selection::OutputSelection, |
10 | 10 | remappings::Remapping, |
| 11 | + serde_helpers::display_from_str_opt, |
11 | 12 | sources::{Source, Sources}, |
12 | 13 | Error, EvmVersion, Settings, Severity, SolcInput, |
13 | 14 | }; |
@@ -190,9 +191,11 @@ impl DerefMut for SolcSettings { |
190 | 191 | } |
191 | 192 | } |
192 | 193 |
|
193 | | -#[derive(Debug, Clone, Copy, Default)] |
| 194 | +#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, Eq, PartialEq)] |
194 | 195 | pub struct EvmVersionRestriction { |
| 196 | + #[serde(default, with = "display_from_str_opt", skip_serializing_if = "Option::is_none")] |
195 | 197 | pub min_evm_version: Option<EvmVersion>, |
| 198 | + #[serde(default, with = "display_from_str_opt", skip_serializing_if = "Option::is_none")] |
196 | 199 | pub max_evm_version: Option<EvmVersion>, |
197 | 200 | } |
198 | 201 |
|
@@ -226,6 +229,8 @@ impl EvmVersionRestriction { |
226 | 229 | pub struct SolcRestrictions { |
227 | 230 | pub evm_version: EvmVersionRestriction, |
228 | 231 | pub via_ir: Option<bool>, |
| 232 | + pub min_optimizer_runs: Option<usize>, |
| 233 | + pub max_optimizer_runs: Option<usize>, |
229 | 234 | } |
230 | 235 |
|
231 | 236 | impl CompilerSettingsRestrictions for SolcRestrictions { |
@@ -305,6 +310,12 @@ impl CompilerSettings for SolcSettings { |
305 | 310 | satisfies &= restrictions.evm_version.satisfies(self.evm_version); |
306 | 311 | satisfies &= |
307 | 312 | restrictions.via_ir.map_or(true, |via_ir| via_ir == self.via_ir.unwrap_or_default()); |
| 313 | + satisfies &= restrictions |
| 314 | + .min_optimizer_runs |
| 315 | + .map_or(true, |min| self.optimizer.runs.map_or(false, |runs| runs >= min)); |
| 316 | + satisfies &= restrictions |
| 317 | + .max_optimizer_runs |
| 318 | + .map_or(true, |max| self.optimizer.runs.map_or(false, |runs| runs <= max)); |
308 | 319 |
|
309 | 320 | satisfies |
310 | 321 | } |
|
0 commit comments