Skip to content

feat(slang): allow runtime require message via Error(string) call#425

Merged
hedgar2017 merged 2 commits into
mainfrom
feat-slang-require-runtime-message
May 28, 2026
Merged

feat(slang): allow runtime require message via Error(string) call#425
hedgar2017 merged 2 commits into
mainfrom
feat-slang-require-runtime-message

Conversation

@hedgar2017
Copy link
Copy Markdown
Contributor

@hedgar2017 hedgar2017 commented May 11, 2026

Lowers require(cond, expr) where expr is not a string literal. The expression is evaluated at runtime, converted to string memory via sol.cast (no-op when the source is already memory), and emitted as sol.require %cond, "Error(string)"(%msg : !sol.string<memory>) {call}, mirroring the per-argument type conversion the custom-error revert path uses.

Integration test delta (M3B3), tests/solidity/simple/:

base tip Δ
PASSED 1895 1899 +4
FAILED 8 8 0
INVALID 306 304 −2
Total 2209 2211 +2

@hedgar2017 hedgar2017 added the ci:slang Trigger slang unit tests on PR label May 11, 2026
@hedgar2017 hedgar2017 force-pushed the feat-slang-struct-constructor branch 5 times, most recently from 41c36de to 95de376 Compare May 14, 2026 17:07
@hedgar2017 hedgar2017 force-pushed the feat-slang-struct-constructor branch 2 times, most recently from 48aef58 to 53db7dd Compare May 26, 2026 16:26
Base automatically changed from feat-slang-struct-constructor to main May 26, 2026 18:33
@hedgar2017 hedgar2017 force-pushed the feat-slang-require-runtime-message branch from 0b3969c to 3781fbc Compare May 27, 2026 04:15
@hedgar2017 hedgar2017 self-assigned this May 27, 2026
@hedgar2017 hedgar2017 requested a review from Copilot May 27, 2026 04:16
@hedgar2017 hedgar2017 marked this pull request as ready for review May 27, 2026 04:16
@hedgar2017 hedgar2017 force-pushed the feat-slang-require-runtime-message branch from 3781fbc to b2775e5 Compare May 27, 2026 04:19
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the Slang lowering path for Solidity require(cond, expr) so non-literal string messages can be evaluated at runtime and emitted through the Error(string) ABI call form.

Changes:

  • Allows require to accept a runtime message expression instead of rejecting all non-literal messages.
  • Extends the MLIR builder helper for sol.require to accept call operands and the {call} marker.
  • Adds a lit test covering literal and runtime-message require lowering.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
solx-slang/src/ast/contract/function/expression/call/built_in.rs Updates require lowering to distinguish no message, literal message, and runtime string expression forms.
solx-mlir/src/context/builder/mod.rs Extends emit_sol_require to pass operands and mark ABI call-style require operations.
solx-mlir/tests/lit/require_runtime_message.sol Adds MLIR checks for literal and runtime require messages.

Comment thread solx-slang/src/ast/contract/function/expression/call/built_in.rs
@hedgar2017 hedgar2017 force-pushed the feat-slang-require-runtime-message branch 6 times, most recently from 8e30a72 to 7d4a37e Compare May 28, 2026 06:28
Bumps slang_solidity_v2 to pick up the fix in NomicFoundation/slang#1801,
which restores `HexNumberExpression::integer_value()` to parsing the
literal text instead of routing through binder typing. Without it, hex
literals in address-returning positions panic during lowering with
"hex literals always evaluate to integers".

Adapts to slang v2 API changes that landed since the previous pin:

- `ContractDefinition::compute_abi_with_file_id(file_id)` is gone; the
  replacement `compute_abi()` derives the file from the contract node.
- `CompilationUnit::get_file_ast_root(file_id)` is gone; the replacement
  flow is `CompilationUnit::file(file_id)` then `File::ast()`.
@hedgar2017 hedgar2017 force-pushed the feat-slang-require-runtime-message branch from 7d4a37e to 3568062 Compare May 28, 2026 06:45
@hedgar2017 hedgar2017 requested review from a team May 28, 2026 06:48
Copy link
Copy Markdown
Contributor

@abinavpp abinavpp left a comment

Choose a reason for hiding this comment

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

thank you! yea, this is broken in solc :(, but the lowering looks correct iirc

Merged via the queue into main with commit bd57c8f May 28, 2026
51 checks passed
@hedgar2017 hedgar2017 deleted the feat-slang-require-runtime-message branch May 28, 2026 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:slang Trigger slang unit tests on PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants