Skip to content

feat(slang): lower additional EVM intrinsics#376

Merged
hedgar2017 merged 1 commit intomainfrom
feat-slang-evm-intrinsics
Apr 28, 2026
Merged

feat(slang): lower additional EVM intrinsics#376
hedgar2017 merged 1 commit intomainfrom
feat-slang-evm-intrinsics

Conversation

@hedgar2017
Copy link
Copy Markdown
Contributor

@hedgar2017 hedgar2017 commented Apr 27, 2026

Wires up five additional EVM intrinsics in the Slang/MLIR adapter: three zero-arg block-namespace globals (block.blobbasefee, block.difficulty, block.prevrandao) and two runtime-base address intrinsics (address.balance, address.codehash). The address-base path is plumbed by passing the full MemberAccessExpression to emit_member_access, so the operand can be evaluated and threaded through sol.balance / sol.code_hash.

The built-in dispatch (assert, require, EVM intrinsics) is extracted from call/mod.rs into a new call/built_in.rs module, keeping call/mod.rs as a thin dispatcher. The two address-base intrinsic arms share a private emit_address_base_intrinsic helper that takes a closure to construct the operation.

Newly passing tests

  • tests/solidity/simple/context/difficulty.sol (all)
  • tests/solidity/simple/context/prevrandao.sol (all)

Out of scope

  • address.code — depends on broader bytes/string lowering not yet in place.
  • address.codehash Solidity-level test — blocked on bytes32 lowering (panics in type_conversion.rs:45).
  • msg.sig — needs a !sol.fixedbytes<4> type which has no FFI constructor in solx-mlir yet.
  • gasleft() — function-call dispatch path (separate from member access).

@hedgar2017 hedgar2017 added the ci:slang Trigger slang unit tests on PR label Apr 27, 2026
@hedgar2017 hedgar2017 requested a review from Copilot April 28, 2026 03:50
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 → MLIR lowering layer to support additional EVM “context/intrinsic” member accesses, including new block.* globals and address.* member intrinsics that require evaluating the base expression.

Changes:

  • Plumbs full MemberAccessExpression into emit_member_access so the operand can be evaluated for address-based intrinsics.
  • Lowers address.balance and address.codehash to Sol-dialect ops taking the computed address operand.
  • Adds Sol-dialect lowering for block.blobbasefee, block.difficulty, and block.prevrandao.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
solx-slang/src/ast/contract/function/expression/mod.rs Updates member-access emission to pass the full MemberAccessExpression into the call emitter.
solx-slang/src/ast/contract/function/expression/call/mod.rs Extends emit_member_access to lower additional block.* and address.* built-ins to Sol-dialect operations.

Comment thread solx-slang/src/ast/contract/function/expression/call/mod.rs Outdated
Comment thread solx-slang/src/ast/contract/function/expression/call/mod.rs Outdated
Comment thread solx-slang/src/ast/contract/function/expression/call/mod.rs Outdated
Comment thread solx-slang/src/ast/contract/function/expression/call/mod.rs Outdated
@hedgar2017 hedgar2017 self-assigned this Apr 28, 2026
@hedgar2017 hedgar2017 force-pushed the feat-slang-evm-intrinsics branch 4 times, most recently from 1755289 to 7f982d2 Compare April 28, 2026 06:58
@hedgar2017 hedgar2017 marked this pull request as ready for review April 28, 2026 08:26
Comment thread solx-slang/src/ast/contract/function/expression/call/built_in.rs Outdated
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

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

Comment thread solx-slang/src/ast/contract/function/expression/call/built_in.rs
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!

@hedgar2017 hedgar2017 force-pushed the feat-slang-evm-intrinsics branch from b41a9a0 to 08b7e54 Compare April 28, 2026 15:30
Wire up `block.blobbasefee`, `block.difficulty`, `block.prevrandao`,
`address.balance`, and `address.codehash` member accesses to their Sol
dialect ops. The address-base intrinsics evaluate the operand
expression and emit `sol.balance` / `sol.code_hash` with the resulting
address value.

Built-in dispatch is routed through slang's `BuiltIn` binder for both
member access and call sites. The lit test for EVM context is extended
with the four new intrinsics; codehash coverage waits on bytes32
lowering.
@hedgar2017 hedgar2017 force-pushed the feat-slang-evm-intrinsics branch from 08b7e54 to 7e3db46 Compare April 28, 2026 15:30
@hedgar2017 hedgar2017 enabled auto-merge April 28, 2026 15:30
@hedgar2017 hedgar2017 added this pull request to the merge queue Apr 28, 2026
Merged via the queue into main with commit 7e47deb Apr 28, 2026
50 checks passed
@hedgar2017 hedgar2017 deleted the feat-slang-evm-intrinsics branch April 28, 2026 16:36
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