[mlir][Sol] Support all event arg types in EmitOp lowering#66
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the Solidity→Yul lowering of sol.emit to better match EVM log topic rules by transforming indexed event arguments into the form expected by yul.log topics, including hashing reference-typed indexed arguments. It also tightens normalizeABIScalarForEncoding to hard-fail when invoked on unsupported (non-scalar) types.
Changes:
- Lower indexed reference-typed event args (
string/array/struct) tokeccak256(abiPackedEncode(arg))before passing as log topics. - Normalize indexed value-typed args to
i256vianormalizeABIScalarForEncoding(topics are i256). - Replace the previous fallback
return val;innormalizeABIScalarForEncodingwith anllvm_unreachablefor non-scalar types.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| mlir/lib/Conversion/SolToStandard/SolToYul.cpp | Updates EmitOp lowering to hash reference-type indexed args and normalize scalar indexed args to i256 topics. |
| mlir/lib/Conversion/SolToStandard/EVMUtil.cpp | Makes normalizeABIScalarForEncoding explicitly unreachable on non-scalar inputs (no silent passthrough). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4daf6f5 to
699727b
Compare
You can test this locally with the following command:git-clang-format --diff 0af903a14710e4a1151d6a9dce67542d0f815f9a d558d0d7a2c0470185ac3f2183f60ca6bd3b162e -- mlir/lib/Conversion/SolToYul/SolToYul.cppView the diff from clang-format here.diff --git a/mlir/lib/Conversion/SolToYul/SolToYul.cpp b/mlir/lib/Conversion/SolToYul/SolToYul.cpp
index 00fc4bf837dc..e251e1ac1c75 100644
--- a/mlir/lib/Conversion/SolToYul/SolToYul.cpp
+++ b/mlir/lib/Conversion/SolToYul/SolToYul.cpp
@@ -3393,8 +3393,7 @@ struct EmitOpLowering : public OpConversionPattern<sol::EmitOp> {
Value scratchStart = evmB.genFreePtr();
Value scratchEnd =
evmB.genABIPackedEncoding(origTy, val, scratchStart, loc);
- Value scratchSize =
- r.create<yul::SubOp>(loc, scratchEnd, scratchStart);
+ Value scratchSize = r.create<yul::SubOp>(loc, scratchEnd, scratchStart);
indexedArgs.push_back(
r.create<yul::Keccak256Op>(loc, scratchStart, scratchSize));
continue;
|
vladimirradosavljevic
approved these changes
May 15, 2026
vladimirradosavljevic
left a comment
Contributor
There was a problem hiding this comment.
LGTM, thanks!
699727b to
07da935
Compare
Indexed reference args hash via keccak256 of the packed encoding; indexed value-type args go through normalizeABIScalarForEncoding. Also tighten normalizeABIScalarForEncoding to assert on non-scalar types.
07da935 to
d558d0d
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.
NomicFoundation/solx-solidity#125