Skip to content

Commit 3d19e36

Browse files
committed
Turbopack: remove Backend TaskState
1 parent 270342e commit 3d19e36

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,
@@ -259,54 +258,13 @@ pub trait TurboTasksBackendApi<B: Backend + 'static>: TurboTasksCallApi + Sync +
259258
/// Returns the duration from the start of the program to the given instant.
260259
fn program_duration_until(&self, instant: Instant) -> Duration;
261260

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

273264
/// Returns a reference to the backend.
274265
fn backend(&self) -> &B;
275266
}
276267

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

412368
impl CurrentTaskState {
413-
fn new(
414-
task_id: TaskId,
415-
execution_id: ExecutionId,
416-
backend_state: Box<dyn Any + Send + Sync>,
417-
) -> Self {
369+
fn new(task_id: TaskId, execution_id: ExecutionId) -> Self {
418370
Self {
419371
task_id,
420372
execution_id,
@@ -423,7 +375,6 @@ impl CurrentTaskState {
423375
cell_counters: Some(AutoMap::default()),
424376
local_tasks: Vec::new(),
425377
local_task_tracker: TaskTracker::new(),
426-
backend_state,
427378
}
428379
}
429380

@@ -685,14 +636,10 @@ impl<B: Backend + 'static> TurboTasks<B> {
685636
let future = async move {
686637
let mut schedule_again = true;
687638
while schedule_again {
688-
let backend_state = this.backend.new_task_state(task_id);
689639
// it's okay for execution ids to overflow and wrap, they're just used for an assert
690640
let execution_id = this.execution_id_factory.wrapping_get();
691-
let current_task_state = Arc::new(RwLock::new(CurrentTaskState::new(
692-
task_id,
693-
execution_id,
694-
Box::new(backend_state),
695-
)));
641+
let current_task_state =
642+
Arc::new(RwLock::new(CurrentTaskState::new(task_id, execution_id)));
696643
let single_execution_future = async {
697644
if this.stopped.load(Ordering::Acquire) {
698645
this.backend.task_execution_canceled(task_id, &*this);
@@ -1454,16 +1401,6 @@ impl<B: Backend + 'static> TurboTasksBackendApi<B> for TurboTasks<B> {
14541401
unsafe { self.transient_task_id_factory.reuse(id.into()) }
14551402
}
14561403

1457-
fn read_task_state_dyn(&self, func: &mut dyn FnMut(&B::TaskState)) {
1458-
CURRENT_TASK_STATE
1459-
.with(move |ts| func(ts.read().unwrap().backend_state.downcast_ref().unwrap()))
1460-
}
1461-
1462-
fn write_task_state_dyn(&self, func: &mut dyn FnMut(&mut B::TaskState)) {
1463-
CURRENT_TASK_STATE
1464-
.with(move |ts| func(ts.write().unwrap().backend_state.downcast_mut().unwrap()))
1465-
}
1466-
14671404
fn is_idle(&self) -> bool {
14681405
self.currently_scheduled_foreground_jobs
14691406
.load(Ordering::Acquire)
@@ -1581,7 +1518,6 @@ pub fn with_turbo_tasks_for_testing<T>(
15811518
Arc::new(RwLock::new(CurrentTaskState::new(
15821519
current_task,
15831520
execution_id,
1584-
Box::new(()),
15851521
))),
15861522
f,
15871523
),

0 commit comments

Comments
 (0)