Skip to content

[mlir][Sol] Unify ABI tuple and packed encoders#67

Merged
vladimirradosavljevic merged 1 commit into
mainfrom
app-event-struct-indexed
May 22, 2026
Merged

[mlir][Sol] Unify ABI tuple and packed encoders#67
vladimirradosavljevic merged 1 commit into
mainfrom
app-event-struct-indexed

Conversation

@abinavpp

@abinavpp abinavpp commented May 6, 2026

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds sol::StructType handling to evm::Builder::genABIPackedEncoding, enabling packed ABI encoding of structs by iterating over members and reading them from calldata/memory/storage via StructEncodeMemberReader.

Changes:

  • Implement struct-type branch in genABIPackedEncoding, selecting a member reader based on DataLocation.
  • Encode each struct member into memory and advance the destination pointer accordingly (including recursive encoding for non-scalar members).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread mlir/lib/Conversion/SolToYul/EVMUtil.cpp Outdated
Comment thread mlir/lib/Conversion/SolToYul/EVMUtil.cpp Outdated
Comment thread mlir/lib/Conversion/SolToYul/EVMUtil.cpp Outdated
@abinavpp abinavpp force-pushed the app-event-arg-types branch from 4daf6f5 to 699727b Compare May 14, 2026 20:39
@abinavpp abinavpp force-pushed the app-event-struct-indexed branch from e1f57d5 to c8fb9c8 Compare May 14, 2026 20:39

@vladimirradosavljevic vladimirradosavljevic left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Even though this PR adds struct handling in packed encoding to support events, I think we should add full support here, including array support.
Old codegen calls tupleEncoderPacked for indexed events. That sets options.dynamicInplace = true, which is not fully supported in the MLIR encoder yet. For example, array cases such as indexed arrays with reference elements still need more work.
It seems like now is a good time to address this properly. Maybe the best solution is to merge/generalize genABIPackedEncoding and genABITupleEncoding into one implementation with encoding options, e.g. padded and dynamicInplace, similar to how solc does it.

@abinavpp abinavpp force-pushed the app-event-struct-indexed branch from c8fb9c8 to be2f854 Compare May 18, 2026 22:15
@abinavpp abinavpp changed the title [mlir][Sol] Support struct types in genABIPackedEncoding [mlir][Sol] Unify ABI tuple and packed encoders May 18, 2026
@abinavpp abinavpp marked this pull request as draft May 18, 2026 22:17
@abinavpp abinavpp requested a review from Copilot May 18, 2026 22:17

Copilot AI left a comment

Copy link
Copy Markdown

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 mlir/lib/Conversion/SolToYul/EVMUtil.cpp Outdated
@github-actions

github-actions Bot commented May 18, 2026

Copy link
Copy Markdown

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff 46ececa84573af6e0f4d4fe0210e4fea8c58f28e d60cb9570cecb538b211a890cf1fad908d93c44e -- mlir/include/mlir/Conversion/SolToYul/EVMUtil.h mlir/include/mlir/Dialect/Sol/Sol.h mlir/lib/Conversion/SolToYul/EVMUtil.cpp mlir/lib/Conversion/SolToYul/SolToYul.cpp mlir/lib/Dialect/Sol/SolBase.cpp mlir/lib/Dialect/Sol/SolOps.cpp
View the diff from clang-format here.
diff --git a/mlir/lib/Conversion/SolToYul/EVMUtil.cpp b/mlir/lib/Conversion/SolToYul/EVMUtil.cpp
index bede8a1b6a4b..40473460a854 100644
--- a/mlir/lib/Conversion/SolToYul/EVMUtil.cpp
+++ b/mlir/lib/Conversion/SolToYul/EVMUtil.cpp
@@ -1852,8 +1852,7 @@ void evm::Builder::genClearStorageArrayTail(Value arraySlot,
 
   Type eltTy = arrTy.getEltType();
   // Multiple elements share one slot when byteSize <= 16 (elemsPerSlot >= 2).
-  bool trulyPacked =
-      sol::canBePacked(eltTy) && sol::getNumBytes(eltTy) <= 16;
+  bool trulyPacked = sol::canBePacked(eltTy) && sol::getNumBytes(eltTy) <= 16;
 
   yul::IfOp ifClear = nullptr;
   if (!isDecrement) {

@abinavpp abinavpp force-pushed the app-event-struct-indexed branch from be2f854 to 3173565 Compare May 18, 2026 23:18
@abinavpp abinavpp marked this pull request as ready for review May 19, 2026 00:23
@abinavpp

abinavpp commented May 19, 2026

Copy link
Copy Markdown
Contributor Author

Even though this PR adds struct handling in packed encoding to support events, I think we should add full support here, including array support.
Old codegen calls tupleEncoderPacked for indexed events. That sets options.dynamicInplace = true, which is not fully supported in the MLIR encoder yet. For example, array cases such as indexed arrays with reference elements still need more work.
It seems like now is a good time to address this properly. Maybe the best solution is to merge/generalize genABIPackedEncoding and genABITupleEncoding into one implementation with encoding options, e.g. padded and dynamicInplace, similar to how solc does it.

Thanks @vladimirradosavljevic, this makes sense. I've added an ABIEncodingOptions struct (padded, dynamicInplace) and unified everything behind a single genABIEncoding(...) API. wdyt?

@vladimirradosavljevic vladimirradosavljevic left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One comment before I do full review. Thanks for doing this!

Comment thread mlir/lib/Conversion/SolToYul/EVMUtil.cpp Outdated
@abinavpp abinavpp force-pushed the app-event-struct-indexed branch from 3173565 to 511415d Compare May 19, 2026 15:33

@vladimirradosavljevic vladimirradosavljevic left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it would be beneficial to make this code more maintainable and readable. Could you please check whether we can achieve that?

Comment thread mlir/lib/Conversion/SolToYul/EVMUtil.cpp Outdated
@abinavpp abinavpp force-pushed the app-event-struct-indexed branch from 511415d to 350fea4 Compare May 21, 2026 11:58
@abinavpp abinavpp marked this pull request as draft May 21, 2026 11:58
@abinavpp abinavpp requested a review from Copilot May 21, 2026 11:58
@abinavpp abinavpp force-pushed the app-event-arg-types branch from 699727b to 07da935 Compare May 21, 2026 12:00

Copilot AI left a comment

Copy link
Copy Markdown

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 6 out of 6 changed files in this pull request and generated 3 comments.

Comment thread mlir/include/mlir/Conversion/SolToYul/EVMUtil.h Outdated
Comment thread mlir/include/mlir/Conversion/SolToYul/EVMUtil.h Outdated
Comment thread mlir/lib/Conversion/SolToYul/EVMUtil.cpp Outdated
@abinavpp abinavpp force-pushed the app-event-struct-indexed branch from 350fea4 to deff035 Compare May 21, 2026 12:17
@abinavpp abinavpp marked this pull request as ready for review May 21, 2026 12:17
@abinavpp

Copy link
Copy Markdown
Contributor Author

I think it would be beneficial to make this code more maintainable and readable. Could you please check whether we can achieve that?

It's a bit more structured now. I still feel we can do a better job, especially with the array encoding. But I think that can wait.

@vladimirradosavljevic vladimirradosavljevic left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM after two comments are addressed.
Thank you and awesome work!

Comment thread mlir/include/mlir/Dialect/Sol/Sol.h Outdated
Comment thread mlir/lib/Conversion/SolToYul/EVMUtil.cpp Outdated
@abinavpp abinavpp force-pushed the app-event-struct-indexed branch from deff035 to 3b55023 Compare May 21, 2026 14:17
@abinavpp abinavpp force-pushed the app-event-arg-types branch from 07da935 to d558d0d Compare May 22, 2026 11:08
@abinavpp abinavpp force-pushed the app-event-struct-indexed branch from 3b55023 to e0a0a46 Compare May 22, 2026 11:08
Base automatically changed from app-event-arg-types to main May 22, 2026 11:50
@vladimirradosavljevic vladimirradosavljevic merged commit 3b768f2 into main May 22, 2026
6 checks passed
@vladimirradosavljevic vladimirradosavljevic deleted the app-event-struct-indexed branch May 22, 2026 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants