Skip to content

Commit

Permalink
fix(turbo-tasks): Remove T: Serialize bound from ResolveVc (#69995)
Browse files Browse the repository at this point in the history
With the default derived implementation, serde would inject a `T: Serialize` or `T: Deserialize` bound.
    
However, like `Vc`, `ResolvedVc` is serialized as a couple numeric IDs (the type of `T` doesn't matter), so we shouldn't have this restriction on `ResolvedVc`.

Also, clean up `Vc<T>` using the same `bound = ""` trick with the derive macro.
  • Loading branch information
bgw authored Sep 23, 2024
1 parent 1718798 commit 60a8a0b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 22 deletions.
23 changes: 2 additions & 21 deletions turbopack/crates/turbo-tasks/src/vc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ use crate::{
/// some_ref.some_method_on_t();
/// ```
#[must_use]
#[derive(Serialize, Deserialize)]
#[serde(transparent, bound = "")]
pub struct Vc<T>
where
T: ?Sized + Send,
Expand Down Expand Up @@ -231,27 +233,6 @@ where

impl<T> Eq for Vc<T> where T: ?Sized + Send {}

impl<T> Serialize for Vc<T>
where
T: ?Sized + Send,
{
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
self.node.serialize(serializer)
}
}

impl<'de, T> Deserialize<'de> for Vc<T>
where
T: ?Sized + Send,
{
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Ok(Vc {
node: RawVc::deserialize(deserializer)?,
_t: PhantomData,
})
}
}

// 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>
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbo-tasks/src/vc/resolved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::{
};

#[derive(Serialize, Deserialize)]
#[serde(transparent)]
#[serde(transparent, bound = "")]
pub struct ResolvedVc<T>
where
T: ?Sized + Send,
Expand Down

0 comments on commit 60a8a0b

Please sign in to comment.