diff --git a/turbopack/crates/turbo-tasks-backend/src/backend/mod.rs b/turbopack/crates/turbo-tasks-backend/src/backend/mod.rs index 34bbde461f4321..530b7b0b7fb7fb 100644 --- a/turbopack/crates/turbo-tasks-backend/src/backend/mod.rs +++ b/turbopack/crates/turbo-tasks-backend/src/backend/mod.rs @@ -2873,9 +2873,6 @@ impl Backend for TurboTasksBackend { self.0.get_task_description(task) } - type TaskState = (); - fn new_task_state(&self, _task: TaskId) -> Self::TaskState {} - fn task_execution_canceled(&self, task: TaskId, turbo_tasks: &dyn TurboTasksBackendApi) { self.0.task_execution_canceled(task, turbo_tasks) } diff --git a/turbopack/crates/turbo-tasks/src/backend.rs b/turbopack/crates/turbo-tasks/src/backend.rs index b444551b60c512..7e17ca3dca374e 100644 --- a/turbopack/crates/turbo-tasks/src/backend.rs +++ b/turbopack/crates/turbo-tasks/src/backend.rs @@ -530,29 +530,6 @@ pub trait Backend: Sync + Send { fn get_task_description(&self, task: TaskId) -> String; - /// Task-local state that stored inside of [`TurboTasksBackendApi`]. Constructed with - /// [`Self::new_task_state`]. - /// - /// This value that can later be written to or read from using - /// [`crate::TurboTasksBackendApiExt::write_task_state`] or - /// [`crate::TurboTasksBackendApiExt::read_task_state`] - /// - /// This data may be shared across multiple threads (must be `Sync`) in order to support - /// detached futures ([`crate::TurboTasksApi::detached_for_testing`]) and [pseudo-tasks using - /// `local` execution][crate::function]. A [`RwLock`][std::sync::RwLock] is used to provide - /// concurrent access. - type TaskState: Send + Sync + 'static; - - /// Constructs a new task-local [`Self::TaskState`] for the given `task_id`. - /// - /// If a task is re-executed (e.g. because it is invalidated), this function will be called - /// again with the same [`TaskId`]. - /// - /// This value can be written to or read from using - /// [`crate::TurboTasksBackendApiExt::write_task_state`] and - /// [`crate::TurboTasksBackendApiExt::read_task_state`] - fn new_task_state(&self, task: TaskId) -> Self::TaskState; - fn try_start_task_execution<'a>( &'a self, task: TaskId, diff --git a/turbopack/crates/turbo-tasks/src/lib.rs b/turbopack/crates/turbo-tasks/src/lib.rs index ff121c46ee56a9..7c4313a3042f77 100644 --- a/turbopack/crates/turbo-tasks/src/lib.rs +++ b/turbopack/crates/turbo-tasks/src/lib.rs @@ -109,9 +109,9 @@ pub use key_value_pair::KeyValuePair; pub use magic_any::MagicAny; pub use manager::{ CurrentCellRef, ReadConsistency, TaskPersistence, TurboTasks, TurboTasksApi, - TurboTasksBackendApi, TurboTasksBackendApiExt, TurboTasksCallApi, Unused, UpdateInfo, - dynamic_call, emit, mark_finished, mark_root, mark_session_dependent, mark_stateful, - prevent_gc, run_once, run_once_with_reason, trait_call, turbo_tasks, turbo_tasks_scope, + TurboTasksBackendApi, TurboTasksCallApi, Unused, UpdateInfo, dynamic_call, emit, mark_finished, + mark_root, mark_session_dependent, mark_stateful, prevent_gc, run_once, run_once_with_reason, + trait_call, turbo_tasks, turbo_tasks_scope, }; pub use output::OutputContent; pub use raw_vc::{CellId, RawVc, ReadRawVcFuture, ResolveTypeError}; diff --git a/turbopack/crates/turbo-tasks/src/manager.rs b/turbopack/crates/turbo-tasks/src/manager.rs index 6aaf08359f1e49..bad7772f2223f4 100644 --- a/turbopack/crates/turbo-tasks/src/manager.rs +++ b/turbopack/crates/turbo-tasks/src/manager.rs @@ -1,5 +1,4 @@ use std::{ - any::Any, future::Future, hash::BuildHasherDefault, mem::take, @@ -262,14 +261,6 @@ pub trait TurboTasksBackendApi: TurboTasksCallApi + Sync + /// Returns the duration from the start of the program to the given instant. fn program_duration_until(&self, instant: Instant) -> Duration; - /// An untyped object-safe version of [`TurboTasksBackendApiExt::read_task_state`]. Callers - /// should prefer the extension trait's version of this method. - fn read_task_state_dyn(&self, func: &mut dyn FnMut(&B::TaskState)); - - /// An untyped object-safe version of [`TurboTasksBackendApiExt::write_task_state`]. Callers - /// should prefer the extension trait's version of this method. - fn write_task_state_dyn(&self, func: &mut dyn FnMut(&mut B::TaskState)); - /// Returns true if the system is idle. fn is_idle(&self) -> bool; @@ -277,39 +268,6 @@ pub trait TurboTasksBackendApi: TurboTasksCallApi + Sync + fn backend(&self) -> &B; } -/// An extension trait for methods of [`TurboTasksBackendApi`] that are not object-safe. This is -/// automatically implemented for all [`TurboTasksBackendApi`]s using a blanket impl. -pub trait TurboTasksBackendApiExt: TurboTasksBackendApi { - /// Allows modification of the [`Backend::TaskState`]. - /// - /// This function holds open a non-exclusive read lock that blocks writes, so `func` is expected - /// to execute quickly in order to release the lock. - fn read_task_state(&self, func: impl FnOnce(&B::TaskState) -> T) -> T { - let mut func = Some(func); - let mut out = None; - self.read_task_state_dyn(&mut |ts| out = Some((func.take().unwrap())(ts))); - out.expect("read_task_state_dyn must call `func`") - } - - /// Allows modification of the [`Backend::TaskState`]. - /// - /// This function holds open a write lock, so `func` is expected to execute quickly in order to - /// release the lock. - fn write_task_state(&self, func: impl FnOnce(&mut B::TaskState) -> T) -> T { - let mut func = Some(func); - let mut out = None; - self.write_task_state_dyn(&mut |ts| out = Some((func.take().unwrap())(ts))); - out.expect("write_task_state_dyn must call `func`") - } -} - -impl TurboTasksBackendApiExt for TT -where - TT: TurboTasksBackendApi + ?Sized, - B: Backend + 'static, -{ -} - #[allow(clippy::manual_non_exhaustive)] pub struct UpdateInfo { pub duration: Duration, @@ -408,16 +366,10 @@ struct CurrentTaskState { /// Tracks currently running local tasks, and defers cleanup of the global task until those /// complete. Also used by `detached_for_testing`. local_task_tracker: TaskTracker, - - backend_state: Box, } impl CurrentTaskState { - fn new( - task_id: TaskId, - execution_id: ExecutionId, - backend_state: Box, - ) -> Self { + fn new(task_id: TaskId, execution_id: ExecutionId) -> Self { Self { task_id, execution_id, @@ -426,7 +378,6 @@ impl CurrentTaskState { cell_counters: Some(AutoMap::default()), local_tasks: Vec::new(), local_task_tracker: TaskTracker::new(), - backend_state, } } @@ -688,14 +639,10 @@ impl TurboTasks { let future = async move { let mut schedule_again = true; while schedule_again { - let backend_state = this.backend.new_task_state(task_id); // it's okay for execution ids to overflow and wrap, they're just used for an assert let execution_id = this.execution_id_factory.wrapping_get(); - let current_task_state = Arc::new(RwLock::new(CurrentTaskState::new( - task_id, - execution_id, - Box::new(backend_state), - ))); + let current_task_state = + Arc::new(RwLock::new(CurrentTaskState::new(task_id, execution_id))); let single_execution_future = async { if this.stopped.load(Ordering::Acquire) { this.backend.task_execution_canceled(task_id, &*this); @@ -1461,16 +1408,6 @@ impl TurboTasksBackendApi for TurboTasks { unsafe { self.transient_task_id_factory.reuse(id.into()) } } - fn read_task_state_dyn(&self, func: &mut dyn FnMut(&B::TaskState)) { - CURRENT_TASK_STATE - .with(move |ts| func(ts.read().unwrap().backend_state.downcast_ref().unwrap())) - } - - fn write_task_state_dyn(&self, func: &mut dyn FnMut(&mut B::TaskState)) { - CURRENT_TASK_STATE - .with(move |ts| func(ts.write().unwrap().backend_state.downcast_mut().unwrap())) - } - fn is_idle(&self) -> bool { self.currently_scheduled_foreground_jobs .load(Ordering::Acquire) @@ -1588,7 +1525,6 @@ pub fn with_turbo_tasks_for_testing( Arc::new(RwLock::new(CurrentTaskState::new( current_task, execution_id, - Box::new(()), ))), f, ),