[mlir][Sol] Unify ABI tuple and packed encoders#67
Conversation
There was a problem hiding this comment.
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 onDataLocation. - 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.
4daf6f5 to
699727b
Compare
e1f57d5 to
c8fb9c8
Compare
vladimirradosavljevic
left a comment
There was a problem hiding this comment.
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.
c8fb9c8 to
be2f854
Compare
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.cppView 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) {
|
be2f854 to
3173565
Compare
Thanks @vladimirradosavljevic, this makes sense. I've added an |
vladimirradosavljevic
left a comment
There was a problem hiding this comment.
One comment before I do full review. Thanks for doing this!
3173565 to
511415d
Compare
vladimirradosavljevic
left a comment
There was a problem hiding this comment.
I think it would be beneficial to make this code more maintainable and readable. Could you please check whether we can achieve that?
511415d to
350fea4
Compare
699727b to
07da935
Compare
350fea4 to
deff035
Compare
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
left a comment
There was a problem hiding this comment.
LGTM after two comments are addressed.
Thank you and awesome work!
deff035 to
3b55023
Compare
07da935 to
d558d0d
Compare
3b55023 to
e0a0a46
Compare
e0a0a46 to
d60cb95
Compare
NomicFoundation/solx-solidity#126