Skip to content

Outline string copy and clear code into helpers - #114

Merged
PavelKopyl merged 2 commits into
mainfrom
kpv-outline-copy
Aug 8, 2026
Merged

Outline string copy and clear code into helpers#114
PavelKopyl merged 2 commits into
mainfrom
kpv-outline-copy

Conversation

@PavelKopyl

@PavelKopyl PavelKopyl commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

NomicFoundation/solx-solidity#159

This includes:

  1. Clearing fixed-size storage arrays with runtime loops

  2. Outline string copy and clear code into 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.

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

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 getOrCreateHelperFn to host helpers either in the enclosing sol.contract or at module level when no contract is present.
  • Replace some compile-time for loops used for storage clearing with BuilderExt::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.

Comment thread mlir/lib/Conversion/SolToYul/EVMUtil.cpp Outdated
Comment thread mlir/include/mlir/Conversion/SolToYul/EVMUtil.h
@PavelKopyl
PavelKopyl force-pushed the kpv-recursive-structs branch 3 times, most recently from 6eb2be3 to 7759735 Compare July 23, 2026 11:34
Base automatically changed from kpv-recursive-structs to main July 23, 2026 22:59

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@PavelKopyl
PavelKopyl requested a review from abinavpp August 7, 2026 00:05

@abinavpp abinavpp 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.

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?

Comment thread mlir/include/mlir/Conversion/SolToYul/EVMUtil.h Outdated
Comment thread mlir/include/mlir/Conversion/SolToYul/EVMUtil.h Outdated
Comment thread mlir/include/mlir/Conversion/SolToYul/EVMUtil.h Outdated
Comment thread mlir/include/mlir/Conversion/SolToYul/EVMUtil.h Outdated
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

✅ With the latest revision this PR passed the C/C++ code formatter.

@PavelKopyl

Copy link
Copy Markdown
Contributor Author

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?

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.
@PavelKopyl
PavelKopyl merged commit 5647c5c into main Aug 8, 2026
6 checks passed
@PavelKopyl
PavelKopyl deleted the kpv-outline-copy branch August 8, 2026 00:11
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