Skip to content

Commit

Permalink
implement dispose root task
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Nov 12, 2024
1 parent 006590d commit 4159087
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
30 changes: 28 additions & 2 deletions turbopack/crates/turbo-tasks-backend/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,32 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
}
task_id
}

fn dispose_root_task(
&self,
task_id: TaskId,
turbo_tasks: &dyn TurboTasksBackendApi<TurboTasksBackend<B>>,
) {
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 {

Check failure on line 1774 in turbopack/crates/turbo-tasks-backend/src/backend/mod.rs

View workflow job for this annotation

GitHub Actions / rust check / build

this `else { if .. }` block can be collapsed
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<B: BackingStorage> Backend for TurboTasksBackend<B> {
Expand Down Expand Up @@ -1991,8 +2017,8 @@ impl<B: BackingStorage> Backend for TurboTasksBackend<B> {
self.0.create_transient_task(task_type)
}

fn dispose_root_task(&self, _: TaskId, _: &dyn TurboTasksBackendApi<Self>) {
// TODO implement
fn dispose_root_task(&self, task_id: TaskId, turbo_tasks: &dyn TurboTasksBackendApi<Self>) {
self.0.dispose_root_task(task_id, turbo_tasks);
}
}

Expand Down
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-backend/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 4159087

Please sign in to comment.