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] #3814: Update iroha_ffi_derive to use syn 2.0 #3830

Merged
merged 11 commits into from
Sep 5, 2023

Conversation

DCNick3
Copy link
Contributor

@DCNick3 DCNick3 commented Aug 21, 2023

Description

Separate parsing & (some) validation of attributes and codegen using darling, by storing this information into a strongly typed struct (FfiTypeInput and alike).

To facilitate this, add parsers for derive(FfiType), getset crate and built-in repr and derive attributes and tests for them.

One unfortunate concern is that now ffi_derive has stopped supporting unions completely, due to a limitation of darling. I don't think they are that useful though, especially in context of a high level API iroha provides

Linked issue

Closes #3814

Benefits

Cleaner code, better macro errors

Checklist

  • Rebase (need less commits and proper messages)
  • [ ] Move utility classes to a common place (iroha-derive-primitives, probably) not a good idea until iroha-derive-primitives is syn2-only
  • Make codegen for ffi!, #[ffi_import] and #[ffi_export] emit! errors rather than bail!ing
  • Clean up stray commented out code
  • Fix lints

@github-actions github-actions bot added the iroha2-dev The re-implementation of a BFT hyperledger in RUST label Aug 21, 2023
@coveralls
Copy link

coveralls commented Aug 21, 2023

Pull Request Test Coverage Report for Build 5949198492

  • 1434 of 1871 (76.64%) changed or added relevant lines in 11 files are covered.
  • 5568 unchanged lines in 94 files lost coverage.
  • Overall coverage decreased (-1.4%) to 57.998%

Changes Missing Coverage Covered Lines Changed/Added Lines %
ffi/derive/src/attr_parse/derive.rs 98 100 98.0%
ffi/derive/src/getset_gen.rs 137 148 92.57%
ffi/derive/src/attr_parse/repr.rs 194 210 92.38%
ffi/derive/src/wrapper.rs 43 64 67.19%
ffi/derive/src/lib.rs 107 134 79.85%
ffi/derive/src/emitter.rs 25 59 42.37%
ffi/derive/src/impl_visitor.rs 81 147 55.1%
ffi/derive/src/convert.rs 295 400 73.75%
ffi/derive/src/attr_parse/getset.rs 441 596 73.99%
Files with Coverage Reduction New Missed Lines %
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%
crypto/src/merkle.rs 1 96.23%
data_model/derive/src/partially_tagged.rs 1 99.67%
data_model/src/account.rs 1 52.21%
data_model/src/domain.rs 1 47.37%
derive_primitives/src/lib.rs 1 0%
Totals Coverage Status
Change from base Build 5423219773: -1.4%
Covered Lines: 21420
Relevant Lines: 36932

💛 - Coveralls

DCNick3 added a commit to DCNick3/iroha that referenced this pull request Aug 23, 2023
DCNick3 added a commit to DCNick3/iroha that referenced this pull request Aug 23, 2023
…arse attributes and use syn 2.0

WIP: do not fail fast in ffi!, ffi_import and ffi_export

WIP: fix clippy lints

WIP: remove commented out code

WIP: make the presence of generic arguments a fatal error

(it leads to dubious errors if codegen is ran)

WIP: actually fix clippy lints
DCNick3 added a commit to DCNick3/iroha that referenced this pull request Aug 23, 2023
…ro-error with manyhow

Signed-off-by: Nikita Strygin <DCNick3@users.noreply.github.com>
DCNick3 added a commit to DCNick3/iroha that referenced this pull request Aug 23, 2023
…arse attributes and use syn 2.0

Signed-off-by: Nikita Strygin <DCNick3@users.noreply.github.com>
@DCNick3 DCNick3 force-pushed the syn2-iroha-ffi branch 2 times, most recently from 73bbc38 to 2567474 Compare August 23, 2023 08:56
@DCNick3 DCNick3 marked this pull request as ready for review August 25, 2023 09:13
Copy link
Contributor

@0x009922 0x009922 left a comment

Choose a reason for hiding this comment

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

Great PR and a huge code & UI improvement, it seems for me. I don't have critical objections, although I am not proficient in FFI & procmacro topics.

However, there are some questions and suggestions.

ffi/derive/src/wrapper.rs Show resolved Hide resolved
ffi/derive/src/attr_parse/repr.rs Outdated Show resolved Hide resolved
ffi/derive/src/attr_parse/repr.rs Outdated Show resolved Hide resolved
ffi/derive/src/getset_gen.rs Show resolved Hide resolved
ffi/derive/src/lib.rs Outdated Show resolved Hide resolved
ffi/derive/src/attr_parse/getset.rs Show resolved Hide resolved
ffi/derive/src/attr_parse/getset.rs Outdated Show resolved Hide resolved
ffi/derive/src/attr_parse/getset.rs Outdated Show resolved Hide resolved
ffi/derive/src/attr_parse/getset.rs Outdated Show resolved Hide resolved
ffi/derive/src/attr_parse/getset.rs Show resolved Hide resolved
ffi/tests/ffi_export.rs Outdated Show resolved Hide resolved
ffi/derive/src/attr_parse/repr.rs Outdated Show resolved Hide resolved
ffi/derive/src/attr_parse/derive.rs Show resolved Hide resolved
ffi/derive/src/attr_parse/derive.rs Outdated Show resolved Hide resolved
ffi/derive/src/attr_parse/derive.rs Outdated Show resolved Hide resolved
ffi/derive/src/attr_parse/getset.rs Outdated Show resolved Hide resolved
ffi/derive/src/attr_parse/repr.rs Outdated Show resolved Hide resolved
ffi/derive/src/convert.rs Outdated Show resolved Hide resolved
ffi/derive/src/impl_visitor.rs Outdated Show resolved Hide resolved
ffi/derive/src/impl_visitor.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@ilchu ilchu left a comment

Choose a reason for hiding this comment

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

Just a small doc typo fix, ping afterwards for approval.

ffi/derive/src/convert.rs Outdated Show resolved Hide resolved
…ro-error with manyhow

Signed-off-by: Nikita Strygin <DCNick3@users.noreply.github.com>
…arse attributes and use syn 2.0

Signed-off-by: Nikita Strygin <DCNick3@users.noreply.github.com>
Signed-off-by: Nikita Strygin <dcnick3@users.noreply.github.com>
…tokens

Signed-off-by: Nikita Strygin <dcnick3@users.noreply.github.com>
…into Emitter::finish_token_stream

Signed-off-by: Nikita Strygin <dcnick3@users.noreply.github.com>
…parsing

Signed-off-by: Nikita Strygin <dcnick3@users.noreply.github.com>
… ffi function args

Signed-off-by: Nikita Strygin <dcnick3@users.noreply.github.com>
… Attrs naming

Signed-off-by: Nikita Strygin <dcnick3@users.noreply.github.com>
…parsing attributes to lib.rs

Signed-off-by: Nikita Strygin <dcnick3@users.noreply.github.com>
Signed-off-by: Nikita Strygin <dcnick3@users.noreply.github.com>
…ives in proc macros

Signed-off-by: Nikita Strygin <dcnick3@users.noreply.github.com>
@DCNick3 DCNick3 merged commit baed2fb into hyperledger-iroha:iroha2-dev Sep 5, 2023
11 checks passed
@DCNick3 DCNick3 mentioned this pull request Sep 21, 2023
12 tasks
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.

4 participants