Replace heap-allocated Stack with fixed-size array#7
Merged
garyschulte merged 2 commits into10d9e:mainfrom Feb 6, 2026
Merged
Conversation
Replace `?std.ArrayList(U256)` with `[STACK_LIMIT]U256` fixed array + `length: usize`, eliminating heap allocation and deinit() calls. Add unsafe methods (pushUnsafe, popUnsafe, peekUnsafe, topMutUnsafe, dupUnsafe, swapUnsafe, shrinkUnsafe) for opcode implementations. Opcode pattern: peek-peek-shrink-overwrite via peekUnsafe + shrinkUnsafe + topMutUnsafe. Add 30 inline tests in stack.zig using idiomatic zig test blocks. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collaborator
Author
|
CC @garyschulte |
garyschulte
reviewed
Feb 6, 2026
Comment on lines
+332
to
+341
| const interpreter_tests = b.addTest(.{ | ||
| .root_module = b.createModule(.{ | ||
| .root_source_file = .{ .src_path = .{ .owner = b, .sub_path = "src/interpreter/stack.zig" } }, | ||
| .target = target, | ||
| .optimize = optimize, | ||
| }), | ||
| }); | ||
| interpreter_tests.root_module.addImport("primitives", primitives_module); | ||
| const run_interpreter_tests = b.addRunArtifact(interpreter_tests); | ||
| test_step.dependOn(&run_interpreter_tests.step); |
Collaborator
There was a problem hiding this comment.
should we add this to test_exe instead?
Collaborator
There was a problem hiding this comment.
@10d9e is there a strong reason to use test_exe versus build addTest ?
bretk1989
approved these changes
Feb 9, 2026
garyschulte
added a commit
to garyschulte/zevm
that referenced
this pull request
Mar 11, 2026
Signed-off-by: garyschulte <garyschulte@gmail.com>
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.
?std.ArrayList(U256)with[STACK_LIMIT]U256fixed array +length: usize,eliminating heap allocation and deinit() calls.
The idea is that opcodes follow the pattern, example for ADD : peek-peek-shrink-overwrite. This reduces the stack mutations to a minum.