Skip to content

Commit 36d06db

Browse files
authored
Turbopack: remove Backend TaskState (#83846)
### What? Backend TaskState is no longer used with the new backend.
1 parent f982260 commit 36d06db

File tree

4 files changed

+6
-96
lines changed

4 files changed

+6
-96
lines changed

turbopack/crates/turbo-tasks-backend/src/backend/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2873,9 +2873,6 @@ impl<B: BackingStorage> Backend for TurboTasksBackend<B> {
28732873
self.0.get_task_description(task)
28742874
}
28752875

2876-
type TaskState = ();
2877-
fn new_task_state(&self, _task: TaskId) -> Self::TaskState {}
2878-
28792876
fn task_execution_canceled(&self, task: TaskId, turbo_tasks: &dyn TurboTasksBackendApi<Self>) {
28802877
self.0.task_execution_canceled(task, turbo_tasks)
28812878
}

turbopack/crates/turbo-tasks/src/backend.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -530,29 +530,6 @@ pub trait Backend: Sync + Send {
530530

531531
fn get_task_description(&self, task: TaskId) -> String;
532532

533-
/// Task-local state that stored inside of [`TurboTasksBackendApi`]. Constructed with
534-
/// [`Self::new_task_state`].
535-
///
536-
/// This value that can later be written to or read from using
537-
/// [`crate::TurboTasksBackendApiExt::write_task_state`] or
538-
/// [`crate::TurboTasksBackendApiExt::read_task_state`]
539-
///
540-
/// This data may be shared across multiple threads (must be `Sync`) in order to support
541-
/// detached futures ([`crate::TurboTasksApi::detached_for_testing`]) and [pseudo-tasks using
542-
/// `local` execution][crate::function]. A [`RwLock`][std::sync::RwLock] is used to provide
543-
/// concurrent access.
544-
type TaskState: Send + Sync + 'static;
545-
546-
/// Constructs a new task-local [`Self::TaskState`] for the given `task_id`.
547-
///
548-
/// If a task is re-executed (e.g. because it is invalidated), this function will be called
549-
/// again with the same [`TaskId`].
550-
///
551-
/// This value can be written to or read from using
552-
/// [`crate::TurboTasksBackendApiExt::write_task_state`] and
553-
/// [`crate::TurboTasksBackendApiExt::read_task_state`]
554-
fn new_task_state(&self, task: TaskId) -> Self::TaskState;
555-
556533
fn try_start_task_execution<'a>(
557534
&'a self,
558535
task: TaskId,

turbopack/crates/turbo-tasks/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ pub use key_value_pair::KeyValuePair;
109109
pub use magic_any::MagicAny;
110110
pub use manager::{
111111
CurrentCellRef, ReadConsistency, TaskPersistence, TurboTasks, TurboTasksApi,
112-
TurboTasksBackendApi, TurboTasksBackendApiExt, TurboTasksCallApi, Unused, UpdateInfo,
113-
dynamic_call, emit, mark_finished, mark_root, mark_session_dependent, mark_stateful,
114-
prevent_gc, run_once, run_once_with_reason, trait_call, turbo_tasks, turbo_tasks_scope,
112+
TurboTasksBackendApi, TurboTasksCallApi, Unused, UpdateInfo, dynamic_call, emit, mark_finished,
113+
mark_root, mark_session_dependent, mark_stateful, prevent_gc, run_once, run_once_with_reason,
114+
trait_call, turbo_tasks, turbo_tasks_scope,
115115
};
116116
pub use output::OutputContent;
117117
pub use raw_vc::{CellId, RawVc, ReadRawVcFuture, ResolveTypeError};

turbopack/crates/turbo-tasks/src/manager.rs

Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::{
2-
any::Any,
32
future::Future,
43
hash::BuildHasherDefault,
54
mem::take,
@@ -262,54 +261,13 @@ pub trait TurboTasksBackendApi<B: Backend + 'static>: TurboTasksCallApi + Sync +
262261
/// Returns the duration from the start of the program to the given instant.
263262
fn program_duration_until(&self, instant: Instant) -> Duration;
264263

265-
/// An untyped object-safe version of [`TurboTasksBackendApiExt::read_task_state`]. Callers
266-
/// should prefer the extension trait's version of this method.
267-
fn read_task_state_dyn(&self, func: &mut dyn FnMut(&B::TaskState));
268-
269-
/// An untyped object-safe version of [`TurboTasksBackendApiExt::write_task_state`]. Callers
270-
/// should prefer the extension trait's version of this method.
271-
fn write_task_state_dyn(&self, func: &mut dyn FnMut(&mut B::TaskState));
272-
273264
/// Returns true if the system is idle.
274265
fn is_idle(&self) -> bool;
275266

276267
/// Returns a reference to the backend.
277268
fn backend(&self) -> &B;
278269
}
279270

280-
/// An extension trait for methods of [`TurboTasksBackendApi`] that are not object-safe. This is
281-
/// automatically implemented for all [`TurboTasksBackendApi`]s using a blanket impl.
282-
pub trait TurboTasksBackendApiExt<B: Backend + 'static>: TurboTasksBackendApi<B> {
283-
/// Allows modification of the [`Backend::TaskState`].
284-
///
285-
/// This function holds open a non-exclusive read lock that blocks writes, so `func` is expected
286-
/// to execute quickly in order to release the lock.
287-
fn read_task_state<T>(&self, func: impl FnOnce(&B::TaskState) -> T) -> T {
288-
let mut func = Some(func);
289-
let mut out = None;
290-
self.read_task_state_dyn(&mut |ts| out = Some((func.take().unwrap())(ts)));
291-
out.expect("read_task_state_dyn must call `func`")
292-
}
293-
294-
/// Allows modification of the [`Backend::TaskState`].
295-
///
296-
/// This function holds open a write lock, so `func` is expected to execute quickly in order to
297-
/// release the lock.
298-
fn write_task_state<T>(&self, func: impl FnOnce(&mut B::TaskState) -> T) -> T {
299-
let mut func = Some(func);
300-
let mut out = None;
301-
self.write_task_state_dyn(&mut |ts| out = Some((func.take().unwrap())(ts)));
302-
out.expect("write_task_state_dyn must call `func`")
303-
}
304-
}
305-
306-
impl<TT, B> TurboTasksBackendApiExt<B> for TT
307-
where
308-
TT: TurboTasksBackendApi<B> + ?Sized,
309-
B: Backend + 'static,
310-
{
311-
}
312-
313271
#[allow(clippy::manual_non_exhaustive)]
314272
pub struct UpdateInfo {
315273
pub duration: Duration,
@@ -408,16 +366,10 @@ struct CurrentTaskState {
408366
/// Tracks currently running local tasks, and defers cleanup of the global task until those
409367
/// complete. Also used by `detached_for_testing`.
410368
local_task_tracker: TaskTracker,
411-
412-
backend_state: Box<dyn Any + Send + Sync>,
413369
}
414370

415371
impl CurrentTaskState {
416-
fn new(
417-
task_id: TaskId,
418-
execution_id: ExecutionId,
419-
backend_state: Box<dyn Any + Send + Sync>,
420-
) -> Self {
372+
fn new(task_id: TaskId, execution_id: ExecutionId) -> Self {
421373
Self {
422374
task_id,
423375
execution_id,
@@ -426,7 +378,6 @@ impl CurrentTaskState {
426378
cell_counters: Some(AutoMap::default()),
427379
local_tasks: Vec::new(),
428380
local_task_tracker: TaskTracker::new(),
429-
backend_state,
430381
}
431382
}
432383

@@ -688,14 +639,10 @@ impl<B: Backend + 'static> TurboTasks<B> {
688639
let future = async move {
689640
let mut schedule_again = true;
690641
while schedule_again {
691-
let backend_state = this.backend.new_task_state(task_id);
692642
// it's okay for execution ids to overflow and wrap, they're just used for an assert
693643
let execution_id = this.execution_id_factory.wrapping_get();
694-
let current_task_state = Arc::new(RwLock::new(CurrentTaskState::new(
695-
task_id,
696-
execution_id,
697-
Box::new(backend_state),
698-
)));
644+
let current_task_state =
645+
Arc::new(RwLock::new(CurrentTaskState::new(task_id, execution_id)));
699646
let single_execution_future = async {
700647
if this.stopped.load(Ordering::Acquire) {
701648
this.backend.task_execution_canceled(task_id, &*this);
@@ -1461,16 +1408,6 @@ impl<B: Backend + 'static> TurboTasksBackendApi<B> for TurboTasks<B> {
14611408
unsafe { self.transient_task_id_factory.reuse(id.into()) }
14621409
}
14631410

1464-
fn read_task_state_dyn(&self, func: &mut dyn FnMut(&B::TaskState)) {
1465-
CURRENT_TASK_STATE
1466-
.with(move |ts| func(ts.read().unwrap().backend_state.downcast_ref().unwrap()))
1467-
}
1468-
1469-
fn write_task_state_dyn(&self, func: &mut dyn FnMut(&mut B::TaskState)) {
1470-
CURRENT_TASK_STATE
1471-
.with(move |ts| func(ts.write().unwrap().backend_state.downcast_mut().unwrap()))
1472-
}
1473-
14741411
fn is_idle(&self) -> bool {
14751412
self.currently_scheduled_foreground_jobs
14761413
.load(Ordering::Acquire)
@@ -1588,7 +1525,6 @@ pub fn with_turbo_tasks_for_testing<T>(
15881525
Arc::new(RwLock::new(CurrentTaskState::new(
15891526
current_task,
15901527
execution_id,
1591-
Box::new(()),
15921528
))),
15931529
f,
15941530
),

0 commit comments

Comments
 (0)