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

Move tuple and list expr collection to lowering pass; support lowering of nested tuples #459

Merged
merged 3 commits into from
Jun 22, 2021

Conversation

sbillig
Copy link
Collaborator

@sbillig sbillig commented Jun 20, 2021

What was wrong?

Another salsa-inspired change. The analyzer collects a bunch of stuff for the later passes, but those passes can collect the stuff just as easily.

How was it fixed?

Added a couple context structs to the lowering pass, and removed tuples_used and list_expressions stuff from the analyzer.

While I was mucking about, I added lowering support for nested tuples, because I can't stop myself from sneaking unrelated stuff into a PR. Generated tuple struct names now include a trailing underscore to differentiate between different tuple nestings. I initially made this a special case for nested tuples, but the special casing didn't seem as aesthetically pleasing to me. Conceptually, the generated tuple struct name replaces each paren and comma with an underscore, and each item type name with its lowered type name.

((A, B), C, D) // tuple_tuple_A_B__C_D_
((A, B, C), D) // tuple_tuple_A_B_C__D_
((A, B, C, D),) // tuple_tuple_A_B_C_D__

Also tuples in type aliases weren't being lowered; eg type T = (u8, u8); they are now. I called this a feature, because I guess tuple type aliases are new functionality.

To-Do

@sbillig sbillig marked this pull request as ready for review June 20, 2021 19:32
@codecov-commenter
Copy link

codecov-commenter commented Jun 20, 2021

Codecov Report

Merging #459 (2719d3e) into master (0ab0f5d) will decrease coverage by 0.14%.
The diff coverage is 95.35%.

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

@@            Coverage Diff             @@
##           master     #459      +/-   ##
==========================================
- Coverage   87.33%   87.18%   -0.15%     
==========================================
  Files          72       73       +1     
  Lines        4975     5011      +36     
==========================================
+ Hits         4345     4369      +24     
- Misses        630      642      +12     
Impacted Files Coverage Δ
analyzer/src/traversal/expressions.rs 91.30% <ø> (-0.09%) ⬇️
analyzer/src/traversal/types.rs 100.00% <ø> (ø)
parser/src/node.rs 58.82% <ø> (ø)
analyzer/src/namespace/types.rs 82.73% <62.50%> (-0.34%) ⬇️
compiler/src/lowering/mappers/module.rs 83.33% <78.78%> (-12.32%) ⬇️
compiler/src/yul/mappers/module.rs 86.66% <87.50%> (ø)
parser/src/ast.rs 48.88% <90.90%> (ø)
parser/src/grammar/module.rs 86.25% <93.33%> (ø)
compiler/src/yul/mappers/contracts.rs 97.14% <95.83%> (ø)
analyzer/src/traversal/contracts.rs 97.46% <96.66%> (ø)
... and 38 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 0ab0f5d...6807996. Read the comment docs.

@sbillig sbillig force-pushed the lowering-context branch 3 times, most recently from ce066af to d6db2d5 Compare June 21, 2021 06:18
@sbillig sbillig requested a review from cburgdorf June 21, 2021 06:21
Copy link
Collaborator

@cburgdorf cburgdorf 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 and makes sense. Left a few comments inline.

@@ -7,7 +7,6 @@ on:
- v*

pull_request:
branches: [master]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Was this intended? What does it do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah; that's in a separate commit. It enables gh actions for all PRs, regardless of the target branch. Sometimes I open a PR that depends on another that's pending review/merge; so I push the branch of the first to the main repo, and have the second PR target that branch (temporarily) so that the changes of the first don't show in the second's diff. (This one depends on #458)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, makes sense 👍

@@ -53,8 +53,6 @@ pub struct ContractAttributes {
/// Events that have been defined by the user.
pub events: Vec<EventDef>,
/// List expressions that the contract uses
pub list_expressions: BTreeSet<Array>,
/// Static strings that the contract defines
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like the wrong comment was removed. (Should have removed the comment from line 55

@@ -28,6 +28,7 @@ maplit = "1.0.2"
once_cell = "1.5.2"
vec1 = "1.8.0"
num-bigint = "0.3.1"
indexmap = "1.6.2"
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice one!

@@ -1,52 +1,52 @@
struct tuple_u256_bool:
struct __Tuple0:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you consider alterations to the current naming scheme that would preserve the readability better? E.g. we could encode the opening and closing parenthesis with some character like an extra _.

((A, B), C, D) // _tuple__tuple_A_B__C_D_
((A, B, C), D) // _tuple__tuple_A_B_C__D_

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I was thinking that that's less readable in the case of a couple nestings, but it's better in the simpler/common cases, so I'll switch it back.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, I guess having to differentiate between two easy to confuse tuples will be rather rare so maybe it's better to keep it readable for the common cases.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's now

(A, B) => tuple_A_B_
(A, (B, C), D) => tuple_A_tuple_B_C__D_

ie, replace parens and commas with underscores, and prefix with "tuple"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks good 👍

// nested structs aren't supported yet. we should move the
// not-yet-implemented error to the compiler.
//
// fe_analyzer::analyze(&actual_lowered_ast, src_id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably worth creating an issue for it and putting it on the active milestone unless you have that work already in progress anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Opened #461

@sbillig sbillig changed the title Move tuple and list expr collection to lowering pass Move tuple and list expr collection to lowering pass; support lowering of nested tuples Jun 21, 2021
@sbillig sbillig force-pushed the lowering-context branch 2 times, most recently from 52be986 to 768df08 Compare June 22, 2021 19:27
@sbillig sbillig changed the base branch from ast-item-structs to master June 22, 2021 19:42
@sbillig sbillig merged commit b0caf12 into ethereum:master Jun 22, 2021
@sbillig sbillig deleted the lowering-context branch June 22, 2021 20:32
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