Skip to content

feat(slang): emit sol.this for ThisKeyword expressions#369

Merged
hedgar2017 merged 1 commit intomainfrom
feat-slang-this-keyword
Apr 25, 2026
Merged

feat(slang): emit sol.this for ThisKeyword expressions#369
hedgar2017 merged 1 commit intomainfrom
feat-slang-this-keyword

Conversation

@hedgar2017
Copy link
Copy Markdown
Contributor

@hedgar2017 hedgar2017 commented Apr 24, 2026

Adds a ThisKeyword match arm in the expression emitter so Solidity this lowers to sol.this with the enclosing contract's !sol.contract<...> type. Mirrors the reference pattern in solx-solidity/libsolidity/codegen/mlir/SolidityToMLIR.cpp:611-616. The contract type is stashed on Context::current_contract_type by the contract emitter, scoped per-function, so the expression layer reads it directly instead of threading the contract name through every emitter.

Foundational for later work on external calls (this.f()), address(this).balance, payable(this), and related patterns — does not flip any test to PASSED on its own because the tests that exercise this also require features still not yet supported (external calls, inline assembly). Regression checked: identical pass/fail counts against tests/solidity/simple with and without this change.

payable is derived from the contract's receive / payable fallback functions, matching ContractType(*currContract).isPayable() in the reference compiler.

@hedgar2017 hedgar2017 added the ci:slang Trigger slang unit tests on PR label Apr 24, 2026
@hedgar2017 hedgar2017 force-pushed the feat-slang-this-keyword branch from 830f89a to 008dd4f Compare April 24, 2026 14:27
@hedgar2017 hedgar2017 requested review from a team and Copilot April 24, 2026 14:47
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

Adds lowering support for Solidity this by emitting a typed sol.this operation, with the enclosing contract’s !sol.contract<...> type sourced from shared MLIR Context state.

Changes:

  • Track the “currently emitting contract” MLIR type on solx_mlir::Context and set it during contract emission (including inferred contract payability).
  • Emit sol.this for Expression::ThisKeyword using the stored contract type.
  • Add Sol dialect ContractType construction via Rust FFI + C++ stub, surfaced through TypeFactory.

Reviewed changes

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

Show a summary per file
File Description
solx-slang/src/ast/contract/mod.rs Computes contract payability and stashes the current contract MLIR type on the shared context.
solx-slang/src/ast/contract/function/expression/mod.rs Adds a ThisKeyword expression arm that emits sol.this typed with the contract type.
solx-mlir/src/ffi.rs Declares new FFI entrypoint for creating sol::ContractType.
solx-mlir/src/context/mod.rs Adds current_contract_type to the shared MLIR compilation context.
solx-mlir/src/context/builder/type_factory.rs Adds TypeFactory::contract() wrapper around the new FFI constructor.
solx-mlir/sol_attr_stubs.cpp Implements solxCreateContractType C wrapper calling mlir::sol::ContractType::get.

Comment thread solx-slang/src/ast/contract/mod.rs
Comment thread solx-slang/src/ast/contract/mod.rs Outdated
Comment thread solx-slang/src/ast/contract/function/expression/mod.rs
Comment thread solx-mlir/sol_attr_stubs.cpp
@hedgar2017 hedgar2017 force-pushed the feat-slang-this-keyword branch from 008dd4f to 39c380b Compare April 24, 2026 15:12
Add a ThisKeyword match arm in the expression emitter and a ContractType
factory on the builder so `this` lowers to `sol.this` with the enclosing
contract's type, mirroring SolidityToMLIR.cpp. The contract type is
stashed on Context::current_contract_type by the contract emitter so the
expression layer reads it directly instead of threading the name through
every emitter.
@hedgar2017 hedgar2017 force-pushed the feat-slang-this-keyword branch from 39c380b to a41086a Compare April 24, 2026 16:46
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 added this pull request to the merge queue Apr 25, 2026
Merged via the queue into main with commit 54a46a7 Apr 25, 2026
50 checks passed
@hedgar2017 hedgar2017 deleted the feat-slang-this-keyword branch April 25, 2026 08:42
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