Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ cd ape-solidity
python3 -m venv venv
source venv/bin/activate

#install setuptools
pip install setuptools

# install ape-solidity into the virtual environment
python setup.py install

Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,22 @@ solidity:
via_ir: True
```

#### Yul Optimization

You can enable `solc`'s `--yul` flag by adding the following values to your `ape-config.yaml`

```yaml
solidity:
optimization_yul: True
```

You can also set the optimizer steps by adding the following values to your `ape-config.yaml`. You can find the list of optimizer steps [here](https://docs.soliditylang.org/en/v0.8.22/using-the-compiler.html#optimizer-steps). This requires the yul optimizer to be enabled.

```yaml
solidity:
optimization_steps: "dhfoDgvulfnTUtnIf"
```

### Contract Flattening

`ape-solidity` has contract-flattening capabilities.
Expand Down
27 changes: 27 additions & 0 deletions ape_solidity/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,20 @@ class SolidityConfig(PluginConfig):
the compiler (same as ``False``).
"""

optimization_yul: Optional[bool] = None
"""
Set to ``True`` to turn on Yul optimization.
Defaults to ``None`` which does not pass the flag to
the compiler (same as ``False``).
"""

optimization_steps: Optional[str] = None
"""
Set to a string of optimizer steps to use.
Defaults to ``None`` which does not pass the flag to
the compiler (same as ``False``).
"""


def _get_flattened_source(path: Path, name: Optional[str] = None) -> str:
name = name or path.name
Expand Down Expand Up @@ -361,6 +375,19 @@ def _get_settings_from_version_map(
if solc_version >= Version("0.7.5") and config.via_ir is not None:
version_settings["viaIR"] = config.via_ir

if config.optimization_yul is not None:
if solc_version >= Version("0.8.22"):
version_settings["optimizer"]["yul"] = config.optimization_yul
if (
config.optimization_steps is not None
): # needs yul so is inside the yul check
version_settings["optimizer"]["steps"] = config.optimization_steps
else:
logger.warning(
"""Yul optimization and steps are not supported for this version of solc
(Need >= 0.8.22)."""
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this likely needs some changes up here https://github.com/ApeWorX/ape-solidity/pull/162/files#diff-de61acbec749a43c9ae1590d091b2924af42588fa689b9cef657a9e02f39e016R359

Maybe move it here to be:

Suggested change
else:
version_settings["optimzer"].update({"enabled": config.optimize, "runs": config.optimization_runs})

(Also remove the setting above it and change the type hint for version_settings to just dict

settings[solc_version] = version_settings

# TODO: Filter out libraries that are not used for this version.
Expand Down
Loading