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

Types cleanup #485

Merged
merged 1 commit into from
Jul 28, 2021
Merged

Types cleanup #485

merged 1 commit into from
Jul 28, 2021

Conversation

g-r-a-n-t
Copy link
Member

@g-r-a-n-t g-r-a-n-t commented Jul 16, 2021

What was wrong?

All type traits were defined in the analyzer crate, when they should have been split up among the crates where they're actually used.

How was it fixed?

  • Removed the AbiEncoding trait and used a new trait called JsonAbi in the abi crate.
  • The yulgen crate now just implements From<..> on AbiType for each Fe type.
  • The FeSized trait was renamed to EvmSized and moved to the yulgen crate.

There were a few other things done in this PR:

  • Consolidated ABI selector code in the abi crate.
  • Created revert operations.

To-Do

  • OPTIONAL: Update Spec if applicable

  • Add entry to the release notes (may forgo for trivial changes)

  • Clean up commit history

@g-r-a-n-t g-r-a-n-t marked this pull request as draft July 16, 2021 17:31
crates/abi/src/elements.rs Outdated Show resolved Hide resolved
crates/analyzer/src/namespace/events.rs Show resolved Hide resolved
crates/abi/src/elements.rs Outdated Show resolved Hide resolved
if let Type::Struct(val) = &error_attributes.typ {
context.revert_errors.insert(val.clone());
if let Type::Struct(_struct) = &error_attributes.typ {
context.revert_errors.insert(_struct.clone());
Copy link
Member Author

Choose a reason for hiding this comment

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

note how we can get rid of this

Copy link
Member Author

Choose a reason for hiding this comment

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

@cburgdorf

Instead of adding this information to the context and then building a list of Yul functions based on it, I think we should accumulate functions as operations are used. This should make things more manageable.

Basically, inside of the operation function, we would have a line like context.add_deps(operation_deps), where operation_deps is a list functions needed in the Yul runtime for the operation to work.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, that sounds like a good idea 👍

crates/yulgen/src/operations/revert.rs Show resolved Hide resolved
crates/yulgen/src/runtime/functions/revert.rs Show resolved Hide resolved
crates/yulgen/src/runtime/mod.rs Outdated Show resolved Hide resolved
crates/yulgen/src/types.rs Show resolved Hide resolved
crates/yulgen/src/types.rs Show resolved Hide resolved
crates/yulgen/src/types.rs Show resolved Hide resolved

let revert_data = expressions::expr(context, error_expr);
let size = abi_operations::encoding_size(&[val.clone()], vec![revert_data.clone()]);
Copy link
Member Author

Choose a reason for hiding this comment

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

encoding size is found in the revert function

@codecov-commenter
Copy link

Codecov Report

Merging #485 (cbec1b6) into master (52df65b) will increase coverage by 0.08%.
The diff coverage is 88.23%.

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

@@            Coverage Diff             @@
##           master     #485      +/-   ##
==========================================
+ Coverage   87.70%   87.79%   +0.08%     
==========================================
  Files          78       80       +2     
  Lines        5263     5268       +5     
==========================================
+ Hits         4616     4625       +9     
+ Misses        647      643       -4     
Impacted Files Coverage Δ
crates/abi/src/builder.rs 95.55% <ø> (ø)
crates/analyzer/src/lib.rs 81.81% <ø> (+54.54%) ⬆️
crates/test-utils/src/lib.rs 83.27% <0.00%> (-0.27%) ⬇️
crates/yulgen/src/lib.rs 100.00% <ø> (ø)
crates/yulgen/src/mappers/assignments.rs 75.00% <ø> (ø)
crates/yulgen/src/mappers/declarations.rs 75.00% <ø> (ø)
crates/yulgen/src/mappers/expressions.rs 90.00% <ø> (ø)
crates/yulgen/src/runtime/functions/structs.rs 100.00% <ø> (ø)
crates/yulgen/src/types.rs 73.21% <73.21%> (ø)
crates/abi/src/elements.rs 87.61% <90.16%> (+2.99%) ⬆️
... and 20 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 52df65b...1e53e88. Read the comment docs.

@g-r-a-n-t g-r-a-n-t requested a review from cburgdorf July 28, 2021 03:59
if (iszero([test])) {
([revert_fn]([msg], [size]))
[revert_operations::error_revert(&AbiType::from(string), msg)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks a whole lot cleaner indeed :)

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 solid 👍

crates/yulgen/src/runtime/functions/revert.rs Show resolved Hide resolved
@g-r-a-n-t g-r-a-n-t marked this pull request as ready for review July 28, 2021 17:23
@g-r-a-n-t g-r-a-n-t merged commit 9fc45b3 into ethereum:master Jul 28, 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.

3 participants