[mlir][Sol] Support packed and unpacked string storage layouts#19
[mlir][Sol] Support packed and unpacked string storage layouts#19PavelKopyl wants to merge 1 commit intomainfrom
Conversation
3d5f103 to
a1963c3
Compare
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
a1963c3 to
a026c6e
Compare
There was a problem hiding this comment.
Pull request overview
This PR extends the Sol dialect lowering to support Solidity bytes/string storage layouts (short in-slot encoding vs long out-of-place encoding) and introduces dedicated string push operations to model push, push(x), pop, length, indexing, and storage↔memory conversions in the Sol→Yul pipeline.
Changes:
- Add
sol.push_stringandsol.push_string_voidops and lower them to new EVM/Yul builder helpers. - Implement storage-specific string helpers in
evm::Builder(length decode, push/pop, indexing, copy to/from memory/storage). - Extend GEP handling to account for storage reference types (string/struct) and wire new ops into the conversion pass.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| mlir/lib/Dialect/Sol/SolOps.cpp | Adds PushStringVoidOp builder; expands storage ref-type handling in GepOp::build. |
| mlir/lib/Conversion/SolToStandard/SolToYul.cpp | Adds lowering patterns for the new string push ops; updates pop/GEP/copy paths for strings. |
| mlir/lib/Conversion/SolToStandard/SolToStandardPass.cpp | Marks new string push ops illegal so they are lowered in stage1. |
| mlir/lib/Conversion/SolToStandard/EVMUtil.cpp | Adds substantial string storage/memory logic (length decode, push/pop, indexing, copy). |
| mlir/include/mlir/Dialect/Sol/SolOps.td | Declares sol.push_string / sol.push_string_void. |
| mlir/include/mlir/Conversion/SolToStandard/Util.h | Adds BuilderExt::genCeilDivision helper. |
| mlir/include/mlir/Conversion/SolToStandard/EVMUtil.h | Exposes new evm::Builder APIs for string operations and generic copy. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
a026c6e to
fc415e9
Compare
abinavpp
left a comment
There was a problem hiding this comment.
Thanks a lot! The impl looks nice! Wish we could figure out a way to remove the ad-hoc push ops somehow.
| std::optional<Location> locArg = std::nullopt); | ||
| /// Generates length of a string. | ||
| mlir::Value | ||
| genStringLength(mlir::Value lengthSlot, mlir::sol::DataLocation dataLoc, |
There was a problem hiding this comment.
Do we have to make this public when we have genDynSize? The existing public api's are more or less type agnostic and we should try following that pattern for consistency
There was a problem hiding this comment.
Actually I use this function in SolToYul.cpp to avoid double reading from storage. In many cases we need bot the full slot value that encodes length and the extracted length itself.
mlir/lib/Dialect/Sol/SolOps.cpp
Outdated
| getDataLocation(baseAddrTy)); | ||
|
|
||
| // Don't generate pointers to reference types in storage. | ||
| // FIXME: have we listed all the types? |
There was a problem hiding this comment.
how about using sol::isNonPtrRefType instead?
| return b.create<LLVM::ExtractValueOp>(loc, i256Ty, addr, | ||
| b.getDenseI64ArrayAttr({1})); | ||
|
|
||
| Value sizeSlot = genLoad(addr, dataLoc, loc); |
There was a problem hiding this comment.
Can we move this under the if block below to avoid the potential double genLoad
There was a problem hiding this comment.
Done, thank you!
fc415e9 to
4771d13
Compare
Thank you!. I've removed PushStringVoidOp and extended PushOp. |
60bc3d5 to
5996b3b
Compare
5996b3b to
fb8689c
Compare
This also adds support for: - Short strings (length < 32 bytes, packed encoding) - Long strings (length >= 32 bytes, unpacked encoding) - String operations: push(), push(x), pop(), length, indexing - Conversions between memory and storage representations
fb8689c to
1514d34
Compare
This also adds support for: