Skip to content

[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

Merged
merged 4 commits into from
Nov 28, 2018
Merged

[Yul] Yul objects parser #5358

merged 4 commits into from
Nov 28, 2018

Conversation

chriseth
Copy link
Contributor

@chriseth chriseth commented Nov 7, 2018

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):

  • implement code generator changes
  • add yul functions to access objects

@axic
Copy link
Member

axic commented Nov 14, 2018

Can you split the specification change out?

@chriseth
Copy link
Contributor Author

Factored out: #5428

@codecov
Copy link

codecov bot commented Nov 21, 2018

Codecov Report

Merging #5358 into develop will increase coverage by 0.02%.
The diff coverage is 89.41%.

Impacted file tree graph

@@             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
Flag Coverage Δ
#all 88.19% <89.41%> (+0.02%) ⬆️
#syntax 28.97% <9.41%> (-0.09%) ⬇️

@chriseth
Copy link
Contributor Author

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?

@axic
Copy link
Member

axic commented Nov 22, 2018

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.

@chriseth
Copy link
Contributor Author

Yep, sounds good! This probably requires some modifications in YulObject. Will work on that next week.

@chriseth chriseth force-pushed the yulObjects branch 3 times, most recently from e951185 to 66e0215 Compare November 26, 2018 18:27
@chriseth chriseth changed the title [Yul][WIP] Yul objects parser [Yul] Yul objects parser Nov 26, 2018
@chriseth chriseth force-pushed the yulObjects branch 2 times, most recently from d8dd0e7 to 5c21ff8 Compare November 26, 2018 19:03
{
// Special case: Code-only form.
object = make_shared<Object>();
object->name = YulString{"object"};
Copy link
Contributor Author

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?

Copy link
Member

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
Copy link
Member

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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used

@chriseth
Copy link
Contributor Author

chriseth commented Nov 27, 2018

About using literal strings or identifiers: I would want to avoid using actual identifiers in code (i.e. in mstore(0, datasize("subContract"))) because then we would have different scoping rules for things that otherwise look identical - it should just be fully opaque for things like the optimizer.

If we agree on that, then I think it also makes sense to use the syntax

object "objectName" { ... }

instead of

object objectName { ... }

Edit: Replaced "literals" by "identifiers"

@chriseth
Copy link
Contributor Author

Will extract the tests into isoltest.

@leonardoalt
Copy link
Member

Wait, you said you do not want to use literals in the code (e.g. "subContract"), but that it makes sense then to use the syntax object "objectName". I'm a bit confused.

leonardoalt
leonardoalt previously approved these changes Nov 27, 2018
shared_ptr<Block> ObjectParser::parseCode()
{
if (currentToken() != Token::Identifier || currentLiteral() != "code")
fatalParserError("Expected keyword \"code\".");
Copy link
Member

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.

Copy link
Contributor Author

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"};
Copy link
Member

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.

@chriseth
Copy link
Contributor Author

@leonardoalt sorry, I meant to write "identifier" instead of "literal" - updated my comment, please take a look.

@chriseth
Copy link
Contributor Author

In summary, I would propose to change the Yul grammar such that:

  • there is no distinction between top-level and general object (i.e. also the top-level object has to be name)
  • code is not optional

@leonardoalt
Copy link
Member

@chriseth I agree with your literal/identifier and grammar points.

@chriseth
Copy link
Contributor Author

OK, then I'll merge this and update the grammar in another PR.

@chriseth
Copy link
Contributor Author

Actually, let me make an addition to the changelog, because the --assembly output changed.

@chriseth
Copy link
Contributor Author

Grammar change is here: #5524

@chriseth chriseth merged commit 7cbf046 into develop Nov 28, 2018
@axic axic deleted the yulObjects branch November 28, 2018 10:58
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