foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.31k stars 1.76k forks source link

Permit "default" as value for "optimizerSteps" #3904

Open PaulRBerg opened 1 year ago

PaulRBerg commented 1 year ago

Component

Forge

Describe the feature you would like

The default Yul optimizer step sequence is quite long-winded - even in the Solidity source code, the default value is split on multiple lines for readability purposes.

My feature request is to make it possible to pass the default value to the optimizerSteps field in the Foundry config, so that users don't have to manually write it up:

[profile.default.optimizer_details.yulDetails]
stackAllocation = true
optimizerSteps = "default"

This is useful because users may want to disable the default step sequence during development (i.e. in the default profile) in order to speed up the compilation time. But then, in a separate profile such as production, users may want to set the step sequence back to the default to get maximum optimization benefits.

Additional context

See the conversation here.

mattsse commented 1 year ago

supportive of that!

mds1 commented 1 year ago

One caveat here is that it's possible the default sequence of optimizer steps will change between solc versions, and if so we'd need to stay on top of that with each solc release and maintain a mapping from version to step sequence. (Or, maybe it's unlikely to change / will never change, not sure)

PaulRBerg commented 1 year ago

Yeah, it's possible that the default sequence will change with time. In this case, I suggest maintaining a mapping as you @mds1 suggest, and throwing an error for those versions for which there is no default value available in Foundry.

cameel commented 1 year ago

Why not just omit the option from the JSON passed to the compiler (or from its CLI arguments) when it's set to "default"? You would not have to keep the mapping. Changes to the sequence aren't rare, especially when we're tweaking the optimizer.

By the way, using specifically "default" to indicate the default does not seem like a good idea because it's in fact a valid sequence: VarDeclInitializer, ExpressionInliner, BlockFlattener, SSATransform, UnusedPruner, CircularReferencesPruner, StructuralSimplifier. :)