diff --git a/turbopack/crates/turbo-tasks-backend/tests/generics.rs b/turbopack/crates/turbo-tasks-backend/tests/generics.rs deleted file mode 120000 index 526d71f58d8ba9..00000000000000 --- a/turbopack/crates/turbo-tasks-backend/tests/generics.rs +++ /dev/null @@ -1 +0,0 @@ -../../turbo-tasks-testing/tests/generics.rs \ No newline at end of file diff --git a/turbopack/crates/turbo-tasks-memory/tests/generics.rs b/turbopack/crates/turbo-tasks-memory/tests/generics.rs deleted file mode 120000 index 526d71f58d8ba9..00000000000000 --- a/turbopack/crates/turbo-tasks-memory/tests/generics.rs +++ /dev/null @@ -1 +0,0 @@ -../../turbo-tasks-testing/tests/generics.rs \ No newline at end of file diff --git a/turbopack/crates/turbo-tasks-testing/tests/generics.rs b/turbopack/crates/turbo-tasks-testing/tests/generics.rs deleted file mode 100644 index c4e5dfa76a06cf..00000000000000 --- a/turbopack/crates/turbo-tasks-testing/tests/generics.rs +++ /dev/null @@ -1,223 +0,0 @@ -#![feature(arbitrary_self_types)] -#![feature(arbitrary_self_types_pointers)] -#![allow(clippy::needless_return)] // tokio macro-generated code doesn't respect this - -use std::sync::{Arc, Mutex}; - -use indexmap::{IndexMap, IndexSet}; -use turbo_tasks::{debug::ValueDebug, Invalidator, ReadRef, TaskId, Vc}; -use turbo_tasks_testing::{register, run, Registration}; - -static REGISTRATION: Registration = register!(); - -#[tokio::test] -async fn test_option_some() { - run(®ISTRATION, || async move { - let vc_42 = Vc::cell(42); - let option: Vc>> = Vc::cell(Some(vc_42)); - assert!(*option.is_some().await?); - assert!(!(*option.is_none().await?)); - assert_eq!(&*option.await?, &Some(vc_42)); - assert_eq!(option.dbg().await?.to_string(), "Some(\n 42,\n)"); - anyhow::Ok(()) - }) - .await - .unwrap() -} - -#[tokio::test] -async fn test_option_none() { - run(®ISTRATION, || async move { - let option: Vc>> = Default::default(); - assert!(!(*option.is_some().await?)); - assert!(*option.is_none().await?); - assert_eq!(&*option.await?, &None); - assert_eq!(option.dbg().await?.to_string(), "None"); - anyhow::Ok(()) - }) - .await - .unwrap() -} - -#[tokio::test] -async fn test_vec() { - run(®ISTRATION, || async move { - let vc_42 = Vc::cell(42); - let vec: Vc>> = Vc::cell(vec![vc_42]); - assert_eq!(*vec.len().await?, 1); - assert!(!(*vec.is_empty().await?)); - assert_eq!(&*vec.await?, &[vc_42]); - assert_eq!(vec.dbg().await?.to_string(), "[\n 42,\n]"); - anyhow::Ok(()) - }) - .await - .unwrap() -} - -#[tokio::test] -async fn test_empty_vec() { - run(®ISTRATION, || async move { - let vec: Vc>> = Default::default(); - assert_eq!(*vec.len().await?, 0); - assert!(*vec.is_empty().await?); - assert_eq!(vec.dbg().await?.to_string(), "[]"); - anyhow::Ok(()) - }) - .await - .unwrap() -} - -#[tokio::test] -async fn test_nested_empty_vec() { - run(®ISTRATION, || async move { - let vec: Vc>>>> = Default::default(); - assert_eq!(*vec.len().await?, 0); - assert_eq!(vec.dbg().await?.to_string(), "[]"); - anyhow::Ok(()) - }) - .await - .unwrap() -} - -#[tokio::test] -async fn test_index_set() { - run(®ISTRATION, || async move { - let vc_42 = Vc::cell(42); - let set: Vc>> = Vc::cell(IndexSet::from([vc_42])); - assert_eq!(*set.len().await?, 1); - assert!(!(*set.is_empty().await?)); - assert_eq!(&*set.await?, &IndexSet::from([vc_42])); - assert_eq!(set.dbg().await?.to_string(), "{\n 42,\n}"); - anyhow::Ok(()) - }) - .await - .unwrap() -} - -#[tokio::test] -async fn test_empty_index_set() { - run(®ISTRATION, || async move { - let set: Vc>> = Default::default(); - assert_eq!(*set.len().await?, 0); - assert!(*set.is_empty().await?); - assert_eq!(&*set.await?, &IndexSet::>::default()); - assert_eq!(set.dbg().await?.to_string(), "{}"); - anyhow::Ok(()) - }) - .await - .unwrap() -} - -#[tokio::test] -async fn test_index_map() { - run(®ISTRATION, || async move { - let vc_42 = Vc::cell(42); - let map: Vc, _>> = Vc::cell(IndexMap::from([(vc_42, vc_42)])); - assert_eq!(*map.len().await?, 1); - assert!(!(*map.is_empty().await?)); - assert_eq!(&*map.await?, &IndexMap::from([(vc_42, vc_42)])); - assert_eq!(map.dbg().await?.to_string(), "{\n 42: 42,\n}"); - anyhow::Ok(()) - }) - .await - .unwrap() -} - -#[tokio::test] -async fn test_empty_index_map() { - run(®ISTRATION, || async move { - let map: Vc, Vc>> = Default::default(); - assert_eq!(*map.len().await?, 0); - assert!(*map.is_empty().await?); - assert_eq!(&*map.await?, &IndexMap::, Vc>::default()); - assert_eq!(map.dbg().await?.to_string(), "{}"); - anyhow::Ok(()) - }) - .await - .unwrap() -} - -// Simulate a non-deterministic function that stores different generic types in -// it's cells each time it runs. -#[tokio::test] -async fn test_changing_generic() { - run(®ISTRATION, || async move { - let state_vc = State::default().cell(); - let state_ref = state_vc.await?; - for _i in 0..10 { - let _ = non_deterministic(state_vc) - .resolve_strongly_consistent() - .await - .unwrap(); - state_ref - .inner - .lock() - .unwrap() - .last_invalidator - .take() - .unwrap() - .invalidate(); - } - anyhow::Ok(()) - }) - .await - .unwrap() -} - -// Test that we can convert a `Vc` to a `ReadRef`, and then back to a `Vc`. -#[tokio::test] -async fn test_read_ref_round_trip() { - run(®ISTRATION, || async move { - let c: Vc>> = Vc::cell(Some(Vc::cell(1))); - let _ = ReadRef::cell(c.await?).await?; - anyhow::Ok(()) - }) - .await - .unwrap() -} - -#[turbo_tasks::value(eq = "manual")] -#[derive(Default)] -struct State { - #[turbo_tasks(debug_ignore, trace_ignore)] - #[serde(skip)] - inner: Arc>, -} - -#[derive(Default)] -struct StateInner { - branch: bool, - last_invalidator: Option, - last_task_id: Option, -} - -impl PartialEq for State { - fn eq(&self, other: &Self) -> bool { - std::ptr::eq(self as *const _, other as *const _) - } -} - -impl Eq for State {} - -#[turbo_tasks::function] -async fn non_deterministic(state: Vc) { - let state = state.await.unwrap(); - let mut state_inner = state.inner.lock().unwrap(); - - let task_id = if state_inner.branch { - let c: Vc>> = Vc::cell(Some(Vc::cell(1))); - println!("u8 branch"); - Vc::into_raw(c).get_task_id() - } else { - let c: Vc>> = Vc::cell(Some(Vc::cell(1))); - println!("u32 branch"); - Vc::into_raw(c).get_task_id() - }; - - state_inner.branch = !state_inner.branch; - if let Some(last_task_id) = state_inner.last_task_id { - assert_eq!(last_task_id, task_id); - } - state_inner.last_task_id = Some(task_id); - state_inner.last_invalidator = Some(turbo_tasks::get_invalidator()); -} diff --git a/turbopack/crates/turbo-tasks-testing/tests/local_cell.rs b/turbopack/crates/turbo-tasks-testing/tests/local_cell.rs index 2fc3d29cc89911..143a61e48c664b 100644 --- a/turbopack/crates/turbo-tasks-testing/tests/local_cell.rs +++ b/turbopack/crates/turbo-tasks-testing/tests/local_cell.rs @@ -33,26 +33,6 @@ async fn test_store_and_read() -> Result<()> { .await } -#[tokio::test] -async fn test_store_and_read_generic() -> Result<()> { - run(®ISTRATION, || async { - // `Vc>>` is stored as `Vc>>` and requires special - // transmute handling - let cells: Vc>> = - Vc::local_cell(vec![Vc::local_cell(1), Vc::local_cell(2), Vc::cell(3)]); - - let mut output = Vec::new(); - for el in cells.await.unwrap() { - output.push(*el.await.unwrap()); - } - - assert_eq!(output, vec![1, 2, 3]); - - Ok(()) - }) - .await -} - #[turbo_tasks::function(local_cells)] async fn returns_resolved_local_vc() -> Vc { let cell = Vc::::cell(42); diff --git a/turbopack/crates/turbo-tasks/src/generics/index_map.rs b/turbopack/crates/turbo-tasks/src/generics/index_map.rs deleted file mode 100644 index 47713c95555dd4..00000000000000 --- a/turbopack/crates/turbo-tasks/src/generics/index_map.rs +++ /dev/null @@ -1,83 +0,0 @@ -use anyhow::Result; -use indexmap::IndexMap; -// This specific macro identifier is detected by turbo-tasks-build. -use turbo_tasks_macros::generic_type as __turbo_tasks_internal_generic_type; - -use crate::{ - self as turbo_tasks, - debug::{ValueDebug, ValueDebugFormat, ValueDebugString}, - ValueDefault, Vc, -}; - -__turbo_tasks_internal_generic_type!(, IndexMap, Vc>); - -#[turbo_tasks::function] -async fn index_map_len(index_map: Vc, Vc<()>>>) -> Result> { - let index_map = index_map.await?; - Ok(Vc::cell(index_map.len())) -} - -#[turbo_tasks::function] -async fn index_map_is_empty(index_map: Vc, Vc<()>>>) -> Result> { - let index_map = index_map.await?; - Ok(Vc::cell(index_map.is_empty())) -} - -impl Vc, Vc>> -where - K: Send, - V: Send, -{ - /// See [`IndexMap::len`]. - pub fn len(self) -> Vc { - index_map_len(Self::to_repr(self)) - } - - /// See [`IndexMap::is_empty`]. - pub fn is_empty(self) -> Vc { - index_map_is_empty(Self::to_repr(self)) - } -} - -#[turbo_tasks::function] -fn index_map_default() -> Vc, Vc<()>>> { - Vc::cell(Default::default()) -} - -impl ValueDefault for IndexMap, Vc> -where - K: Send, - V: Send, -{ - fn value_default() -> Vc { - // Safety: `index_map_default` creates an empty map, which is a valid - // representation of any index set of `Vc`. - unsafe { Vc::::from_repr(index_map_default()) } - } -} - -#[turbo_tasks::function] -async fn index_map_dbg_depth( - index_map: Vc, Vc<()>>>, - depth: usize, -) -> Result> { - index_map - .await? - .value_debug_format(depth) - .try_to_value_debug_string() - .await -} - -impl ValueDebug for IndexMap, Vc> -where - K: Send, - V: Send, -{ - fn dbg(self: Vc) -> Vc { - index_map_dbg_depth(Vc::::to_repr(self), usize::MAX) - } - - fn dbg_depth(self: Vc, depth: usize) -> Vc { - index_map_dbg_depth(Vc::::to_repr(self), depth) - } -} diff --git a/turbopack/crates/turbo-tasks/src/generics/index_set.rs b/turbopack/crates/turbo-tasks/src/generics/index_set.rs deleted file mode 100644 index 49e6bce7d4108c..00000000000000 --- a/turbopack/crates/turbo-tasks/src/generics/index_set.rs +++ /dev/null @@ -1,80 +0,0 @@ -use anyhow::Result; -use indexmap::IndexSet; -// This specific macro identifier is detected by turbo-tasks-build. -use turbo_tasks_macros::generic_type as __turbo_tasks_internal_generic_type; - -use crate::{ - self as turbo_tasks, - debug::{ValueDebug, ValueDebugFormat, ValueDebugString}, - ValueDefault, Vc, -}; - -__turbo_tasks_internal_generic_type!(, IndexSet>); - -#[turbo_tasks::function] -async fn index_set_len(index_set: Vc>>) -> Result> { - let index_set = index_set.await?; - Ok(Vc::cell(index_set.len())) -} - -#[turbo_tasks::function] -async fn index_set_is_empty(index_set: Vc>>) -> Result> { - let index_set = index_set.await?; - Ok(Vc::cell(index_set.is_empty())) -} - -impl Vc>> -where - T: Send, -{ - /// See [`IndexSet::len`]. - pub fn len(self) -> Vc { - index_set_len(Self::to_repr(self)) - } - - /// See [`IndexSet::is_empty`]. - pub fn is_empty(self) -> Vc { - index_set_is_empty(Self::to_repr(self)) - } -} - -#[turbo_tasks::function] -fn index_set_default() -> Vc>> { - Vc::cell(Default::default()) -} - -impl ValueDefault for IndexSet> -where - T: Send, -{ - fn value_default() -> Vc { - // Safety: `index_set_default` creates an empty set, which is a valid - // representation of any index set of `Vc`. - unsafe { Vc::::from_repr(index_set_default()) } - } -} - -#[turbo_tasks::function] -async fn index_set_dbg_depth( - index_set: Vc>>, - depth: usize, -) -> Result> { - index_set - .await? - .value_debug_format(depth) - .try_to_value_debug_string() - .await -} - -impl ValueDebug for IndexSet> -where - T: Send, -{ - fn dbg(self: Vc) -> Vc { - index_set_dbg_depth(Vc::::to_repr(self), usize::MAX) - } - - fn dbg_depth(self: Vc, depth: usize) -> Vc { - index_set_dbg_depth(Vc::::to_repr(self), depth) - } -} diff --git a/turbopack/crates/turbo-tasks/src/generics/mod.rs b/turbopack/crates/turbo-tasks/src/generics/mod.rs deleted file mode 100644 index 9bbc961eb1b69d..00000000000000 --- a/turbopack/crates/turbo-tasks/src/generics/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub(crate) mod index_map; -pub(crate) mod index_set; -pub(crate) mod option; -pub(crate) mod vec; diff --git a/turbopack/crates/turbo-tasks/src/generics/option.rs b/turbopack/crates/turbo-tasks/src/generics/option.rs deleted file mode 100644 index 2b4710ffd3e821..00000000000000 --- a/turbopack/crates/turbo-tasks/src/generics/option.rs +++ /dev/null @@ -1,79 +0,0 @@ -use anyhow::Result; -// This specific macro identifier is detected by turbo-tasks-build. -use turbo_tasks_macros::generic_type as __turbo_tasks_internal_generic_type; - -use crate::{ - self as turbo_tasks, - debug::{ValueDebug, ValueDebugFormat, ValueDebugString}, - ValueDefault, Vc, -}; - -__turbo_tasks_internal_generic_type!(, Option>); - -#[turbo_tasks::function] -async fn option_is_none(option: Vc>>) -> Result> { - let option = option.await?; - Ok(Vc::cell(option.is_none())) -} - -#[turbo_tasks::function] -async fn option_is_some(option: Vc>>) -> Result> { - let option = option.await?; - Ok(Vc::cell(option.is_some())) -} - -impl Vc>> -where - T: Send, -{ - /// See [`Option::is_none`]. - pub fn is_none(self) -> Vc { - option_is_none(Self::to_repr(self)) - } - - /// See [`Option::is_some`]. - pub fn is_some(self) -> Vc { - option_is_some(Self::to_repr(self)) - } -} - -#[turbo_tasks::function] -fn option_default() -> Vc>> { - Vc::cell(Default::default()) -} - -impl ValueDefault for Option> -where - T: Send, -{ - fn value_default() -> Vc { - // Safety: `option_default` creates a None variant, which is a valid - // representation of any option of `Vc`. - unsafe { Vc::::from_repr(option_default()) } - } -} - -#[turbo_tasks::function] -async fn option_dbg_depth( - option: Vc>>, - depth: usize, -) -> Result> { - option - .await? - .value_debug_format(depth) - .try_to_value_debug_string() - .await -} - -impl ValueDebug for Option> -where - T: Send, -{ - fn dbg(self: Vc) -> Vc { - option_dbg_depth(Vc::::to_repr(self), usize::MAX) - } - - fn dbg_depth(self: Vc, depth: usize) -> Vc { - option_dbg_depth(Vc::::to_repr(self), depth) - } -} diff --git a/turbopack/crates/turbo-tasks/src/generics/vec.rs b/turbopack/crates/turbo-tasks/src/generics/vec.rs deleted file mode 100644 index 4472e6b86c9de7..00000000000000 --- a/turbopack/crates/turbo-tasks/src/generics/vec.rs +++ /dev/null @@ -1,75 +0,0 @@ -use anyhow::Result; -// This specific macro identifier is detected by turbo-tasks-build. -use turbo_tasks_macros::generic_type as __turbo_tasks_internal_generic_type; - -use crate::{ - self as turbo_tasks, - debug::{ValueDebug, ValueDebugFormat, ValueDebugString}, - ValueDefault, Vc, -}; - -__turbo_tasks_internal_generic_type!(, Vec>); - -#[turbo_tasks::function] -async fn vec_len(vec: Vc>>) -> Result> { - let vec = vec.await?; - Ok(Vc::cell(vec.len())) -} - -#[turbo_tasks::function] -async fn vec_is_empty(vec: Vc>>) -> Result> { - let vec = vec.await?; - Ok(Vc::cell(vec.is_empty())) -} - -impl Vc>> -where - T: Send, -{ - /// See [`Vec::len`]. - pub fn len(self) -> Vc { - vec_len(Self::to_repr(self)) - } - - /// See [`Vec::is_empty`]. - pub fn is_empty(self) -> Vc { - vec_is_empty(Self::to_repr(self)) - } -} - -#[turbo_tasks::function] -fn vec_default() -> Vc>> { - Vc::cell(Default::default()) -} - -impl ValueDefault for Vec> -where - T: Send, -{ - fn value_default() -> Vc { - // Safety: `vec_default` creates an empty vector, which is a valid - // representation of any vector of `Vc`s. - unsafe { Vc::::from_repr(vec_default()) } - } -} - -#[turbo_tasks::function] -async fn vec_dbg_depth(vec: Vc>>, depth: usize) -> Result> { - vec.await? - .value_debug_format(depth) - .try_to_value_debug_string() - .await -} - -impl ValueDebug for Vec> -where - T: Send, -{ - fn dbg(self: Vc) -> Vc { - vec_dbg_depth(Vc::::to_repr(self), usize::MAX) - } - - fn dbg_depth(self: Vc, depth: usize) -> Vc { - vec_dbg_depth(Vc::::to_repr(self), depth) - } -} diff --git a/turbopack/crates/turbo-tasks/src/lib.rs b/turbopack/crates/turbo-tasks/src/lib.rs index e111b0e6fa0075..2ce0329048bb1c 100644 --- a/turbopack/crates/turbo-tasks/src/lib.rs +++ b/turbopack/crates/turbo-tasks/src/lib.rs @@ -44,7 +44,6 @@ pub mod debug; mod display; pub mod duration_span; pub mod event; -mod generics; pub mod graph; mod id; mod id_factory; diff --git a/turbopack/crates/turbo-tasks/src/vc/mod.rs b/turbopack/crates/turbo-tasks/src/vc/mod.rs index 78312e81ae0691..b0a8ebfabfdfb4 100644 --- a/turbopack/crates/turbo-tasks/src/vc/mod.rs +++ b/turbopack/crates/turbo-tasks/src/vc/mod.rs @@ -323,18 +323,6 @@ where vc.node } - /// Creates a `Vc` from a `RawVc`. - /// - /// # Safety - /// - /// The caller must ensure that `RawVc` points to a value of type `T`. - pub(crate) unsafe fn from_raw(vc: RawVc) -> Self { - Vc { - node: vc, - _t: std::marker::PhantomData, - } - } - /// Upcasts the given `Vc` to a `Vc>`. /// /// This is also available as an `Into`/`From` conversion.