From 17e777b9fc40a39fa3889b814a4649c36fb1f6e6 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Tue, 12 Nov 2024 10:09:57 +0100 Subject: [PATCH] implement dispose root task --- .../turbo-tasks-backend/src/backend/mod.rs | 30 +++++++++++++++++-- .../crates/turbo-tasks-backend/src/data.rs | 1 + 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/turbopack/crates/turbo-tasks-backend/src/backend/mod.rs b/turbopack/crates/turbo-tasks-backend/src/backend/mod.rs index 01132a53846339..552c170d1de6a7 100644 --- a/turbopack/crates/turbo-tasks-backend/src/backend/mod.rs +++ b/turbopack/crates/turbo-tasks-backend/src/backend/mod.rs @@ -1753,6 +1753,32 @@ impl TurboTasksBackendInner { } task_id } + + fn dispose_root_task( + &self, + task_id: TaskId, + turbo_tasks: &dyn TurboTasksBackendApi>, + ) { + let mut ctx = self.execute_context(turbo_tasks); + let mut task = ctx.task(task_id, TaskDataCategory::All); + let is_dirty = get!(task, Dirty).map_or(false, |dirty| dirty.get(self.session_id)); + let has_dirty_containers = get!(task, AggregatedDirtyContainerCount) + .map_or(false, |dirty_containers| { + dirty_containers.get(self.session_id) > 0 + }); + if is_dirty || has_dirty_containers { + if let Some(root_state) = get_mut!(task, AggregateRoot) { + // We will finish the task, but it would be removed after the task is done + root_state.ty = ActiveType::CachedActiveUntilClean; + }; + } else { + if let Some(root_state) = remove!(task, AggregateRoot) { + // Technically nobody should be listening to this event, but just in case + // we notify it anyway + root_state.all_clean_event.notify(usize::MAX); + } + } + } } impl Backend for TurboTasksBackend { @@ -1991,8 +2017,8 @@ impl Backend for TurboTasksBackend { self.0.create_transient_task(task_type) } - fn dispose_root_task(&self, _: TaskId, _: &dyn TurboTasksBackendApi) { - // TODO implement + fn dispose_root_task(&self, task_id: TaskId, turbo_tasks: &dyn TurboTasksBackendApi) { + self.0.dispose_root_task(task_id, turbo_tasks); } } diff --git a/turbopack/crates/turbo-tasks-backend/src/data.rs b/turbopack/crates/turbo-tasks-backend/src/data.rs index 8e6ef6be0faf01..9e628e94ac3c08 100644 --- a/turbopack/crates/turbo-tasks-backend/src/data.rs +++ b/turbopack/crates/turbo-tasks-backend/src/data.rs @@ -583,6 +583,7 @@ impl CachedDataItemKey { #[allow(non_upper_case_globals, dead_code)] pub mod allow_mut_access { pub const InProgress: () = (); + pub const AggregateRoot: () = (); } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]