Skip to content
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

Lower list expressions #388

Merged
merged 2 commits into from
May 5, 2021

Conversation

cburgdorf
Copy link
Collaborator

@cburgdorf cburgdorf commented May 4, 2021

What was wrong?

We do not yet support list expressions e.g. [1, 2, 3]

How was it fixed?

  1. List expressions are taken care of in the lowering pass. They are lowered to a function call where in the function we do an array declaration and individual assignments.
  2. Added a blanket trait with into_node() and into_boxed_node() methods to make working without significant spans less annoying
  3. Added tests for the lowering as well as for the feature itself

@sbillig
Copy link
Collaborator

sbillig commented May 4, 2021

BTW, the parser doesn't allow newlines inside of square brackets at the moment. I made an issue for it #389.

@cburgdorf cburgdorf force-pushed the christoph/feat/list_expr branch 2 times, most recently from 1f05ba2 to f789cba Compare May 5, 2021 13:08
@cburgdorf cburgdorf marked this pull request as ready for review May 5, 2021 13:08
@cburgdorf cburgdorf requested a review from g-r-a-n-t May 5, 2021 13:08
.contract_scope()
.borrow()
.function_def(func_name)
}) = called_func
Copy link
Collaborator Author

@cburgdorf cburgdorf May 5, 2021

Choose a reason for hiding this comment

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

Moving this out of the if let was needed to mitigate a borrow_mut() violation...this took me way to long to find 😅

Copy link
Member

Choose a reason for hiding this comment

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

yeah, Ive ran into this too

// Turn List Expression into a function call
return fe::Expr::Call {
func: fe::Expr::Attribute {
value: fe::Expr::Name(_self.to_string()).into_boxed_node(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm sure there's a nicer way to get the string of the Object::Self that would allow me to move it back inline here but I wasn't able to find it. /cc @sbillig

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess the best way is probably to derive strum::ToString instead of (or in addition to) IntoStaticStr, and do fe::Expr::Name(Object::Self_.to_string())

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

haha, it's that simple, thanks!

@codecov-commenter
Copy link

codecov-commenter commented May 5, 2021

Codecov Report

Merging #388 (fb2ae32) into master (77090b3) will increase coverage by 0.17%.
The diff coverage is 100.00%.

❗ Current head fb2ae32 differs from pull request most recent head 4fb26e6. Consider uploading reports for the commit 4fb26e6 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #388      +/-   ##
==========================================
+ Coverage   86.33%   86.51%   +0.17%     
==========================================
  Files          66       67       +1     
  Lines        4011     4048      +37     
==========================================
+ Hits         3463     3502      +39     
+ Misses        548      546       -2     
Impacted Files Coverage Δ
compiler/src/lowering/mod.rs 100.00% <ø> (ø)
analyzer/src/context.rs 92.81% <100.00%> (+0.03%) ⬆️
analyzer/src/namespace/scopes.rs 96.00% <100.00%> (+0.06%) ⬆️
analyzer/src/namespace/types.rs 90.05% <100.00%> (+0.05%) ⬆️
analyzer/src/traversal/expressions.rs 92.20% <100.00%> (+0.46%) ⬆️
compiler/src/lowering/mappers/contracts.rs 100.00% <100.00%> (ø)
compiler/src/lowering/mappers/expressions.rs 100.00% <100.00%> (ø)
compiler/src/lowering/names.rs 73.33% <100.00%> (+7.94%) ⬆️
compiler/src/lowering/utils.rs 100.00% <100.00%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 77090b3...4fb26e6. Read the comment docs.

contract Foo:

pub def bar() -> u256:
my_array: u256[3] = [10, 20, 30]
Copy link
Member

Choose a reason for hiding this comment

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

what happens if we, say, use an array of size 20? 👿

Im wondering if we have stack problems during yul compilation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh yeah, I missed to check that...I'll check it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated the tests, appears to be working fine 😅

Copy link
Member

Choose a reason for hiding this comment

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

bruns

Copy link
Member

@g-r-a-n-t g-r-a-n-t left a comment

Choose a reason for hiding this comment

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

looks good 👍

.contract_scope()
.borrow()
.function_def(func_name)
}) = called_func
Copy link
Member

Choose a reason for hiding this comment

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

yeah, Ive ran into this too

@cburgdorf cburgdorf force-pushed the christoph/feat/list_expr branch from f789cba to cab4436 Compare May 5, 2021 19:41
@cburgdorf cburgdorf force-pushed the christoph/feat/list_expr branch from cab4436 to 4fb26e6 Compare May 5, 2021 19:45
@cburgdorf cburgdorf merged commit b15235b into ethereum:master May 5, 2021
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.

4 participants