diff --git a/turbopack/crates/turbo-tasks/src/collectibles.rs b/turbopack/crates/turbo-tasks/src/collectibles.rs index e4f9aed0de1aef..65161ba983f736 100644 --- a/turbopack/crates/turbo-tasks/src/collectibles.rs +++ b/turbopack/crates/turbo-tasks/src/collectibles.rs @@ -3,6 +3,6 @@ use auto_hash_map::AutoSet; use crate::{Vc, VcValueTrait}; pub trait CollectiblesSource { - fn take_collectibles(self) -> AutoSet>; - fn peek_collectibles(self) -> AutoSet>; + fn take_collectibles(self) -> AutoSet>; + fn peek_collectibles(self) -> AutoSet>; } diff --git a/turbopack/crates/turbo-tasks/src/manager.rs b/turbopack/crates/turbo-tasks/src/manager.rs index 3b06e1ef04a852..0134c7d3354808 100644 --- a/turbopack/crates/turbo-tasks/src/manager.rs +++ b/turbopack/crates/turbo-tasks/src/manager.rs @@ -504,7 +504,7 @@ impl TurboTasks { /// Creates a new root task pub fn spawn_root_task(&self, functor: F) -> TaskId where - T: Send, + T: ?Sized, F: Fn() -> Fut + Send + Sync + Clone + 'static, Fut: Future>> + Send, { @@ -529,7 +529,7 @@ impl TurboTasks { #[track_caller] pub fn spawn_once_task(&self, future: Fut) -> TaskId where - T: Send, + T: ?Sized, Fut: Future>> + Send + 'static, { let id = self.backend.create_transient_task( @@ -1741,7 +1741,7 @@ pub fn notify_scheduled_tasks() { with_turbo_tasks(|tt| tt.notify_scheduled_tasks()) } -pub fn emit(collectible: Vc) { +pub fn emit(collectible: Vc) { with_turbo_tasks(|tt| tt.emit_collectible(T::get_trait_type_id(), collectible.node)) } diff --git a/turbopack/crates/turbo-tasks/src/raw_vc.rs b/turbopack/crates/turbo-tasks/src/raw_vc.rs index 72273489563a65..1654ee746aef42 100644 --- a/turbopack/crates/turbo-tasks/src/raw_vc.rs +++ b/turbopack/crates/turbo-tasks/src/raw_vc.rs @@ -252,7 +252,7 @@ impl RawVc { } impl CollectiblesSource for RawVc { - fn peek_collectibles(self) -> AutoSet> { + fn peek_collectibles(self) -> AutoSet> { let tt = turbo_tasks(); tt.notify_scheduled_tasks(); let map = tt.read_task_collectibles(self.get_task_id(), T::get_trait_type_id()); @@ -261,7 +261,7 @@ impl CollectiblesSource for RawVc { .collect() } - fn take_collectibles(self) -> AutoSet> { + fn take_collectibles(self) -> AutoSet> { let tt = turbo_tasks(); tt.notify_scheduled_tasks(); let map = tt.read_task_collectibles(self.get_task_id(), T::get_trait_type_id()); @@ -430,7 +430,4 @@ impl Future for ReadRawVcFuture { } } -unsafe impl Send for ReadRawVcFuture {} -unsafe impl Sync for ReadRawVcFuture {} - impl Unpin for ReadRawVcFuture {} diff --git a/turbopack/crates/turbo-tasks/src/task/from_task_input.rs b/turbopack/crates/turbo-tasks/src/task/from_task_input.rs index 8ddd8207f505a4..223b7e9fa7e859 100644 --- a/turbopack/crates/turbo-tasks/src/task/from_task_input.rs +++ b/turbopack/crates/turbo-tasks/src/task/from_task_input.rs @@ -12,14 +12,14 @@ mod private { /// Implements the sealed trait pattern: /// pub trait Sealed {} - impl Sealed for ResolvedVc where T: Send {} + impl Sealed for ResolvedVc where T: ?Sized {} impl Sealed for Vec where T: FromTaskInput {} impl Sealed for Option where T: FromTaskInput {} } impl FromTaskInput for ResolvedVc where - T: Send, + T: Send + Sync + ?Sized, { type TaskInput = Vc; fn from_task_input(from: Vc) -> ResolvedVc { diff --git a/turbopack/crates/turbo-tasks/src/task/task_input.rs b/turbopack/crates/turbo-tasks/src/task/task_input.rs index 5da843a58ba38c..ddc6b560e41f87 100644 --- a/turbopack/crates/turbo-tasks/src/task/task_input.rs +++ b/turbopack/crates/turbo-tasks/src/task/task_input.rs @@ -95,7 +95,7 @@ where impl TaskInput for Vc where - T: Send, + T: Send + Sync + ?Sized, { fn is_resolved(&self) -> bool { Vc::is_resolved(*self) @@ -114,7 +114,7 @@ where // `Vc`, but it is useful for structs that contain `ResolvedVc` and want to derive `TaskInput`. impl TaskInput for ResolvedVc where - T: Send, + T: Send + Sync + ?Sized, { fn is_resolved(&self) -> bool { true diff --git a/turbopack/crates/turbo-tasks/src/task/task_output.rs b/turbopack/crates/turbo-tasks/src/task/task_output.rs index c14ed7507f67e2..41d36c2826f726 100644 --- a/turbopack/crates/turbo-tasks/src/task/task_output.rs +++ b/turbopack/crates/turbo-tasks/src/task/task_output.rs @@ -15,7 +15,7 @@ pub trait TaskOutput { impl TaskOutput for Vc where - T: ?Sized + Send, + T: ?Sized, { type Return = Vc; diff --git a/turbopack/crates/turbo-tasks/src/trait_ref.rs b/turbopack/crates/turbo-tasks/src/trait_ref.rs index 6789c5cfaf2211..2c5660c1bb8bd4 100644 --- a/turbopack/crates/turbo-tasks/src/trait_ref.rs +++ b/turbopack/crates/turbo-tasks/src/trait_ref.rs @@ -100,7 +100,7 @@ where impl TraitRef where - T: VcValueTrait + ?Sized + Send, + T: VcValueTrait + ?Sized, { /// Returns a new cell that points to a value that implements the value /// trait `T`. @@ -130,7 +130,7 @@ pub trait IntoTraitRef { impl IntoTraitRef for Vc where - T: VcValueTrait + ?Sized + Send, + T: VcValueTrait + ?Sized, { type ValueTrait = T; diff --git a/turbopack/crates/turbo-tasks/src/vc/mod.rs b/turbopack/crates/turbo-tasks/src/vc/mod.rs index 107dad4ec673cd..b34458bdb659bb 100644 --- a/turbopack/crates/turbo-tasks/src/vc/mod.rs +++ b/turbopack/crates/turbo-tasks/src/vc/mod.rs @@ -7,6 +7,7 @@ mod traits; use std::{ any::Any, + fmt::Debug, future::{Future, IntoFuture}, hash::{Hash, Hasher}, marker::PhantomData, @@ -50,7 +51,7 @@ use crate::{ #[serde(transparent, bound = "")] pub struct Vc where - T: ?Sized + Send, + T: ?Sized, { pub(crate) node: RawVc, #[doc(hidden)] @@ -186,7 +187,7 @@ where #[doc(hidden)] impl Deref for Vc where - T: ?Sized + Send, + T: ?Sized, { type Target = VcDeref; @@ -200,14 +201,11 @@ where } } -impl Copy for Vc where T: ?Sized + Send {} - -unsafe impl Send for Vc where T: ?Sized + Send {} -unsafe impl Sync for Vc where T: ?Sized + Send {} +impl Copy for Vc where T: ?Sized {} impl Clone for Vc where - T: ?Sized + Send, + T: ?Sized, { fn clone(&self) -> Self { *self @@ -216,7 +214,7 @@ where impl Hash for Vc where - T: ?Sized + Send, + T: ?Sized, { fn hash(&self, state: &mut H) { self.node.hash(state); @@ -225,20 +223,23 @@ where impl PartialEq> for Vc where - T: ?Sized + Send, + T: ?Sized, { fn eq(&self, other: &Self) -> bool { self.node == other.node } } -impl Eq for Vc where T: ?Sized + Send {} +impl Eq for Vc where T: ?Sized {} -// TODO(alexkirsz) This should not be implemented for Vc. Instead, users should -// use the `ValueDebug` implementation to get a `D: Debug`. -impl std::fmt::Debug for Vc +/// Generates an opaque debug representation of the [`Vc`] itself, but not the data inside of it. +/// +/// This is implemented to allow types containing [`Vc`] to implement the synchronous [`Debug`] +/// trait, but in most cases users should use the [`ValueDebug`] implementation to get a string +/// representation of the contents of the cell. +impl Debug for Vc where - T: Send, + T: ?Sized, { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("Vc").field("node", &self.node).finish() @@ -309,7 +310,7 @@ where impl Vc where - T: ?Sized + Send, + T: ?Sized, { /// Connects the operation pointed to by this `Vc` to the current task. pub fn connect(vc: Self) { @@ -340,19 +341,14 @@ where pub fn upcast(vc: Self) -> Vc where T: Upcast, - K: VcValueTrait + ?Sized + Send, + K: VcValueTrait + ?Sized, { Vc { node: vc.node, _t: PhantomData, } } -} -impl Vc -where - T: ?Sized + Send, -{ /// Resolve the reference until it points to a cell directly. /// /// Resolving will wait for task execution to be finished, so that the @@ -415,7 +411,7 @@ where impl Vc where - T: VcValueTrait + ?Sized + Send, + T: VcValueTrait + ?Sized, { /// Attempts to sidecast the given `Vc>` to a `Vc>`. /// This operation also resolves the `Vc`. @@ -427,7 +423,7 @@ where /// removing the need for a `Result` return type. pub async fn try_resolve_sidecast(vc: Self) -> Result>, ResolveTypeError> where - K: VcValueTrait + ?Sized + Send, + K: VcValueTrait + ?Sized, { let raw_vc: RawVc = vc.node; let raw_vc = raw_vc @@ -446,8 +442,7 @@ where /// Returns `None` if the underlying value type is not a `K`. pub async fn try_resolve_downcast(vc: Self) -> Result>, ResolveTypeError> where - K: Upcast, - K: VcValueTrait + ?Sized + Send, + K: Upcast + VcValueTrait + ?Sized, { let raw_vc: RawVc = vc.node; let raw_vc = raw_vc @@ -466,8 +461,7 @@ where /// Returns `None` if the underlying value type is not a `K`. pub async fn try_resolve_downcast_type(vc: Self) -> Result>, ResolveTypeError> where - K: Upcast, - K: VcValueType, + K: Upcast + VcValueType, { let raw_vc: RawVc = vc.node; let raw_vc = raw_vc @@ -482,20 +476,20 @@ where impl CollectiblesSource for Vc where - T: ?Sized + Send, + T: ?Sized, { - fn take_collectibles(self) -> AutoSet> { + fn take_collectibles(self) -> AutoSet> { self.node.take_collectibles() } - fn peek_collectibles(self) -> AutoSet> { + fn peek_collectibles(self) -> AutoSet> { self.node.peek_collectibles() } } impl From for Vc where - T: ?Sized + Send, + T: ?Sized, { fn from(node: RawVc) -> Self { Self { @@ -507,7 +501,7 @@ where impl TraceRawVcs for Vc where - T: ?Sized + Send, + T: ?Sized, { fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) { TraceRawVcs::trace_raw_vcs(&self.node, trace_context); @@ -516,8 +510,7 @@ where impl ValueDebugFormat for Vc where - T: ?Sized + Send, - T: Upcast>, + T: Upcast> + Send + Sync + ?Sized, { fn value_debug_format(&self, depth: usize) -> ValueDebugFormatString { ValueDebugFormatString::Async(Box::pin(async move { @@ -560,11 +553,11 @@ where } } -impl Unpin for Vc where T: ?Sized + Send {} +impl Unpin for Vc where T: ?Sized {} impl Default for Vc where - T: ValueDefault + Send, + T: ValueDefault, { fn default() -> Self { T::value_default() diff --git a/turbopack/crates/turbo-tasks/src/vc/resolved.rs b/turbopack/crates/turbo-tasks/src/vc/resolved.rs index 330d53231a4c09..78c1c849d79df5 100644 --- a/turbopack/crates/turbo-tasks/src/vc/resolved.rs +++ b/turbopack/crates/turbo-tasks/src/vc/resolved.rs @@ -2,6 +2,7 @@ use std::{ any::Any, cell::RefCell, collections::{BTreeMap, BTreeSet, HashMap, HashSet}, + fmt::Debug, future::IntoFuture, hash::{Hash, Hasher}, marker::PhantomData, @@ -32,16 +33,16 @@ use crate::{ #[serde(transparent, bound = "")] pub struct ResolvedVc where - T: ?Sized + Send, + T: ?Sized, { pub(crate) node: Vc, } -impl Copy for ResolvedVc where T: ?Sized + Send {} +impl Copy for ResolvedVc where T: ?Sized {} impl Clone for ResolvedVc where - T: ?Sized + Send, + T: ?Sized, { fn clone(&self) -> Self { *self @@ -50,7 +51,7 @@ where impl Deref for ResolvedVc where - T: ?Sized + Send, + T: ?Sized, { type Target = Vc; @@ -61,18 +62,18 @@ where impl PartialEq> for ResolvedVc where - T: ?Sized + Send, + T: ?Sized, { fn eq(&self, other: &Self) -> bool { self.node == other.node } } -impl Eq for ResolvedVc where T: ?Sized + Send {} +impl Eq for ResolvedVc where T: ?Sized {} impl Hash for ResolvedVc where - T: ?Sized + Send, + T: ?Sized, { fn hash(&self, state: &mut H) { self.node.hash(state); @@ -126,7 +127,7 @@ where impl ResolvedVc where - T: ?Sized + Send, + T: ?Sized, { /// Upcasts the given `ResolvedVc` to a `ResolvedVc>`. /// @@ -135,7 +136,7 @@ where pub fn upcast(this: Self) -> ResolvedVc where T: Upcast, - K: VcValueTrait + ?Sized + Send, + K: VcValueTrait + ?Sized, { ResolvedVc { node: Vc::upcast(this.node), @@ -145,7 +146,7 @@ where impl ResolvedVc where - T: VcValueTrait + ?Sized + Send, + T: VcValueTrait + ?Sized, { /// Attempts to sidecast the given `Vc>` to a `Vc>`. /// @@ -157,7 +158,7 @@ where /// See also: [`Vc::try_resolve_sidecast`]. pub async fn try_sidecast(this: Self) -> Result>, ResolveTypeError> where - K: VcValueTrait + ?Sized + Send, + K: VcValueTrait + ?Sized, { // must be async, as we must read the cell to determine the type Ok(Vc::try_resolve_sidecast(this.node) @@ -173,8 +174,7 @@ where /// See also: [`Vc::try_resolve_downcast`]. pub async fn try_downcast(this: Self) -> Result>, ResolveTypeError> where - K: Upcast, - K: VcValueTrait + ?Sized + Send, + K: Upcast + VcValueTrait + ?Sized, { Ok(Vc::try_resolve_downcast(this.node) .await? @@ -188,8 +188,7 @@ where /// See also: [`Vc::try_resolve_downcast_type`]. pub async fn try_downcast_type(this: Self) -> Result>, ResolveTypeError> where - K: Upcast, - K: VcValueType, + K: Upcast + VcValueType, { Ok(Vc::try_resolve_downcast_type(this.node) .await? @@ -197,9 +196,15 @@ where } } -impl std::fmt::Debug for ResolvedVc +/// Generates an opaque debug representation of the [`ResolvedVc`] itself, but not the data inside +/// of it. +/// +/// This is implemented to allow types containing [`ResolvedVc`] to implement the synchronous +/// [`Debug`] trait, but in most cases users should use the [`ValueDebug`] implementation to get a +/// string representation of the contents of the cell. +impl Debug for ResolvedVc where - T: Send, + T: ?Sized, { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("ResolvedVc") @@ -210,7 +215,7 @@ where impl TraceRawVcs for ResolvedVc where - T: ?Sized + Send, + T: ?Sized, { fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) { TraceRawVcs::trace_raw_vcs(&self.node, trace_context); @@ -219,8 +224,7 @@ where impl ValueDebugFormat for ResolvedVc where - T: ?Sized + Send, - T: Upcast>, + T: Upcast> + Send + Sync + ?Sized, { fn value_debug_format(&self, depth: usize) -> ValueDebugFormatString { self.node.value_debug_format(depth) @@ -237,7 +241,7 @@ where /// crate::value] to do it for you. pub unsafe trait ResolvedValue {} -unsafe impl ResolvedValue for ResolvedVc {} +unsafe impl ResolvedValue for ResolvedVc {} macro_rules! impl_resolved { ($ty:ty) => { diff --git a/turbopack/crates/turbo-tasks/src/vc/traits.rs b/turbopack/crates/turbo-tasks/src/vc/traits.rs index 9bff007466d804..ef8c205952fd92 100644 --- a/turbopack/crates/turbo-tasks/src/vc/traits.rs +++ b/turbopack/crates/turbo-tasks/src/vc/traits.rs @@ -23,8 +23,8 @@ pub unsafe trait VcValueType: ShrinkToFit + Sized + Send + Sync + 'static { } /// A trait implemented on all values trait object references that can be put -/// into a Value Cell ([`Vc<&dyn Trait>`][crate::Vc]). -pub trait VcValueTrait { +/// into a Value Cell ([`Vc>`][crate::Vc]). +pub trait VcValueTrait: Send + Sync + 'static { fn get_trait_type_id() -> TraitTypeId; } @@ -35,9 +35,9 @@ pub trait VcValueTrait { /// /// The implementor of this trait must ensure that `Self` implements the /// trait `T`. -pub unsafe trait Upcast: Send +pub unsafe trait Upcast where - T: VcValueTrait + ?Sized + Send, + T: VcValueTrait + ?Sized, { } @@ -48,9 +48,9 @@ where /// /// The implementor of this trait must ensure that `Self` implements the /// trait `T`. -pub unsafe trait Dynamic: Send +pub unsafe trait Dynamic where - T: VcValueTrait + ?Sized + Send, + T: VcValueTrait + ?Sized, { } diff --git a/turbopack/crates/turbopack-core/src/chunk/evaluate.rs b/turbopack/crates/turbopack-core/src/chunk/evaluate.rs index 1d2f49c7284ad1..565f80c9130035 100644 --- a/turbopack/crates/turbopack-core/src/chunk/evaluate.rs +++ b/turbopack/crates/turbopack-core/src/chunk/evaluate.rs @@ -17,7 +17,7 @@ use crate::{ #[turbo_tasks::value_trait] pub trait EvaluatableAsset: Asset + Module + ChunkableModule {} -pub trait EvaluatableAssetExt: Send { +pub trait EvaluatableAssetExt { fn to_evaluatable( self: Vc, asset_context: Vc>, diff --git a/turbopack/crates/turbopack-core/src/chunk/mod.rs b/turbopack/crates/turbopack-core/src/chunk/mod.rs index 7d85afd17af72c..ec2747d170a738 100644 --- a/turbopack/crates/turbopack-core/src/chunk/mod.rs +++ b/turbopack/crates/turbopack-core/src/chunk/mod.rs @@ -758,7 +758,7 @@ pub type ChunkItemWithAsyncModuleInfo = (Vc>, Option); -pub trait ChunkItemExt: Send { +pub trait ChunkItemExt { /// Returns the module id of this chunk item. fn id(self: Vc) -> Vc; } diff --git a/turbopack/crates/turbopack-dev-server/src/source/mod.rs b/turbopack/crates/turbopack-dev-server/src/source/mod.rs index 1e799bb3ef7afb..be9b1abbf3a357 100644 --- a/turbopack/crates/turbopack-dev-server/src/source/mod.rs +++ b/turbopack/crates/turbopack-dev-server/src/source/mod.rs @@ -417,7 +417,7 @@ pub trait ContentSource { } } -pub trait ContentSourceExt: Send { +pub trait ContentSourceExt { fn issue_file_path( self: Vc, file_path: Vc, diff --git a/turbopack/crates/turbopack-ecmascript/src/chunk/item.rs b/turbopack/crates/turbopack-ecmascript/src/chunk/item.rs index f2f8e6bfdcfb13..d2b288b76d0241 100644 --- a/turbopack/crates/turbopack-ecmascript/src/chunk/item.rs +++ b/turbopack/crates/turbopack-ecmascript/src/chunk/item.rs @@ -227,7 +227,7 @@ pub trait EcmascriptChunkItem: ChunkItem { } } -pub trait EcmascriptChunkItemExt: Send { +pub trait EcmascriptChunkItemExt { /// Generates the module factory for this chunk item. fn code(self: Vc, async_module_info: Option>) -> Vc; }