-
Notifications
You must be signed in to change notification settings - Fork 234
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
Foreign BackgroundQueue type #1734
Comments
The initial motivation for this was cancellation. PR#1697 made it so if an async function was cancelled we would eventually release the resources. However, it would be better if we could immedately release the resources. In order to implement that, I realized I needed to change the future FFI quite a bit. The new FFI is simpler overall and supports cancel and drop operations. Cancel ensures that the foreign code will resume and break out of its async code. Drop ensures that all resources from the wrapped future are relased. The new code does not use ForeignExecutor and that code is in a state of limbo for now. I hope to repurpose it for foreign dispatch queues (mozilla#1734). If that doesn't work out, we can just delete it. It's tricky to implement FFI calls that inputted type-erased `RustFutureHandle`, since the `F` parameter is an anonymous type that implements Future. Made a new system that is based to converting an `Arc<RustFuture<F, T, U>>` into a `Box<Arc<dyn RustFutureFFI>>` before sending it across the FFI. `Arc<dyn RustFutureFFI>` implements the FFI and the extra Box converts the wide pointer into a normal pointer. It's fairly messy, but I hope mozilla#1730 will improve things. - Updated the futures fixture tests for this to hold on to the mutex longer in the initial call. This makes it so they will fail unless the future is dropped while the mutex is still locked. Before they would only succeed as long as the mutex was dropped once the timeout expired. - Updated `RustCallStatus.code` field to be an enum. Added `Cancelled` as one of the variants. `Cancelled` is only used for async functions. - Removed the FutureCallback and invoke_future_callback from `FfiConverter`. - New syncronization handling code in RustFuture that's hopefully clearer, more correct, and more understandable than the old stuff. - Updated `UNIFFI_CONTRACT_VERSION` since this is an ABI change - Removed the `RustCallStatus` param from async scaffolding functions. These functions can't fail, so there's no need.
The initial motivation for this was cancellation. PR#1697 made it so if an async function was cancelled we would eventually release the resources. However, it would be better if we could immedately release the resources. In order to implement that, I realized I needed to change the future FFI quite a bit. The new FFI is simpler overall and supports cancel and drop operations. Cancel ensures that the foreign code will resume and break out of its async code. Drop ensures that all resources from the wrapped future are relased. The new code does not use ForeignExecutor anymore, so that code is in a state of limbo. I hope to repurpose it for foreign dispatch queues (mozilla#1734). If that doesn't work out, we can just delete it. The FFI calls need some care since we pass a type-erased handle to the foreign code, while RustFuture is generic over an anonymous Future type: - The concrete RustFuture type implements the RustFutureFFI. - We give the foreign side a raw Box<Arc<dyn RustFutureFFI>>>. This makes it easy to call the FFI from the scaffolding code. The extra Box turns the wide pointer into a normal sized pointer, which simplifies the foreign code. - The last bit of complexity is completing a Rust future, since the future can output any of the FFI types that we return from sync functions. Handled this with a brute-force monomorphization. The scaffolding code defines a completion function for each FFI type and the bindings code has to call the correct one for the future. - Updated the futures fixture tests for this to hold on to the mutex longer in the initial call. This makes it so they will fail unless the future is dropped while the mutex is still locked. Before they would only succeed as long as the mutex was dropped once the timeout expired. - Updated `RustCallStatus.code` field to be an enum. Added `Cancelled` as one of the variants. `Cancelled` is only used for async functions. - Removed the FutureCallback and invoke_future_callback from `FfiConverter`. - New syncronization handling code in RustFuture that's hopefully clearer, more correct, and more understandable than the old stuff. - Updated `UNIFFI_CONTRACT_VERSION` since this is an ABI change - Removed the `RustCallStatus` param from async scaffolding functions. These functions can't fail, so there's no need.
The initial motivation for this was cancellation. PR#1697 made it so if an async function was cancelled we would eventually release the resources. However, it would be better if we could immedately release the resources. In order to implement that, I realized I needed to change the future FFI quite a bit. The new FFI is simpler overall and supports cancel and drop operations. Cancel ensures that the foreign code will resume and break out of its async code. Drop ensures that all resources from the wrapped future are relased. The new code does not use ForeignExecutor anymore, so that code is in a state of limbo. I hope to repurpose it for foreign dispatch queues (mozilla#1734). If that doesn't work out, we can just delete it. The FFI calls need some care since we pass a type-erased handle to the foreign code, while RustFuture is generic over an anonymous Future type: - The concrete RustFuture type implements the RustFutureFFI. - We give the foreign side a raw Box<Arc<dyn RustFutureFFI>>>. This makes it easy to call the FFI from the scaffolding code. The extra Box turns the wide pointer into a normal sized pointer, which simplifies the foreign code. - The last bit of complexity is completing a Rust future, since the future can output any of the FFI types that we return from sync functions. Handled this with a brute-force monomorphization. The scaffolding code defines a completion function for each FFI type and the bindings code has to call the correct one for the future. - Updated the futures fixture tests for this to hold on to the mutex longer in the initial call. This makes it so they will fail unless the future is dropped while the mutex is still locked. Before they would only succeed as long as the mutex was dropped once the timeout expired. - Updated `RustCallStatus.code` field to be an enum. Added `Cancelled` as one of the variants. `Cancelled` is only used for async functions. - Removed the FutureCallback and invoke_future_callback from `FfiConverter`. - New syncronization handling code in RustFuture that's hopefully clearer, more correct, and more understandable than the old stuff. - Updated `UNIFFI_CONTRACT_VERSION` since this is an ABI change - Removed the `RustCallStatus` param from async scaffolding functions. These functions can't fail, so there's no need. - Added is_async() to the Callable trait.
The initial motivation for this was cancellation. PR#1697 made it so if an async function was cancelled we would eventually release the resources. However, it would be better if we could immedately release the resources. In order to implement that, I realized I needed to change the future FFI quite a bit. The new FFI is simpler overall and supports cancel and drop operations. Cancel ensures that the foreign code will resume and break out of its async code. Drop ensures that all resources from the wrapped future are relased. The new code does not use ForeignExecutor anymore, so that code is in a state of limbo. I hope to repurpose it for foreign dispatch queues (mozilla#1734). If that doesn't work out, we can just delete it. The FFI calls need some care since we pass a type-erased handle to the foreign code, while RustFuture is generic over an anonymous Future type: - The concrete RustFuture type implements the RustFutureFFI. - We give the foreign side a raw Box<Arc<dyn RustFutureFFI>>>. This makes it easy to call the FFI from the scaffolding code. The extra Box turns the wide pointer into a normal sized pointer, which simplifies the foreign code. - The last bit of complexity is completing a Rust future, since the future can output any of the FFI types that we return from sync functions. Handled this with a brute-force monomorphization. The scaffolding code defines a completion function for each FFI type and the bindings code has to call the correct one for the future. - Updated the futures fixture tests for this to hold on to the mutex longer in the initial call. This makes it so they will fail unless the future is dropped while the mutex is still locked. Before they would only succeed as long as the mutex was dropped once the timeout expired. - Updated `RustCallStatus.code` field to be an enum. Added `Cancelled` as one of the variants. `Cancelled` is only used for async functions. - Removed the FutureCallback and invoke_future_callback from `FfiConverter`. - New syncronization handling code in RustFuture that's hopefully clearer, more correct, and more understandable than the old stuff. - Updated `UNIFFI_CONTRACT_VERSION` since this is an ABI change - Removed the `RustCallStatus` param from async scaffolding functions. These functions can't fail, so there's no need. - Added is_async() to the Callable trait.
The initial motivation for this was cancellation. PR#1697 made it so if an async function was cancelled we would eventually release the resources. However, it would be better if we could immedately release the resources. In order to implement that, I realized I needed to change the future FFI quite a bit. The new FFI is simpler overall and supports cancel and drop operations. Cancel ensures that the foreign code will resume and break out of its async code. Drop ensures that all resources from the wrapped future are relased. The new code does not use ForeignExecutor anymore, so that code is in a state of limbo. I hope to repurpose it for foreign dispatch queues (mozilla#1734). If that doesn't work out, we can just delete it. The FFI calls need some care since we pass a type-erased handle to the foreign code, while RustFuture is generic over an anonymous Future type: - The concrete RustFuture type implements the RustFutureFFI. - We give the foreign side a raw Box<Arc<dyn RustFutureFFI>>>. This makes it easy to call the FFI from the scaffolding code. The extra Box turns the wide pointer into a normal sized pointer, which simplifies the foreign code. - The last bit of complexity is completing a Rust future, since the future can output any of the FFI types that we return from sync functions. Handled this with a brute-force monomorphization. The scaffolding code defines a completion function for each FFI type and the bindings code has to call the correct one for the future. - Updated the futures fixture tests for this to hold on to the mutex longer in the initial call. This makes it so they will fail unless the future is dropped while the mutex is still locked. Before they would only succeed as long as the mutex was dropped once the timeout expired. - Updated `RustCallStatus.code` field to be an enum. Added `Cancelled` as one of the variants. `Cancelled` is only used for async functions. - Removed the FutureCallback and invoke_future_callback from `FfiConverter`. - New syncronization handling code in RustFuture that's hopefully clearer, more correct, and more understandable than the old stuff. - Updated `UNIFFI_CONTRACT_VERSION` since this is an ABI change - Removed the `RustCallStatus` param from async scaffolding functions. These functions can't fail, so there's no need. - Added is_async() to the Callable trait.
The initial motivation for this was cancellation. PR#1697 made it so if an async function was cancelled we would eventually release the resources. However, it would be better if we could immedately release the resources. In order to implement that, I realized I needed to change the future FFI quite a bit. The new FFI is simpler overall and supports cancel and drop operations. Cancel ensures that the foreign code will resume and break out of its async code. Drop ensures that all resources from the wrapped future are relased. The new code does not use ForeignExecutor anymore, so that code is in a state of limbo. I hope to repurpose it for foreign dispatch queues (mozilla#1734). If that doesn't work out, we can just delete it. The FFI calls need some care since we pass a type-erased handle to the foreign code, while RustFuture is generic over an anonymous Future type: - The concrete RustFuture type implements the RustFutureFFI. - We give the foreign side a raw Box<Arc<dyn RustFutureFFI>>>. This makes it easy to call the FFI from the scaffolding code. The extra Box turns the wide pointer into a normal sized pointer, which simplifies the foreign code. - The last bit of complexity is completing a Rust future, since the future can output any of the FFI types that we return from sync functions. Handled this with a brute-force monomorphization. The scaffolding code defines a completion function for each FFI type and the bindings code has to call the correct one for the future. - Updated the futures fixture tests for this to hold on to the mutex longer in the initial call. This makes it so they will fail unless the future is dropped while the mutex is still locked. Before they would only succeed as long as the mutex was dropped once the timeout expired. - Updated `RustCallStatus.code` field to be an enum. Added `Cancelled` as one of the variants. `Cancelled` is only used for async functions. - Removed the FutureCallback and invoke_future_callback from `FfiConverter`. - New syncronization handling code in RustFuture that's hopefully clearer, more correct, and more understandable than the old stuff. - Updated `UNIFFI_CONTRACT_VERSION` since this is an ABI change - Removed the `RustCallStatus` param from async scaffolding functions. These functions can't fail, so there's no need. - Added is_async() to the Callable trait.
The initial motivation for this was cancellation. PR#1697 made it so if an async function was cancelled we would eventually release the resources. However, it would be better if we could immedately release the resources. In order to implement that, I realized I needed to change the future FFI quite a bit. The new FFI is simpler overall and supports cancel and drop operations. Cancel ensures that the foreign code will resume and break out of its async code. Drop ensures that all resources from the wrapped future are relased. The new code does not use ForeignExecutor anymore, so that code is in a state of limbo. I hope to repurpose it for foreign dispatch queues (mozilla#1734). If that doesn't work out, we can just delete it. The FFI calls need some care since we pass a type-erased handle to the foreign code, while RustFuture is generic over an anonymous Future type: - The concrete RustFuture type implements the RustFutureFFI. - We give the foreign side a raw Box<Arc<dyn RustFutureFFI>>>. This makes it easy to call the FFI from the scaffolding code. The extra Box turns the wide pointer into a normal sized pointer, which simplifies the foreign code. - The last bit of complexity is completing a Rust future, since the future can output any of the FFI types that we return from sync functions. Handled this with a brute-force monomorphization. The scaffolding code defines a completion function for each FFI type and the bindings code has to call the correct one for the future. - Updated the futures fixture tests for this to hold on to the mutex longer in the initial call. This makes it so they will fail unless the future is dropped while the mutex is still locked. Before they would only succeed as long as the mutex was dropped once the timeout expired. - Updated `RustCallStatus.code` field to be an enum. Added `Cancelled` as one of the variants. `Cancelled` is only used for async functions. - Removed the FutureCallback and invoke_future_callback from `FfiConverter`. - New syncronization handling code in RustFuture that's hopefully clearer, more correct, and more understandable than the old stuff. - Updated `UNIFFI_CONTRACT_VERSION` since this is an ABI change - Removed the `RustCallStatus` param from async scaffolding functions. These functions can't fail, so there's no need. - Added is_async() to the Callable trait.
The initial motivation for this was cancellation. PR#1697 made it so if an async function was cancelled we would eventually release the resources. However, it would be better if we could immedately release the resources. In order to implement that, I realized I needed to change the future FFI quite a bit. The new FFI is simpler overall and supports cancel and drop operations. Cancel ensures that the foreign code will resume and break out of its async code. Drop ensures that all resources from the wrapped future are relased. The new code does not use ForeignExecutor anymore, so that code is in a state of limbo. I hope to repurpose it for foreign dispatch queues (mozilla#1734). If that doesn't work out, we can just delete it. The FFI calls need some care since we pass a type-erased handle to the foreign code, while RustFuture is generic over an anonymous Future type: - The concrete RustFuture type implements the RustFutureFFI. - We give the foreign side a raw Box<Arc<dyn RustFutureFFI>>>. This makes it easy to call the FFI from the scaffolding code. The extra Box turns the wide pointer into a normal sized pointer, which simplifies the foreign code. - The last bit of complexity is completing a Rust future, since the future can output any of the FFI types that we return from sync functions. Handled this with a brute-force monomorphization. The scaffolding code defines a completion function for each FFI type and the bindings code has to call the correct one for the future. - Updated the futures fixture tests for this to hold on to the mutex longer in the initial call. This makes it so they will fail unless the future is dropped while the mutex is still locked. Before they would only succeed as long as the mutex was dropped once the timeout expired. - Updated `RustCallStatus.code` field to be an enum. Added `Cancelled` as one of the variants. `Cancelled` is only used for async functions. - Removed the FutureCallback and invoke_future_callback from `FfiConverter`. - New syncronization handling code in RustFuture that's hopefully clearer, more correct, and more understandable than the old stuff. - Updated `UNIFFI_CONTRACT_VERSION` since this is an ABI change - Removed the `RustCallStatus` param from async scaffolding functions. These functions can't fail, so there's no need. - Added is_async() to the Callable trait.
The initial motivation for this was cancellation. PR#1697 made it so if an async function was cancelled we would eventually release the resources. However, it would be better if we could immedately release the resources. In order to implement that, I realized I needed to change the future FFI quite a bit. The new FFI is simpler overall and supports cancel and drop operations. Cancel ensures that the foreign code will resume and break out of its async code. Drop ensures that all resources from the wrapped future are relased. The new code does not use ForeignExecutor anymore, so that code is in a state of limbo. I hope to repurpose it for foreign dispatch queues (mozilla#1734). If that doesn't work out, we can just delete it. The FFI calls need some care since we pass a type-erased handle to the foreign code, while RustFuture is generic over an anonymous Future type: - The concrete RustFuture type implements the RustFutureFFI. - We give the foreign side a raw Box<Arc<dyn RustFutureFFI>>>. This makes it easy to call the FFI from the scaffolding code. The extra Box turns the wide pointer into a normal sized pointer, which simplifies the foreign code. - The last bit of complexity is completing a Rust future, since the future can output any of the FFI types that we return from sync functions. Handled this with a brute-force monomorphization. The scaffolding code defines a completion function for each FFI type and the bindings code has to call the correct one for the future. - Updated the futures fixture tests for this to hold on to the mutex longer in the initial call. This makes it so they will fail unless the future is dropped while the mutex is still locked. Before they would only succeed as long as the mutex was dropped once the timeout expired. - Updated `RustCallStatus.code` field to be an enum. Added `Cancelled` as one of the variants. `Cancelled` is only used for async functions. - Removed the FutureCallback and invoke_future_callback from `FfiConverter`. - New syncronization handling code in RustFuture that's hopefully clearer, more correct, and more understandable than the old stuff. - Updated `UNIFFI_CONTRACT_VERSION` since this is an ABI change - Removed the `RustCallStatus` param from async scaffolding functions. These functions can't fail, so there's no need. - Added is_async() to the Callable trait.
The initial motivation for this was cancellation. PR#1697 made it so if an async function was cancelled we would eventually release the resources. However, it would be better if we could immedately release the resources. In order to implement that, I realized I needed to change the future FFI quite a bit. The new FFI is simpler overall and supports cancel and drop operations. Cancel ensures that the foreign code will resume and break out of its async code. Drop ensures that all resources from the wrapped future are relased. The new code does not use ForeignExecutor anymore, so that code is in a state of limbo. I hope to repurpose it for foreign dispatch queues (mozilla#1734). If that doesn't work out, we can just delete it. The FFI calls need some care since we pass a type-erased handle to the foreign code, while RustFuture is generic over an anonymous Future type: - The concrete RustFuture type implements the RustFutureFFI. - We give the foreign side a raw Box<Arc<dyn RustFutureFFI>>>. This makes it easy to call the FFI from the scaffolding code. The extra Box turns the wide pointer into a normal sized pointer, which simplifies the foreign code. - The last bit of complexity is completing a Rust future, since the future can output any of the FFI types that we return from sync functions. Handled this with a brute-force monomorphization. The scaffolding code defines a completion function for each FFI type and the bindings code has to call the correct one for the future. - Updated the futures fixture tests for this to hold on to the mutex longer in the initial call. This makes it so they will fail unless the future is dropped while the mutex is still locked. Before they would only succeed as long as the mutex was dropped once the timeout expired. - Updated `RustCallStatus.code` field to be an enum. Added `Cancelled` as one of the variants. `Cancelled` is only used for async functions. - Removed the FutureCallback and invoke_future_callback from `FfiConverter`. - New syncronization handling code in RustFuture that's hopefully clearer, more correct, and more understandable than the old stuff. - Updated `UNIFFI_CONTRACT_VERSION` since this is an ABI change - Removed the `RustCallStatus` param from async scaffolding functions. These functions can't fail, so there's no need. - Added is_async() to the Callable trait.
The initial motivation for this was cancellation. PR#1697 made it so if an async function was cancelled we would eventually release the resources. However, it would be better if we could immedately release the resources. In order to implement that, I realized I needed to change the future FFI quite a bit. The new FFI is simpler overall and supports cancel and drop operations. Cancel ensures that the foreign code will resume and break out of its async code. Drop ensures that all resources from the wrapped future are relased. The new code does not use ForeignExecutor anymore, so that code is in a state of limbo. I hope to repurpose it for foreign dispatch queues (mozilla#1734). If that doesn't work out, we can just delete it. The FFI calls need some care since we pass a type-erased handle to the foreign code, while RustFuture is generic over an anonymous Future type: - The concrete RustFuture type implements the RustFutureFFI. - We give the foreign side a raw Box<Arc<dyn RustFutureFFI>>>. This makes it easy to call the FFI from the scaffolding code. The extra Box turns the wide pointer into a normal sized pointer, which simplifies the foreign code. - The last bit of complexity is completing a Rust future, since the future can output any of the FFI types that we return from sync functions. Handled this with a brute-force monomorphization. The scaffolding code defines a completion function for each FFI type and the bindings code has to call the correct one for the future. - Updated the futures fixture tests for this to hold on to the mutex longer in the initial call. This makes it so they will fail unless the future is dropped while the mutex is still locked. Before they would only succeed as long as the mutex was dropped once the timeout expired. - Updated `RustCallStatus.code` field to be an enum. Added `Cancelled` as one of the variants. `Cancelled` is only used for async functions. - Removed the FutureCallback and invoke_future_callback from `FfiConverter`. - New syncronization handling code in RustFuture that's hopefully clearer, more correct, and more understandable than the old stuff. - Updated `UNIFFI_CONTRACT_VERSION` since this is an ABI change - Removed the `RustCallStatus` param from async scaffolding functions. These functions can't fail, so there's no need. - Added is_async() to the Callable trait.
The initial motivation for this was cancellation. PR#1697 made it so if an async function was cancelled we would eventually release the resources. However, it would be better if we could immedately release the resources. In order to implement that, I realized I needed to change the future FFI quite a bit. The new FFI is simpler overall and supports cancel and drop operations. Cancel ensures that the foreign code will resume and break out of its async code. Drop ensures that all resources from the wrapped future are relased. The new code does not use ForeignExecutor anymore, so that code is in a state of limbo. I hope to repurpose it for foreign dispatch queues (mozilla#1734). If that doesn't work out, we can just delete it. The FFI calls need some care since we pass a type-erased handle to the foreign code, while RustFuture is generic over an anonymous Future type: - The concrete RustFuture type implements the RustFutureFFI. - We give the foreign side a raw Box<Arc<dyn RustFutureFFI>>>. This makes it easy to call the FFI from the scaffolding code. The extra Box turns the wide pointer into a normal sized pointer, which simplifies the foreign code. - The last bit of complexity is completing a Rust future, since the future can output any of the FFI types that we return from sync functions. Handled this with a brute-force monomorphization. The scaffolding code defines a completion function for each FFI type and the bindings code has to call the correct one for the future. More changes: - Updated the futures fixture tests for this to hold on to the mutex longer in the initial call. This makes it so they will fail unless the future is dropped while the mutex is still locked. Before they would only succeed as long as the mutex was dropped once the timeout expired. - Updated `RustCallStatus.code` field to be an enum. Added `Cancelled` as one of the variants. `Cancelled` is only used for async functions. - Removed the FutureCallback and invoke_future_callback from `FfiConverter`. - New syncronization handling code in RustFuture that's hopefully clearer, more correct, and more understandable than the old stuff. - Updated `UNIFFI_CONTRACT_VERSION` since this is an ABI change - Removed the `RustCallStatus` param from async scaffolding functions. These functions can't fail, so there's no need. - Added is_async() to the Callable trait.
The initial motivation for this was cancellation. PR#1697 made it so if an async function was cancelled we would eventually release the resources. However, it would be better if we could immedately release the resources. In order to implement that, I realized I needed to change the future FFI quite a bit. The new FFI is simpler overall and supports cancel and drop operations. Cancel ensures that the foreign code will resume and break out of its async code. Drop ensures that all resources from the wrapped future are relased. The new code does not use ForeignExecutor anymore, so that code is in a state of limbo. I hope to repurpose it for foreign dispatch queues (mozilla#1734). If that doesn't work out, we can just delete it. The FFI calls need some care since we pass a type-erased handle to the foreign code, while RustFuture is generic over an anonymous Future type: - The concrete RustFuture type implements the RustFutureFFI. - We give the foreign side a raw Box<Arc<dyn RustFutureFFI>>>. This makes it easy to call the FFI from the scaffolding code. The extra Box turns the wide pointer into a normal sized pointer, which simplifies the foreign code. - The last bit of complexity is completing a Rust future, since the future can output any of the FFI types that we return from sync functions. Handled this with a brute-force monomorphization. The scaffolding code defines a completion function for each FFI type and the bindings code has to call the correct one for the future. More changes: - Updated the futures fixture tests for this to hold on to the mutex longer in the initial call. This makes it so they will fail unless the future is dropped while the mutex is still locked. Before they would only succeed as long as the mutex was dropped once the timeout expired. - Updated `RustCallStatus.code` field to be an enum. Added `Cancelled` as one of the variants. `Cancelled` is only used for async functions. - Removed the FutureCallback and invoke_future_callback from `FfiConverter`. - New syncronization handling code in RustFuture that's hopefully clearer, more correct, and more understandable than the old stuff. - Updated `UNIFFI_CONTRACT_VERSION` since this is an ABI change - Removed the `RustCallStatus` param from async scaffolding functions. These functions can't fail, so there's no need. - Added is_async() to the Callable trait.
The initial motivation for this was cancellation. PR#1697 made it so if an async function was cancelled we would eventually release the resources. However, it would be better if we could immedately release the resources. In order to implement that, I realized I needed to change the future FFI quite a bit. The new FFI is simpler overall and supports cancel and drop operations. Cancel ensures that the foreign code will resume and break out of its async code. Drop ensures that all resources from the wrapped future are relased. The new code does not use ForeignExecutor anymore, so that code is in a state of limbo. I hope to repurpose it for foreign dispatch queues (mozilla#1734). If that doesn't work out, we can just delete it. The FFI calls need some care since we pass a type-erased handle to the foreign code, while RustFuture is generic over an anonymous Future type: - The concrete RustFuture type implements the RustFutureFFI. - We give the foreign side a raw Box<Arc<dyn RustFutureFFI>>>. This makes it easy to call the FFI from the scaffolding code. The extra Box turns the wide pointer into a normal sized pointer, which simplifies the foreign code. - The last bit of complexity is completing a Rust future, since the future can output any of the FFI types that we return from sync functions. Handled this with a brute-force monomorphization. The scaffolding code defines a completion function for each FFI type and the bindings code has to call the correct one for the future. More changes: - Updated the futures fixture tests for this to hold on to the mutex longer in the initial call. This makes it so they will fail unless the future is dropped while the mutex is still locked. Before they would only succeed as long as the mutex was dropped once the timeout expired. - Updated `RustCallStatus.code` field to be an enum. Added `Cancelled` as one of the variants. `Cancelled` is only used for async functions. - Removed the FutureCallback and invoke_future_callback from `FfiConverter`. - New syncronization handling code in RustFuture that's hopefully clearer, more correct, and more understandable than the old stuff. - Updated `UNIFFI_CONTRACT_VERSION` since this is an ABI change - Removed the `RustCallStatus` param from async scaffolding functions. These functions can't fail, so there's no need. - Added is_async() to the Callable trait.
The initial motivation for this was cancellation. PR#1697 made it so if an async function was cancelled we would eventually release the resources. However, it would be better if we could immedately release the resources. In order to implement that, I realized I needed to change the future FFI quite a bit. The new FFI is simpler overall and supports cancel and drop operations. Cancel ensures that the foreign code will resume and break out of its async code. Drop ensures that all resources from the wrapped future are relased. The new code does not use ForeignExecutor anymore, so that code is in a state of limbo. I hope to repurpose it for foreign dispatch queues (mozilla#1734). If that doesn't work out, we can just delete it. The FFI calls need some care since we pass a type-erased handle to the foreign code, while RustFuture is generic over an anonymous Future type: - The concrete RustFuture type implements the RustFutureFFI. - We give the foreign side a raw Box<Arc<dyn RustFutureFFI>>>. This makes it easy to call the FFI from the scaffolding code. The extra Box turns the wide pointer into a normal sized pointer, which simplifies the foreign code. - The last bit of complexity is completing a Rust future, since the future can output any of the FFI types that we return from sync functions. Handled this with a brute-force monomorphization. The scaffolding code defines a completion function for each FFI type and the bindings code has to call the correct one for the future. More changes: - Updated the futures fixture tests for this to hold on to the mutex longer in the initial call. This makes it so they will fail unless the future is dropped while the mutex is still locked. Before they would only succeed as long as the mutex was dropped once the timeout expired. - Updated `RustCallStatus.code` field to be an enum. Added `Cancelled` as one of the variants. `Cancelled` is only used for async functions. - Removed the FutureCallback and invoke_future_callback from `FfiConverter`. - New syncronization handling code in RustFuture that's hopefully clearer, more correct, and more understandable than the old stuff. - Updated `UNIFFI_CONTRACT_VERSION` since this is an ABI change - Removed the `RustCallStatus` param from async scaffolding functions. These functions can't fail, so there's no need. - Added is_async() to the Callable trait.
The initial motivation for this was cancellation. PR#1697 made it so if an async function was cancelled we would eventually release the resources. However, it would be better if we could immedately release the resources. In order to implement that, I realized I needed to change the future FFI quite a bit. The new FFI is simpler overall and supports cancel and drop operations. Cancel ensures that the foreign code will resume and break out of its async code. Drop ensures that all resources from the wrapped future are relased. The new code does not use ForeignExecutor anymore, so that code is in a state of limbo. I hope to repurpose it for foreign dispatch queues (mozilla#1734). If that doesn't work out, we can just delete it. The FFI calls need some care since we pass a type-erased handle to the foreign code, while RustFuture is generic over an anonymous Future type: - The concrete RustFuture type implements the RustFutureFFI. - We give the foreign side a raw Box<Arc<dyn RustFutureFFI>>>. This makes it easy to call the FFI from the scaffolding code. The extra Box turns the wide pointer into a normal sized pointer, which simplifies the foreign code. - The last bit of complexity is completing a Rust future, since the future can output any of the FFI types that we return from sync functions. Handled this with a brute-force monomorphization. The scaffolding code defines a completion function for each FFI type and the bindings code has to call the correct one for the future. More changes: - Updated the futures fixture tests for this to hold on to the mutex longer in the initial call. This makes it so they will fail unless the future is dropped while the mutex is still locked. Before they would only succeed as long as the mutex was dropped once the timeout expired. - Updated `RustCallStatus.code` field to be an enum. Added `Cancelled` as one of the variants. `Cancelled` is only used for async functions. - Removed the FutureCallback and invoke_future_callback from `FfiConverter`. - New syncronization handling code in RustFuture that's hopefully clearer, more correct, and more understandable than the old stuff. - Updated `UNIFFI_CONTRACT_VERSION` since this is an ABI change - Removed the `RustCallStatus` param from async scaffolding functions. These functions can't fail, so there's no need. - Added is_async() to the Callable trait.
The initial motivation for this was cancellation. PR#1697 made it so if an async function was cancelled we would eventually release the resources. However, it would be better if we could immedately release the resources. In order to implement that, I realized I needed to change the future FFI quite a bit. The new FFI is simpler overall and supports cancel and drop operations. Cancel ensures that the foreign code will resume and break out of its async code. Drop ensures that all resources from the wrapped future are relased. The new code does not use ForeignExecutor anymore, so that code is in a state of limbo. I hope to repurpose it for foreign dispatch queues (mozilla#1734). If that doesn't work out, we can just delete it. The FFI calls need some care since we pass a type-erased handle to the foreign code, while RustFuture is generic over an anonymous Future type: - The concrete RustFuture type implements the RustFutureFFI. - We give the foreign side a raw Box<Arc<dyn RustFutureFFI>>>. This makes it easy to call the FFI from the scaffolding code. The extra Box turns the wide pointer into a normal sized pointer, which simplifies the foreign code. - The last bit of complexity is completing a Rust future, since the future can output any of the FFI types that we return from sync functions. Handled this with a brute-force monomorphization. The scaffolding code defines a completion function for each FFI type and the bindings code has to call the correct one for the future. More changes: - Updated the futures fixture tests for this to hold on to the mutex longer in the initial call. This makes it so they will fail unless the future is dropped while the mutex is still locked. Before they would only succeed as long as the mutex was dropped once the timeout expired. - Updated `RustCallStatus.code` field to be an enum. Added `Cancelled` as one of the variants. `Cancelled` is only used for async functions. - Removed the FutureCallback and invoke_future_callback from `FfiConverter`. - New syncronization handling code in RustFuture that's hopefully clearer, more correct, and more understandable than the old stuff. - Updated `UNIFFI_CONTRACT_VERSION` since this is an ABI change - Removed the `RustCallStatus` param from async scaffolding functions. These functions can't fail, so there's no need. - Added is_async() to the Callable trait.
The initial motivation for this was cancellation. PR#1697 made it so if an async function was cancelled we would eventually release the resources. However, it would be better if we could immedately release the resources. In order to implement that, I realized I needed to change the future FFI quite a bit. The new FFI is simpler overall and supports cancel and drop operations. Cancel ensures that the foreign code will resume and break out of its async code. Drop ensures that all resources from the wrapped future are relased. The new code does not use ForeignExecutor anymore, so that code is in a state of limbo. I hope to repurpose it for foreign dispatch queues (mozilla#1734). If that doesn't work out, we can just delete it. The FFI calls need some care since we pass a type-erased handle to the foreign code, while RustFuture is generic over an anonymous Future type: - The concrete RustFuture type implements the RustFutureFFI. - We give the foreign side a raw Box<Arc<dyn RustFutureFFI>>>. This makes it easy to call the FFI from the scaffolding code. The extra Box turns the wide pointer into a normal sized pointer, which simplifies the foreign code. - The last bit of complexity is completing a Rust future, since the future can output any of the FFI types that we return from sync functions. Handled this with a brute-force monomorphization. The scaffolding code defines a completion function for each FFI type and the bindings code has to call the correct one for the future. More changes: - Updated the futures fixture tests for this to hold on to the mutex longer in the initial call. This makes it so they will fail unless the future is dropped while the mutex is still locked. Before they would only succeed as long as the mutex was dropped once the timeout expired. - Updated `RustCallStatus.code` field to be an enum. Added `Cancelled` as one of the variants. `Cancelled` is only used for async functions. - Removed the FutureCallback and invoke_future_callback from `FfiConverter`. - New syncronization handling code in RustFuture that's hopefully clearer, more correct, and more understandable than the old stuff. - Updated `UNIFFI_CONTRACT_VERSION` since this is an ABI change - Removed the `RustCallStatus` param from async scaffolding functions. These functions can't fail, so there's no need. - Added is_async() to the Callable trait.
The initial motivation for this was cancellation. PR#1697 made it so if an async function was cancelled we would eventually release the resources. However, it would be better if we could immedately release the resources. In order to implement that, I realized I needed to change the future FFI quite a bit. The new FFI is simpler overall and supports cancel and drop operations. Cancel ensures that the foreign code will resume and break out of its async code. Drop ensures that all resources from the wrapped future are relased. The new code does not use ForeignExecutor anymore, so that code is in a state of limbo. I hope to repurpose it for foreign dispatch queues (mozilla#1734). If that doesn't work out, we can just delete it. The FFI calls need some care since we pass a type-erased handle to the foreign code, while RustFuture is generic over an anonymous Future type: - The concrete RustFuture type implements the RustFutureFFI. - We give the foreign side a raw Box<Arc<dyn RustFutureFFI>>>. This makes it easy to call the FFI from the scaffolding code. The extra Box turns the wide pointer into a normal sized pointer, which simplifies the foreign code. - The last bit of complexity is completing a Rust future, since the future can output any of the FFI types that we return from sync functions. Handled this with a brute-force monomorphization. The scaffolding code defines a completion function for each FFI type and the bindings code has to call the correct one for the future. More changes: - Updated the futures fixture tests for this to hold on to the mutex longer in the initial call. This makes it so they will fail unless the future is dropped while the mutex is still locked. Before they would only succeed as long as the mutex was dropped once the timeout expired. - Updated `RustCallStatus.code` field to be an enum. Added `Cancelled` as one of the variants. `Cancelled` is only used for async functions. - Removed the FutureCallback and invoke_future_callback from `FfiConverter`. - New syncronization handling code in RustFuture that's hopefully clearer, more correct, and more understandable than the old stuff. - Updated `UNIFFI_CONTRACT_VERSION` since this is an ABI change - Removed the `RustCallStatus` param from async scaffolding functions. These functions can't fail, so there's no need. - Added is_async() to the Callable trait.
The initial motivation for this was cancellation. PR#1697 made it so if an async function was cancelled we would eventually release the resources. However, it would be better if we could immedately release the resources. In order to implement that, the future FFI needed to change quite a bit and most of these changes are good. The new FFI is simpler overall and supports cancel and drop operations. It's actually quite close to the initial FFI that Hywan proposed. Cancel ensures that the foreign code will resume and break out of its async code. Drop ensures that all resources from the wrapped future are relased. Note: the new FFI has a cancel method, but no bindings use it yet. For Python/Kotlin we don't need to because they throw cancellation exceptions, which means cancellation support falls out of the new API. This cancel method could be used for Swift, but we still need to think this through in a different PR. The new code does not use ForeignExecutor anymore, so that code is in a state of limbo. I hope to repurpose it for foreign dispatch queues (mozilla#1734). If that doesn't work out, we can just delete it. The FFI calls need some care since we pass a type-erased handle to the foreign code, while RustFuture is generic over an anonymous Future type: - The concrete RustFuture type implements the `RustFutureFFI<F>` trait. - We give the foreign side a leaked `Box<Arc<dyn RustFutureFFI<F>>>>`. - We hand-monomorphize, creating a scaffolding function for each RustFutureFFI method, for each possible FFI type. Updated proc macros lift arguments in 2 phases. First we call `try_lift` on all arguments, generating a `Result<LiftedArgsTuple>`. Then we call the rust function using that tuple or handle the error. This is needed because the new async code adds a `Send` bound futures. The `Send` bound is good because futures are going to be moving across threads as we poll/wake them. However, the lift code won't always be Send because it may deal with raw pointers. To deal with that, we perform the non-Send lifting outside of the future, then create a Send future from the result. This means that the lift phase is executed outside of the async context, but it should be very fast. This change also allows futures that return Results to attempt to downcast lift errors. More changes: - Updated the futures fixture tests for this to hold on to the mutex longer in the initial call. This makes it so they will fail unless the future is dropped while the mutex is still locked. Before they would only succeed as long as the mutex was dropped once the timeout expired. - Updated `RustCallStatus.code` field to be an enum. Added `Cancelled` as one of the variants. `Cancelled` is only used for async functions. - Removed the FutureCallback and invoke_future_callback from `FfiConverter`. - New syncronization handling code in RustFuture that's hopefully clearer, more correct, and more understandable than the old stuff. - Updated `UNIFFI_CONTRACT_VERSION` since this is an ABI change - Removed the `RustCallStatus` param from async scaffolding functions. These functions can't fail, so there's no need. - Added is_async() to the Callable trait. - Changed `handle_failed_lift` signature. Now, if a `Result<>` is able to downcast the error, it returns `Self::Err` directly instead of serializing the error into `RustBuffer`. Co-authored-by: Ivan Enderlin <[email protected]> Co-authored-by: Jonas Platte <[email protected]>
The initial motivation for this was cancellation. PR#1697 made it so if an async function was cancelled we would eventually release the resources. However, it would be better if we could immedately release the resources. In order to implement that, the future FFI needed to change quite a bit and most of these changes are good. The new FFI is simpler overall and supports cancel and drop operations. It's actually quite close to the initial FFI that Hywan proposed. Cancel ensures that the foreign code will resume and break out of its async code. Drop ensures that all resources from the wrapped future are relased. Note: the new FFI has a cancel method, but no bindings use it yet. For Python/Kotlin we don't need to because they throw cancellation exceptions, which means cancellation support falls out of the new API. This cancel method could be used for Swift, but we still need to think this through in a different PR. The new code does not use ForeignExecutor anymore, so that code is in a state of limbo. I hope to repurpose it for foreign dispatch queues (mozilla#1734). If that doesn't work out, we can just delete it. The FFI calls need some care since we pass a type-erased handle to the foreign code, while RustFuture is generic over an anonymous Future type: - The concrete RustFuture type implements the `RustFutureFFI<F>` trait. - We give the foreign side a leaked `Box<Arc<dyn RustFutureFFI<F>>>>`. - We hand-monomorphize, creating a scaffolding function for each RustFutureFFI method, for each possible FFI type. Updated proc macros lift arguments in 2 phases. First we call `try_lift` on all arguments, generating a `Result<LiftedArgsTuple>`. Then we call the rust function using that tuple or handle the error. This is needed because the new async code adds a `Send` bound futures. The `Send` bound is good because futures are going to be moving across threads as we poll/wake them. However, the lift code won't always be Send because it may deal with raw pointers. To deal with that, we perform the non-Send lifting outside of the future, then create a Send future from the result. This means that the lift phase is executed outside of the async context, but it should be very fast. This change also allows futures that return Results to attempt to downcast lift errors. More changes: - Updated the futures fixture tests for this to hold on to the mutex longer in the initial call. This makes it so they will fail unless the future is dropped while the mutex is still locked. Before they would only succeed as long as the mutex was dropped once the timeout expired. - Updated `RustCallStatus.code` field to be an enum. Added `Cancelled` as one of the variants. `Cancelled` is only used for async functions. - Removed the FutureCallback and invoke_future_callback from `FfiConverter`. - New syncronization handling code in RustFuture that's hopefully clearer, more correct, and more understandable than the old stuff. - Updated `UNIFFI_CONTRACT_VERSION` since this is an ABI change - Removed the `RustCallStatus` param from async scaffolding functions. These functions can't fail, so there's no need. - Added is_async() to the Callable trait. - Changed `handle_failed_lift` signature. Now, if a `Result<>` is able to downcast the error, it returns `Self::Err` directly instead of serializing the error into `RustBuffer`. Co-authored-by: Ivan Enderlin <[email protected]> Co-authored-by: Jonas Platte <[email protected]>
The initial motivation for this was cancellation. PR#1697 made it so if an async function was cancelled we would eventually release the resources. However, it would be better if we could immedately release the resources. In order to implement that, the future FFI needed to change quite a bit and most of these changes are good. The new FFI is simpler overall and supports cancel and drop operations. It's actually quite close to the initial FFI that Hywan proposed. Cancel ensures that the foreign code will resume and break out of its async code. Drop ensures that all resources from the wrapped future are relased. Note: the new FFI has a cancel method, but no bindings use it yet. For Python/Kotlin we don't need to because they throw cancellation exceptions, which means cancellation support falls out from the new API without any extra work. This cancel method could be used for Swift, but we still need to think this through in a different PR. The new code does not use ForeignExecutor anymore, so that code is in a state of limbo. I hope to repurpose it for foreign dispatch queues (mozilla#1734). If that doesn't work out, we can just delete it. The FFI calls need some care since we pass a type-erased handle to the foreign code, while RustFuture is generic over an anonymous Future type: - The concrete RustFuture type implements the `RustFutureFFI<F>` trait. - We give the foreign side a leaked `Box<Arc<dyn RustFutureFFI<F>>>>`. - We hand-monomorphize, creating a scaffolding function for each RustFutureFFI method, for each possible FFI type. Updated proc macros lift arguments in 2 phases. First we call `try_lift` on all arguments, generating a `Result<LiftedArgsTuple>`. Then we call the rust function using that tuple or handle the error. This is needed because the new async code adds a `Send` bound futures. The `Send` bound is good because futures are going to be moving across threads as we poll/wake them. However, the lift code won't always be Send because it may deal with raw pointers. To deal with that, we perform the non-Send lifting outside of the future, then create a Send future from the result. This means that the lift phase is executed outside of the async context, but it should be very fast. This change also allows futures that return Results to attempt to downcast lift errors. More changes: - Updated the futures fixture tests for this to hold on to the mutex longer in the initial call. This makes it so they will fail unless the future is dropped while the mutex is still locked. Before they would only succeed as long as the mutex was dropped once the timeout expired. - Updated `RustCallStatus.code` field to be an enum. Added `Cancelled` as one of the variants. `Cancelled` is only used for async functions. - Removed the FutureCallback and invoke_future_callback from `FfiConverter`. - New syncronization handling code in RustFuture that's hopefully clearer, more correct, and more understandable than the old stuff. - Updated `UNIFFI_CONTRACT_VERSION` since this is an ABI change - Removed the `RustCallStatus` param from async scaffolding functions. These functions can't fail, so there's no need. - Added is_async() to the Callable trait. - Changed `handle_failed_lift` signature. Now, if a `Result<>` is able to downcast the error, it returns `Self::Err` directly instead of serializing the error into `RustBuffer`. Co-authored-by: Ivan Enderlin <[email protected]> Co-authored-by: Jonas Platte <[email protected]>
The initial motivation for this was cancellation. PR#1697 made it so if an async function was cancelled we would eventually release the resources. However, it would be better if we could immedately release the resources. In order to implement that, the future FFI needed to change quite a bit and most of these changes are good. The new FFI is simpler overall and supports cancel and drop operations. It's actually quite close to the initial FFI that Hywan proposed. Cancel ensures that the foreign code will resume and break out of its async code. Drop ensures that all resources from the wrapped future are relased. Note: the new FFI has a cancel method, but no bindings use it yet. For Python/Kotlin we don't need to because they throw cancellation exceptions, which means cancellation support falls out from the new API without any extra work. This cancel method could be used for Swift, but we still need to think this through in a different PR. The new code does not use ForeignExecutor anymore, so that code is in a state of limbo. I hope to repurpose it for foreign dispatch queues (mozilla#1734). If that doesn't work out, we can just delete it. The FFI calls need some care since we pass a type-erased handle to the foreign code, while RustFuture is generic over an anonymous Future type: - The concrete RustFuture type implements the `RustFutureFFI<F>` trait. - We give the foreign side a leaked `Box<Arc<dyn RustFutureFFI<F>>>>`. - We hand-monomorphize, creating a scaffolding function for each RustFutureFFI method, for each possible FFI type. Updated proc macros lift arguments in 2 phases. First we call `try_lift` on all arguments, generating a `Result<LiftedArgsTuple>`. Then we call the rust function using that tuple or handle the error. This is needed because the new async code adds a `Send` bound futures. The `Send` bound is good because futures are going to be moving across threads as we poll/wake them. However, the lift code won't always be Send because it may deal with raw pointers. To deal with that, we perform the non-Send lifting outside of the future, then create a Send future from the result. This means that the lift phase is executed outside of the async context, but it should be very fast. This change also allows futures that return Results to attempt to downcast lift errors. More changes: - Updated the futures fixture tests for this to hold on to the mutex longer in the initial call. This makes it so they will fail unless the future is dropped while the mutex is still locked. Before they would only succeed as long as the mutex was dropped once the timeout expired. - Updated `RustCallStatus.code` field to be an enum. Added `Cancelled` as one of the variants. `Cancelled` is only used for async functions. - Removed the FutureCallback and invoke_future_callback from `FfiConverter`. - New syncronization handling code in RustFuture that's hopefully clearer, more correct, and more understandable than the old stuff. - Updated `UNIFFI_CONTRACT_VERSION` since this is an ABI change - Removed the `RustCallStatus` param from async scaffolding functions. These functions can't fail, so there's no need. - Added is_async() to the Callable trait. - Changed `handle_failed_lift` signature. Now, if a `Result<>` is able to downcast the error, it returns `Self::Err` directly instead of serializing the error into `RustBuffer`. Co-authored-by: Ivan Enderlin <[email protected]> Co-authored-by: Jonas Platte <[email protected]>
I think |
"background thread" implies "low priority thread" to me, which I don't think is the actual intent. The actual use-cases here tend to be more about thread blocking than thread priority. I was going to suggest something like |
You're right, it really is about blocking more than anything. |
using the same terminology as tokio is certainly appealing! |
A common pattern we use in application-services is to run SQLite queries using a foreign-managed task queue (
Dispatchers.IO
on Kotlin,DispatchQueue
on Swift, etc). Could UniFFI support this as a first-class type?This would require:
The text was updated successfully, but these errors were encountered: