-
Notifications
You must be signed in to change notification settings - Fork 27.1k
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
refactor(turbo-tasks): Simplify most type bounds on Vc<T> and related types #72823
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<T> | ||
where | ||
T: ?Sized + Send, | ||
T: ?Sized, | ||
{ | ||
pub(crate) node: RawVc, | ||
#[doc(hidden)] | ||
|
@@ -186,7 +187,7 @@ where | |
#[doc(hidden)] | ||
impl<T> Deref for Vc<T> | ||
where | ||
T: ?Sized + Send, | ||
T: ?Sized, | ||
{ | ||
type Target = VcDeref<T>; | ||
|
||
|
@@ -200,14 +201,11 @@ where | |
} | ||
} | ||
|
||
impl<T> Copy for Vc<T> where T: ?Sized + Send {} | ||
|
||
unsafe impl<T> Send for Vc<T> where T: ?Sized + Send {} | ||
unsafe impl<T> Sync for Vc<T> where T: ?Sized + Send {} | ||
Comment on lines
-204
to
-206
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These unsafe impls were okay (there's no way to construct a The only effect of removing these was a couple added bounds on |
||
impl<T> Copy for Vc<T> where T: ?Sized {} | ||
|
||
impl<T> Clone for Vc<T> | ||
where | ||
T: ?Sized + Send, | ||
T: ?Sized, | ||
{ | ||
fn clone(&self) -> Self { | ||
*self | ||
|
@@ -216,7 +214,7 @@ where | |
|
||
impl<T> Hash for Vc<T> | ||
where | ||
T: ?Sized + Send, | ||
T: ?Sized, | ||
{ | ||
fn hash<H: Hasher>(&self, state: &mut H) { | ||
self.node.hash(state); | ||
|
@@ -225,20 +223,23 @@ where | |
|
||
impl<T> PartialEq<Vc<T>> for Vc<T> | ||
where | ||
T: ?Sized + Send, | ||
T: ?Sized, | ||
{ | ||
fn eq(&self, other: &Self) -> bool { | ||
self.node == other.node | ||
} | ||
} | ||
|
||
impl<T> Eq for Vc<T> where T: ?Sized + Send {} | ||
impl<T> Eq for Vc<T> 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<T> std::fmt::Debug for Vc<T> | ||
/// 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<T> Debug for Vc<T> | ||
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<T> Vc<T> | ||
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<K>(vc: Self) -> Vc<K> | ||
where | ||
T: Upcast<K>, | ||
K: VcValueTrait + ?Sized + Send, | ||
K: VcValueTrait + ?Sized, | ||
{ | ||
Vc { | ||
node: vc.node, | ||
_t: PhantomData, | ||
} | ||
} | ||
} | ||
|
||
impl<T> Vc<T> | ||
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<T> Vc<T> | ||
where | ||
T: VcValueTrait + ?Sized + Send, | ||
T: VcValueTrait + ?Sized, | ||
{ | ||
/// Attempts to sidecast the given `Vc<Box<dyn T>>` to a `Vc<Box<dyn K>>`. | ||
/// 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<K>(vc: Self) -> Result<Option<Vc<K>>, 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<K>(vc: Self) -> Result<Option<Vc<K>>, ResolveTypeError> | ||
where | ||
K: Upcast<T>, | ||
K: VcValueTrait + ?Sized + Send, | ||
Comment on lines
-449
to
-450
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Repeating the same left-hand-side for a where clause is valid, but unconventional. Converting this to use |
||
K: Upcast<T> + 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<K>(vc: Self) -> Result<Option<Vc<K>>, ResolveTypeError> | ||
where | ||
K: Upcast<T>, | ||
K: VcValueType, | ||
K: Upcast<T> + VcValueType, | ||
{ | ||
let raw_vc: RawVc = vc.node; | ||
let raw_vc = raw_vc | ||
|
@@ -482,20 +476,20 @@ where | |
|
||
impl<T> CollectiblesSource for Vc<T> | ||
where | ||
T: ?Sized + Send, | ||
T: ?Sized, | ||
{ | ||
fn take_collectibles<Vt: VcValueTrait + Send>(self) -> AutoSet<Vc<Vt>> { | ||
fn take_collectibles<Vt: VcValueTrait>(self) -> AutoSet<Vc<Vt>> { | ||
self.node.take_collectibles() | ||
} | ||
|
||
fn peek_collectibles<Vt: VcValueTrait + Send>(self) -> AutoSet<Vc<Vt>> { | ||
fn peek_collectibles<Vt: VcValueTrait>(self) -> AutoSet<Vc<Vt>> { | ||
self.node.peek_collectibles() | ||
} | ||
} | ||
|
||
impl<T> From<RawVc> for Vc<T> | ||
where | ||
T: ?Sized + Send, | ||
T: ?Sized, | ||
{ | ||
fn from(node: RawVc) -> Self { | ||
Self { | ||
|
@@ -507,7 +501,7 @@ where | |
|
||
impl<T> TraceRawVcs for Vc<T> | ||
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<T> ValueDebugFormat for Vc<T> | ||
where | ||
T: ?Sized + Send, | ||
T: Upcast<Box<dyn ValueDebug>>, | ||
T: Upcast<Box<dyn ValueDebug>> + Send + Sync + ?Sized, | ||
{ | ||
fn value_debug_format(&self, depth: usize) -> ValueDebugFormatString { | ||
ValueDebugFormatString::Async(Box::pin(async move { | ||
|
@@ -560,11 +553,11 @@ where | |
} | ||
} | ||
|
||
impl<T> Unpin for Vc<T> where T: ?Sized + Send {} | ||
impl<T> Unpin for Vc<T> where T: ?Sized {} | ||
|
||
impl<T> Default for Vc<T> | ||
where | ||
T: ValueDefault + Send, | ||
T: ValueDefault, | ||
{ | ||
fn default() -> Self { | ||
T::value_default() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out these unsafe impls weren't needed at all. The future is already
Send + Sync
without them.