Rewrite concat using tuples - #563
Draft
axic wants to merge 7 commits into
Draft
Conversation
axic
force-pushed
the
concat-tuple
branch
2 times, most recently
from
August 17, 2026 11:51
5aca184 to
d9a92cd
Compare
Memory-store wrappers (std.opcodes mstore/mstore8) have bodies of the form
`assembly { mstore(a, b) }`. asmIsInterpretable whitelists mstore/mstore8 so
comptime scratch-memory blocks stay foldable, which caused computePureFuns to
classify the mstore wrapper — and therefore any caller whose only effect is a
call to it — as pure.
The concat rewrite exposed the resulting unsoundness: the new MemoryEncode
instances for bytes32/uint256 do their work via `mstore(target, rep(v))` and
`return 32` (a compile-time constant). Being "pure", these encodeInto calls
were folded by tryInline/evalFunBody to their constant byte count, and the
mstore statement was silently dropped (evalFunBody skips MastStmtExp). concat
then wrote the correct length but left the payload zeroed — e.g.
concat_b32_b32 returned 64 zero bytes instead of the two operands. The
memory(bytes) instances were unaffected because they use mcopy, which is not
whitelisted as interpretable.
Mark the mstore/mstore8 wrappers impure so their callers stay out of pureFuns
and the writes survive partial evaluation. This is narrow: asmIsInterpretable
is untouched (direct comptime asm folding and the comptime-check read-exclusion
are unchanged), and mcopy/sstore/log* wrappers were already impure — only the
two whitelisted store ops needed correcting.
Co-Authored-By: Alex Beregszaszi <alex@rtfs.hu>
…unctions" This reverts commit 5f2ea47.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.