Skip to content

Commit

Permalink
Turbo tasks: Reuse aggregation context and apply queued updates (#7847)
Browse files Browse the repository at this point in the history
This resolves an issue that caused Turbopack to panic with
https://github.com/vercel/turbo/blob/04e2a9f0cb9439913975a325ce3eb59b46380ff8/crates/turbo-tasks-memory/src/task/aggregation.rs#L211

When marking a task dirty:
- Reuse the aggregation context instead of creating
- Apply queued updates


Closes PACK-2846
  • Loading branch information
wbinnssmith committed Mar 26, 2024
1 parent f20dd90 commit 5f0cd3e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion crates/turbo-tasks-memory/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ impl Task {
outdated_dependencies: take(outdated_dependencies),
};
state.aggregation_leaf.change(
&TaskAggregationContext::new(turbo_tasks, backend),
&aggregation_context,
&TaskChange {
dirty_tasks_update: vec![(self.id, -1)],
..Default::default()
Expand Down Expand Up @@ -1248,6 +1248,7 @@ impl Task {
}
}
}
aggregation_context.apply_queued_updates();
}

pub(crate) fn schedule_when_dirty_from_aggregation(
Expand Down
15 changes: 8 additions & 7 deletions crates/turbo-tasks/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,17 +798,18 @@ impl<B: Backend + 'static> TurboTasks<B> {
}

fn finish_current_task_state(&self) -> bool {
CURRENT_TASK_STATE.with(|cell| {
let (stateful, tasks) = CURRENT_TASK_STATE.with(|cell| {
let CurrentTaskState {
tasks_to_notify,
stateful,
} = &mut *cell.borrow_mut();
let tasks = take(tasks_to_notify);
if !tasks.is_empty() {
self.backend.invalidate_tasks(&tasks, self);
}
*stateful
})
(*stateful, take(tasks_to_notify))
});

if !tasks.is_empty() {
self.backend.invalidate_tasks(&tasks, self);
}
stateful
}

pub fn backend(&self) -> &B {
Expand Down

0 comments on commit 5f0cd3e

Please sign in to comment.