Compare commits

..

8 Commits

Author SHA1 Message Date
Omar Abdulla 425e970eb1 Make the all field of Selection public 2025-07-25 14:54:16 +03:00
dependabot[bot] 56aadce0a9 Bump @eslint/plugin-kit from 0.3.1 to 0.3.3 (#363)
Bumps
[@eslint/plugin-kit](https://github.com/eslint/rewrite/tree/HEAD/packages/plugin-kit)
from 0.3.1 to 0.3.3.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/eslint/rewrite/releases"><code>@​eslint/plugin-kit</code>'s
releases</a>.</em></p>
<blockquote>
<h2>plugin-kit: v0.3.3</h2>
<h2><a
href="https://github.com/eslint/rewrite/compare/plugin-kit-v0.3.2...plugin-kit-v0.3.3">0.3.3</a>
(2025-06-25)</h2>
<h3>Dependencies</h3>
<ul>
<li>The following workspace dependencies were updated
<ul>
<li>dependencies
<ul>
<li><code>@​eslint/core</code> bumped from ^0.15.0 to ^0.15.1</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2>plugin-kit: v0.3.2</h2>
<h2><a
href="https://github.com/eslint/rewrite/compare/plugin-kit-v0.3.1...plugin-kit-v0.3.2">0.3.2</a>
(2025-06-09)</h2>
<h3>Dependencies</h3>
<ul>
<li>The following workspace dependencies were updated
<ul>
<li>dependencies
<ul>
<li><code>@​eslint/core</code> bumped from ^0.14.0 to ^0.15.0</li>
</ul>
</li>
</ul>
</li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/eslint/rewrite/blob/main/packages/plugin-kit/CHANGELOG.md"><code>@​eslint/plugin-kit</code>'s
changelog</a>.</em></p>
<blockquote>
<h2><a
href="https://github.com/eslint/rewrite/compare/plugin-kit-v0.3.2...plugin-kit-v0.3.3">0.3.3</a>
(2025-06-25)</h2>
<h3>Dependencies</h3>
<ul>
<li>The following workspace dependencies were updated
<ul>
<li>dependencies
<ul>
<li><code>@​eslint/core</code> bumped from ^0.15.0 to ^0.15.1</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2><a
href="https://github.com/eslint/rewrite/compare/plugin-kit-v0.3.1...plugin-kit-v0.3.2">0.3.2</a>
(2025-06-09)</h2>
<h3>Dependencies</h3>
<ul>
<li>The following workspace dependencies were updated
<ul>
<li>dependencies
<ul>
<li><code>@​eslint/core</code> bumped from ^0.14.0 to ^0.15.0</li>
</ul>
</li>
</ul>
</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/eslint/rewrite/commit/0496201974aad87fdcf3aa2a63ec74e91b54825e"><code>0496201</code></a>
chore: release main (<a
href="https://github.com/eslint/rewrite/tree/HEAD/packages/plugin-kit/issues/229">#229</a>)</li>
<li><a
href="https://github.com/eslint/rewrite/commit/f5e6d683ee00b24b98777291c0a9a83719fe3402"><code>f5e6d68</code></a>
chore: hoist cli tools to root level (<a
href="https://github.com/eslint/rewrite/tree/HEAD/packages/plugin-kit/issues/224">#224</a>)</li>
<li><a
href="https://github.com/eslint/rewrite/commit/48b1f849476582257e1b6a110c4af55adbbec2e8"><code>48b1f84</code></a>
chore: release main (<a
href="https://github.com/eslint/rewrite/tree/HEAD/packages/plugin-kit/issues/216">#216</a>)</li>
<li><a
href="https://github.com/eslint/rewrite/commit/147afec6be22b6ed4151c1e0a8fc40c061d626d6"><code>147afec</code></a>
chore: update <code>package.json</code> to follow template (<a
href="https://github.com/eslint/rewrite/tree/HEAD/packages/plugin-kit/issues/225">#225</a>)</li>
<li><a
href="https://github.com/eslint/rewrite/commit/0a6aad0a70cc7261a303df614a4466e0b1f525b8"><code>0a6aad0</code></a>
docs: fix bun command and update documentation (<a
href="https://github.com/eslint/rewrite/tree/HEAD/packages/plugin-kit/issues/222">#222</a>)</li>
<li><a
href="https://github.com/eslint/rewrite/commit/2a8913cdae0aa57dfea993256dbe6a04029909da"><code>2a8913c</code></a>
docs: Update README sponsors</li>
<li><a
href="https://github.com/eslint/rewrite/commit/cb858ffb8b77ea76187a857546c7a838a1fb4881"><code>cb858ff</code></a>
refactor: update and fix error types in JSDoc comments (<a
href="https://github.com/eslint/rewrite/tree/HEAD/packages/plugin-kit/issues/213">#213</a>)</li>
<li><a
href="https://github.com/eslint/rewrite/commit/4ec089e5b60d64f695d09a973dbc4eb72026f112"><code>4ec089e</code></a>
docs: Update README sponsors</li>
<li><a
href="https://github.com/eslint/rewrite/commit/1ddb2ed129e2999c2164f933282d8df1884bbd6c"><code>1ddb2ed</code></a>
docs: Update README sponsors</li>
<li><a
href="https://github.com/eslint/rewrite/commit/aa6a48b789a5a48eb405c03502a71e5879905876"><code>aa6a48b</code></a>
docs: Update README sponsors</li>
<li>See full diff in <a
href="https://github.com/eslint/rewrite/commits/plugin-kit-v0.3.3/packages/plugin-kit">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=@eslint/plugin-kit&package-manager=npm_and_yarn&previous-version=0.3.1&new-version=0.3.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/paritytech/revive/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: xermicus <cyrill@parity.io>
2025-07-22 18:45:52 +02:00
xermicus 9751481f6b the revive-explorer utility (#364)
A maintainable and more precise version of what was a hacky but useful
script, exploring the compilers YUL lowering unit.

It analyzes a given shared objects from the debug dump and outputs:
- The count of each YUL statement translated.
- A per YUL statement break-down of bytecode size contributed per.
- Estimated `yul-phaser` cost parameters.

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-07-22 09:17:55 +02:00
xermicus c285a6ec3d add columns to debug information (#362)
- Add column numbers to debug information.
- Do not build allocas at entry for now.

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-07-17 09:53:54 +02:00
xermicus a0396dd6d0 solc-json-interface: support for YUL optimizer details (#361)
- Add support for the YUL optimizer details in the standard json input
definition.
- Make optimizer settings optional. They can be omitted and solc will
pick default values ([see here for
reference](https://docs.soliditylang.org/en/latest/using-the-compiler.html#input-description)).

For example allows to use the
[`yul-phaser`](https://github.com/ethereum/solidity/blob/0917604a5ec7cff8bd40a1137f4fcb303fb90527/tools/yulPhaser/README.md?plain=1)
utility. I did a single search with slightly adjusted costs (just made
some educated guess) and after an hour or so this already found an
optimizer sequence
(`OESsShMxeoufcSTvlFxtelTfnfEvicdFxnsvopgCaIeLcnvsTtUrUgdVTUttaeUomccTTTuujsVVvVDvvueUrTjUOmjrrhuuTtj`)
which shrinks the size of the `EndpointV2.sol` from LayerZero by 10%.

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Signed-off-by: xermicus <cyrill@parity.io>
2025-07-14 11:25:45 +02:00
Alexander Samusev 141a8b752c Make nigthly version semver compliant (#360)
cc https://github.com/paritytech/revive/pull/357
2025-07-08 17:17:05 +02:00
Alexander Samusev 7c932f719b Generate nightly builds and json files (#357)
PR adds a nightly release pipeline.
Since the logic for the nightly build and release differs significantly
from the usual pipeline, I decided to put it in a separate file. The
same applies to the Python script that generates JSON files.

The nightly pipeline runs at 01:00 UTC every day, producing artefacts
and retaining them for 40 days if commits are made the day before it
runs.

cc https://github.com/paritytech/revive/issues/355
cc https://github.com/paritytech/devops/issues/4141
2025-07-07 17:46:55 +02:00
xermicus b238913a7d emit YUL builtins debug line info and fix debug info source file (#358)
This PR fixes and enhances debug info generation:
1. Adds line information for each lowered YUL builtin and the `if`
statement.
2. Fixes the debug info source path to match the YUL file of the
contract dumped to the `--debug-output-dir`.

This improves inspection of the generated code a lot. Excerpt from
`llvm-objdump -Sl /tmp/dbg/contracts_EndpointV2.sol.EndpointV2.so`:

```
; /tmp/dbg/contracts_EndpointV2.sol.EndpointV2.yul:203
;                 let _1 := memoryguard(0x80)
   13c3e: 3aa5b023      sd      a0, 0x3a0(a1)
   13c42: 38a5bc23      sd      a0, 0x398(a1)
   13c46: 38a5b823      sd      a0, 0x390(a1)
   13c4a: 08000513      li      a0, 0x80
   13c4e: 38a5b423      sd      a0, 0x388(a1)
; /tmp/dbg/contracts_EndpointV2.sol.EndpointV2.yul:204
;                 mstore(64, _1)
   13c52: 3885b503      ld      a0, 0x388(a1)
   13c56: 3905b603      ld      a2, 0x390(a1)
   13c5a: 3985b683      ld      a3, 0x398(a1)
   13c5e: 3a05b703      ld      a4, 0x3a0(a1)
   13c62: 38e5b023      sd      a4, 0x380(a1)
   13c66: 36d5bc23      sd      a3, 0x378(a1)
   13c6a: 36c5b823      sd      a2, 0x370(a1)
   13c6e: 36a5b423      sd      a0, 0x368(a1)
   13c72: 04000513      li      a0, 0x40
   13c76: 65d9          lui     a1, 0x16
   13c78: a605859b      addiw   a1, a1, -0x5a0
   13c7c: 95a6          add     a1, a1, s1
   13c7e: 00000097      auipc   ra, 0x0
   13c82: 000080e7      jalr    ra <__runtime+0x1de>

0000000000013c86 <.Lpcrel_hi27>:
; /tmp/dbg/contracts_EndpointV2.sol.EndpointV2.yul:205
;                 if iszero(lt(calldatasize(), 4))
   13c86: 00000517      auipc   a0, 0x0
   13c8a: 00053503      ld      a0, 0x0(a0)
   13c8e: 4108          lw      a0, 0x0(a0)
   13c90: 4591          li      a1, 0x4
   13c92: 06b56263      bltu    a0, a1, 0x13cf6 <.Lpcrel_hi27+0x70>
   13c96: a009          j       0x13c98 <.Lpcrel_hi27+0x12>
```

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-07-04 19:56:52 +02:00
51 changed files with 1569 additions and 256 deletions
+10
View File
@@ -1,3 +1,13 @@
#!/usr/bin/env python3
"""
This script generates JSON files for different platforms based on GitHub release data.
It fetches release information from a specified GitHub repository and tag,
parses the release assets, and generates JSON files for each platform with relevant metadata.
It also handles checksum files and updates a list.json file for each platform.
It requires the GITHUB_TOKEN environment variable to be set for authentication.
Usage:
python json_generator.py <repo> <tag>
"""
import os
import sys
import json
+155
View File
@@ -0,0 +1,155 @@
#!/usr/bin/env python3
"""
This script generates JSON files for different platforms based on GitHub data.
Requires the GITHUB_SHA, FIRST_SOLC_VERSION, LAST_SOLC_VERSION, TAG and FILEPATH environment variables to be set.
Usage:
python json_generator_nightly.py
"""
import os
import sys
import json
from datetime import datetime
def validate_env_variables():
"""Validate that environment variables are set."""
if "GITHUB_SHA" not in os.environ:
print("Error: GITHUB_SHA environment variable is not set.")
sys.exit(1)
if "FIRST_SOLC_VERSION" not in os.environ:
print("Error: FIRST_SOLC_VERSION environment variable is not set.")
sys.exit(1)
if "LAST_SOLC_VERSION" not in os.environ:
print("Error: LAST_SOLC_VERSION environment variable is not set.")
sys.exit(1)
if "TAG" not in os.environ:
print("Error: TAG environment variable is not set.")
sys.exit(1)
if "FILEPATH" not in os.environ:
print("Error: FILEPATH environment variable is not set.")
sys.exit(1)
def fetch_data_file():
"""
Fetch the data.json file with artifacts urls and sha256 checksums
and parse it into a single dictionary mapping artifact names to their URLs and SHAs.
"""
# read data.json file
artifacts_data = {}
data_file_path = os.environ["FILEPATH"]
if not os.path.exists(data_file_path):
print("Error: data.json file not found.")
sys.exit(1)
with open(data_file_path, 'r') as f:
try:
artifacts_data = json.load(f)
except json.JSONDecodeError:
print("Error: data.json file is not a valid JSON.")
sys.exit(1)
result = {}
for item in artifacts_data:
for key, value in item.items():
if key.endswith('_url'):
base_key = key.rsplit('_url', 1)[0]
if base_key not in result:
result[base_key] = {}
result[base_key]['url'] = value
elif key.endswith('_sha'):
base_key = key.rsplit('_sha', 1)[0]
if base_key not in result:
result[base_key] = {}
result[base_key]['sha'] = value
return result
def extract_build_hash():
"""Extract the first 8 characters of the commit hash."""
sha = os.environ.get("GITHUB_SHA")
return f"commit.{sha[:8]}"
def generate_asset_json_nightly(name, url, checksum):
"""Generate JSON for a specific asset."""
# Date in format YYYY-MM-DD
date = datetime.now().strftime("%Y.%-m.%-d")
last_version = os.environ.get("TAG").replace('v','')
version = f"{last_version}-nightly.{date}"
SHA = os.environ.get("GITHUB_SHA", "")[:8]
build = f"commit.{SHA}"
long_version = f"{version}+{build}"
return {
"name": name,
"version": version,
"build": build,
"longVersion": long_version,
"url": url,
"sha256": checksum,
"firstSolcVersion": os.environ.get("FIRST_SOLC_VERSION"),
"lastSolcVersion": os.environ.get("LAST_SOLC_VERSION")
}
def save_platform_json(platform_folder, asset_json):
"""Save asset JSON and update list.json for a specific platform."""
# Create platform folder if it doesn't exist
os.makedirs(platform_folder, exist_ok=True)
# Update or create list.json
list_file_path = os.path.join(platform_folder, "list.json")
if os.path.exists(list_file_path):
with open(list_file_path, 'r') as f:
try:
list_data = json.load(f)
except json.JSONDecodeError:
list_data = {"builds": [], "releases": {}, "latestRelease": ""}
else:
list_data = {"builds": [], "releases": {}, "latestRelease": ""}
# Remove any existing entry with the same path
list_data['builds'] = [
build for build in list_data['builds']
if build['version'] != asset_json['version']
]
# Add the new build
list_data['builds'].append(asset_json)
# Update releases
version = asset_json['version']
list_data['releases'][version] = f"{asset_json['name']}+{asset_json['longVersion']}"
# Update latest release
list_data['latestRelease'] = version
with open(list_file_path, 'w') as f:
json.dump(list_data, f, indent=4)
def main():
validate_env_variables()
data = fetch_data_file()
# Mapping of asset names to platform folders
platform_mapping = {
'resolc-x86_64-unknown-linux-musl': 'linux',
'resolc-universal-apple-darwin': 'macos',
'resolc-x86_64-pc-windows-msvc': 'windows',
'resolc-web.js': 'wasm'
}
# Process each asset
for asset in data.keys():
platform_name = platform_mapping.get(asset)
if platform_name:
platform_folder = os.path.join(platform_name)
asset_json = generate_asset_json_nightly(asset, data[asset]['url'], data[asset]['sha'])
save_platform_json(platform_folder, asset_json)
print(f"Processed {asset} for {platform_name}")
if __name__ == "__main__":
main()
+385
View File
@@ -0,0 +1,385 @@
name: Nightly Release
on:
schedule:
# Run every day at 01:00 UTC
- cron: "0 1 * * *"
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
RUST_MUSL_CROSS_IMAGE: messense/rust-musl-cross@sha256:c0154e992adb791c3b848dd008939d19862549204f8cb26f5ca7a00f629e6067
jobs:
# check if there were commits yesterday
check_commits:
runs-on: ubuntu-latest
outputs:
has_commits: ${{ steps.check_commits.outputs.has_commits }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full history to check previous commits
ref: "main"
- name: Check for commits from yesterday
id: check_commits
run: |
# Get yesterday's date in YYYY-MM-DD format
YESTERDAY=$(date -d "yesterday" +%Y-%m-%d)
echo "Checking for commits from: $YESTERDAY"
# Check if there were any commits yesterday
COMMIT_COUNT=$(git log --oneline --since="$YESTERDAY 00:00:00" --until="$YESTERDAY 23:59:59" | wc -l)
echo "Found $COMMIT_COUNT commits from yesterday"
if [ $COMMIT_COUNT -gt 0 ]; then
echo "has_commits=true" >> $GITHUB_OUTPUT
echo "✅ Found $COMMIT_COUNT commits from yesterday - continuing workflow"
else
echo "has_commits=false" >> $GITHUB_OUTPUT
echo "❌ No commits found from yesterday - skipping remaining steps"
echo "::notice::❌ No commits found from yesterday - skipping remaining steps"
fi
build:
# github actions matrix jobs don't support multiple outputs
# ugly workaround from https://github.com/orgs/community/discussions/17245#discussioncomment-11222880
if: ${{ needs.check_commits.outputs.has_commits == 'true' }}
outputs:
resolc-x86_64-unknown-linux-musl_url: ${{ steps.set-output.outputs.resolc-x86_64-unknown-linux-musl_url }}
resolc-x86_64-unknown-linux-musl_sha: ${{ steps.set-output.outputs.resolc-x86_64-unknown-linux-musl_sha }}
resolc-aarch64-apple-darwin_url: ${{ steps.set-output.outputs.resolc-aarch64-apple-darwin_url }}
resolc-aarch64-apple-darwin_sha: ${{ steps.set-output.outputs.resolc-aarch64-apple-darwin_sha }}
resolc-x86_64-apple-darwin_url: ${{ steps.set-output.outputs.resolc-x86_64-apple-darwin_url }}
resolc-x86_64-apple-darwin_sha: ${{ steps.set-output.outputs.resolc-x86_64-apple-darwin_sha }}
resolc-x86_64-pc-windows-msvc_url: ${{ steps.set-output.outputs.resolc-x86_64-pc-windows-msvc_url }}
resolc-x86_64-pc-windows-msvc_sha: ${{ steps.set-output.outputs.resolc-x86_64-pc-windows-msvc_sha }}
strategy:
matrix:
target:
[
x86_64-unknown-linux-musl,
aarch64-apple-darwin,
x86_64-apple-darwin,
x86_64-pc-windows-msvc,
]
include:
- target: x86_64-unknown-linux-musl
type: musl
runner: ubuntu-24.04
- target: aarch64-apple-darwin
type: native
runner: macos-14
- target: x86_64-apple-darwin
type: native
runner: macos-13
- target: x86_64-pc-windows-msvc
type: native
runner: windows-2022
runs-on: ${{ matrix.runner }}
needs: [check_commits]
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
# without this it will override our rust flags
rustflags: ""
cache-key: ${{ matrix.target }}
- name: Download LLVM
uses: ./.github/actions/get-llvm
with:
target: ${{ matrix.target }}
- name: Build
if: ${{ matrix.type == 'native' }}
shell: bash
run: |
export LLVM_SYS_181_PREFIX=$PWD/llvm-${{ matrix.target }}
make install-bin
mv target/release/resolc resolc-${{ matrix.target }} || mv target/release/resolc.exe resolc-${{ matrix.target }}.exe
- name: Build
if: ${{ matrix.type == 'musl' }}
run: |
docker run -v $PWD:/opt/revive $RUST_MUSL_CROSS_IMAGE /bin/bash -c "
cd /opt/revive
chown -R root:root .
apt update && apt upgrade -y && apt install -y pkg-config
export LLVM_SYS_181_PREFIX=/opt/revive/llvm-${{ matrix.target }}
make install-bin
mv target/${{ matrix.target }}/release/resolc resolc-${{ matrix.target }}
"
sudo chown -R $(id -u):$(id -g) .
- name: Install Solc
uses: ./.github/actions/get-solc
- name: Basic Sanity Check
shell: bash
run: |
result=$(./resolc-${{ matrix.target }} --bin crates/integration/contracts/flipper.sol)
echo $result
if [[ $result == *'0x50564d'* ]]; then exit 0; else exit 1; fi
- name: Upload artifacts (nightly)
uses: actions/upload-artifact@v4
id: artifact-upload-step
with:
name: resolc-${{ matrix.target }}
path: resolc-${{ matrix.target }}*
retention-days: 40
- name: Set output variables (nightly)
id: set-output
shell: bash
run: |
echo "Artifact URL is ${{ steps.artifact-upload-step.outputs.artifact-url }}"
echo "Artifact SHA is ${{ steps.artifact-upload-step.outputs.artifact-digest }}"
echo "resolc-${{ matrix.target }}_url=${{ steps.artifact-upload-step.outputs.artifact-url }}"
echo "resolc-${{ matrix.target }}_url=${{ steps.artifact-upload-step.outputs.artifact-url }}" >> "$GITHUB_OUTPUT"
echo "resolc-${{ matrix.target }}_sha=${{ steps.artifact-upload-step.outputs.artifact-digest }}"
echo "resolc-${{ matrix.target }}_sha=${{ steps.artifact-upload-step.outputs.artifact-digest }}" >> "$GITHUB_OUTPUT"
build-wasm:
runs-on: ubuntu-24.04
needs: [check_commits]
if: ${{ needs.check_commits.outputs.has_commits == 'true' }}
outputs:
resolc-web.js_url: ${{ steps.set-output.outputs.resolc_web_js_url }}
resolc-web.js_sha: ${{ steps.set-output.outputs.resolc_web_js_sha }}
env:
RELEASE_RESOLC_WASM_URI: https://github.com/paritytech/revive/releases/download/${{ github.ref_name }}/resolc.wasm
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: wasm32-unknown-emscripten
# without this it will override our rust flags
rustflags: ""
- name: Download Host LLVM
uses: ./.github/actions/get-llvm
with:
target: x86_64-unknown-linux-gnu
- name: Download Wasm LLVM
uses: ./.github/actions/get-llvm
with:
target: wasm32-unknown-emscripten
- name: Download EMSDK
uses: ./.github/actions/get-emsdk
- name: Build
run: |
export LLVM_SYS_181_PREFIX=$PWD/llvm-x86_64-unknown-linux-gnu
export REVIVE_LLVM_TARGET_PREFIX=$PWD/llvm-wasm32-unknown-emscripten
source emsdk/emsdk_env.sh
make install-wasm
chmod -x ./target/wasm32-unknown-emscripten/release/resolc.wasm
- name: Set Up Node.js
uses: actions/setup-node@v3
with:
node-version: "20"
- name: Basic Sanity Check
run: |
mkdir -p solc
curl -sSLo solc/soljson.js https://github.com/ethereum/solidity/releases/download/v0.8.30/soljson.js
node -e "
const soljson = require('solc/soljson');
const createRevive = require('./target/wasm32-unknown-emscripten/release/resolc.js');
const compiler = createRevive();
compiler.soljson = soljson;
const standardJsonInput =
{
language: 'Solidity',
sources: {
'MyContract.sol': {
content: 'pragma solidity ^0.8.0; contract MyContract { function greet() public pure returns (string memory) { return \'Hello\'; } }',
},
},
settings: { optimizer: { enabled: false } }
};
compiler.writeToStdin(JSON.stringify(standardJsonInput));
compiler.callMain(['--standard-json']);
// Collect output
const stdout = compiler.readFromStdout();
const stderr = compiler.readFromStderr();
if (stderr) { console.error(stderr); process.exit(1); }
let out = JSON.parse(stdout);
let bytecode = out.contracts['MyContract.sol']['MyContract'].evm.bytecode.object
console.log(bytecode);
if(!bytecode.startsWith('50564d')) { process.exit(1); }
"
- name: Compress Artifact
run: |
mkdir -p resolc-wasm32-unknown-emscripten
mv ./target/wasm32-unknown-emscripten/release/resolc.js ./resolc-wasm32-unknown-emscripten/
mv ./target/wasm32-unknown-emscripten/release/resolc.wasm ./resolc-wasm32-unknown-emscripten/
mv ./target/wasm32-unknown-emscripten/release/resolc_web.js ./resolc-wasm32-unknown-emscripten/
# There is no way to upload several files as several artifacts with a single upload-artifact step
# It's needed to have resolc_web.js separately for night builds for resolc-bin repo
# https://github.com/actions/upload-artifact/issues/331
- name: Upload artifact resolc.js (nightly)
uses: actions/upload-artifact@v4
with:
name: resolc.js
path: resolc-wasm32-unknown-emscripten/resolc.js
retention-days: 40
- name: Upload artifacts resolc.wasm (nightly)
uses: actions/upload-artifact@v4
with:
name: resolc.wasm
path: resolc-wasm32-unknown-emscripten/resolc.wasm
retention-days: 40
- name: Upload artifacts resolc_web.js (nightly)
uses: actions/upload-artifact@v4
id: artifact-upload-step
with:
name: resolc_web.js
path: resolc-wasm32-unknown-emscripten/resolc_web.js
retention-days: 40
- name: Set output variables
id: set-output
env:
TARGET: resolc_web_js
run: |
echo "Artifact URL is ${{ steps.artifact-upload-step.outputs.artifact-url }}"
echo "Artifact SHA is ${{ steps.artifact-upload-step.outputs.artifact-digest }}"
echo "${TARGET}_url=${{ steps.artifact-upload-step.outputs.artifact-url }}"
echo "${TARGET}_url=${{ steps.artifact-upload-step.outputs.artifact-url }}" >> "$GITHUB_OUTPUT"
echo "${TARGET}_sha=${{ steps.artifact-upload-step.outputs.artifact-digest }}""
echo "${TARGET}_sha=${{ steps.artifact-upload-step.outputs.artifact-digest }}"" >> "$GITHUB_OUTPUT"
create-macos-fat-binary:
if: ${{ needs.check_commits.outputs.has_commits == 'true' }}
needs: [build]
outputs:
resolc-universal-apple-darwin_url: ${{ steps.set-output.outputs.resolc-universal-apple-darwin_url }}
resolc-universal-apple-darwin_sha: ${{ steps.set-output.outputs.resolc-universal-apple-darwin_sha }}
runs-on: macos-14
steps:
- uses: actions/download-artifact@v4
with:
merge-multiple: true
- name: Create macOS Fat Binary
run: |
lipo resolc-aarch64-apple-darwin resolc-x86_64-apple-darwin -create -output resolc-universal-apple-darwin
- name: Make Executable
run: |
chmod +x resolc-universal-apple-darwin
- uses: actions/upload-artifact@v4
id: artifact-upload-step
with:
name: resolc-universal-apple-darwin
path: resolc-universal-apple-darwin
retention-days: 40
- name: Set output variables
id: set-output
env:
TARGET: resolc-universal-apple-darwin
run: |
echo "Artifact URL is ${{ steps.artifact-upload-step.outputs.artifact-url }}"
echo "Artifact SHA is ${{ steps.artifact-upload-step.outputs.artifact-digest }}"
echo "${TARGET}_url=${{ steps.artifact-upload-step.outputs.artifact-url }}"
echo "${TARGET}_url=${{ steps.artifact-upload-step.outputs.artifact-url }}" >> "$GITHUB_OUTPUT"
echo "${TARGET}_sha=${{ steps.artifact-upload-step.outputs.artifact-digest }}""
echo "${TARGET}_sha=${{ steps.artifact-upload-step.outputs.artifact-digest }}"" >> "$GITHUB_OUTPUT"
generate-nightly-json:
runs-on: ubuntu-24.04
if: ${{ needs.check_commits.outputs.has_commits == 'true' }}
environment: tags
needs: [build-wasm, build, create-macos-fat-binary, check_commits]
steps:
- name: Checkout revive
uses: actions/checkout@v4
with:
path: revive
- name: Checkout resolc-bin
uses: actions/checkout@v4
with:
repository: paritytech/resolc-bin
path: resolc-bin
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
merge-multiple: true
path: bins
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.REVIVE_JSON_APP_ID }}
private-key: ${{ secrets.REVIVE_JSON_APP_KEY }}
owner: paritytech
repositories: resolc-bin
- name: Generate JSON
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TOKEN: ${{ steps.app-token.outputs.token }}
APP_NAME: "paritytech-revive-json"
Green: "\e[32m"
NC: "\e[0m"
run: |
echo '[' > data.json
echo '${{ toJSON(needs.build.outputs) }}' >> data.json
echo ',' >> data.json
echo '${{ toJSON(needs.build-wasm.outputs) }}' >> data.json
echo ',' >> data.json
echo '${{ toJSON(needs.create-macos-fat-binary.outputs) }}' >> data.json
echo ']' >> data.json
chmod +x bins/resolc-x86_64-unknown-linux-musl
export FIRST_SOLC_VERSION=$(./bins/resolc-x86_64-unknown-linux-musl --supported-solc-versions | cut -f 1 -d "," | tr -d ">=")
export LAST_SOLC_VERSION=$(./bins/resolc-x86_64-unknown-linux-musl --supported-solc-versions | cut -f 2 -d "," | tr -d "<=")
export FILEPATH=$(readlink -f data.json)
export TAG=$(cd revive;gh release list --json name,isLatest --jq '.[] | select(.isLatest)|.name')
cd resolc-bin
mkdir -p nightly
cd nightly
python3 ../../revive/.github/scripts/json_generator_nightly.py
cd ..
git status
echo "${Green}Add new remote with gh app token${NC}"
git remote set-url origin $(git config remote.origin.url | sed "s/github.com/${APP_NAME}:${TOKEN}@github.com/g")
echo "${Green}Remove http section that causes issues with gh app auth token${NC}"
sed -i.bak '/\[http/d' ./.git/config
sed -i.bak '/extraheader/d' ./.git/config
git config user.email "ci@parity.io"
git config user.name "${APP_NAME}"
git add nightly/
git commit -m "Update nightly json"
git push origin main
echo "::notice::nightly info.list files were successfully published to https://github.com/paritytech/resolc-bin"
+1
View File
@@ -14,6 +14,7 @@ concurrency:
env:
CARGO_TERM_COLOR: always
# if changed, dont forget to update the env var in release-nightly.yml
RUST_MUSL_CROSS_IMAGE: messense/rust-musl-cross@sha256:c0154e992adb791c3b848dd008939d19862549204f8cb26f5ca7a00f629e6067
jobs:
+15
View File
@@ -6,6 +6,21 @@ This is a development pre-release.
Supported `polkadot-sdk` rev: `2503.0.1`
## v0.4.0
This is a development pre-release.
Supported `polkadot-sdk` rev: `2503.0.1`
### Added
- Line debug information per YUL builtin and for `if` statements.
- Column numbers in debug information.
- Support for the YUL optimizer details in the standard json input definition.
- The `revive-explorer` compiler utility.
### Fixed
- The debug info source file matches the YUL path in `--debug-output-dir`, allowing tools to display the source line.
## v0.3.0
This is a development pre-release.
Generated
+10
View File
@@ -8615,6 +8615,16 @@ dependencies = [
"tempfile",
]
[[package]]
name = "revive-explorer"
version = "0.1.0"
dependencies = [
"anyhow",
"clap",
"num_cpus",
"revive-yul",
]
[[package]]
name = "revive-integration"
version = "0.1.1"
+1
View File
@@ -19,6 +19,7 @@ revive-benchmarks = { version = "0.1.0", path = "crates/benchmarks" }
revive-builtins = { version = "0.1.0", path = "crates/builtins" }
revive-common = { version = "0.1.0", path = "crates/common" }
revive-differential = { version = "0.1.0", path = "crates/differential" }
revive-explorer = { version = "0.1.0", path = "crates/explore" }
revive-integration = { version = "0.1.1", path = "crates/integration" }
revive-linker = { version = "0.1.0", path = "crates/linker" }
lld-sys = { version = "0.1.0", path = "crates/lld-sys" }
+5 -1
View File
@@ -6,6 +6,7 @@
install-llvm-builder \
install-llvm \
install-revive-runner \
install-revive-explorer \
format \
clippy \
machete \
@@ -43,6 +44,9 @@ install-llvm: install-llvm-builder
install-revive-runner:
cargo install --locked --force --path crates/runner --no-default-features
install-revive-explorer:
cargo install --locked --force --path crates/explorer --no-default-features
format:
cargo fmt --all --check
@@ -53,7 +57,7 @@ machete:
cargo install cargo-machete
cargo machete
test: format clippy machete test-cli test-workspace install-revive-runner
test: format clippy machete test-cli test-workspace install-revive-runner install-revive-explorer
test-integration: install-bin
cargo test --package revive-integration
+20
View File
@@ -0,0 +1,20 @@
[package]
name = "revive-explorer"
version.workspace = true
license.workspace = true
edition.workspace = true
repository.workspace = true
authors.workspace = true
description = "Helper utility to inspect debug builds"
[[bin]]
name = "revive-explorer"
path = "src/main.rs"
[dependencies]
anyhow = { workspace = true }
clap = { workspace = true, features = ["help", "std", "derive"] }
num_cpus = { workspace = true }
revive-yul = { workspace = true }
+49
View File
@@ -0,0 +1,49 @@
# revive-explorer
The `revive-explorer` is a helper utility for exploring the compilers YUL lowering unit.
It analyzes a given shared objects from the debug dump and outputs:
- The count of each YUL statement translated.
- A per YUL statement break-down of bytecode size contributed per.
- Estimated `yul-phaser` cost parameters.
Example:
```
statements count:
block 532
Caller 20
Not 73
Gas 24
Shr 2
...
Shl 259
SetImmutable 2
CodeSize 1
CallDataLoad 87
Return 56
bytes per statement:
Or 756
CodeCopy 158
Log3 620
Return 1562
MStore 36128
...
ReturnDataCopy 2854
DataOffset 28
assignment 1194
Number 540
CallValue 4258
yul-phaser parameters:
--break-cost 1
--variable-declaration-cost 3
--function-call-cost 8
--if-cost 4
--expression-statement-cost 6
--function-definition-cost 11
--switch-cost 3
--block-cost 1
--leave-cost 1
--assignment-cost 1
```
+59
View File
@@ -0,0 +1,59 @@
//! The `llvm-dwarfdump` utility helper library.
use std::{
path::{Path, PathBuf},
process::{Command, Stdio},
};
pub static EXECUTABLE: &str = "llvm-dwarfdump";
pub static DEBUG_LINES_ARGUMENTS: [&str; 1] = ["--debug-line"];
pub static SOURCE_FILE_ARGUMENTS: [&str; 1] = ["--show-sources"];
/// Calls the `llvm-dwarfdump` tool to extract debug line information
/// from the shared object at `path`. Returns the output.
///
/// Provide `Some(dwarfdump_exectuable)` to override the default executable.
pub fn debug_lines(
shared_object: &Path,
dwarfdump_executable: &Option<PathBuf>,
) -> anyhow::Result<String> {
dwarfdump(shared_object, dwarfdump_executable, &DEBUG_LINES_ARGUMENTS)
}
/// Calls the `llvm-dwarfdump` tool to extract the source file name.
/// Returns the source file path.
///
/// Provide `Some(dwarfdump_exectuable)` to override the default executable.
pub fn source_file(
shared_object: &Path,
dwarfdump_executable: &Option<PathBuf>,
) -> anyhow::Result<PathBuf> {
let output = dwarfdump(shared_object, dwarfdump_executable, &SOURCE_FILE_ARGUMENTS)?;
Ok(output.trim().into())
}
/// The internal `llvm-dwarfdump` helper function.
fn dwarfdump(
shared_object: &Path,
dwarfdump_executable: &Option<PathBuf>,
arguments: &[&str],
) -> anyhow::Result<String> {
let executable = dwarfdump_executable
.to_owned()
.unwrap_or_else(|| PathBuf::from(EXECUTABLE));
let output = Command::new(executable)
.args(arguments)
.arg(shared_object)
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()?
.wait_with_output()?;
if !output.status.success() {
anyhow::bail!(String::from_utf8_lossy(&output.stderr).to_string());
}
Ok(String::from_utf8_lossy(&output.stdout).to_string())
}
+250
View File
@@ -0,0 +1,250 @@
//! The core dwarf dump analyzer library.
use std::{
collections::HashMap,
path::{Path, PathBuf},
};
use revive_yul::lexer::token::location::Location;
use crate::location_mapper::{self, map_locations, LocationMap};
/// Unknwon code.
pub const OTHER: &str = "other";
/// Compiler internal code.
pub const INTERNAL: &str = "internal";
/// YUL block code.
pub const BLOCK: &str = "block";
/// YUL function call code.
pub const FUNCTION_CALL: &str = "function_call";
/// YUL conditional code.
pub const IF: &str = "if";
/// YUL loop code.
pub const FOR: &str = "for";
/// YUL loop continue code.
pub const CONTINUE: &str = "continue";
/// YUL loop break code.
pub const BREAK: &str = "break";
/// YUL switch code.
pub const SWITCH: &str = "switch";
/// YUL variable declaration code.
pub const DECLARATION: &str = "let";
/// YUL variable assignment code.
pub const ASSIGNMENT: &str = "assignment";
/// YUL function definition code.
pub const FUNCTION_DEFINITION: &str = "function_definition";
/// YUL function leave code.
pub const LEAVE: &str = "leave";
/// The dwarf dump analyzer.
///
/// Loads debug information from `llvm-dwarfdump` and calculates statistics
/// about the compiled YUL statements:
/// - Statements count
/// - Per-statement
#[derive(Debug, Default)]
pub struct DwarfdumpAnalyzer {
/// The YUL source file path.
source: PathBuf,
/// The YUL location to statements map.
location_map: LocationMap,
/// The `llvm-dwarfdump --debug-lines` output.
debug_lines: String,
/// The observed statements.
statements_count: HashMap<String, usize>,
/// The observed statement to instructions size.
statements_size: HashMap<String, u64>,
}
impl DwarfdumpAnalyzer {
/// The debug info analyzer constructor.
///
/// `source` is the path to the YUL source file.
/// `debug_lines` is the `llvm-dwarfdump --debug-lines` output.
pub fn new(source: &Path, debug_lines: String) -> Self {
Self {
source: source.to_path_buf(),
debug_lines,
..Default::default()
}
}
/// Run the analysis.
pub fn analyze(&mut self) -> anyhow::Result<()> {
self.map_locations()?;
self.analyze_statements()?;
Ok(())
}
/// Populate the maps so that we can always unwrap later.
fn map_locations(&mut self) -> anyhow::Result<()> {
self.location_map = map_locations(&self.source)?;
self.statements_count = HashMap::with_capacity(self.location_map.len());
self.statements_size = HashMap::with_capacity(self.location_map.len());
for statement in self.location_map.values() {
if !self.statements_size.contains_key(statement) {
self.statements_size.insert(statement.clone(), 0);
}
*self.statements_count.entry(statement.clone()).or_insert(0) += 1;
}
Ok(())
}
/// Analyze how much bytes of insturctions each statement contributes.
fn analyze_statements(&mut self) -> anyhow::Result<()> {
let mut previous_offset = 0;
let mut previous_location = Location::new(0, 0);
for line in self
.debug_lines
.lines()
.skip_while(|line| !line.starts_with("Address"))
.skip(2)
{
let mut parts = line.split_whitespace();
let (Some(offset), Some(line), Some(column)) =
(parts.next(), parts.next(), parts.next())
else {
continue;
};
let current_offset = u64::from_str_radix(offset.trim_start_matches("0x"), 16)?;
let mut current_location = Location::new(line.parse()?, column.parse()?);
// TODO: A bug? Needs further investigation.
if current_location.line == 0 && current_location.column != 0 {
current_location.line = previous_location.line;
}
if let Some(statement) = self.location_map.get(&previous_location) {
let contribution = current_offset - previous_offset;
*self.statements_size.get_mut(statement).unwrap() += contribution;
}
previous_offset = current_offset;
previous_location = current_location;
}
Ok(())
}
/// Print the per-statement count break-down.
pub fn display_statement_count(&self) {
println!("statements count:");
for (statement, count) in self.statements_count.iter() {
println!("\t{statement} {count}");
}
}
/// Print the per-statement byte size contribution break-down.
pub fn display_statement_size(&self) {
println!("bytes per statement:");
for (statement, size) in self.statements_size.iter() {
println!("\t{statement} {size}");
}
}
/// Print the estimated `yul-phaser` cost parameters.
pub fn display_phaser_costs(&self, yul_phaser_scale: u64) {
println!("yul-phaser parameters:");
for (parameter, cost) in self.phaser_costs(yul_phaser_scale) {
println!("\t{parameter} {cost}");
}
}
/// Estimate the `yul-phaser` costs using the simplified weight function:
/// `Total size / toal count = cost`
pub fn phaser_costs(&self, yul_phaser_scale: u64) -> Vec<(String, u64)> {
let mut costs: HashMap<String, (usize, u64)> = HashMap::with_capacity(16);
for (statement, count) in self
.statements_count
.iter()
.filter(|(_, count)| **count > 0)
{
let size = self.statements_size.get(statement).unwrap();
let cost = match statement.as_str() {
location_mapper::FOR => "--for-loop-cost",
location_mapper::OTHER => continue,
location_mapper::INTERNAL => continue,
location_mapper::BLOCK => "--block-cost",
location_mapper::FUNCTION_CALL => "--function-call-cost",
location_mapper::IF => "--if-cost",
location_mapper::CONTINUE => "--continue-cost",
location_mapper::BREAK => "--break-cost",
location_mapper::LEAVE => "--leave-cost",
location_mapper::SWITCH => "--switch-cost",
location_mapper::DECLARATION => "--variable-declaration-cost",
location_mapper::ASSIGNMENT => "--assignment-cost",
location_mapper::FUNCTION_DEFINITION => "--function-definition-cost",
_ => "--expression-statement-cost",
};
let entry = costs.entry(cost.to_string()).or_default();
entry.0 += count;
entry.1 += size;
}
let costs = costs
.iter()
.map(|(cost, (count, size))| {
let ratio = *size / *count as u64;
(cost.to_string(), ratio.min(100))
})
.collect::<Vec<_>>();
let scaled_costs = scale_to(
costs
.iter()
.map(|(_, ratio)| *ratio)
.collect::<Vec<_>>()
.as_slice(),
yul_phaser_scale,
);
costs
.iter()
.zip(scaled_costs)
.map(|((cost, _), scaled_ratio)| (cost.to_string(), scaled_ratio))
.collect()
}
}
/// Given a slice of u64 values, returns a Vec<u64> where each element
/// is linearly scaled into the closed interval [1, 10].
fn scale_to(data: &[u64], scale_max: u64) -> Vec<u64> {
if data.is_empty() {
return Vec::new();
}
let mut min = data[0];
let mut max = data[0];
for &x in &data[1..] {
if x < min {
min = x;
}
if x > max {
max = x;
}
}
if max < scale_max {
return data.to_vec();
}
let range = max - min;
data.iter()
.map(|&x| {
if range == 0 {
1
} else {
1 + (x - min) * scale_max / range
}
})
.collect()
}
+6
View File
@@ -0,0 +1,6 @@
//! The revive explorer leverages debug info to get insights into emitted code.
pub mod dwarfdump;
pub mod dwarfdump_analyzer;
pub mod location_mapper;
pub mod yul_phaser;
+158
View File
@@ -0,0 +1,158 @@
//! The location mapper utility maps YUL source locations to AST statements.
//!
//! TODO: Refactor when the AST visitor is implemented.
use std::{collections::HashMap, path::Path};
use revive_yul::{
lexer::{token::location::Location, Lexer},
parser::statement::{
block::Block,
expression::{function_call::name::Name, Expression},
object::Object,
Statement,
},
};
/// Code attributed to an unknown location.
pub const OTHER: &str = "other";
/// Code attributed to a compiler internal location.
pub const INTERNAL: &str = "internal";
/// Code attributed to a
pub const BLOCK: &str = "block";
pub const FUNCTION_CALL: &str = "function_call";
pub const FOR: &str = "for";
pub const IF: &str = "if";
pub const CONTINUE: &str = "continue";
pub const BREAK: &str = "break";
pub const LEAVE: &str = "leave";
pub const SWITCH: &str = "switch";
pub const DECLARATION: &str = "let";
pub const ASSIGNMENT: &str = "assignment";
pub const FUNCTION_DEFINITION: &str = "function_definition";
/// The location to statements map type alias.
pub type LocationMap = HashMap<Location, String>;
/// Construct a [LocationMap] from the given YUL `source` file.
pub fn map_locations(source: &Path) -> anyhow::Result<LocationMap> {
let mut lexer = Lexer::new(std::fs::read_to_string(source)?);
let ast = Object::parse(&mut lexer, None).map_err(|error| {
anyhow::anyhow!("Contract `{}` parsing error: {:?}", source.display(), error)
})?;
let mut location_map = HashMap::with_capacity(1024);
crate::location_mapper::object_mapper(&mut location_map, &ast);
location_map.insert(Location::new(0, 0), OTHER.to_string());
location_map.insert(Location::new(1, 0), INTERNAL.to_string());
Ok(location_map)
}
/// Map the [Block].
fn block_mapper(map: &mut LocationMap, block: &Block) {
map.insert(block.location, BLOCK.to_string());
for statement in &block.statements {
statement_mapper(map, statement);
}
}
/// Map the [Expression].
fn expression_mapper(map: &mut LocationMap, expression: &Expression) {
if let Expression::FunctionCall(call) = expression {
let id = match call.name {
Name::UserDefined(_) => FUNCTION_CALL.to_string(),
_ => format!("{:?}", call.name),
};
map.insert(expression.location(), id);
for expression in &call.arguments {
expression_mapper(map, expression);
}
}
}
/// Map the [Statement].
fn statement_mapper(map: &mut LocationMap, statement: &Statement) {
match statement {
Statement::Object(object) => object_mapper(map, object),
Statement::Code(code) => block_mapper(map, &code.block),
Statement::Block(block) => block_mapper(map, block),
Statement::ForLoop(for_loop) => {
map.insert(for_loop.location, FOR.to_string());
expression_mapper(map, &for_loop.condition);
block_mapper(map, &for_loop.body);
block_mapper(map, &for_loop.initializer);
block_mapper(map, &for_loop.finalizer);
}
Statement::IfConditional(if_conditional) => {
map.insert(if_conditional.location, IF.to_string());
expression_mapper(map, &if_conditional.condition);
block_mapper(map, &if_conditional.block);
}
Statement::Expression(expression) => expression_mapper(map, expression),
Statement::Continue(location) => {
map.insert(*location, CONTINUE.to_string());
}
Statement::Leave(location) => {
map.insert(*location, LEAVE.to_string());
}
Statement::Break(location) => {
map.insert(*location, BREAK.to_string());
}
Statement::Switch(switch) => {
map.insert(switch.expression.location(), SWITCH.to_string());
expression_mapper(map, &switch.expression);
for case in &switch.cases {
block_mapper(map, &case.block);
}
if let Some(block) = switch.default.as_ref() {
block_mapper(map, block);
}
}
Statement::Assignment(assignment) => {
map.insert(assignment.location, ASSIGNMENT.to_string());
expression_mapper(map, &assignment.initializer);
}
Statement::VariableDeclaration(declaration) => {
map.insert(declaration.location, DECLARATION.to_string());
if let Some(expression) = declaration.expression.as_ref() {
expression_mapper(map, expression);
}
}
Statement::FunctionDefinition(definition) => {
map.insert(definition.location, FUNCTION_DEFINITION.to_string());
block_mapper(map, &definition.body);
}
}
}
/// Map the [Object].
fn object_mapper(map: &mut LocationMap, object: &Object) {
map.insert(object.location, object.identifier.clone());
block_mapper(map, &object.code.block);
if let Some(object) = object.inner_object.as_ref() {
object_mapper(map, object);
}
}
+56
View File
@@ -0,0 +1,56 @@
use std::path::PathBuf;
use clap::Parser;
use revive_explorer::{dwarfdump, dwarfdump_analyzer::DwarfdumpAnalyzer, yul_phaser};
/// The `revive-explorer` is a helper utility for exploring the compilers YUL lowering unit.
///
/// It analyzes a given shared objects from the debug dump and outputs:
/// - The count of each YUL statement translated.
/// - A per YUL statement break-down of bytecode size contributed per.
/// - Estimated `yul-phaser` cost parameters.
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
/// Path of the dwarfdump executable.
#[arg(short, long)]
dwarfdump: Option<PathBuf>,
/// The YUL phaser cost scale maximum value.
#[arg(short, long, default_value_t = 10)]
cost_scale: u64,
/// Run the provided yul-phaser executable using the estimated costs.
#[arg(short, long)]
yul_phaser: Option<PathBuf>,
/// Path of the shared object to analyze.
file: PathBuf,
}
fn main() -> anyhow::Result<()> {
let args = Args::parse();
let source_file = dwarfdump::source_file(&args.file, &args.dwarfdump)?;
let debug_lines = dwarfdump::debug_lines(&args.file, &args.dwarfdump)?;
let mut analyzer = DwarfdumpAnalyzer::new(source_file.as_path(), debug_lines);
analyzer.analyze()?;
if let Some(path) = args.yul_phaser.as_ref() {
yul_phaser::run(
path,
source_file.as_path(),
analyzer.phaser_costs(args.cost_scale).as_slice(),
num_cpus::get() / 2, // TODO: should be configurable.
)?;
return Ok(());
}
analyzer.display_statement_count();
analyzer.display_statement_size();
analyzer.display_phaser_costs(args.cost_scale);
Ok(())
}
+79
View File
@@ -0,0 +1,79 @@
//! The revive explorer YUL phaser utility library.
//!
//! This can be used to invoke the `yul-phaser` utility,
//! used to find better YUL optimizer sequences.
use std::{
path::{Path, PathBuf},
process::{Command, Stdio},
thread,
time::{SystemTime, UNIX_EPOCH},
};
/// The `yul-phaser` sane default arguments:
/// - Less verbose output.
/// - Sufficient rounds.
/// - Sufficient random population start.
const ARGUMENTS: [&str; 6] = [
"--hide-round",
"--rounds",
"1000",
"--random-population",
"100",
"--show-only-top-chromosome",
];
/// Run multiple YUL phaser executables in parallel.
pub fn run(
executable: &Path,
source: &Path,
costs: &[(String, u64)],
n_threads: usize,
) -> anyhow::Result<()> {
let mut handles = Vec::with_capacity(n_threads);
for n in 0..n_threads {
let executable = executable.to_path_buf();
let source = source.to_path_buf();
let costs = costs.to_vec();
handles.push(thread::spawn(move || {
spawn_process(executable, source, costs, n)
}));
}
for handle in handles {
let _ = handle.join();
}
Ok(())
}
/// The `yul-phaser` process spawning helper function.
fn spawn_process(
executable: PathBuf,
source: PathBuf,
costs: Vec<(String, u64)>,
seed: usize,
) -> anyhow::Result<()> {
let cost_parameters = costs
.iter()
.flat_map(|(parameter, cost)| vec![parameter.clone(), cost.to_string()]);
let secs = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Time went backwards")
.as_secs();
Command::new(executable)
.args(cost_parameters)
.args(ARGUMENTS)
.arg("--seed")
.arg((seed + secs as usize).to_string())
.arg(source)
.stdin(Stdio::null())
.spawn()?
.wait()?;
Ok(())
}
+8 -8
View File
@@ -1,10 +1,10 @@
{
"Baseline": 939,
"Computation": 2282,
"DivisionArithmetics": 8849,
"ERC20": 18308,
"Events": 1640,
"FibonacciIterative": 1497,
"Flipper": 2099,
"SHA1": 8243
"Baseline": 960,
"Computation": 2367,
"DivisionArithmetics": 9108,
"ERC20": 17655,
"Events": 1680,
"FibonacciIterative": 1536,
"Flipper": 2137,
"SHA1": 8299
}
+39 -4
View File
@@ -2,6 +2,7 @@
pub mod ir_type;
use std::path::Path;
use std::path::PathBuf;
use serde::Deserialize;
@@ -16,6 +17,14 @@ pub struct DebugConfig {
pub output_directory: Option<PathBuf>,
/// Whether debug info should be emitted.
pub emit_debug_info: bool,
/// The YUL debug output file path.
///
/// Is expected to be configured when running in YUL mode.
pub contract_path: Option<PathBuf>,
/// The YUL input file path.
///
/// Is expected to be configured when not running in YUL mode.
pub yul_path: Option<PathBuf>,
}
impl DebugConfig {
@@ -24,15 +33,41 @@ impl DebugConfig {
Self {
output_directory,
emit_debug_info,
contract_path: None,
yul_path: None,
}
}
/// Set the current YUL path.
pub fn set_yul_path(&mut self, yul_path: &Path) {
self.yul_path = yul_path.to_path_buf().into();
}
/// Set the current contract path.
pub fn set_contract_path(&mut self, contract_path: &str) {
self.contract_path = self.yul_source_path(contract_path);
}
/// Returns with the following precedence:
/// 1. The YUL source path if it was configured.
/// 2. The source YUL path from the debug output dir if it was configured.
/// 3. `None` if there is no debug output directory.
pub fn yul_source_path(&self, contract_path: &str) -> Option<PathBuf> {
if let Some(path) = self.yul_path.as_ref() {
return Some(path.clone());
}
self.output_directory.as_ref().map(|output_directory| {
let mut file_path = output_directory.to_owned();
let full_file_name = Self::full_file_name(contract_path, None, IRType::Yul);
file_path.push(full_file_name);
file_path
})
}
/// Dumps the Yul IR.
pub fn dump_yul(&self, contract_path: &str, code: &str) -> anyhow::Result<()> {
if let Some(output_directory) = self.output_directory.as_ref() {
let mut file_path = output_directory.to_owned();
let full_file_name = Self::full_file_name(contract_path, None, IRType::Yul);
file_path.push(full_file_name);
if let Some(file_path) = self.yul_source_path(contract_path) {
std::fs::write(file_path, code)?;
}
@@ -51,11 +51,20 @@ pub struct DebugInfo<'ctx> {
impl<'ctx> DebugInfo<'ctx> {
/// A shortcut constructor.
pub fn new(module: &inkwell::module::Module<'ctx>) -> Self {
pub fn new(
module: &inkwell::module::Module<'ctx>,
debug_config: &crate::debug_config::DebugConfig,
) -> Self {
let module_name = module.get_name().to_string_lossy();
let yul_name = debug_config
.contract_path
.as_ref()
.map(|path| path.display().to_string());
let (builder, compile_unit) = module.create_debug_info_builder(
true,
inkwell::debug_info::DWARFSourceLanguage::C,
module.get_name().to_string_lossy().as_ref(),
yul_name.as_deref().unwrap_or_else(|| module_name.as_ref()),
"",
"",
false,
@@ -48,6 +48,7 @@ where
function_type,
0,
Some(inkwell::module::Linkage::External),
None,
)?;
self.inner.declare(context)
@@ -74,7 +75,6 @@ where
}
context.set_basic_block(context.current_function().borrow().return_block());
context.set_debug_location(0, 0, None)?;
context.build_return(None);
context.pop_debug_scope();
@@ -145,6 +145,7 @@ where
entry_function_type,
0,
Some(inkwell::module::Linkage::External),
None,
)?;
context.declare_global(
@@ -48,6 +48,7 @@ where
function_type,
0,
Some(inkwell::module::Linkage::External),
None,
)?;
self.inner.declare(context)
+26 -13
View File
@@ -247,7 +247,7 @@ where
let intrinsics = Intrinsics::new(llvm, &module);
let llvm_runtime = LLVMRuntime::new(llvm, &module, &optimizer);
let debug_info = debug_config.emit_debug_info.then(|| {
let debug_info = DebugInfo::new(&module);
let debug_info = DebugInfo::new(&module, &debug_config);
debug_info.initialize_module(llvm, &module);
debug_info
});
@@ -463,6 +463,7 @@ where
r#type: inkwell::types::FunctionType<'ctx>,
return_values_length: usize,
linkage: Option<inkwell::module::Linkage>,
location: Option<(u32, u32)>,
) -> anyhow::Result<Rc<RefCell<Function<'ctx>>>> {
let value = self.module().add_function(name, r#type, linkage);
@@ -478,7 +479,8 @@ where
Some(scp) => scp,
};
self.push_debug_scope(func_scope.as_debug_info_scope());
self.set_debug_location(0, 0, Some(func_scope.as_debug_info_scope()))?;
let (line, column) = location.unwrap_or((0, 0));
self.set_debug_location(line, column, Some(func_scope.as_debug_info_scope()))?;
}
let entry_block = self.llvm.append_basic_block(value, "entry");
@@ -533,7 +535,11 @@ where
/// Sets the current active function. If debug-info generation is enabled,
/// constructs a debug-scope and pushes in on the scope-stack.
pub fn set_current_function(&mut self, name: &str, line: Option<u32>) -> anyhow::Result<()> {
pub fn set_current_function(
&mut self,
name: &str,
location: Option<(u32, u32)>,
) -> anyhow::Result<()> {
let function = self.functions.get(name).cloned().ok_or_else(|| {
anyhow::anyhow!("Failed to activate an undeclared function `{}`", name)
})?;
@@ -542,7 +548,8 @@ where
if let Some(scope) = self.current_function().borrow().get_debug_scope() {
self.push_debug_scope(scope);
}
self.set_debug_location(line.unwrap_or_default(), 0, None)?;
let (line, column) = location.unwrap_or_default();
self.set_debug_location(line, column, None)?;
Ok(())
}
@@ -723,17 +730,23 @@ where
r#type: T,
name: &str,
) -> Pointer<'ctx> {
let current_block = self.basic_block();
let entry_block = self.current_function().borrow().entry_block();
// TODO: Revisit. While at entry should be preferred in theory:
// - It has negligible code size impact on real word contracts.
// - Sometimes has negative impact on code size.
// - Messes up debug information used to analyze code size issues.
self.build_alloca(r#type, name)
match entry_block.get_first_instruction() {
Some(instruction) => self.builder().position_before(&instruction),
None => self.builder().position_at_end(entry_block),
}
// let current_block = self.basic_block();
// let entry_block = self.current_function().borrow().entry_block();
let pointer = self.build_alloca(r#type, name);
self.set_basic_block(current_block);
pointer
// match entry_block.get_first_instruction() {
// Some(instruction) => self.builder().position_before(&instruction),
// None => self.builder().position_at_end(entry_block),
// }
// let pointer = self.build_alloca(r#type, name);
// self.set_basic_block(current_block);
// pointer
}
/// Builds an aligned stack allocation at the current position.
@@ -35,6 +35,7 @@ where
Self::r#type(context),
0,
Some(inkwell::module::Linkage::External),
None,
)?;
let mut attributes = Self::ATTRIBUTES.to_vec();
@@ -40,6 +40,7 @@ pub fn check_attribute_null_pointer_is_invalid() {
.fn_type(&[context.word_type().into()], false),
1,
Some(inkwell::module::Linkage::External),
None,
)
.expect("Failed to add function");
assert!(!function
@@ -63,6 +64,7 @@ pub fn check_attribute_optimize_for_size_mode_3() {
.fn_type(&[context.word_type().into()], false),
1,
Some(inkwell::module::Linkage::External),
None,
)
.expect("Failed to add function");
assert!(!function
@@ -86,6 +88,7 @@ pub fn check_attribute_optimize_for_size_mode_z() {
.fn_type(&[context.word_type().into()], false),
1,
Some(inkwell::module::Linkage::External),
None,
)
.expect("Failed to add function");
assert!(function
@@ -109,6 +112,7 @@ pub fn check_attribute_min_size_mode_3() {
.fn_type(&[context.word_type().into()], false),
1,
Some(inkwell::module::Linkage::External),
None,
)
.expect("Failed to add function");
assert!(!function
@@ -132,6 +136,7 @@ pub fn check_attribute_min_size_mode_z() {
.fn_type(&[context.word_type().into()], false),
1,
Some(inkwell::module::Linkage::External),
None,
)
.expect("Failed to add function");
assert!(function
@@ -2,13 +2,13 @@
use inkwell::values::BasicValue;
//use crate::polkavm::context::runtime::RuntimeFunction;
use crate::polkavm::context::runtime::RuntimeFunction;
use crate::polkavm::context::Context;
use crate::polkavm::Dependency;
//use crate::PolkaVMDivisionFunction;
//use crate::PolkaVMRemainderFunction;
//use crate::PolkaVMSignedDivisionFunction;
//use crate::PolkaVMSignedRemainderFunction;
use crate::PolkaVMDivisionFunction;
use crate::PolkaVMRemainderFunction;
use crate::PolkaVMSignedDivisionFunction;
use crate::PolkaVMSignedRemainderFunction;
/// Translates the arithmetic addition.
pub fn addition<'ctx, D>(
@@ -64,21 +64,11 @@ pub fn division<'ctx, D>(
where
D: Dependency + Clone,
{
let result_pointer = context.build_alloca_at_entry(context.word_type(), "div_result_pointer");
let operand_1_pointer = context.build_alloca_at_entry(context.word_type(), "operand_1_pointer");
let operand_2_pointer = context.build_alloca_at_entry(context.word_type(), "operand_2_pointer");
context.build_store(operand_1_pointer, operand_1)?;
context.build_store(operand_2_pointer, operand_2)?;
let arguments = &[
result_pointer.to_int(context).into(),
operand_1_pointer.to_int(context).into(),
operand_2_pointer.to_int(context).into(),
];
context.build_runtime_call(revive_runtime_api::polkavm_imports::DIV, arguments);
context.build_load(result_pointer, "div_result")
let name = <PolkaVMDivisionFunction as RuntimeFunction<D>>::NAME;
let declaration = <PolkaVMDivisionFunction as RuntimeFunction<D>>::declaration(context);
Ok(context
.build_call(declaration, &[operand_1.into(), operand_2.into()], "div")
.unwrap_or_else(|| panic!("revive runtime function {name} should return a value",)))
}
/// Translates the arithmetic remainder.
@@ -90,21 +80,11 @@ pub fn remainder<'ctx, D>(
where
D: Dependency + Clone,
{
let result_pointer = context.build_alloca_at_entry(context.word_type(), "rem_result_pointer");
let operand_1_pointer = context.build_alloca_at_entry(context.word_type(), "operand_1_pointer");
let operand_2_pointer = context.build_alloca_at_entry(context.word_type(), "operand_2_pointer");
context.build_store(operand_1_pointer, operand_1)?;
context.build_store(operand_2_pointer, operand_2)?;
let arguments = &[
result_pointer.to_int(context).into(),
operand_1_pointer.to_int(context).into(),
operand_2_pointer.to_int(context).into(),
];
context.build_runtime_call(revive_runtime_api::polkavm_imports::MOD, arguments);
context.build_load(result_pointer, "rem_result")
let name = <PolkaVMRemainderFunction as RuntimeFunction<D>>::NAME;
let declaration = <PolkaVMRemainderFunction as RuntimeFunction<D>>::declaration(context);
Ok(context
.build_call(declaration, &[operand_1.into(), operand_2.into()], "rem")
.unwrap_or_else(|| panic!("revive runtime function {name} should return a value",)))
}
/// Translates the signed arithmetic division.
@@ -119,21 +99,11 @@ pub fn division_signed<'ctx, D>(
where
D: Dependency + Clone,
{
let result_pointer = context.build_alloca_at_entry(context.word_type(), "sdiv_result_pointer");
let operand_1_pointer = context.build_alloca_at_entry(context.word_type(), "operand_1_pointer");
let operand_2_pointer = context.build_alloca_at_entry(context.word_type(), "operand_2_pointer");
context.build_store(operand_1_pointer, operand_1)?;
context.build_store(operand_2_pointer, operand_2)?;
let arguments = &[
result_pointer.to_int(context).into(),
operand_1_pointer.to_int(context).into(),
operand_2_pointer.to_int(context).into(),
];
context.build_runtime_call(revive_runtime_api::polkavm_imports::SDIV, arguments);
context.build_load(result_pointer, "sdiv_result")
let name = <PolkaVMSignedDivisionFunction as RuntimeFunction<D>>::NAME;
let declaration = <PolkaVMSignedDivisionFunction as RuntimeFunction<D>>::declaration(context);
Ok(context
.build_call(declaration, &[operand_1.into(), operand_2.into()], "sdiv")
.unwrap_or_else(|| panic!("revive runtime function {name} should return a value",)))
}
/// Translates the signed arithmetic remainder.
@@ -145,19 +115,9 @@ pub fn remainder_signed<'ctx, D>(
where
D: Dependency + Clone,
{
let result_pointer = context.build_alloca_at_entry(context.word_type(), "srem_result_pointer");
let operand_1_pointer = context.build_alloca_at_entry(context.word_type(), "operand_1_pointer");
let operand_2_pointer = context.build_alloca_at_entry(context.word_type(), "operand_2_pointer");
context.build_store(operand_1_pointer, operand_1)?;
context.build_store(operand_2_pointer, operand_2)?;
let arguments = &[
result_pointer.to_int(context).into(),
operand_1_pointer.to_int(context).into(),
operand_2_pointer.to_int(context).into(),
];
context.build_runtime_call(revive_runtime_api::polkavm_imports::SMOD, arguments);
context.build_load(result_pointer, "rsem_result")
let name = <PolkaVMSignedRemainderFunction as RuntimeFunction<D>>::NAME;
let declaration = <PolkaVMSignedRemainderFunction as RuntimeFunction<D>>::declaration(context);
Ok(context
.build_call(declaration, &[operand_1.into(), operand_2.into()], "srem")
.unwrap_or_else(|| panic!("revive runtime function {name} should return a value",)))
}
+38 -72
View File
@@ -1,5 +1,7 @@
//! Translates the mathematical operations.
use inkwell::values::BasicValue;
use crate::polkavm::context::Context;
use crate::polkavm::Dependency;
@@ -13,26 +15,17 @@ pub fn add_mod<'ctx, D>(
where
D: Dependency + Clone,
{
let result_pointer =
context.build_alloca_at_entry(context.word_type(), "addmod_result_pointer");
let operand_1_pointer = context.build_alloca_at_entry(context.word_type(), "addmod_operand_1");
let operand_2_pointer = context.build_alloca_at_entry(context.word_type(), "addmod_operand_2");
let modulo_pointer =
context.build_alloca_at_entry(context.word_type(), "addmod_modulo_operand");
context.build_store(operand_2_pointer, operand_2)?;
context.build_store(operand_1_pointer, operand_1)?;
context.build_store(modulo_pointer, modulo)?;
let arguments = &[
result_pointer.to_int(context).into(),
operand_1_pointer.to_int(context).into(),
operand_2_pointer.to_int(context).into(),
modulo_pointer.to_int(context).into(),
];
context.build_runtime_call(revive_runtime_api::polkavm_imports::ADDMOD, arguments);
context.build_load(result_pointer, "addmod_result")
Ok(context
.build_call(
context.llvm_runtime().add_mod,
&[
operand_1.as_basic_value_enum(),
operand_2.as_basic_value_enum(),
modulo.as_basic_value_enum(),
],
"add_mod_call",
)
.expect("Always exists"))
}
/// Translates the `mulmod` instruction.
@@ -45,26 +38,17 @@ pub fn mul_mod<'ctx, D>(
where
D: Dependency + Clone,
{
let result_pointer =
context.build_alloca_at_entry(context.word_type(), "mulmod_result_pointer");
let operand_1_pointer = context.build_alloca_at_entry(context.word_type(), "mulmod_operand_1");
let operand_2_pointer = context.build_alloca_at_entry(context.word_type(), "mulmod_operand_2");
let modulo_pointer =
context.build_alloca_at_entry(context.word_type(), "mulmod_modulo_operand");
context.build_store(operand_2_pointer, operand_2)?;
context.build_store(operand_1_pointer, operand_1)?;
context.build_store(modulo_pointer, modulo)?;
let arguments = &[
result_pointer.to_int(context).into(),
operand_1_pointer.to_int(context).into(),
operand_2_pointer.to_int(context).into(),
modulo_pointer.to_int(context).into(),
];
context.build_runtime_call(revive_runtime_api::polkavm_imports::MULMOD, arguments);
context.build_load(result_pointer, "addmod_result")
Ok(context
.build_call(
context.llvm_runtime().mul_mod,
&[
operand_1.as_basic_value_enum(),
operand_2.as_basic_value_enum(),
modulo.as_basic_value_enum(),
],
"mul_mod_call",
)
.expect("Always exists"))
}
/// Translates the `exp` instruction.
@@ -76,22 +60,13 @@ pub fn exponent<'ctx, D>(
where
D: Dependency + Clone,
{
let result_pointer = context.build_alloca_at_entry(context.word_type(), "exp_result_pointer");
let value_pointer = context.build_alloca_at_entry(context.word_type(), "exp_value_pointer");
let exponent_pointer =
context.build_alloca_at_entry(context.word_type(), "exp_exponent_pointer");
context.build_store(value_pointer, value)?;
context.build_store(exponent_pointer, exponent)?;
let arguments = &[
result_pointer.to_int(context).into(),
value_pointer.to_int(context).into(),
exponent_pointer.to_int(context).into(),
];
context.build_runtime_call(revive_runtime_api::polkavm_imports::EXP, arguments);
context.build_load(result_pointer, "exponent_result")
Ok(context
.build_call(
context.llvm_runtime().exp,
&[value.as_basic_value_enum(), exponent.as_basic_value_enum()],
"exp_call",
)
.expect("Always exists"))
}
/// Translates the `signextend` instruction.
@@ -103,20 +78,11 @@ pub fn sign_extend<'ctx, D>(
where
D: Dependency + Clone,
{
let result_pointer =
context.build_alloca_at_entry(context.word_type(), "signext_result_pointer");
let bytes_pointer = context.build_alloca_at_entry(context.word_type(), "bytes_pointer");
let value_pointer = context.build_alloca_at_entry(context.word_type(), "signext_value_pointer");
context.build_store(bytes_pointer, bytes)?;
context.build_store(value_pointer, value)?;
let arguments = &[
result_pointer.to_int(context).into(),
bytes_pointer.to_int(context).into(),
value_pointer.to_int(context).into(),
];
context.build_runtime_call(revive_runtime_api::polkavm_imports::EXP, arguments);
context.build_load(result_pointer, "signext_mod_result")
Ok(context
.build_call(
context.llvm_runtime().sign_extend,
&[bytes.as_basic_value_enum(), value.as_basic_value_enum()],
"sign_extend_call",
)
.expect("Always exists"))
}
+2 -1
View File
@@ -54,7 +54,7 @@ pub fn yul<T: Compiler>(
solc: &mut T,
optimizer_settings: revive_llvm_context::OptimizerSettings,
include_metadata_hash: bool,
debug_config: revive_llvm_context::DebugConfig,
mut debug_config: revive_llvm_context::DebugConfig,
llvm_arguments: &[String],
memory_config: SolcStandardJsonInputSettingsPolkaVMMemory,
) -> anyhow::Result<Build> {
@@ -77,6 +77,7 @@ pub fn yul<T: Compiler>(
let solc_validator = Some(&*solc);
let project = Project::try_from_yul_path(path, solc_validator)?;
debug_config.set_yul_path(path);
let build = project.compile(
optimizer_settings,
include_metadata_hash,
+2 -1
View File
@@ -77,7 +77,7 @@ impl Contract {
project: Project,
optimizer_settings: revive_llvm_context::OptimizerSettings,
include_metadata_hash: bool,
debug_config: revive_llvm_context::DebugConfig,
mut debug_config: revive_llvm_context::DebugConfig,
llvm_arguments: &[String],
memory_config: SolcStandardJsonInputSettingsPolkaVMMemory,
) -> anyhow::Result<ContractBuild> {
@@ -117,6 +117,7 @@ impl Contract {
_ => llvm.create_module(self.path.as_str()),
};
debug_config.set_contract_path(&self.path);
let mut context = revive_llvm_context::PolkaVMContext::new(
&llvm,
module,
+1 -3
View File
@@ -45,8 +45,6 @@ impl Compiler for SolcCompiler {
include_paths: Vec<String>,
allow_paths: Option<String>,
) -> anyhow::Result<SolcStandardJsonOutput> {
let version = self.version()?.validate(&include_paths)?.default;
let mut command = std::process::Command::new(self.executable.as_str());
command.stdin(std::process::Stdio::piped());
command.stdout(std::process::Stdio::piped());
@@ -65,7 +63,7 @@ impl Compiler for SolcCompiler {
command.arg(allow_paths);
}
input.normalize(&version);
input.normalize();
let suppressed_warnings = input.suppressed_warnings.take().unwrap_or_default();
+1 -2
View File
@@ -40,8 +40,7 @@ impl Compiler for SoljsonCompiler {
anyhow::bail!("configuring allow paths is not supported with solJson")
}
let version = self.version()?.validate(&include_paths)?.default;
input.normalize(&version);
input.normalize();
let suppressed_warnings = input.suppressed_warnings.take().unwrap_or_default();
-16
View File
@@ -104,19 +104,3 @@ POLKAVM_IMPORT(uint64_t, set_storage, uint32_t, uint32_t, uint32_t, uint32_t, ui
POLKAVM_IMPORT(void, value_transferred, uint32_t)
POLKAVM_IMPORT(void, weight_to_fee, uint64_t, uint64_t, uint32_t);
POLKAVM_IMPORT(void, div, uint32_t, uint32_t, uint32_t);
POLKAVM_IMPORT(void, sdiv, uint32_t, uint32_t, uint32_t);
POLKAVM_IMPORT(void, addmod, uint32_t, uint32_t, uint32_t, uint32_t);
POLKAVM_IMPORT(void, mulmod, uint32_t, uint32_t, uint32_t, uint32_t);
POLKAVM_IMPORT(void, mod, uint32_t, uint32_t, uint32_t);
POLKAVM_IMPORT(void, smod, uint32_t, uint32_t, uint32_t);
POLKAVM_IMPORT(void, exp, uint32_t, uint32_t, uint32_t);
POLKAVM_IMPORT(void, signext, uint32_t, uint32_t, uint32_t);
+1 -19
View File
@@ -68,27 +68,9 @@ pub static VALUE_TRANSFERRED: &str = "value_transferred";
pub static WEIGHT_TO_FEE: &str = "weight_to_fee";
pub static DIV: &str = "div";
pub static SDIV: &str = "sdiv";
pub static ADDMOD: &str = "addmod";
pub static MULMOD: &str = "mulmod";
pub static MOD: &str = "mod";
pub static SMOD: &str = "smod";
pub static EXP: &str = "exp";
pub static SIGNEXT: &str = "signext";
/// All imported runtime API symbols.
/// Useful for configuring common attributes and linkage.
pub static IMPORTS: [&str; 41] = [
DIV,
SDIV,
ADDMOD,
MULMOD,
MOD,
SMOD,
EXP,
SIGNEXT,
//
pub static IMPORTS: [&str; 33] = [
ADDRESS,
BALANCE,
BALANCE_OF,
+1
View File
@@ -7,6 +7,7 @@ pub use self::combined_json::contract::Contract as CombinedJsonContract;
pub use self::standard_json::input::language::Language as SolcStandardJsonInputLanguage;
pub use self::standard_json::input::settings::metadata::Metadata as SolcStandardJsonInputSettingsMetadata;
pub use self::standard_json::input::settings::metadata_hash::MetadataHash as SolcStandardJsonInputSettingsMetadataHash;
pub use self::standard_json::input::settings::optimizer::yul_details::YulDetails as SolcStandardJsonInputSettingsYulOptimizerDetails;
pub use self::standard_json::input::settings::optimizer::Optimizer as SolcStandardJsonInputSettingsOptimizer;
pub use self::standard_json::input::settings::polkavm::memory::MemoryConfig as SolcStandardJsonInputSettingsPolkaVMMemory;
pub use self::standard_json::input::settings::polkavm::memory::DEFAULT_HEAP_SIZE as PolkaVMDefaultHeapMemorySize;
@@ -140,7 +140,7 @@ impl Input {
}
/// Sets the necessary defaults.
pub fn normalize(&mut self, version: &semver::Version) {
self.settings.normalize(version);
pub fn normalize(&mut self) {
self.settings.normalize();
}
}
@@ -74,9 +74,9 @@ impl Settings {
}
/// Sets the necessary defaults.
pub fn normalize(&mut self, version: &semver::Version) {
pub fn normalize(&mut self) {
self.polkavm = None;
self.optimizer.normalize(version);
self.optimizer.normalize();
}
/// Parses the library list and returns their double hashmap with path and name as keys.
@@ -3,37 +3,54 @@
use serde::Deserialize;
use serde::Serialize;
use crate::standard_json::input::settings::optimizer::yul_details::YulDetails;
/// The `solc --standard-json` input settings optimizer details.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Details {
/// Whether the pass is enabled.
pub peephole: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub peephole: Option<bool>,
/// Whether the pass is enabled.
#[serde(skip_serializing_if = "Option::is_none")]
pub inliner: Option<bool>,
/// Whether the pass is enabled.
pub jumpdest_remover: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub jumpdest_remover: Option<bool>,
/// Whether the pass is enabled.
pub order_literals: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub order_literals: Option<bool>,
/// Whether the pass is enabled.
pub deduplicate: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub deduplicate: Option<bool>,
/// Whether the pass is enabled.
pub cse: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub cse: Option<bool>,
/// Whether the pass is enabled.
pub constant_optimizer: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub constant_optimizer: Option<bool>,
/// Whether the YUL optimizer is enabled.
#[serde(skip_serializing_if = "Option::is_none")]
pub yul: Option<bool>,
/// The YUL optimizer configuration.
#[serde(skip_serializing_if = "Option::is_none")]
pub yul_details: Option<YulDetails>,
}
impl Details {
/// A shortcut constructor.
#[allow(clippy::too_many_arguments)]
pub fn new(
peephole: bool,
peephole: Option<bool>,
inliner: Option<bool>,
jumpdest_remover: bool,
order_literals: bool,
deduplicate: bool,
cse: bool,
constant_optimizer: bool,
jumpdest_remover: Option<bool>,
order_literals: Option<bool>,
deduplicate: Option<bool>,
cse: Option<bool>,
constant_optimizer: Option<bool>,
yul: Option<bool>,
yul_details: Option<YulDetails>,
) -> Self {
Self {
peephole,
@@ -43,10 +60,11 @@ impl Details {
deduplicate,
cse,
constant_optimizer,
yul,
yul_details,
}
}
/// Creates a set of disabled optimizations.
pub fn disabled(version: &semver::Version) -> Self {
let inliner = if version >= &semver::Version::new(0, 8, 5) {
Some(false)
@@ -54,6 +72,16 @@ impl Details {
None
};
Self::new(false, inliner, false, false, false, false, false)
Self::new(
Some(false),
inliner,
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
None,
None,
)
}
}
@@ -1,6 +1,7 @@
//! The `solc --standard-json` input settings optimizer.
pub mod details;
pub mod yul_details;
use serde::Deserialize;
use serde::Serialize;
@@ -41,13 +42,8 @@ impl Optimizer {
}
/// Sets the necessary defaults.
pub fn normalize(&mut self, version: &semver::Version) {
pub fn normalize(&mut self) {
self.mode = None;
self.fallback_to_optimizing_for_size = None;
self.details = if version >= &semver::Version::new(0, 5, 5) {
Some(Details::disabled(version))
} else {
None
};
}
}
@@ -0,0 +1,26 @@
//! The `solc --standard-json` input settings YUL optimizer details.
use serde::Deserialize;
use serde::Serialize;
/// The `solc --standard-json` input settings optimizer YUL details.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct YulDetails {
/// Whether the stack allocation pass is enabled.
#[serde(skip_serializing_if = "Option::is_none")]
pub stack_allocation: Option<bool>,
/// The optimization step sequence string.
#[serde(skip_serializing_if = "Option::is_none")]
pub optimizer_steps: Option<String>,
}
impl YulDetails {
/// A shortcut constructor.
pub fn new(stack_allocation: Option<bool>, optimizer_steps: Option<String>) -> Self {
Self {
stack_allocation,
optimizer_steps,
}
}
}
@@ -14,7 +14,7 @@ use self::file::File as FileSelection;
pub struct Selection {
/// Only the 'all' wildcard is available for robustness reasons.
#[serde(rename = "*", skip_serializing_if = "Option::is_none")]
all: Option<FileSelection>,
pub all: Option<FileSelection>,
#[serde(skip_serializing_if = "BTreeMap::is_empty", flatten)]
pub files: BTreeMap<String, FileSelection>,
+10
View File
@@ -1,5 +1,8 @@
//! The lexical token location.
use std::hash::Hash;
use std::hash::Hasher;
use serde::Deserialize;
use serde::Serialize;
@@ -48,6 +51,13 @@ impl PartialEq for Location {
}
}
impl Hash for Location {
fn hash<H: Hasher>(&self, state: &mut H) {
self.line.hash(state);
self.column.hash(state);
}
}
impl std::fmt::Display for Location {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}:{}", self.line, self.column)
@@ -119,7 +119,7 @@ where
mut self,
context: &mut revive_llvm_context::PolkaVMContext<D>,
) -> anyhow::Result<()> {
context.set_debug_location(self.location.line, 0, None)?;
context.set_debug_location(self.location.line, self.location.column, None)?;
let value = match self.initializer.into_llvm(context)? {
Some(value) => value,
@@ -149,7 +149,7 @@ where
context.build_store(tuple_pointer, value)?;
for (index, binding) in self.bindings.into_iter().enumerate() {
context.set_debug_location(self.location.line, 0, None)?;
context.set_debug_location(self.location.line, self.location.column, None)?;
let field_pointer = context.build_gep(
tuple_pointer,
+10 -3
View File
@@ -155,7 +155,10 @@ where
function.into_llvm(context)?;
}
context.set_current_function(current_function.as_str(), Some(self.location.line))?;
context.set_current_function(
current_function.as_str(),
Some((self.location.line, self.location.column)),
)?;
if let Some(debug_info) = context.debug_info() {
let di_builder = debug_info.builder();
@@ -169,12 +172,16 @@ where
)
.as_debug_info_scope();
context.push_debug_scope(di_block_scope);
context.set_debug_location(self.location.line, 0, None)?;
context.set_debug_location(self.location.line, self.location.column, None)?;
}
context.set_basic_block(current_block);
for statement in local_statements.into_iter() {
context.set_debug_location(statement.location().line, 0, None)?;
context.set_debug_location(
statement.location().line,
statement.location().column,
None,
)?;
if context.basic_block().get_terminator().is_some() {
break;
}
@@ -123,6 +123,7 @@ impl FunctionCall {
D: revive_llvm_context::PolkaVMDependency + Clone,
{
let location = self.location;
context.set_debug_location(location.line, location.column, None)?;
match self.name {
Name::UserDefined(name) => {
@@ -996,6 +997,8 @@ impl FunctionCall {
}
arguments.reverse();
context.set_debug_location(self.location.line, self.location.column, None)?;
Ok(arguments.try_into().expect("Always successful"))
}
@@ -1013,6 +1016,8 @@ impl FunctionCall {
}
arguments.reverse();
context.set_debug_location(self.location.line, self.location.column, None)?;
Ok(arguments.try_into().expect("Always successful"))
}
}
@@ -72,6 +72,7 @@ where
let increment_block = context.append_basic_block("for_increment");
let join_block = context.append_basic_block("for_join");
context.set_debug_location(self.location.line, self.location.column, None)?;
context.build_unconditional_branch(condition_block);
context.set_basic_block(condition_block);
let condition = self
@@ -80,6 +81,7 @@ where
.expect("Always exists")
.access(context)?
.into_int_value();
context.set_debug_location(self.location.line, self.location.column, None)?;
let condition = context.builder().build_int_z_extend_or_bit_cast(
condition,
context.word_type(),
@@ -98,10 +100,12 @@ where
context.set_basic_block(body_block);
self.body.into_llvm(context)?;
context.build_unconditional_branch(increment_block);
context.set_debug_location(self.location.line, self.location.column, None)?;
context.set_basic_block(increment_block);
self.finalizer.into_llvm(context)?;
context.build_unconditional_branch(condition_block);
context.set_debug_location(self.location.line, self.location.column, None)?;
context.pop_loop();
context.set_basic_block(join_block);
@@ -196,6 +196,7 @@ where
&mut self,
context: &mut revive_llvm_context::PolkaVMContext<D>,
) -> anyhow::Result<()> {
context.set_debug_location(self.location.line, self.location.column, None)?;
let argument_types: Vec<_> = self
.arguments
.iter()
@@ -212,6 +213,7 @@ where
function_type,
self.result.len(),
Some(inkwell::module::Linkage::External),
Some((self.location.line, self.location.column)),
)?;
revive_llvm_context::PolkaVMFunction::set_attributes(
context.llvm(),
@@ -230,7 +232,10 @@ where
mut self,
context: &mut revive_llvm_context::PolkaVMContext<D>,
) -> anyhow::Result<()> {
context.set_current_function(self.identifier.as_str(), Some(self.location.line))?;
context.set_current_function(
self.identifier.as_str(),
Some((self.location.line, self.location.column)),
)?;
context.set_basic_block(context.current_function().borrow().entry_block());
let r#return = context.current_function().borrow().r#return();
@@ -290,7 +295,7 @@ where
}
self.body.into_llvm(context)?;
context.set_debug_location(self.location.line, 0, None)?;
context.set_debug_location(self.location.line, self.location.column, None)?;
match context
.basic_block()
@@ -59,6 +59,7 @@ where
.expect("Always exists")
.access(context)?
.into_int_value();
context.set_debug_location(self.location.line, self.location.column, None)?;
let condition = context.builder().build_int_z_extend_or_bit_cast(
condition,
context.word_type(),
+10 -10
View File
@@ -204,10 +204,10 @@ where
revive_llvm_context::PolkaVMEventLogFunction::<3>.declare(context)?;
revive_llvm_context::PolkaVMEventLogFunction::<4>.declare(context)?;
//revive_llvm_context::PolkaVMDivisionFunction.declare(context)?;
//revive_llvm_context::PolkaVMSignedDivisionFunction.declare(context)?;
//revive_llvm_context::PolkaVMRemainderFunction.declare(context)?;
//revive_llvm_context::PolkaVMSignedRemainderFunction.declare(context)?;
revive_llvm_context::PolkaVMDivisionFunction.declare(context)?;
revive_llvm_context::PolkaVMSignedDivisionFunction.declare(context)?;
revive_llvm_context::PolkaVMRemainderFunction.declare(context)?;
revive_llvm_context::PolkaVMSignedRemainderFunction.declare(context)?;
revive_llvm_context::PolkaVMSbrkFunction.declare(context)?;
@@ -258,10 +258,10 @@ where
revive_llvm_context::PolkaVMEventLogFunction::<3>.into_llvm(context)?;
revive_llvm_context::PolkaVMEventLogFunction::<4>.into_llvm(context)?;
//revive_llvm_context::PolkaVMDivisionFunction.into_llvm(context)?;
//revive_llvm_context::PolkaVMSignedDivisionFunction.into_llvm(context)?;
//revive_llvm_context::PolkaVMRemainderFunction.into_llvm(context)?;
//revive_llvm_context::PolkaVMSignedRemainderFunction.into_llvm(context)?;
revive_llvm_context::PolkaVMDivisionFunction.into_llvm(context)?;
revive_llvm_context::PolkaVMSignedDivisionFunction.into_llvm(context)?;
revive_llvm_context::PolkaVMRemainderFunction.into_llvm(context)?;
revive_llvm_context::PolkaVMSignedRemainderFunction.into_llvm(context)?;
revive_llvm_context::PolkaVMSbrkFunction.into_llvm(context)?;
@@ -279,17 +279,17 @@ where
context.push_debug_scope(object_scope.as_debug_info_scope());
}
context.set_debug_location(self.location.line, self.location.column, None)?;
if self.identifier.ends_with("_deployed") {
revive_llvm_context::PolkaVMRuntimeCodeFunction::new(self.code).into_llvm(context)?;
} else {
revive_llvm_context::PolkaVMDeployCodeFunction::new(self.code).into_llvm(context)?;
}
context.set_debug_location(self.location.line, 0, None)?;
if let Some(object) = self.inner_object {
object.into_llvm(context)?;
}
context.set_debug_location(self.location.line, 0, None)?;
context.set_debug_location(self.location.line, self.location.column, None)?;
context.pop_debug_scope();
@@ -123,6 +123,7 @@ where
D: revive_llvm_context::PolkaVMDependency + Clone,
{
fn into_llvm(self, context: &mut revive_llvm_context::PolkaVMContext<D>) -> anyhow::Result<()> {
context.set_debug_location(self.location.line, self.location.column, None)?;
let scrutinee = self.expression.into_llvm(context)?;
if self.cases.is_empty() {
@@ -143,6 +144,7 @@ where
.append_basic_block(format!("switch_case_branch_{}_block", index + 1).as_str());
context.set_basic_block(expression_block);
case.block.into_llvm(context)?;
context.set_debug_location(self.location.line, self.location.column, None)?;
context.build_unconditional_branch(join_block);
branches.push((constant.into_int_value(), expression_block));
@@ -159,6 +161,7 @@ where
None => join_block,
};
context.set_debug_location(self.location.line, self.location.column, None)?;
context.set_basic_block(current_block);
context.builder().build_switch(
scrutinee
@@ -169,6 +172,7 @@ where
branches.as_slice(),
)?;
context.set_debug_location(self.location.line, self.location.column, None)?;
context.set_basic_block(join_block);
Ok(())
@@ -101,7 +101,7 @@ where
) -> anyhow::Result<()> {
if self.bindings.len() == 1 {
let identifier = self.bindings.remove(0);
context.set_debug_location(self.location.line, 0, None)?;
context.set_debug_location(self.location.line, self.location.column, None)?;
let identifier_type = identifier.r#type.clone().unwrap_or_default();
let r#type = identifier_type.into_llvm(context);
let pointer = context.build_alloca(r#type, identifier.inner.as_str());
@@ -133,7 +133,7 @@ where
}
for (index, binding) in self.bindings.iter().enumerate() {
context.set_debug_location(self.location.line, 0, None)?;
context.set_debug_location(self.location.line, self.location.column, None)?;
let yul_type = binding
.r#type
+16 -4
View File
@@ -743,18 +743,30 @@
}
},
"node_modules/@eslint/plugin-kit": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.3.1.tgz",
"integrity": "sha512-0J+zgWxHN+xXONWIyPWKFMgVuJoZuGiIFu8yxk7RJjxkzpGmyja5wRFqZIVtjDVOQpV+Rw0iOAjYPE2eQyjr0w==",
"version": "0.3.3",
"resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.3.3.tgz",
"integrity": "sha512-1+WqvgNMhmlAambTvT3KPtCl/Ibr68VldY2XY40SL1CE0ZXiakFR/cbTspaF5HsnpDMvcYYoJHfl4980NBjGag==",
"license": "Apache-2.0",
"dependencies": {
"@eslint/core": "^0.14.0",
"@eslint/core": "^0.15.1",
"levn": "^0.4.1"
},
"engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
}
},
"node_modules/@eslint/plugin-kit/node_modules/@eslint/core": {
"version": "0.15.1",
"resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.15.1.tgz",
"integrity": "sha512-bkOp+iumZCCbt1K1CmWf0R9pM5yKpDv+ZXtvSyQpudrI9kuFLp+bM2WOPXImuD/ceQuaa8f5pj93Y7zyECIGNA==",
"license": "Apache-2.0",
"dependencies": {
"@types/json-schema": "^7.0.15"
},
"engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
}
},
"node_modules/@eth-optimism/contracts": {
"version": "0.5.40",
"resolved": "https://registry.npmjs.org/@eth-optimism/contracts/-/contracts-0.5.40.tgz",