Outline string copy and clear code into helpers - #114
Conversation
There was a problem hiding this comment.
Pull request overview
This PR factors previously inline string/bytes storage copy/cleanup logic into reusable sol.func helpers and expands helper hosting so helpers can be emitted at module scope when lowering standalone free functions.
Changes:
- Outline string tail-clearing, string-to-storage copy, and storage→memory string-data copy into dedicated helper functions (
__sol.*) with inline backends. - Extend
getOrCreateHelperFnto host helpers either in the enclosingsol.contractor at module level when no contract is present. - Replace some compile-time
forloops used for storage clearing withBuilderExt::createCountedLoop(with optional unrolling).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
mlir/lib/Conversion/SolToYul/EVMUtil.cpp |
Introduces helper-backed implementations for string copy/clear paths, adds new helper kinds/spellings, and allows module-level helper hosting. |
mlir/include/mlir/Conversion/SolToYul/EVMUtil.h |
Adds private inline-helper declarations and documents new helper emission behavior and helper kinds. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
6eb2be3 to
7759735
Compare
93b4356 to
3f7bb32
Compare
3f7bb32 to
53fb3ef
Compare
abinavpp
left a comment
There was a problem hiding this comment.
mostly lgtm, just some nits. thank you!
Regarding the helper naming we discussed in DM: the only thing I could think of is moving the name generation to typed per-helper generators under a namespace, e.g.
namespace helpersym {
std::string copy(sol::DataLocation src, sol::DataLocation dst, StringRef tyName);
std::string clearStorage(sol::StructType ty);
std::string clearStringTail();
std::string copyStringData(sol::DataLocation src, sol::DataLocation dst);
}getOrCreateHelperFn would take the resulting string as the key. This avoids the
string based approach and gives more structure to the naming. What do you think?
53fb3ef to
e6a9f1a
Compare
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Thank you, that makes sense, fixed. |
Helpers: __sol.copy.<src>.storage.string for whole value copies to storage __sol.copy_string_data.storage.memory for the raw byte copy __sol.clear_string_tail for zeroing stale out-of-place data slots Helpers are hosted by the enclosing contract as before. When there is none (a free function that no contract references, lowered standalone at module level), the module hosts them. TODO: the module level hosting is a subject of future removal. The pipeline should stop lowering free functions that no contract references, matching the upstream solc pipeline.
e6a9f1a to
e3b520f
Compare
NomicFoundation/solx-solidity#159
This includes:
Clearing fixed-size storage arrays with runtime loops
Outline string copy and clear code into helpers
__sol.copy.<src>.storage.stringfor whole value copies to storage__sol.copy_string_data.storage.memoryfor the raw byte copy__sol.clear_string_tailfor zeroing stale out-of-place data slotsHelpers are hosted by the enclosing contract as before. When there is
none (a free function that no contract references, lowered standalone
at module level), the module hosts them.