-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Subassembly syntax for plain EVM assembly tests #16021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// ==== | ||
// outputs: InputAssemblyJSON,Assembly,Bytecode,Opcodes,SourceMappings | ||
// ---- | ||
// InputAssemblyJSON: { | ||
// ".code": [] | ||
// } | ||
// Assembly: | ||
// Bytecode: | ||
// Opcodes: | ||
// SourceMappings: |
33 changes: 33 additions & 0 deletions
33
test/libevmasm/evmAssemblyTests/isoltestTesting/pushsize.asm
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
PUSHSIZE | ||
|
||
.sub | ||
PUSHSIZE | ||
// ==== | ||
// outputs: InputAssemblyJSON,Assembly,Bytecode,Opcodes,SourceMappings | ||
// ---- | ||
// InputAssemblyJSON: { | ||
// ".code": [ | ||
// { | ||
// "name": "PUSHSIZE" | ||
// } | ||
// ], | ||
// ".data": { | ||
// "0": { | ||
// ".code": [ | ||
// { | ||
// "name": "PUSHSIZE" | ||
// } | ||
// ] | ||
// } | ||
// } | ||
// } | ||
// Assembly: | ||
// bytecodeSize | ||
// stop | ||
// | ||
// sub_0: assembly { | ||
// bytecodeSize | ||
// } | ||
// Bytecode: 6003fe | ||
// Opcodes: PUSH1 0x3 INVALID | ||
// SourceMappings: :::-:0 |
72 changes: 72 additions & 0 deletions
72
test/libevmasm/evmAssemblyTests/isoltestTesting/pushsubsize.asm
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
PUSH [$] 0x0000 | ||
PUSH #[$] 0x0000 | ||
|
||
.sub | ||
PUSH [$] 0x0 | ||
PUSH #[$] 0x2 | ||
|
||
.sub | ||
.sub | ||
.sub | ||
// ==== | ||
// outputs: InputAssemblyJSON,Assembly,Bytecode,Opcodes,SourceMappings | ||
// ---- | ||
// InputAssemblyJSON: { | ||
// ".code": [ | ||
// { | ||
// "name": "PUSH [$]", | ||
// "value": "0000" | ||
// }, | ||
// { | ||
// "name": "PUSH #[$]", | ||
// "value": "0000" | ||
// } | ||
// ], | ||
// ".data": { | ||
// "0": { | ||
// ".code": [ | ||
// { | ||
// "name": "PUSH [$]", | ||
// "value": "0" | ||
// }, | ||
// { | ||
// "name": "PUSH #[$]", | ||
// "value": "2" | ||
// } | ||
// ], | ||
// ".data": { | ||
// "0": { | ||
// ".code": [] | ||
// }, | ||
// "1": { | ||
// ".code": [] | ||
// }, | ||
// "2": { | ||
// ".code": [] | ||
// } | ||
// } | ||
// } | ||
// } | ||
// } | ||
// Assembly: | ||
// dataOffset(sub_0) | ||
// dataSize(sub_0) | ||
// stop | ||
// | ||
// sub_0: assembly { | ||
// dataOffset(sub_0) | ||
// dataSize(sub_2) | ||
// stop | ||
// | ||
// sub_0: assembly { | ||
// } | ||
// | ||
// sub_1: assembly { | ||
// } | ||
// | ||
// sub_2: assembly { | ||
// } | ||
// } | ||
// Bytecode: 60056005fe60056000fe | ||
// Opcodes: PUSH1 0x5 PUSH1 0x5 INVALID PUSH1 0x5 PUSH1 0x0 INVALID | ||
// SourceMappings: :::-:0; |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was very suspicious of the
subassemblyID
and thought it might lead to lifetime issues. Turns out,nlohmann_json
copies the thing. So this is fine!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, any other behavior here would be unsafe. Storing references to something you don't own and don't know the lifetime of would be a pretty bad design decision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though I have to say that this PR took much more time than I expected, mainly due to me having to fight with dangling references, so it's a valid concern in general.
We don't normally make heavy use of
string_view
, but here I tried to use it more to avoid copies. Turns out there are many new ways to silently shoot yourself that I just didn't have to think about before. For example, even if your object owns both the parentstring
and thestring_view
s pointing at it, it's not necessarily enough on its own to prevent dangling references. When you copy the object, yourstring_view
s still point at the original. If youmove
it, you'll have a bad time :)I also learned that taking references to nested parts of a nlohmann
json
objects leads to weird results. They seem to be very easily invalidated when modifying even unrelated parts of the object. I initially used a stack of references to subassemblies, but had to switch to a recursive implementation and refactor the parsing a bit due to that.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that sounds painful.
The way I personally like the most to deal with nlohmann json is to set up a corresponding hierarchy of POD structs with
to_json
methods in the same namespace (orfrom_json
). Then you can just build up the object with stl tools and implicitly convert it to json in the end - ADL and the json lib does the rest.