-
Notifications
You must be signed in to change notification settings - Fork 6.1k
[Yul] Yul objects parser #5358
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
[Yul] Yul objects parser #5358
Conversation
Can you split the specification change out? |
Factored out: #5428 |
Codecov Report
@@ Coverage Diff @@
## develop #5358 +/- ##
===========================================
+ Coverage 88.17% 88.19% +0.02%
===========================================
Files 314 319 +5
Lines 31497 31649 +152
Branches 3775 3791 +16
===========================================
+ Hits 27773 27914 +141
- Misses 2457 2459 +2
- Partials 1267 1276 +9
|
Question: Is the order of sub-objects relevant? Should we retain it? Currently, the printer sorts the sub objects according to the YulString sorting order, which is bad. We should either sort the sub objects by binary string order or retain the order. Any opinions? |
I don't think the ordering should matter, but I can definitely see that being expected from others, so I would suggest to keep the order it was parsed or the order it was inserted into the AST. |
Yep, sounds good! This probably requires some modifications in YulObject. Will work on that next week. |
e951185
to
66e0215
Compare
d8dd0e7
to
5c21ff8
Compare
{ | ||
// Special case: Code-only form. | ||
object = make_shared<Object>(); | ||
object->name = YulString{"object"}; |
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.
This is the default name for the object if only code is given. Any better ideas?
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 think this name is fine.
I would suggest that the names of objects and data could be either string literals or identifiers. |
libyul/Object.h
Outdated
|
||
#include <libdevcore/Common.h> | ||
|
||
#include <boost/variant.hpp> |
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.
Not used
About using literal strings or identifiers: I would want to avoid using actual identifiers in code (i.e. in If we agree on that, then I think it also makes sense to use the syntax
instead of
Edit: Replaced "literals" by "identifiers" |
Will extract the tests into isoltest. |
Wait, you said you do not want to use literals in the code (e.g. |
shared_ptr<Block> ObjectParser::parseCode() | ||
{ | ||
if (currentToken() != Token::Identifier || currentLiteral() != "code") | ||
fatalParserError("Expected keyword \"code\"."); |
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.
The grammar says that code
is optional, but the parser returns an error if it's not there. By looking at the rest of the code, I assume the grammar is wrong.
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.
Ah, I did not remember that! I guess it does not make too much sense to have objects without code. If you really want to have an object without code, you can also use empty code.
Another thing I noticed is that according to the grammar, the top level object has no name. This is a mistake, I would say.
{ | ||
// Special case: Code-only form. | ||
object = make_shared<Object>(); | ||
object->name = YulString{"object"}; |
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 think this name is fine.
@leonardoalt sorry, I meant to write "identifier" instead of "literal" - updated my comment, please take a look. |
In summary, I would propose to change the Yul grammar such that:
|
@chriseth I agree with your literal/identifier and grammar points. |
OK, then I'll merge this and update the grammar in another PR. |
Actually, let me make an addition to the changelog, because the |
Grammar change is here: #5524 |
Parser for yul objects. Backwards-compatible in that it generates a yul object with only code if it is given only code.
Also modifies the assembly stack and the
solc --assemble
functionality to use yul objects.What is still missing (different PR):