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

[refactor]: introduce syn 2.0, manyhow and darling for proc-macros #3727

Merged

Conversation

DCNick3
Copy link
Contributor

@DCNick3 DCNick3 commented Jul 20, 2023

Description

This PR adds syn 2.0 to the workspace (under the name of syn2, to allow co-existence of different versions).

It then updates iroha_version_derive, iroha_primitives_derive and iroha_derive to use syn2, as well as moving from unmaintained proc-macro-error to manyhow.

It also changes some macro APIs:

I also propose the following changes for VariantCount macro (not yet implemented):

  • confusingly, attributes for VariantCount are placed on fields instead of enum variants. I suggest we move them to variants, as it's really a property of the variant
  • the naming of #[skip_try_from] is confusing in the context of #[skip_from]: the different in names is in the try, but they correspond to different directions of the generated conversions: from is for Variant -> Enum and try_from is for Enum -> Variant. I suggest changing the name to #[skip_into] or #[skip_try_into] to properly represent the change of conversion direction, even if the actual generated trait is From
  • Maybe change #[skip_container] to #[skip_from_container]?

Benefits

Unlike proc-macro-error, manyhow is actively maintained and has cleaner API that does not rely on global state.

Using darling streamlines parsing of (most) attributes by using a declarative serde-like model, also providing reasonable error messages.

@github-actions github-actions bot added the iroha2-dev The re-implementation of a BFT hyperledger in RUST label Jul 20, 2023
@DCNick3 DCNick3 changed the title [refactor] introduce syn 2.0 + manyhow showcase [refactor]: introduce syn 2.0 + manyhow showcase Jul 20, 2023
@coveralls
Copy link

coveralls commented Jul 20, 2023

Pull Request Test Coverage Report for Build 5689584713

  • 183 of 205 (89.27%) changed or added relevant lines in 4 files are covered.
  • 4094 unchanged lines in 80 files lost coverage.
  • Overall coverage decreased (-1.5%) to 57.945%

Changes Missing Coverage Covered Lines Changed/Added Lines %
primitives/derive/src/socket_addr.rs 24 25 96.0%
version/derive/src/lib.rs 38 48 79.17%
macro/derive/src/lib.rs 118 129 91.47%
Files with Coverage Reduction New Missed Lines %
client_cli/src/main.rs 1 0%
cli/src/main.rs 1 0%
cli/src/torii/pagination.rs 1 98.9%
config/base/src/runtime_upgrades.rs 1 51.72%
config/src/torii.rs 1 96.67%
core/src/smartcontracts/isi/block.rs 1 87.5%
core/src/sumeragi/network_topology.rs 1 96.76%
crypto/src/merkle.rs 1 96.23%
data_model/src/account.rs 1 52.21%
data_model/src/domain.rs 1 47.37%
Totals Coverage Status
Change from base Build 5423219773: -1.5%
Covered Lines: 19791
Relevant Lines: 34155

💛 - Coveralls

@DCNick3 DCNick3 changed the title [refactor]: introduce syn 2.0 + manyhow showcase [refactor]: introduce syn 2.0 + manyhow and darling showcase Jul 20, 2023
version/derive/Cargo.toml Outdated Show resolved Hide resolved
version/derive/src/lib.rs Outdated Show resolved Hide resolved
version/derive/src/lib.rs Outdated Show resolved Hide resolved
@DCNick3 DCNick3 changed the title [refactor]: introduce syn 2.0 + manyhow and darling showcase [refactor]: introduce syn 2.0, manyhow and darling for proc-macros Jul 21, 2023
@DCNick3 DCNick3 marked this pull request as ready for review July 21, 2023 13:05
appetrosyan
appetrosyan previously approved these changes Jul 24, 2023
@DCNick3 DCNick3 mentioned this pull request Jul 24, 2023
3 tasks
@DCNick3 DCNick3 force-pushed the syn2-manyhow-showcase branch 2 times, most recently from 05a71e5 to 5ead4f2 Compare July 26, 2023 13:31
appetrosyan
appetrosyan previously approved these changes Jul 26, 2023
appetrosyan
appetrosyan previously approved these changes Jul 26, 2023
Erigara
Erigara previously approved these changes Jul 28, 2023
Copy link
Contributor

@Erigara Erigara left a comment

Choose a reason for hiding this comment

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

Good job!

macro/derive/src/lib.rs Show resolved Hide resolved
macro/derive/src/lib.rs Show resolved Hide resolved
@DCNick3 DCNick3 dismissed stale reviews from Erigara and appetrosyan via 5055e57 July 28, 2023 07:13
…proc-macro-error with manyhow

Signed-off-by: Nikita Strygin <DCNick3@users.noreply.github.com>
Also update names of parameters of `#[version]` attribute

Signed-off-by: Nikita Strygin <DCNick3@users.noreply.github.com>
Signed-off-by: Nikita Strygin <DCNick3@users.noreply.github.com>
Signed-off-by: Nikita Strygin <DCNick3@users.noreply.github.com>
It's just strum::EnumCount anyways

Signed-off-by: Nikita Strygin <DCNick3@users.noreply.github.com>
- use darling's traits to parse the input
- cover attributes with tests
- add a diagnostic for a common error: attribute on variant instead of field
- ensure spans for generated enums are linked to enum variants, which improves "conflicting implementation" errors

Signed-off-by: Nikita Strygin <DCNick3@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iroha2-dev The re-implementation of a BFT hyperledger in RUST
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants