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

support ffi_export on trait implementations #2488

Closed
mversic opened this issue Jul 15, 2022 · 1 comment
Closed

support ffi_export on trait implementations #2488

mversic opened this issue Jul 15, 2022 · 1 comment
Assignees
Labels
iroha2-dev The re-implementation of a BFT hyperledger in RUST

Comments

@mversic
Copy link
Contributor

mversic commented Jul 15, 2022

ffi_export attribute can be attached on inherent impls. This is not a hard limitation, this attribute could be made to support trait impls as well. This is not a very difficult thing to do but requires the macro library to support parsing of associated types.

If you take a look at data_model::name you can see that Name__from_str is implemented manually and is essentially a wrapper around FromStr implementation for Name. Impls such as this could be generated with ffi_export as well like this:

#[ffi_export]
impl FromStr for Name {
    type Err = ParseError;

    fn from_str(candidate: &str) -> Result<Self, Self::Err> {
        Self::validate_str(candidate).map(|_| Self(ConstString::from(candidate)))
    }
}

which would generate, once macro is expanded, something like:

extern fn Name__from_str(candidate: <<&str> as TryFromReprC>::Source) -> iroha_ffi::FfiResult {
    // ... generated code ...
}
@mversic mversic added the iroha2-dev The re-implementation of a BFT hyperledger in RUST label Jul 15, 2022
@mversic
Copy link
Contributor Author

mversic commented Jul 25, 2022

after some thought, I'm not sure this is what should be done in case of every trait impl, at least not for the traits in the std.

  1. Traits in std that don't contain associated types should be implemented with gen_ffi_impl in iroha_ffi::handle which forces multiplexing and reduces the size of the dynamically linked executable (smartcontract).
  2. Traits in std that contain associated types can support implementation via ffi_export because their associated methods are most likely generic over the contained associated type. This is FromStr in the previous example
  3. User defined traits, having associated types or not, cannot be known ahead of time and for them it might make sense to offer implementation via ffi_export. However, if technically feasible, their implementations should also be multiplexed

@Erigara Erigara self-assigned this Aug 4, 2022
Erigara added a commit that referenced this issue Aug 15, 2022
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
@Erigara Erigara closed this as completed Aug 16, 2022
mversic pushed a commit to mversic/iroha that referenced this issue Sep 6, 2022
…_export`

Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
mversic pushed a commit to mversic/iroha that referenced this issue Sep 6, 2022
…_export`

Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
mversic pushed a commit to mversic/iroha that referenced this issue Sep 6, 2022
…_export`

Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
mversic pushed a commit to mversic/iroha that referenced this issue Sep 7, 2022
…_export`

Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
BAStos525 pushed a commit to mversic/iroha that referenced this issue Sep 7, 2022
…_export`

Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Signed-off-by: BAStos525 <jungle.vas@yandex.ru>
mversic pushed a commit to mversic/iroha that referenced this issue Sep 8, 2022
…_export`

Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
mversic pushed a commit to mversic/iroha that referenced this issue Sep 9, 2022
…_export`

Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
mversic pushed a commit to mversic/iroha that referenced this issue Sep 9, 2022
…_export`

Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
BAStos525 pushed a commit to mversic/iroha that referenced this issue Sep 9, 2022
…_export`

Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
mversic pushed a commit to mversic/iroha that referenced this issue Sep 9, 2022
…_export`

Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
BAStos525 pushed a commit to mversic/iroha that referenced this issue Sep 9, 2022
…_export`

Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
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

No branches or pull requests

3 participants