Allow Gd<T> to be passed as a parameter in async signals#1091
Allow Gd<T> to be passed as a parameter in async signals#1091Bromeon merged 1 commit intogodot-rust:masterfrom
Gd<T> to be passed as a parameter in async signals#1091Conversation
|
API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-1091 |
godot-core/src/task/futures.rs
Outdated
| impl_maybe_send!( | ||
| Send; | ||
| bool, u8, u16, u32, u64, i8, i16, i32, i64, f32, f64, StringName, Transform2D, Transform3D, Vector2, Vector2i, Vector2Axis, | ||
| Vector3, Vector3i, Vector3Axis, Vector4, Vector4i, Rect2, Rect2i, Plane, Quaternion, Aabb, Basis, Projection, Color, Rid | ||
| ); | ||
|
|
||
| impl_maybe_send!( | ||
| !Send; | ||
| Variant, GString, Dictionary, VariantArray, Callable, NodePath, PackedByteArray, PackedInt32Array, PackedInt64Array, PackedFloat32Array, | ||
| PackedFloat64Array, PackedStringArray, PackedVector2Array, PackedVector3Array, PackedColorArray, PackedVector4Array, Signal | ||
| ); |
There was a problem hiding this comment.
There are already several lists that set some compile-time attributes for each variant type:
- for
Var/Export/BuiltinExport - for FFI traits
GodotConvert/ToGodot/FromGodotwhich are registered in distributed code
I wonder if we should just keep adding those lists decentrally, or rather provide more parameters to existing lists that influence the Send property here.
Having fewer lists also makes it exceedingly unlikely to forget an implementation (as types simply unusable without basic trait support). So that makes the special machinery to "check if all are covered" redundant.
And overall, it means of course supporting new types needs changes in fewer places, reducing maintenance overhead.
There was a problem hiding this comment.
We could define the macros in the respective modules, but have a central module that calls all of them for each type.
There was a problem hiding this comment.
That sounds great, then we'd still have the logic local to the files, but central registration 👍
There was a problem hiding this comment.
Maybe you could integrate the checks here into one of the existing macros.
Possibly this is the best candidate?
Try to keep changes there as minimal. We can then at a later point refactor the other lists...
There was a problem hiding this comment.
We should also not forget this point later 🙂
There was a problem hiding this comment.
I tried to keep the changed minimal. Do you want to merge impl_ffi_variant and impl_dynamic_send?
godot-core/src/task/futures.rs
Outdated
| // This should be kept in sync with crate::registry::signal::variadic. | ||
| impl_maybe_send!(tuple; ); | ||
| impl_maybe_send!(tuple; A1); | ||
| impl_maybe_send!(tuple; A1, A2); | ||
| impl_maybe_send!(tuple; A1, A2, A3); | ||
| impl_maybe_send!(tuple; A1, A2, A3, A4); | ||
| impl_maybe_send!(tuple; A1, A2, A3, A4, A5); | ||
| impl_maybe_send!(tuple; A1, A2, A3, A4, A5, A6); | ||
| impl_maybe_send!(tuple; A1, A2, A3, A4, A5, A6, A7); | ||
| impl_maybe_send!(tuple; A1, A2, A3, A4, A5, A6, A7, A8); | ||
| impl_maybe_send!(tuple; A1, A2, A3, A4, A5, A6, A7, A8, A9); |
There was a problem hiding this comment.
This should be kept in sync with crate::registry::signal::variadic.
Then maybe we could add it directly to those macros.
Of course it would mean that the responsibility of Send is now mixed with other responsibilities, but this coupling exists either way -- it's just that here it's implicit and only with a comment.
And it would play into my previous comment regarding centralization of static type properties.
There was a problem hiding this comment.
You resolved this but it's still there -- I assume, we would try to centralize it later, maybe with #1042...
There was a problem hiding this comment.
Ah I see, to me, this fell under:
Try to keep changes there as minimal. We can then at a later point refactor the other lists...
I.e. we will merge crate::registry::signal::variadic into crate::bulitin::variant::impls in a later PR.
There was a problem hiding this comment.
Sounds good! Maybe wait for #1042, otherwise there will likely be merge conflicts.
60a907a to
56367f0
Compare
The syntax does not differ from any other argument type. signal.to_future::<(Gd<Object>,)>().awaitOr signal.to_future::<(bool, Gd<Object>, u32)>().await
I have now added it to the existing I test, but I will also add a negative test to assert that it panics correctly. |
c9c5952 to
0977874
Compare
6ae6547 to
0910aa9
Compare
There was a problem hiding this comment.
There are some resolved conversations that haven't been addressed yet. To me, it's fine if we do the refactoring later (separate from the feature PR here), just so we don't forget:
-
Do not list all builtin impls separately, but integrate them into existing macros.
That also makes the "check if all cases"matchobsolete.- see comment
-
Tuple impls could be combined with #1042 variadic traits.
- see comment
Anything else from your side? Or is this ready?
godot-core/src/task/futures.rs
Outdated
| // This should be kept in sync with crate::registry::signal::variadic. | ||
| impl_maybe_send!(tuple; ); | ||
| impl_maybe_send!(tuple; A1); | ||
| impl_maybe_send!(tuple; A1, A2); | ||
| impl_maybe_send!(tuple; A1, A2, A3); | ||
| impl_maybe_send!(tuple; A1, A2, A3, A4); | ||
| impl_maybe_send!(tuple; A1, A2, A3, A4, A5); | ||
| impl_maybe_send!(tuple; A1, A2, A3, A4, A5, A6); | ||
| impl_maybe_send!(tuple; A1, A2, A3, A4, A5, A6, A7); | ||
| impl_maybe_send!(tuple; A1, A2, A3, A4, A5, A6, A7, A8); | ||
| impl_maybe_send!(tuple; A1, A2, A3, A4, A5, A6, A7, A8, A9); |
There was a problem hiding this comment.
You resolved this but it's still there -- I assume, we would try to centralize it later, maybe with #1042...
godot-core/src/task/futures.rs
Outdated
| impl_maybe_send!( | ||
| Send; | ||
| bool, u8, u16, u32, u64, i8, i16, i32, i64, f32, f64, StringName, Transform2D, Transform3D, Vector2, Vector2i, Vector2Axis, | ||
| Vector3, Vector3i, Vector3Axis, Vector4, Vector4i, Rect2, Rect2i, Plane, Quaternion, Aabb, Basis, Projection, Color, Rid | ||
| ); | ||
|
|
||
| impl_maybe_send!( | ||
| !Send; | ||
| Variant, GString, Dictionary, VariantArray, Callable, NodePath, PackedByteArray, PackedInt32Array, PackedInt64Array, PackedFloat32Array, | ||
| PackedFloat64Array, PackedStringArray, PackedVector2Array, PackedVector3Array, PackedColorArray, PackedVector4Array, Signal | ||
| ); |
There was a problem hiding this comment.
We should also not forget this point later 🙂
0910aa9 to
8334785
Compare
Nothing else I think. |
Introduce a runtime check if the passed signal argument was actually sent between threads while being
!Send.This allows
Gd<T>to be used when awaiting signals, as long as the signal is not emitted on a different thread than the main-thread. Should the user await a signal with a non!Sendargument from a different thread, a panic will occur.Resolves #1074.
Depends on #1090.