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

Split up FfiConverter #1766

Merged
merged 1 commit into from
Oct 3, 2023
Merged

Split up FfiConverter #1766

merged 1 commit into from
Oct 3, 2023

Conversation

bendk
Copy link
Contributor

@bendk bendk commented Sep 25, 2023

We've been discussing this for a while, here's my attempt at it. This makes it so the macro code stops using FfiConverter and starts using more specialized traits Return, Lift, etc. The FfiConverter trait lives on, but just as a simple way to implement all the traits that we actually use in the generated code.

This is rebased on top of the async-cancellation branch because that one had some changes to how we handled callback returns. Ignore all commits except the last. If we end up not taking that branch, I think it should be pretty easy to rebase over main too.

@bendk bendk requested review from mhammond and jplatte September 25, 2023 21:45
@bendk bendk requested a review from a team as a code owner September 25, 2023 21:45
@bendk bendk force-pushed the split-up-fficonverter branch 2 times, most recently from ee94c6c to 767d02c Compare September 25, 2023 23:00
Copy link
Collaborator

@jplatte jplatte left a comment

Choose a reason for hiding this comment

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

Very nice! I have some ideas for follow-ups, but want to experiment with that myself after this is merged :)

Comment on lines 350 to 351
// Note that because of webidl limitations,
// the key must always be of the String type.
Copy link
Collaborator

Choose a reason for hiding this comment

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

… if UDL is used?

Copy link
Member

@mhammond mhammond left a comment

Choose a reason for hiding this comment

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

I agree, very nice!

//!
//! These traits define how to pass values over the FFI in various ways: as arguments or as return
//! values, from Rust to the foreign side and vice-versa. These traits are mainly used by the
//! proc-macro generated code. The goal is to allow the proc-macros to go from a type name to the
Copy link
Member

Choose a reason for hiding this comment

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

I think this para might be better dropping the word "proc-macro" from "proc-macro generated code"? It almost implies "not by UDL" which I don't think is the intent.

//! | |
//! | --------------
//! | | |
//! [Return] [LiftRef] [ForeignReturn]
Copy link
Member

Choose a reason for hiding this comment

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

Not too keen on Return and ForeignReturn - it's a little clearer once you see the trait definiton, but less so when reading code referencing the trait without a method. How about LowerReturn/LiftForeignReturn (any maybe even dropping Foreign in the latter?)

@bendk bendk force-pushed the split-up-fficonverter branch from 767d02c to 06f1d2a Compare September 26, 2023 15:43
Copy link
Contributor

@Hywan Hywan left a comment

Choose a reason for hiding this comment

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

Really nice!

Added new traits for specific operations (lift, lower, return, etc) and
use those in the macro code.  Added the `derive_ffi_traits!` macro to
derive impls for those traits for types that define FfiConverter.

The new system allows us have more fine grained control over what types
implement.  We now can implement Lower without Lift, Return without
Lower, etc.

This simplifies callback error handling. No more need for the
handle_unknown_callback_error attribute.  Errors that implement
From<UnexpectedUniFFICallbackError> work with callback interfaces and
errors that don't will result in a compile-time error.

Many exported functions that used to cause UniFFI panics when called,
like functions that inputted errors or results will now fail to compile.
This required some changes to the keywords fixtures.  It also means that
we don't need to implement `FfiConverter` methods with a body that just
panics.
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.

4 participants