Skip to content

feat(slang): add a Solidity version setting - #787

Merged
nebasuke merged 10 commits into
mainfrom
solidity-version-flag
Oct 5, 2026
Merged

nebasuke merged 10 commits into
mainfrom
solidity-version-flag

Conversation

@nebasuke

@nebasuke nebasuke commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

Add support for --solidity-version and standard JSON setting settings.solidityVersion. This enables Hardhat 3 plugin integration, see NomicFoundation/hardhat#8658.

Claude summary

Adds --solidity-version and the solx-only standard JSON setting settings.solidityVersion, which set the Solidity version Slang compiles the sources as, from 0.8.0 up to the latest one Slang supports.

  • Every pragma solidity must allow the chosen version, so a pinned pragma such as pragma solidity 0.8.20; compiles once that version is set.
  • Without an EVM version, Slang analyzes at solc's default for the chosen version. Versions before 0.8.25 default to an EVM version older than Cancun, which solx does not support yet, so they compile for Cancun with a warning until the older EVM versions are supported.
  • The CBOR metadata records the chosen version, and --version reports the latest supported one.
  • Without a setting, the latest supported version is used.
  • In standard JSON mode the version comes only from settings.solidityVersion, and --solidity-version is rejected there, as --evm-version is.

@nebasuke
nebasuke force-pushed the solidity-version-flag branch 2 times, most recently from de38f2f to 713e3bb Compare October 4, 2026 10:44
@nebasuke
nebasuke changed the base branch from main to az-default-evm-version October 4, 2026 10:44
@nebasuke
nebasuke added this pull request to stack #788 October 4, 2026 10:49
@github-actions

github-actions Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Coverage Summary

Crate Line Coverage Function Coverage
solx 🟢 83.8% 🔴 20.0%
solx-benchmark-converter 🔴 0.0% 🔴 0.0%
solx-codegen-evm 🟡 57.5% 🟡 51.5%
solx-compiler-downloader 🔴 0.0% 🔴 0.0%
solx-core 🔴 46.1% 🟡 54.8%
solx-dev 🔴 3.2% 🔴 4.2%
solx-mlir 🟡 54.5% 🟡 50.8%
solx-slang 🔴 25.0% 🔴 30.6%
solx-solc-test-adapter 🔴 1.7% 🔴 2.1%
solx-standard-json 🔴 41.2% 🔴 45.8%
solx-tester 🔴 36.6% 🔴 34.6%
solx-utils 🔴 35.7% 🔴 39.3%
Total 🔴 13.2% 🔴 16.4%

Codecov Report | HTML Report | Workflow Run

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Version-dependent analysis, EVM defaults, and metadata across both compilation interfaces warrant human validation.

Review effort: Balanced
Findings: None

What changed in this PR

Adds Solidity language-version selection to solx’s compilation pipeline, enabling Hardhat 3 integration.

Changes:

  • Exposes version selection through CLI and standard JSON.
  • Applies version-aware EVM defaults and records the chosen version in metadata.
  • Adds tests and documentation for supported versions and mode restrictions.
File Description
solx/​tests/​data/​standard_json_input/​solidity_version.json Adds supported-version input.
solx/​tests/​data/​standard_json_input/​solidity_version_unsupported.json Adds unsupported-version input.
solx/​tests/​data/​contracts/​solidity/​TransientStorage.sol Provides version-gated syntax.
solx/​tests/​data/​contracts/​solidity/​PinnedPragma.sol Provides a pinned-pragma contract.
solx/​tests/​cli/​solidity_version.rs Tests selection, defaults, metadata, and restrictions.
solx/​tests/​cli/​mod.rs Registers version-option tests.
solx-tester/​src/​compilers/​solidity/​mod.rs Updates input constructor calls.
solx-tester/​src/​compilers/​input_ext.rs Leaves version selection unset for existing helpers.
solx-standard-json/​src/​input/​settings/​mod.rs Defines the optional version setting.
solx-standard-json/​src/​input/​mod.rs Passes version selection through constructors.
solx-slang/​src/​slang/​mod.rs Resolves language versions and EVM defaults.
solx-core/​src/​project/​mod.rs Carries the chosen version into CBOR metadata.
solx-core/​src/​project/​contract/​metadata.rs Accepts the selected semantic version.
solx-core/​src/​compiler.rs Connects selection to compilation and metadata.
solx-core/​src/​arguments.rs Adds the CLI option and mode checks.
docs/​src/​user-guide/​03-standard-json.md Documents JSON selection and defaults.
docs/​src/​user-guide/​02-command-line-interface.md Documents CLI selection and defaults.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@nebasuke
nebasuke force-pushed the solidity-version-flag branch from efc4c78 to d436b4f Compare October 4, 2026 18:24
@nebasuke nebasuke added the ci:sanitizer Trigger sanitizer workflow on PR label Oct 4, 2026
Comment thread solx-slang/src/slang/mod.rs Outdated
Comment thread solx-slang/src/slang/mod.rs Outdated

@hedgar2017 hedgar2017 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks! Mostly code shape stuff.

Comment thread solx-slang/src/slang/mod.rs Outdated
Comment thread solx/tests/cli/solidity_version.rs Outdated
@nebasuke
nebasuke requested a review from hedgar2017 October 5, 2026 08:13

@hedgar2017 hedgar2017 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks! One nit left.

Comment thread solx-slang/src/slang/mod.rs Outdated
Slang compiled every source as its latest language version, so any file
whose pragma excludes it, such as `pragma solidity 0.8.20;`, was rejected.
`--solidity-version` and the solx-only `settings.solidityVersion` pick the
version instead, which the Hardhat plugin can set per compilation job.
The CBOR metadata records the version compiled as, while `--version` keeps
reporting the latest one Slang supports.

Without a version the latest is still used; inferring it from the pragmas
replaces that default later.
Solidity versions before 0.8.25 default to an EVM version older than
Cancun. With a selectable Solidity version, compiling one of those
without an EVM version panicked; it now reports an error asking for
Cancun or later.
Requiring an EVM version for Solidity versions before 0.8.25 only made
users pass the Cancun fallback by hand, which yields the same analysis
and bytecode. Picking it with a warning keeps pinned-pragma projects
compiling, such as Hardhat ones that leave evmVersion unset, until solx
targets the older EVM versions solc defaults to.
standard_json returned the version next to the output, so every early
error return had to make one up, and both callers already stop on those
errors. Writing it into settings.solidityVersion keeps the return type
and leaves the version unset only where nothing reads it.
Any default solx could not convert fell back to Cancun, including one
newer than Osaka. Slang already knows Amsterdam, so the first Solidity
version defaulting to it would have compiled for Cancun under a warning
calling Cancun the oldest supported version. It now panics instead, and
a test resolves the default of every Solidity version Slang supports.
Only a build suffix was tested, while language_version strips a
prerelease suffix such as solc nightlies carry too.
The project only reads the version itself, so both callers wrapped the
resolved version in a solx_standard_json::Version whose long form
nothing used.
A --solidity-version suffix longer than eight bytes is heap-allocated by
semver behind an encoded pointer. Both CLI exits skip destructors, so
LeakSanitizer reported it as a direct leak and failed the suffix tests.
…sion

The default was always the language version's own, so passing it
separately only enabled a contradictory pair in a test. CLI tests already
cover the Cancun fallback, and every compile at the latest version goes
through the expect, so the unit tests go. Public items now precede
private ones, a rule CLAUDE.md now states.
One inherent impl block per type keeps the public API and its private helpers in one place; the CLAUDE.md layout rule now says so instead of permitting the split.
@nebasuke
nebasuke force-pushed the solidity-version-flag branch from fc87878 to a371743 Compare October 5, 2026 12:35
@nebasuke nebasuke added feat New feature or request and removed ci:sanitizer Trigger sanitizer workflow on PR labels Oct 5, 2026
@nebasuke
nebasuke added this pull request to the merge queue Oct 5, 2026
Merged via the queue into main with commit a8e454c Oct 5, 2026
65 of 67 checks passed
@nebasuke
nebasuke deleted the solidity-version-flag branch October 5, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants