From a04120408b7ef90391cc01f82f8f96b1eb1ea820 Mon Sep 17 00:00:00 2001 From: Benjamin Woodruff Date: Thu, 14 Nov 2024 10:59:55 -0800 Subject: [PATCH 1/3] refactor(turbo-tasks): Simplify most type bounds on Vc and related types --- .../crates/turbo-tasks/src/collectibles.rs | 4 +- turbopack/crates/turbo-tasks/src/manager.rs | 6 +- turbopack/crates/turbo-tasks/src/raw_vc.rs | 7 +- .../turbo-tasks/src/task/from_task_input.rs | 4 +- .../crates/turbo-tasks/src/task/task_input.rs | 4 +- .../turbo-tasks/src/task/task_output.rs | 2 +- turbopack/crates/turbo-tasks/src/trait_ref.rs | 4 +- turbopack/crates/turbo-tasks/src/vc/mod.rs | 76 ++++++++++--------- .../crates/turbo-tasks/src/vc/resolved.rs | 41 +++++----- turbopack/crates/turbo-tasks/src/vc/traits.rs | 12 +-- .../turbopack-core/src/chunk/evaluate.rs | 2 +- .../crates/turbopack-core/src/chunk/mod.rs | 2 +- .../turbopack-dev-server/src/source/mod.rs | 2 +- .../turbopack-ecmascript/src/chunk/item.rs | 2 +- 14 files changed, 89 insertions(+), 79 deletions(-) diff --git a/turbopack/crates/turbo-tasks/src/collectibles.rs b/turbopack/crates/turbo-tasks/src/collectibles.rs index e4f9aed0de1ae..65161ba983f73 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 3b06e1ef04a85..0134c7d335480 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 72273489563a6..1654ee746aef4 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 8ddd8207f505a..d944a401ad12e 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: ?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 5da843a58ba38..ab9cf62075c9f 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: ?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: ?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 c14ed7507f67e..41d36c2826f72 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 6789c5cfaf221..2c5660c1bb8bd 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 107dad4ec673c..7a62e45d3fb96 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,24 @@ where } } -impl Copy for Vc where T: ?Sized + Send {} +impl Copy for Vc where T: ?Sized {} -unsafe impl Send for Vc where T: ?Sized + Send {} -unsafe impl Sync for Vc where T: ?Sized + Send {} +// SAFETY: `Vc` doesn't auto-implement these for all `T` because we use `PhantomData`, and `T` +// isn't `Send + Sync` on the struct. `Vc` is really just a few indexes, which are always `Send + +// Sync`. +// +// The bounds are checked during construction before writing to the global cells. It's impossible to +// construct or cast to a `Vc` that doesn't contain a `T: Send` as all constructors require +// `T: VcValueType` or `T: VcValueTrait`, both of which are subtraits of `Send + Sync`. +// +// These unsafe implementations are provided for convenience, so that callsites don't need to +// enforce `T: Send + Sync` themselves. +unsafe impl Send for Vc where T: ?Sized {} +unsafe impl Sync for Vc where T: ?Sized {} impl Clone for Vc where - T: ?Sized + Send, + T: ?Sized, { fn clone(&self) -> Self { *self @@ -216,7 +227,7 @@ where impl Hash for Vc where - T: ?Sized + Send, + T: ?Sized, { fn hash(&self, state: &mut H) { self.node.hash(state); @@ -225,20 +236,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 +323,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 +354,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 +424,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 +436,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 +455,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 +474,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 +489,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 +514,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 +523,7 @@ where impl ValueDebugFormat for Vc where - T: ?Sized + Send, - T: Upcast>, + T: Upcast> + ?Sized, { fn value_debug_format(&self, depth: usize) -> ValueDebugFormatString { ValueDebugFormatString::Async(Box::pin(async move { @@ -560,11 +566,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 330d53231a4c0..42c29f18a0d85 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) @@ -174,7 +175,7 @@ where pub async fn try_downcast(this: Self) -> Result>, ResolveTypeError> where K: Upcast, - K: VcValueTrait + ?Sized + Send, + K: VcValueTrait + ?Sized, { Ok(Vc::try_resolve_downcast(this.node) .await? @@ -197,9 +198,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 +217,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,7 +226,7 @@ where impl ValueDebugFormat for ResolvedVc where - T: ?Sized + Send, + T: ?Sized, T: Upcast>, { fn value_debug_format(&self, depth: usize) -> ValueDebugFormatString { @@ -237,7 +244,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 9bff007466d80..ef8c205952fd9 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 1d2f49c7284ad..565f80c913003 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 7d85afd17af72..ec2747d170a73 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 1e799bb3ef7af..be9b1abbf3a35 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 f2f8e6bfdcfb1..d2b288b76d024 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; } From be07f274032a76d42684d4d21326ecbcac8283e2 Mon Sep 17 00:00:00 2001 From: Benjamin Woodruff Date: Thu, 14 Nov 2024 11:07:08 -0800 Subject: [PATCH 2/3] Remove unsafe impl for Send + Sync on all Vc, as it doesn't actually provide much value --- .../turbo-tasks/src/task/from_task_input.rs | 2 +- .../crates/turbo-tasks/src/task/task_input.rs | 4 ++-- turbopack/crates/turbo-tasks/src/vc/mod.rs | 15 +-------------- turbopack/crates/turbo-tasks/src/vc/resolved.rs | 3 +-- 4 files changed, 5 insertions(+), 19 deletions(-) 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 d944a401ad12e..223b7e9fa7e85 100644 --- a/turbopack/crates/turbo-tasks/src/task/from_task_input.rs +++ b/turbopack/crates/turbo-tasks/src/task/from_task_input.rs @@ -19,7 +19,7 @@ mod private { impl FromTaskInput for ResolvedVc where - T: ?Sized, + 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 ab9cf62075c9f..ddc6b560e41f8 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: ?Sized, + 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: ?Sized, + T: Send + Sync + ?Sized, { fn is_resolved(&self) -> bool { true diff --git a/turbopack/crates/turbo-tasks/src/vc/mod.rs b/turbopack/crates/turbo-tasks/src/vc/mod.rs index 7a62e45d3fb96..b34458bdb659b 100644 --- a/turbopack/crates/turbo-tasks/src/vc/mod.rs +++ b/turbopack/crates/turbo-tasks/src/vc/mod.rs @@ -203,19 +203,6 @@ where impl Copy for Vc where T: ?Sized {} -// SAFETY: `Vc` doesn't auto-implement these for all `T` because we use `PhantomData`, and `T` -// isn't `Send + Sync` on the struct. `Vc` is really just a few indexes, which are always `Send + -// Sync`. -// -// The bounds are checked during construction before writing to the global cells. It's impossible to -// construct or cast to a `Vc` that doesn't contain a `T: Send` as all constructors require -// `T: VcValueType` or `T: VcValueTrait`, both of which are subtraits of `Send + Sync`. -// -// These unsafe implementations are provided for convenience, so that callsites don't need to -// enforce `T: Send + Sync` themselves. -unsafe impl Send for Vc where T: ?Sized {} -unsafe impl Sync for Vc where T: ?Sized {} - impl Clone for Vc where T: ?Sized, @@ -523,7 +510,7 @@ where impl ValueDebugFormat for Vc where - T: Upcast> + ?Sized, + T: Upcast> + Send + Sync + ?Sized, { fn value_debug_format(&self, depth: usize) -> ValueDebugFormatString { ValueDebugFormatString::Async(Box::pin(async move { diff --git a/turbopack/crates/turbo-tasks/src/vc/resolved.rs b/turbopack/crates/turbo-tasks/src/vc/resolved.rs index 42c29f18a0d85..371da22e7db1c 100644 --- a/turbopack/crates/turbo-tasks/src/vc/resolved.rs +++ b/turbopack/crates/turbo-tasks/src/vc/resolved.rs @@ -226,8 +226,7 @@ where impl ValueDebugFormat for ResolvedVc where - T: ?Sized, - T: Upcast>, + T: Upcast> + Send + Sync + ?Sized, { fn value_debug_format(&self, depth: usize) -> ValueDebugFormatString { self.node.value_debug_format(depth) From bd9cb9ffdc3f6eea824dda9f47545adfe9408cfa Mon Sep 17 00:00:00 2001 From: Benjamin Woodruff Date: Thu, 14 Nov 2024 11:08:34 -0800 Subject: [PATCH 3/3] Normalize syntax for a few more type bounds --- turbopack/crates/turbo-tasks/src/vc/resolved.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/turbopack/crates/turbo-tasks/src/vc/resolved.rs b/turbopack/crates/turbo-tasks/src/vc/resolved.rs index 371da22e7db1c..78c1c849d79df 100644 --- a/turbopack/crates/turbo-tasks/src/vc/resolved.rs +++ b/turbopack/crates/turbo-tasks/src/vc/resolved.rs @@ -174,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, + K: Upcast + VcValueTrait + ?Sized, { Ok(Vc::try_resolve_downcast(this.node) .await? @@ -189,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?