diff options
| author | mo khan <mo@mokhan.ca> | 2025-07-15 16:37:08 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-07-17 16:30:22 -0600 |
| commit | 45df4d0d9b577fecee798d672695fe24ff57fb1b (patch) | |
| tree | 1b99bf645035b58e0d6db08c7a83521f41f7a75b /vendor/futures-task/src | |
| parent | f94f79608393d4ab127db63cc41668445ef6b243 (diff) | |
feat: migrate from Cedar to SpiceDB authorization system
This is a major architectural change that replaces the Cedar policy-based
authorization system with SpiceDB's relation-based authorization.
Key changes:
- Migrate from Rust to Go implementation
- Replace Cedar policies with SpiceDB schema and relationships
- Switch from envoy `ext_authz` with Cedar to SpiceDB permission checks
- Update build system and dependencies for Go ecosystem
- Maintain Envoy integration for external authorization
This change enables more flexible permission modeling through SpiceDB's
Google Zanzibar inspired relation-based system, supporting complex
hierarchical permissions that were difficult to express in Cedar.
Breaking change: Existing Cedar policies and Rust-based configuration
will no longer work and need to be migrated to SpiceDB schema.
Diffstat (limited to 'vendor/futures-task/src')
| -rw-r--r-- | vendor/futures-task/src/arc_wake.rs | 49 | ||||
| -rw-r--r-- | vendor/futures-task/src/future_obj.rs | 335 | ||||
| -rw-r--r-- | vendor/futures-task/src/lib.rs | 50 | ||||
| -rw-r--r-- | vendor/futures-task/src/noop_waker.rs | 63 | ||||
| -rw-r--r-- | vendor/futures-task/src/spawn.rs | 192 | ||||
| -rw-r--r-- | vendor/futures-task/src/waker.rs | 60 | ||||
| -rw-r--r-- | vendor/futures-task/src/waker_ref.rs | 66 |
7 files changed, 0 insertions, 815 deletions
diff --git a/vendor/futures-task/src/arc_wake.rs b/vendor/futures-task/src/arc_wake.rs deleted file mode 100644 index aa6de0fc..00000000 --- a/vendor/futures-task/src/arc_wake.rs +++ /dev/null @@ -1,49 +0,0 @@ -use alloc::sync::Arc; - -/// A way of waking up a specific task. -/// -/// By implementing this trait, types that are expected to be wrapped in an `Arc` -/// can be converted into [`Waker`] objects. -/// Those Wakers can be used to signal executors that a task it owns -/// is ready to be `poll`ed again. -/// -/// Currently, there are two ways to convert `ArcWake` into [`Waker`]: -/// -/// * [`waker`](super::waker()) converts `Arc<impl ArcWake>` into [`Waker`]. -/// * [`waker_ref`](super::waker_ref()) converts `&Arc<impl ArcWake>` into [`WakerRef`] that -/// provides access to a [`&Waker`][`Waker`]. -/// -/// [`Waker`]: std::task::Waker -/// [`WakerRef`]: super::WakerRef -// Note: Send + Sync required because `Arc<T>` doesn't automatically imply -// those bounds, but `Waker` implements them. -pub trait ArcWake: Send + Sync { - /// Indicates that the associated task is ready to make progress and should - /// be `poll`ed. - /// - /// This function can be called from an arbitrary thread, including threads which - /// did not create the `ArcWake` based [`Waker`]. - /// - /// Executors generally maintain a queue of "ready" tasks; `wake` should place - /// the associated task onto this queue. - /// - /// [`Waker`]: std::task::Waker - fn wake(self: Arc<Self>) { - Self::wake_by_ref(&self) - } - - /// Indicates that the associated task is ready to make progress and should - /// be `poll`ed. - /// - /// This function can be called from an arbitrary thread, including threads which - /// did not create the `ArcWake` based [`Waker`]. - /// - /// Executors generally maintain a queue of "ready" tasks; `wake_by_ref` should place - /// the associated task onto this queue. - /// - /// This function is similar to [`wake`](ArcWake::wake), but must not consume the provided data - /// pointer. - /// - /// [`Waker`]: std::task::Waker - fn wake_by_ref(arc_self: &Arc<Self>); -} diff --git a/vendor/futures-task/src/future_obj.rs b/vendor/futures-task/src/future_obj.rs deleted file mode 100644 index a6113821..00000000 --- a/vendor/futures-task/src/future_obj.rs +++ /dev/null @@ -1,335 +0,0 @@ -use core::{ - fmt, - future::Future, - marker::PhantomData, - mem, - pin::Pin, - task::{Context, Poll}, -}; - -/// A custom trait object for polling futures, roughly akin to -/// `Box<dyn Future<Output = T> + 'a>`. -/// -/// This custom trait object was introduced as currently it is not possible to -/// take `dyn Trait` by value and `Box<dyn Trait>` is not available in no_std -/// contexts. -pub struct LocalFutureObj<'a, T> { - future: *mut (dyn Future<Output = T> + 'static), - drop_fn: unsafe fn(*mut (dyn Future<Output = T> + 'static)), - _marker: PhantomData<&'a ()>, -} - -// As LocalFutureObj only holds pointers, even if we move it, the pointed to values won't move, -// so this is safe as long as we don't provide any way for a user to directly access the pointers -// and move their values. -impl<T> Unpin for LocalFutureObj<'_, T> {} - -#[allow(single_use_lifetimes)] -#[allow(clippy::transmute_ptr_to_ptr)] -unsafe fn remove_future_lifetime<'a, T>( - ptr: *mut (dyn Future<Output = T> + 'a), -) -> *mut (dyn Future<Output = T> + 'static) { - unsafe { mem::transmute(ptr) } -} - -#[allow(single_use_lifetimes)] -unsafe fn remove_drop_lifetime<'a, T>( - ptr: unsafe fn(*mut (dyn Future<Output = T> + 'a)), -) -> unsafe fn(*mut (dyn Future<Output = T> + 'static)) { - unsafe { mem::transmute(ptr) } -} - -impl<'a, T> LocalFutureObj<'a, T> { - /// Create a `LocalFutureObj` from a custom trait object representation. - #[inline] - pub fn new<F: UnsafeFutureObj<'a, T> + 'a>(f: F) -> Self { - Self { - future: unsafe { remove_future_lifetime(f.into_raw()) }, - drop_fn: unsafe { remove_drop_lifetime(F::drop) }, - _marker: PhantomData, - } - } - - /// Converts the `LocalFutureObj` into a `FutureObj`. - /// - /// # Safety - /// - /// To make this operation safe one has to ensure that the `UnsafeFutureObj` - /// instance from which this `LocalFutureObj` was created actually - /// implements `Send`. - #[inline] - pub unsafe fn into_future_obj(self) -> FutureObj<'a, T> { - FutureObj(self) - } -} - -impl<T> fmt::Debug for LocalFutureObj<'_, T> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("LocalFutureObj").finish() - } -} - -impl<'a, T> From<FutureObj<'a, T>> for LocalFutureObj<'a, T> { - #[inline] - fn from(f: FutureObj<'a, T>) -> Self { - f.0 - } -} - -impl<T> Future for LocalFutureObj<'_, T> { - type Output = T; - - #[inline] - fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<T> { - unsafe { Pin::new_unchecked(&mut *self.future).poll(cx) } - } -} - -impl<T> Drop for LocalFutureObj<'_, T> { - fn drop(&mut self) { - unsafe { (self.drop_fn)(self.future) } - } -} - -/// A custom trait object for polling futures, roughly akin to -/// `Box<dyn Future<Output = T> + Send + 'a>`. -/// -/// This custom trait object was introduced as currently it is not possible to -/// take `dyn Trait` by value and `Box<dyn Trait>` is not available in no_std -/// contexts. -/// -/// You should generally not need to use this type outside of `no_std` or when -/// implementing `Spawn`, consider using `BoxFuture` instead. -pub struct FutureObj<'a, T>(LocalFutureObj<'a, T>); - -impl<T> Unpin for FutureObj<'_, T> {} -unsafe impl<T> Send for FutureObj<'_, T> {} - -impl<'a, T> FutureObj<'a, T> { - /// Create a `FutureObj` from a custom trait object representation. - #[inline] - pub fn new<F: UnsafeFutureObj<'a, T> + Send>(f: F) -> Self { - Self(LocalFutureObj::new(f)) - } -} - -impl<T> fmt::Debug for FutureObj<'_, T> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("FutureObj").finish() - } -} - -impl<T> Future for FutureObj<'_, T> { - type Output = T; - - #[inline] - fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<T> { - Pin::new(&mut self.0).poll(cx) - } -} - -/// A custom implementation of a future trait object for `FutureObj`, providing -/// a vtable with drop support. -/// -/// This custom representation is typically used only in `no_std` contexts, -/// where the default `Box`-based implementation is not available. -/// -/// # Safety -/// -/// See the safety notes on individual methods for what guarantees an -/// implementor must provide. -pub unsafe trait UnsafeFutureObj<'a, T>: 'a { - /// Convert an owned instance into a (conceptually owned) fat pointer. - /// - /// # Safety - /// - /// ## Implementor - /// - /// The trait implementor must guarantee that it is safe to convert the - /// provided `*mut (dyn Future<Output = T> + 'a)` into a `Pin<&mut (dyn - /// Future<Output = T> + 'a)>` and call methods on it, non-reentrantly, - /// until `UnsafeFutureObj::drop` is called with it. - #[allow(clippy::unnecessary_safety_doc)] - fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a); - - /// Drops the future represented by the given fat pointer. - /// - /// # Safety - /// - /// ## Implementor - /// - /// The trait implementor must guarantee that it is safe to call this - /// function once per `into_raw` invocation. - /// - /// ## Caller - /// - /// The caller must ensure: - /// - /// * the pointer passed was obtained from an `into_raw` invocation from - /// this same trait object - /// * the pointer is not currently in use as a `Pin<&mut (dyn Future<Output - /// = T> + 'a)>` - /// * the pointer must not be used again after this function is called - unsafe fn drop(ptr: *mut (dyn Future<Output = T> + 'a)); -} - -unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for &'a mut F -where - F: Future<Output = T> + Unpin + 'a, -{ - fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { - self as *mut dyn Future<Output = T> - } - - unsafe fn drop(_ptr: *mut (dyn Future<Output = T> + 'a)) {} -} - -unsafe impl<'a, T> UnsafeFutureObj<'a, T> for &'a mut (dyn Future<Output = T> + Unpin + 'a) { - fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { - self as *mut dyn Future<Output = T> - } - - unsafe fn drop(_ptr: *mut (dyn Future<Output = T> + 'a)) {} -} - -unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for Pin<&'a mut F> -where - F: Future<Output = T> + 'a, -{ - fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { - unsafe { self.get_unchecked_mut() as *mut dyn Future<Output = T> } - } - - unsafe fn drop(_ptr: *mut (dyn Future<Output = T> + 'a)) {} -} - -unsafe impl<'a, T> UnsafeFutureObj<'a, T> for Pin<&'a mut (dyn Future<Output = T> + 'a)> { - fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { - unsafe { self.get_unchecked_mut() as *mut dyn Future<Output = T> } - } - - unsafe fn drop(_ptr: *mut (dyn Future<Output = T> + 'a)) {} -} - -#[cfg(feature = "alloc")] -mod if_alloc { - use super::*; - use alloc::boxed::Box; - - unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for Box<F> - where - F: Future<Output = T> + 'a, - { - fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { - Box::into_raw(self) - } - - unsafe fn drop(ptr: *mut (dyn Future<Output = T> + 'a)) { - drop(unsafe { Box::from_raw(ptr.cast::<F>()) }) - } - } - - unsafe impl<'a, T: 'a> UnsafeFutureObj<'a, T> for Box<dyn Future<Output = T> + 'a> { - fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { - Box::into_raw(self) - } - - unsafe fn drop(ptr: *mut (dyn Future<Output = T> + 'a)) { - drop(unsafe { Box::from_raw(ptr) }) - } - } - - unsafe impl<'a, T: 'a> UnsafeFutureObj<'a, T> for Box<dyn Future<Output = T> + Send + 'a> { - fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { - Box::into_raw(self) - } - - unsafe fn drop(ptr: *mut (dyn Future<Output = T> + 'a)) { - drop(unsafe { Box::from_raw(ptr) }) - } - } - - unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for Pin<Box<F>> - where - F: Future<Output = T> + 'a, - { - fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { - let mut this = mem::ManuallyDrop::new(self); - unsafe { this.as_mut().get_unchecked_mut() as *mut _ } - } - - unsafe fn drop(ptr: *mut (dyn Future<Output = T> + 'a)) { - drop(Pin::from(unsafe { Box::from_raw(ptr) })) - } - } - - unsafe impl<'a, T: 'a> UnsafeFutureObj<'a, T> for Pin<Box<dyn Future<Output = T> + 'a>> { - fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { - let mut this = mem::ManuallyDrop::new(self); - unsafe { this.as_mut().get_unchecked_mut() as *mut _ } - } - - unsafe fn drop(ptr: *mut (dyn Future<Output = T> + 'a)) { - drop(Pin::from(unsafe { Box::from_raw(ptr) })) - } - } - - unsafe impl<'a, T: 'a> UnsafeFutureObj<'a, T> for Pin<Box<dyn Future<Output = T> + Send + 'a>> { - fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { - let mut this = mem::ManuallyDrop::new(self); - unsafe { this.as_mut().get_unchecked_mut() as *mut _ } - } - - unsafe fn drop(ptr: *mut (dyn Future<Output = T> + 'a)) { - drop(Pin::from(unsafe { Box::from_raw(ptr) })) - } - } - - impl<'a, F: Future<Output = ()> + Send + 'a> From<Box<F>> for FutureObj<'a, ()> { - fn from(boxed: Box<F>) -> Self { - Self::new(boxed) - } - } - - impl<'a> From<Box<dyn Future<Output = ()> + Send + 'a>> for FutureObj<'a, ()> { - fn from(boxed: Box<dyn Future<Output = ()> + Send + 'a>) -> Self { - Self::new(boxed) - } - } - - impl<'a, F: Future<Output = ()> + Send + 'a> From<Pin<Box<F>>> for FutureObj<'a, ()> { - fn from(boxed: Pin<Box<F>>) -> Self { - Self::new(boxed) - } - } - - impl<'a> From<Pin<Box<dyn Future<Output = ()> + Send + 'a>>> for FutureObj<'a, ()> { - fn from(boxed: Pin<Box<dyn Future<Output = ()> + Send + 'a>>) -> Self { - Self::new(boxed) - } - } - - impl<'a, F: Future<Output = ()> + 'a> From<Box<F>> for LocalFutureObj<'a, ()> { - fn from(boxed: Box<F>) -> Self { - Self::new(boxed) - } - } - - impl<'a> From<Box<dyn Future<Output = ()> + 'a>> for LocalFutureObj<'a, ()> { - fn from(boxed: Box<dyn Future<Output = ()> + 'a>) -> Self { - Self::new(boxed) - } - } - - impl<'a, F: Future<Output = ()> + 'a> From<Pin<Box<F>>> for LocalFutureObj<'a, ()> { - fn from(boxed: Pin<Box<F>>) -> Self { - Self::new(boxed) - } - } - - impl<'a> From<Pin<Box<dyn Future<Output = ()> + 'a>>> for LocalFutureObj<'a, ()> { - fn from(boxed: Pin<Box<dyn Future<Output = ()> + 'a>>) -> Self { - Self::new(boxed) - } - } -} diff --git a/vendor/futures-task/src/lib.rs b/vendor/futures-task/src/lib.rs deleted file mode 100644 index c119b6b1..00000000 --- a/vendor/futures-task/src/lib.rs +++ /dev/null @@ -1,50 +0,0 @@ -//! Tools for working with tasks. - -#![no_std] -#![doc(test( - no_crate_inject, - attr( - deny(warnings, rust_2018_idioms, single_use_lifetimes), - allow(dead_code, unused_assignments, unused_variables) - ) -))] -#![warn(missing_docs, unsafe_op_in_unsafe_fn)] - -#[cfg(feature = "alloc")] -extern crate alloc; -#[cfg(feature = "std")] -extern crate std; - -mod spawn; -pub use crate::spawn::{LocalSpawn, Spawn, SpawnError}; - -#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))] -#[cfg(feature = "alloc")] -mod arc_wake; -#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))] -#[cfg(feature = "alloc")] -pub use crate::arc_wake::ArcWake; - -#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))] -#[cfg(feature = "alloc")] -mod waker; -#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))] -#[cfg(feature = "alloc")] -pub use crate::waker::waker; - -#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))] -#[cfg(feature = "alloc")] -mod waker_ref; -#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))] -#[cfg(feature = "alloc")] -pub use crate::waker_ref::{waker_ref, WakerRef}; - -mod future_obj; -pub use crate::future_obj::{FutureObj, LocalFutureObj, UnsafeFutureObj}; - -mod noop_waker; -pub use crate::noop_waker::noop_waker; -pub use crate::noop_waker::noop_waker_ref; - -#[doc(no_inline)] -pub use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker}; diff --git a/vendor/futures-task/src/noop_waker.rs b/vendor/futures-task/src/noop_waker.rs deleted file mode 100644 index f76a8a2e..00000000 --- a/vendor/futures-task/src/noop_waker.rs +++ /dev/null @@ -1,63 +0,0 @@ -//! Utilities for creating zero-cost wakers that don't do anything. - -use core::ptr::null; -use core::task::{RawWaker, RawWakerVTable, Waker}; - -unsafe fn noop_clone(_data: *const ()) -> RawWaker { - noop_raw_waker() -} - -unsafe fn noop(_data: *const ()) {} - -const NOOP_WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(noop_clone, noop, noop, noop); - -const fn noop_raw_waker() -> RawWaker { - RawWaker::new(null(), &NOOP_WAKER_VTABLE) -} - -/// Create a new [`Waker`] which does -/// nothing when `wake()` is called on it. -/// -/// # Examples -/// -/// ``` -/// use futures::task::noop_waker; -/// let waker = noop_waker(); -/// waker.wake(); -/// ``` -#[inline] -pub fn noop_waker() -> Waker { - // FIXME: Since 1.46.0 we can use transmute in consts, allowing this function to be const. - unsafe { Waker::from_raw(noop_raw_waker()) } -} - -/// Get a static reference to a [`Waker`] which -/// does nothing when `wake()` is called on it. -/// -/// # Examples -/// -/// ``` -/// use futures::task::noop_waker_ref; -/// let waker = noop_waker_ref(); -/// waker.wake_by_ref(); -/// ``` -#[inline] -pub fn noop_waker_ref() -> &'static Waker { - struct SyncRawWaker(RawWaker); - unsafe impl Sync for SyncRawWaker {} - - static NOOP_WAKER_INSTANCE: SyncRawWaker = SyncRawWaker(noop_raw_waker()); - - // SAFETY: `Waker` is #[repr(transparent)] over its `RawWaker`. - unsafe { &*(&NOOP_WAKER_INSTANCE.0 as *const RawWaker as *const Waker) } -} - -#[cfg(test)] -mod tests { - #[test] - #[cfg(feature = "std")] - fn issue_2091_cross_thread_segfault() { - let waker = std::thread::spawn(super::noop_waker_ref).join().unwrap(); - waker.wake_by_ref(); - } -} diff --git a/vendor/futures-task/src/spawn.rs b/vendor/futures-task/src/spawn.rs deleted file mode 100644 index 4a9a45a4..00000000 --- a/vendor/futures-task/src/spawn.rs +++ /dev/null @@ -1,192 +0,0 @@ -use crate::{FutureObj, LocalFutureObj}; -use core::fmt; - -/// The `Spawn` trait allows for pushing futures onto an executor that will -/// run them to completion. -pub trait Spawn { - /// Spawns a future that will be run to completion. - /// - /// # Errors - /// - /// The executor may be unable to spawn tasks. Spawn errors should - /// represent relatively rare scenarios, such as the executor - /// having been shut down so that it is no longer able to accept - /// tasks. - fn spawn_obj(&self, future: FutureObj<'static, ()>) -> Result<(), SpawnError>; - - /// Determines whether the executor is able to spawn new tasks. - /// - /// This method will return `Ok` when the executor is *likely* - /// (but not guaranteed) to accept a subsequent spawn attempt. - /// Likewise, an `Err` return means that `spawn` is likely, but - /// not guaranteed, to yield an error. - #[inline] - fn status(&self) -> Result<(), SpawnError> { - Ok(()) - } -} - -/// The `LocalSpawn` is similar to [`Spawn`], but allows spawning futures -/// that don't implement `Send`. -pub trait LocalSpawn { - /// Spawns a future that will be run to completion. - /// - /// # Errors - /// - /// The executor may be unable to spawn tasks. Spawn errors should - /// represent relatively rare scenarios, such as the executor - /// having been shut down so that it is no longer able to accept - /// tasks. - fn spawn_local_obj(&self, future: LocalFutureObj<'static, ()>) -> Result<(), SpawnError>; - - /// Determines whether the executor is able to spawn new tasks. - /// - /// This method will return `Ok` when the executor is *likely* - /// (but not guaranteed) to accept a subsequent spawn attempt. - /// Likewise, an `Err` return means that `spawn` is likely, but - /// not guaranteed, to yield an error. - #[inline] - fn status_local(&self) -> Result<(), SpawnError> { - Ok(()) - } -} - -/// An error that occurred during spawning. -pub struct SpawnError { - _priv: (), -} - -impl fmt::Debug for SpawnError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_tuple("SpawnError").field(&"shutdown").finish() - } -} - -impl fmt::Display for SpawnError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "Executor is shutdown") - } -} - -#[cfg(feature = "std")] -impl std::error::Error for SpawnError {} - -impl SpawnError { - /// Spawning failed because the executor has been shut down. - pub fn shutdown() -> Self { - Self { _priv: () } - } - - /// Check whether spawning failed to the executor being shut down. - pub fn is_shutdown(&self) -> bool { - true - } -} - -impl<Sp: ?Sized + Spawn> Spawn for &Sp { - fn spawn_obj(&self, future: FutureObj<'static, ()>) -> Result<(), SpawnError> { - Sp::spawn_obj(self, future) - } - - fn status(&self) -> Result<(), SpawnError> { - Sp::status(self) - } -} - -impl<Sp: ?Sized + Spawn> Spawn for &mut Sp { - fn spawn_obj(&self, future: FutureObj<'static, ()>) -> Result<(), SpawnError> { - Sp::spawn_obj(self, future) - } - - fn status(&self) -> Result<(), SpawnError> { - Sp::status(self) - } -} - -impl<Sp: ?Sized + LocalSpawn> LocalSpawn for &Sp { - fn spawn_local_obj(&self, future: LocalFutureObj<'static, ()>) -> Result<(), SpawnError> { - Sp::spawn_local_obj(self, future) - } - - fn status_local(&self) -> Result<(), SpawnError> { - Sp::status_local(self) - } -} - -impl<Sp: ?Sized + LocalSpawn> LocalSpawn for &mut Sp { - fn spawn_local_obj(&self, future: LocalFutureObj<'static, ()>) -> Result<(), SpawnError> { - Sp::spawn_local_obj(self, future) - } - - fn status_local(&self) -> Result<(), SpawnError> { - Sp::status_local(self) - } -} - -#[cfg(feature = "alloc")] -mod if_alloc { - use super::*; - use alloc::{boxed::Box, rc::Rc}; - - impl<Sp: ?Sized + Spawn> Spawn for Box<Sp> { - fn spawn_obj(&self, future: FutureObj<'static, ()>) -> Result<(), SpawnError> { - (**self).spawn_obj(future) - } - - fn status(&self) -> Result<(), SpawnError> { - (**self).status() - } - } - - impl<Sp: ?Sized + LocalSpawn> LocalSpawn for Box<Sp> { - fn spawn_local_obj(&self, future: LocalFutureObj<'static, ()>) -> Result<(), SpawnError> { - (**self).spawn_local_obj(future) - } - - fn status_local(&self) -> Result<(), SpawnError> { - (**self).status_local() - } - } - - impl<Sp: ?Sized + Spawn> Spawn for Rc<Sp> { - fn spawn_obj(&self, future: FutureObj<'static, ()>) -> Result<(), SpawnError> { - (**self).spawn_obj(future) - } - - fn status(&self) -> Result<(), SpawnError> { - (**self).status() - } - } - - impl<Sp: ?Sized + LocalSpawn> LocalSpawn for Rc<Sp> { - fn spawn_local_obj(&self, future: LocalFutureObj<'static, ()>) -> Result<(), SpawnError> { - (**self).spawn_local_obj(future) - } - - fn status_local(&self) -> Result<(), SpawnError> { - (**self).status_local() - } - } - - #[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))] - impl<Sp: ?Sized + Spawn> Spawn for alloc::sync::Arc<Sp> { - fn spawn_obj(&self, future: FutureObj<'static, ()>) -> Result<(), SpawnError> { - (**self).spawn_obj(future) - } - - fn status(&self) -> Result<(), SpawnError> { - (**self).status() - } - } - - #[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))] - impl<Sp: ?Sized + LocalSpawn> LocalSpawn for alloc::sync::Arc<Sp> { - fn spawn_local_obj(&self, future: LocalFutureObj<'static, ()>) -> Result<(), SpawnError> { - (**self).spawn_local_obj(future) - } - - fn status_local(&self) -> Result<(), SpawnError> { - (**self).status_local() - } - } -} diff --git a/vendor/futures-task/src/waker.rs b/vendor/futures-task/src/waker.rs deleted file mode 100644 index ce90aa83..00000000 --- a/vendor/futures-task/src/waker.rs +++ /dev/null @@ -1,60 +0,0 @@ -use super::arc_wake::ArcWake; -use alloc::sync::Arc; -use core::mem; -use core::task::{RawWaker, RawWakerVTable, Waker}; - -pub(super) fn waker_vtable<W: ArcWake + 'static>() -> &'static RawWakerVTable { - &RawWakerVTable::new( - clone_arc_raw::<W>, - wake_arc_raw::<W>, - wake_by_ref_arc_raw::<W>, - drop_arc_raw::<W>, - ) -} - -/// Creates a [`Waker`] from an `Arc<impl ArcWake>`. -/// -/// The returned [`Waker`] will call -/// [`ArcWake.wake()`](ArcWake::wake) if awoken. -pub fn waker<W>(wake: Arc<W>) -> Waker -where - W: ArcWake + 'static, -{ - let ptr = Arc::into_raw(wake).cast::<()>(); - - unsafe { Waker::from_raw(RawWaker::new(ptr, waker_vtable::<W>())) } -} - -// FIXME: panics on Arc::clone / refcount changes could wreak havoc on the -// code here. We should guard against this by aborting. - -#[allow(clippy::redundant_clone)] // The clone here isn't actually redundant. -unsafe fn increase_refcount<T: ArcWake + 'static>(data: *const ()) { - // Retain Arc, but don't touch refcount by wrapping in ManuallyDrop - let arc = mem::ManuallyDrop::new(unsafe { Arc::<T>::from_raw(data.cast::<T>()) }); - // Now increase refcount, but don't drop new refcount either - let _arc_clone: mem::ManuallyDrop<_> = arc.clone(); -} - -// used by `waker_ref` -#[inline(always)] -unsafe fn clone_arc_raw<T: ArcWake + 'static>(data: *const ()) -> RawWaker { - unsafe { increase_refcount::<T>(data) } - RawWaker::new(data, waker_vtable::<T>()) -} - -unsafe fn wake_arc_raw<T: ArcWake + 'static>(data: *const ()) { - let arc: Arc<T> = unsafe { Arc::from_raw(data.cast::<T>()) }; - ArcWake::wake(arc); -} - -// used by `waker_ref` -unsafe fn wake_by_ref_arc_raw<T: ArcWake + 'static>(data: *const ()) { - // Retain Arc, but don't touch refcount by wrapping in ManuallyDrop - let arc = mem::ManuallyDrop::new(unsafe { Arc::<T>::from_raw(data.cast::<T>()) }); - ArcWake::wake_by_ref(&arc); -} - -unsafe fn drop_arc_raw<T: ArcWake + 'static>(data: *const ()) { - drop(unsafe { Arc::<T>::from_raw(data.cast::<T>()) }) -} diff --git a/vendor/futures-task/src/waker_ref.rs b/vendor/futures-task/src/waker_ref.rs deleted file mode 100644 index 5957b4d4..00000000 --- a/vendor/futures-task/src/waker_ref.rs +++ /dev/null @@ -1,66 +0,0 @@ -use super::arc_wake::ArcWake; -use super::waker::waker_vtable; -use alloc::sync::Arc; -use core::marker::PhantomData; -use core::mem::ManuallyDrop; -use core::ops::Deref; -use core::task::{RawWaker, Waker}; - -/// A [`Waker`] that is only valid for a given lifetime. -/// -/// Note: this type implements [`Deref<Target = Waker>`](std::ops::Deref), -/// so it can be used to get a `&Waker`. -#[derive(Debug)] -pub struct WakerRef<'a> { - waker: ManuallyDrop<Waker>, - _marker: PhantomData<&'a ()>, -} - -impl<'a> WakerRef<'a> { - /// Create a new [`WakerRef`] from a [`Waker`] reference. - #[inline] - pub fn new(waker: &'a Waker) -> Self { - // copy the underlying (raw) waker without calling a clone, - // as we won't call Waker::drop either. - let waker = ManuallyDrop::new(unsafe { core::ptr::read(waker) }); - Self { waker, _marker: PhantomData } - } - - /// Create a new [`WakerRef`] from a [`Waker`] that must not be dropped. - /// - /// Note: this if for rare cases where the caller created a [`Waker`] in - /// an unsafe way (that will be valid only for a lifetime to be determined - /// by the caller), and the [`Waker`] doesn't need to or must not be - /// destroyed. - #[inline] - pub fn new_unowned(waker: ManuallyDrop<Waker>) -> Self { - Self { waker, _marker: PhantomData } - } -} - -impl Deref for WakerRef<'_> { - type Target = Waker; - - #[inline] - fn deref(&self) -> &Waker { - &self.waker - } -} - -/// Creates a reference to a [`Waker`] from a reference to `Arc<impl ArcWake>`. -/// -/// The resulting [`Waker`] will call -/// [`ArcWake.wake()`](ArcWake::wake) if awoken. -#[inline] -pub fn waker_ref<W>(wake: &Arc<W>) -> WakerRef<'_> -where - W: ArcWake + 'static, -{ - // simply copy the pointer instead of using Arc::into_raw, - // as we don't actually keep a refcount by using ManuallyDrop.< - let ptr = Arc::as_ptr(wake).cast::<()>(); - - let waker = - ManuallyDrop::new(unsafe { Waker::from_raw(RawWaker::new(ptr, waker_vtable::<W>())) }); - WakerRef::new_unowned(waker) -} |
