Skip to content
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

fix(turbo-tasks): Implement IntoFuture for ResolvedVc #69986

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-memory/tests/resolved_vc.rs
22 changes: 22 additions & 0 deletions turbopack/crates/turbo-tasks-testing/tests/resolved_vc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#![feature(arbitrary_self_types)]

use anyhow::Result;
use turbo_tasks::{ReadRef, ResolvedVc, Vc};
use turbo_tasks_testing::{register, run, Registration};

static REGISTRATION: Registration = register!();

#[tokio::test]
async fn test_conversion() -> Result<()> {
run(&REGISTRATION, || async {
let unresolved: Vc<u32> = Vc::cell(42);
let resolved: ResolvedVc<u32> = unresolved.to_resolved().await?;
let _: Vc<u32> = *resolved;
let _: ReadRef<u32> = resolved.await?;
let _: ReadRef<u32> = (&resolved).await?;
let _: u32 = *resolved.await?;
let _: u32 = *(&resolved).await?;
Ok(())
})
.await
}
21 changes: 20 additions & 1 deletion turbopack/crates/turbo-tasks/src/vc/resolved.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
cell::RefCell,
collections::{BTreeMap, BTreeSet, HashMap, HashSet},
future::IntoFuture,
hash::{Hash, Hasher},
marker::PhantomData,
ops::Deref,
Expand All @@ -22,7 +23,7 @@ use serde::{Deserialize, Serialize};
use crate::{
trace::{TraceRawVcs, TraceRawVcsContext},
vc::Vc,
RcStr,
RcStr, VcValueType,
};

#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -76,6 +77,24 @@ where
}
}

macro_rules! into_future {
($ty:ty) => {
impl<T> IntoFuture for $ty
where
T: VcValueType,
{
type Output = <Vc<T> as IntoFuture>::Output;
type IntoFuture = <Vc<T> as IntoFuture>::IntoFuture;
fn into_future(self) -> Self::IntoFuture {
(*self).into_future()
}
}
};
}

into_future!(ResolvedVc<T>);
into_future!(&ResolvedVc<T>);

impl<T> std::fmt::Debug for ResolvedVc<T>
where
T: Send,
Expand Down
Loading