-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix(coverage): add new option "--ir-minimum" to resolve the "stack too deep" error #5349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,11 +28,12 @@ use forge::{ | |
MultiContractRunnerBuilder, TestOptions, | ||
}; | ||
use foundry_common::{compile::ProjectCompiler, evm::EvmArgs, fs}; | ||
use foundry_config::Config; | ||
use foundry_config::{Config, SolcReq}; | ||
use foundry_evm::utils::evm_spec; | ||
use semver::Version; | ||
use std::{collections::HashMap, sync::mpsc::channel}; | ||
use tracing::trace; | ||
use yansi::Paint; | ||
|
||
// Loads project's figment and merges the build cli arguments into it | ||
foundry_config::impl_figment_convert!(CoverageArgs, opts, evm_opts); | ||
|
@@ -46,6 +47,13 @@ pub struct CoverageArgs { | |
#[clap(long, value_enum, default_value = "summary")] | ||
report: Vec<CoverageReportKind>, | ||
|
||
/// Enable viaIR with minimum optimization | ||
/// | ||
/// This can fix most of the "stack too deep" errors while resulting a | ||
/// relatively accurate source map. | ||
#[clap(long)] | ||
ir_minimum: bool, | ||
|
||
#[clap(flatten)] | ||
filter: FilterArgs, | ||
|
||
|
@@ -96,11 +104,41 @@ impl CoverageArgs { | |
let project = { | ||
let mut project = config.ephemeral_no_artifacts_project()?; | ||
|
||
// Disable the optimizer for more accurate source maps | ||
project.solc_config.settings.optimizer.disable(); | ||
project.solc_config.settings.optimizer.runs = None; | ||
project.solc_config.settings.optimizer.details = None; | ||
project.solc_config.settings.via_ir = None; | ||
if self.ir_minimum { | ||
// TODO: How to detect solc version if the user does not specify a solc version in | ||
// config case1: specify local installed solc ? | ||
// case2: mutliple solc versions used and auto_detect_solc == true | ||
Comment on lines
+108
to
+110
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can ignore this this, all options are sanitized in ethers-solc depending on version, meaning unsupported options are removed before calling solc |
||
if let Some(SolcReq::Version(version)) = &config.solc { | ||
if *version < Version::new(0, 8, 13) { | ||
return Err(eyre::eyre!( | ||
"viaIR with minimum optimization is only available in Solidity 0.8.13 and above." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great! |
||
)); | ||
} | ||
} | ||
|
||
// print warning message | ||
p_println!(!self.opts.silent => "{}", | ||
Paint::yellow( | ||
concat!( | ||
"Warning! \"--ir-minimum\" flag enables viaIR with minimum optimization, which can result in inaccurate source mappings.\n", | ||
"Only use this flag as a workaround if you are experiencing \"stack too deep\" errors.\n", | ||
"Note that \"viaIR\" is only available in Solidity 0.8.13 and above.\n", | ||
"See more:\n", | ||
"https://github.com/foundry-rs/foundry/issues/3357\n" | ||
))); | ||
Comment on lines
+120
to
+128
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Evalir CLI warning added |
||
|
||
// Enable viaIR with minimum optimization | ||
// https://github.com/ethereum/solidity/issues/12533#issuecomment-1013073350 | ||
// And also in new releases of solidity: | ||
// https://github.com/ethereum/solidity/issues/13972#issuecomment-1628632202 | ||
project.solc_config.settings = | ||
project.solc_config.settings.with_via_ir_minimum_optimization() | ||
} else { | ||
project.solc_config.settings.optimizer.disable(); | ||
project.solc_config.settings.optimizer.runs = None; | ||
project.solc_config.settings.optimizer.details = None; | ||
project.solc_config.settings.via_ir = None; | ||
} | ||
|
||
project | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vir-ir
andir-minimum
will only work in solidity 0.8.13 and above.I don't find a better way to reject the unsatisfied compilers.