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]: Use context in IntoFfi #2633

Closed

Conversation

mversic
Copy link
Contributor

@mversic mversic commented Aug 17, 2022

Description of the Change

Issue

Benefits

Possible Drawbacks

Usage Examples or Tests [optional]

Alternate Designs [optional]

@github-actions github-actions bot added the iroha2-dev The re-implementation of a BFT hyperledger in RUST label Aug 17, 2022
@mversic mversic force-pushed the refactor_into_ffi branch from ed03bbb to fab69d4 Compare August 17, 2022 15:18
@mversic mversic force-pushed the refactor_into_ffi branch 2 times, most recently from fc4d49c to 4a4a802 Compare August 17, 2022 17:49
@Erigara Erigara self-assigned this Aug 18, 2022
@mversic mversic force-pushed the refactor_into_ffi branch 20 times, most recently from 799bab5 to b9db95b Compare August 18, 2022 21:32
@mversic mversic requested a review from Erigara August 18, 2022 21:33
@mversic mversic force-pushed the refactor_into_ffi branch from b9db95b to e93a7c5 Compare August 18, 2022 21:34
ffi/src/owned.rs Outdated
self.into_iter().map(IntoFfi::into_ffi).collect()
store
.0
.insert(unsafe { data_store.as_ptr().cast::<[T::ReprC; N]>().read() })
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this should be fine?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think so, it's open issue about this.
We don't need to mem::forgot(data_store) since ReprC: Copy.

ffi/src/lib.rs Outdated
/// Convert from &[`Self`] into [`Self::Target`].
fn as_ref(&'itm self) -> Self::Target;
/// Type that can be returned from an FFI function via out-pointer function argument
pub trait Output: FfiType {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This trait is tricky, and might be too permissive, I should add tests as a guard

}

// NOTE: Arrays must be converted into pointers
impl<T: IntoFfi, const N: usize> IntoFfi for [T; N]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think now it's possible to convert [T;0] into ffi which could be problematic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if you still think this is an issue, I'd open an issue

Copy link
Contributor

Choose a reason for hiding this comment

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

I second opening an issue.

ffi/src/owned.rs Outdated
self.into_iter().map(IntoFfi::into_ffi).collect()
store
.0
.insert(unsafe { data_store.as_ptr().cast::<[T::ReprC; N]>().read() })
Copy link
Contributor

Choose a reason for hiding this comment

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

I think so, it's open issue about this.
We don't need to mem::forgot(data_store) since ReprC: Copy.

@mversic mversic force-pushed the refactor_into_ffi branch 4 times, most recently from 02f0f31 to 755e130 Compare August 19, 2022 15:24
@mversic mversic requested a review from Erigara August 19, 2022 15:27
@mversic mversic force-pushed the refactor_into_ffi branch 2 times, most recently from 3cfeb87 to 8c18da2 Compare August 20, 2022 15:58
Signed-off-by: Marin Veršić <[email protected]>
@mversic mversic force-pushed the refactor_into_ffi branch from 8c18da2 to 4bcbb9d Compare August 20, 2022 16:34
@@ -96,7 +96,7 @@ impl AsRef<str> for Name {
impl FromStr for Name {
type Err = ParseError;

fn from_str(candidate: &str) -> Result<Self, Self::Err> {
fn from_str(candidate: &str) -> Result<Self, <Self as FromStr>::Err> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why?

let arg_name = arg.name();
let arg_type = arg.ffi_type_resolved(true);

let (arg_name, arg_type) = (arg.name(), arg.ffi_type_resolved(true));
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't really make it more readable (in fact, less).

}

// NOTE: Arrays must be converted into pointers
impl<T: IntoFfi, const N: usize> IntoFfi for [T; N]
Copy link
Contributor

Choose a reason for hiding this comment

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

I second opening an issue.

Comment on lines +95 to +129
// TODO: Be sure to match the bounds correctly
//impl<'itm, T> IntoFfiVec for &'itm T
//where
// Self: FfiVec<ReprC = <Self as FfiType>::ReprC>,
//{
// type Store = (Vec<<Self as FfiVec>::ReprC>, Vec<<Self as IntoFfi>::Store>);
//
// fn into_ffi(source: Vec<Self>, store: &mut Self::Store) -> Local<SliceRef<Self::ReprC>> {
// store.0 = source
// .into_iter()
// .enumerate()
// .map(|(i, item)| IntoFfi::into_ffi(item, &mut store.1[i]))
// .collect();
//
// Local(SliceRef::from_slice(&store.0))
// }
//}
//
//impl<T: IntoFfiVec> IntoFfiVec for Vec<T>
//where
// Self: FfiVec<ReprC = SliceRef<T::ReprC>>,
//{
// type Store = (Vec<<Self as FfiVec>::ReprC>, Vec<<T as IntoFfiVec>::Store>);
//
// fn into_ffi(source: Vec<Self>, store: &mut Self::Store) -> Local<SliceRef<Self::ReprC>> {
// store.0 = source
// .into_iter()
// .enumerate()
// .map(|(i, item)| IntoFfiVec::into_ffi(item, &mut store.1[i]).0)
// .collect();
//
// Local(SliceRef::from_slice(&store.0))
// }
//}

Copy link
Contributor

Choose a reason for hiding this comment

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

Add issue if commented code is to be merged. Add it to the epic.

Comment on lines +311 to +317
// let mut i = 0;
// while let Some((first, rest)) = substore.split_first_mut() {
// let elem: &$ffi_ty<$($ty::ReprC,)*> = &slice[i];
// res.push(Clone::clone(TryFromReprC::try_from_repr_c(elem, first)?));
// substore = rest;
// i += 1;
// }
Copy link
Contributor

@appetrosyan appetrosyan Aug 22, 2022

Choose a reason for hiding this comment

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

I'd recommend fixing this before merge. If you decide to merge as is, remove and create an issue.

Comment on lines +407 to +416
//impl_tuple! {(A, B, C) -> FfiTuple3}
//impl_tuple! {(A, B, C, D) -> FfiTuple4}
//impl_tuple! {(A, B, C, D, E) -> FfiTuple5}
//impl_tuple! {(A, B, C, D, E, F) -> FfiTuple6}
//impl_tuple! {(A, B, C, D, E, F, G) -> FfiTuple7}
//impl_tuple! {(A, B, C, D, E, F, G, H) -> FfiTuple8}
//impl_tuple! {(A, B, C, D, E, F, G, H, I) -> FfiTuple9}
//impl_tuple! {(A, B, C, D, E, F, G, H, I, J) -> FfiTuple10}
//impl_tuple! {(A, B, C, D, E, F, G, H, I, J, K) -> FfiTuple11}
//impl_tuple! {(A, B, C, D, E, F, G, H, I, J, K, L) -> FfiTuple12}
Copy link
Contributor

Choose a reason for hiding this comment

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

No longer needed? It would be nice if we can automate this process.

@mversic
Copy link
Contributor Author

mversic commented Aug 23, 2022

closed in favor of #2625

@mversic mversic closed this Aug 23, 2022
@mversic mversic deleted the refactor_into_ffi branch December 27, 2022 23:35
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.

3 participants