-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the proc-macro FfiConverter impls canonical
* Split out the proc-macro code to generate `FfiConverter` implementations and added standalone macros for that. * Removed the `FfiConverter` implementations from the Askama template code. Instead, the templates now invoke the macros. * Made the blanket `Arc<T>` impl in `uniffi_core` depend on a separate `Interface` trait that gets defined by macros. * Added attribute to generate a `try_lift` method for flat errors. This is required to support callback interface errors. The reason for this is: * I want to add some more functionality to `FfiConverter`, but don't want to implement it twice and test it two different ways. * The Interface trait allows us to customize the `Arc<T>` implementation. I plan to push some code that takes advantage of this and I also think it could be useful for #1457. * Everything goes through one code path, which should give us some more confidence as we migrate to proc-macros. This change caused me to fix some bugs with the macro-code and add some features.
- Loading branch information
Showing
17 changed files
with
465 additions
and
365 deletions.
There are no files selected for viewing
18 changes: 7 additions & 11 deletions
18
fixtures/uitests/tests/ui/fieldless_errors_used_in_callbacks_cant_have_fields.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
error[E0063]: missing field `numerator` in initializer of `ArithmeticError` | ||
--> $OUT_DIR[uniffi_uitests]/errors.uniffi.rs | ||
| | ||
| 2 => r#ArithmeticError::r#DivisionByZero{ }, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `numerator` | ||
|
||
error[E0063]: missing field `0` in initializer of `ArithmeticError` | ||
--> $OUT_DIR[uniffi_uitests]/errors.uniffi.rs | ||
| | ||
| 3 => r#ArithmeticError::r#UnexpectedError{ }, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `0` | ||
error[E0533]: expected unit struct, unit variant or constant, found struct variant `Self::DivisionByZero` | ||
--> $OUT_DIR[uniffi_uitests]/errors.uniffi.rs | ||
| | ||
| #[::uniffi::ffi_converter_error(crate::UniFfiTag)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: this error originates in the attribute macro `::uniffi::ffi_converter_error` (in Nightly builds, run with -Z macro-backtrace for more info) |
44 changes: 7 additions & 37 deletions
44
fixtures/uitests/tests/ui/interface_not_sync_and_send.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,18 @@ | ||
error[E0277]: `Cell<u32>` cannot be shared between threads safely | ||
--> $OUT_DIR[uniffi_uitests]/counter.uniffi.rs | ||
| | ||
| uniffi::deps::static_assertions::assert_impl_all!(r#Counter: Sync, Send); | ||
| ^^^^^^^^^ `Cell<u32>` cannot be shared between threads safely | ||
| #[::uniffi::ffi_converter_interface(crate::UniFfiTag)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Cell<u32>` cannot be shared between threads safely | ||
| | ||
= help: within `Counter`, the trait `Sync` is not implemented for `Cell<u32>` | ||
note: required because it appears within the type `Counter` | ||
--> tests/ui/interface_not_sync_and_send.rs:9:12 | ||
| | ||
9 | pub struct Counter { | ||
| ^^^^^^^ | ||
note: required by a bound in `assert_impl_all` | ||
--> $OUT_DIR[uniffi_uitests]/counter.uniffi.rs | ||
| | ||
| uniffi::deps::static_assertions::assert_impl_all!(r#Counter: Sync, Send); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all` | ||
= note: this error originates in the macro `uniffi::deps::static_assertions::assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0277]: `Cell<u32>` cannot be shared between threads safely | ||
--> $OUT_DIR[uniffi_uitests]/counter.uniffi.rs | ||
| | ||
| <std::sync::Arc<r#Counter> as uniffi::FfiConverter<crate::UniFfiTag>>::lower(_arc) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Cell<u32>` cannot be shared between threads safely | ||
note: required by a bound in `Interface` | ||
--> $WORKSPACE/uniffi_core/src/lib.rs | ||
| | ||
= help: within `Counter`, the trait `Sync` is not implemented for `Cell<u32>` | ||
= help: the trait `FfiConverter<UT>` is implemented for `Arc<T>` | ||
note: required because it appears within the type `Counter` | ||
--> tests/ui/interface_not_sync_and_send.rs:9:12 | ||
| | ||
9 | pub struct Counter { | ||
| ^^^^^^^ | ||
= note: required for `Arc<Counter>` to implement `FfiConverter<UniFfiTag>` | ||
|
||
error[E0277]: `Cell<u32>` cannot be shared between threads safely | ||
--> $OUT_DIR[uniffi_uitests]/counter.uniffi.rs | ||
| | ||
| match<std::sync::Arc<r#Counter> as uniffi::FfiConverter<crate::UniFfiTag>>::try_lift(r#ptr) { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Cell<u32>` cannot be shared between threads safely | ||
| | ||
= help: within `Counter`, the trait `Sync` is not implemented for `Cell<u32>` | ||
= help: the trait `FfiConverter<UT>` is implemented for `Arc<T>` | ||
note: required because it appears within the type `Counter` | ||
--> tests/ui/interface_not_sync_and_send.rs:9:12 | ||
| | ||
9 | pub struct Counter { | ||
| ^^^^^^^ | ||
= note: required for `Arc<Counter>` to implement `FfiConverter<UniFfiTag>` | ||
| pub trait Interface<UT>: Send + Sync + Sized {} | ||
| ^^^^ required by this bound in `Interface` | ||
= note: this error originates in the attribute macro `::uniffi::ffi_converter_interface` (in Nightly builds, run with -Z macro-backtrace for more info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,19 @@ | ||
error[E0271]: type mismatch resolving `<Arc<child::Foo> as child::_::_::{closure#0}::TypeEq>::This == Arc<Foo>` | ||
--> tests/ui/proc_macro_arc.rs:21:22 | ||
error[E0277]: the trait bound `Foo: Interface<UniFfiTag>` is not satisfied | ||
--> tests/ui/proc_macro_arc.rs:10:1 | ||
| | ||
21 | fn take_foo(foo: Arc<Foo>) { | ||
| ^^^^^^^^ type mismatch resolving `<Arc<child::Foo> as child::_::_::{closure#0}::TypeEq>::This == Arc<Foo>` | ||
10 | #[uniffi::export] | ||
| ^^^^^^^^^^^^^^^^^ the trait `Interface<UniFfiTag>` is not implemented for `Foo` | ||
| | ||
note: expected this to be `Arc<Foo>` | ||
--> tests/ui/proc_macro_arc.rs:21:22 | ||
= help: the trait `FfiConverter<UT>` is implemented for `Arc<T>` | ||
= note: required for `Arc<Foo>` to implement `FfiConverter<UniFfiTag>` | ||
= note: this error originates in the attribute macro `uniffi::export` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0277]: the trait bound `child::Foo: Interface<UniFfiTag>` is not satisfied | ||
--> tests/ui/proc_macro_arc.rs:20:5 | ||
| | ||
21 | fn take_foo(foo: Arc<Foo>) { | ||
| ^^^ | ||
= note: enum `child::Foo` and struct `Foo` have similar names, but are actually distinct types | ||
note: enum `child::Foo` is defined in module `crate::child` of the current crate | ||
--> tests/ui/proc_macro_arc.rs:18:5 | ||
20 | #[uniffi::export] | ||
| ^^^^^^^^^^^^^^^^^ the trait `Interface<UniFfiTag>` is not implemented for `child::Foo` | ||
| | ||
18 | enum Foo {} | ||
| ^^^^^^^^ | ||
note: struct `Foo` is defined in module `crate` of the current crate | ||
--> tests/ui/proc_macro_arc.rs:8:1 | ||
| | ||
8 | pub struct Foo; | ||
| ^^^^^^^^^^^^^^ | ||
note: required by a bound in `child::_::_::{closure#0}::assert_type_eq_all` | ||
--> tests/ui/proc_macro_arc.rs:21:22 | ||
| | ||
21 | fn take_foo(foo: Arc<Foo>) { | ||
| ^^^ | ||
| | | ||
| required by a bound in this | ||
| required by this bound in `child::_::_::{closure#0}::assert_type_eq_all` | ||
= note: this error originates in the macro `::uniffi::deps::static_assertions::assert_type_eq_all` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
= help: the trait `FfiConverter<UT>` is implemented for `Arc<T>` | ||
= note: required for `Arc<child::Foo>` to implement `FfiConverter<UniFfiTag>` | ||
= note: this error originates in the attribute macro `uniffi::export` (in Nightly builds, run with -Z macro-backtrace for more info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.