-
Notifications
You must be signed in to change notification settings - Fork 241
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
Split up FfiConverter #1766
Conversation
ee94c6c
to
767d02c
Compare
There was a problem hiding this 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 :)
// Note that because of webidl limitations, | ||
// the key must always be of the String type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
… if UDL is used?
There was a problem hiding this 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 |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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?)
767d02c
to
06f1d2a
Compare
There was a problem hiding this 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.
06f1d2a
to
496ed73
Compare
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 traitsReturn
,Lift
, etc. TheFfiConverter
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.