feat(slang): emit sol.this for ThisKeyword expressions#369
Merged
hedgar2017 merged 1 commit intomainfrom Apr 25, 2026
Merged
Conversation
830f89a to
008dd4f
Compare
There was a problem hiding this comment.
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::Contextand set it during contract emission (including inferred contract payability). - Emit
sol.thisforExpression::ThisKeywordusing the stored contract type. - Add Sol dialect
ContractTypeconstruction via Rust FFI + C++ stub, surfaced throughTypeFactory.
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. |
008dd4f to
39c380b
Compare
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.
39c380b to
a41086a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
ThisKeywordmatch arm in the expression emitter so Soliditythislowers tosol.thiswith the enclosing contract's!sol.contract<...>type. Mirrors the reference pattern insolx-solidity/libsolidity/codegen/mlir/SolidityToMLIR.cpp:611-616. The contract type is stashed onContext::current_contract_typeby 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 exercisethisalso require features still not yet supported (external calls, inline assembly). Regression checked: identical pass/fail counts againsttests/solidity/simplewith and without this change.payableis derived from the contract'sreceive/ payablefallbackfunctions, matchingContractType(*currContract).isPayable()in the reference compiler.