diff --git a/crates/turbo-tasks-memory/src/task.rs b/crates/turbo-tasks-memory/src/task.rs index e00366a94ed43..897a2ace35ca5 100644 --- a/crates/turbo-tasks-memory/src/task.rs +++ b/crates/turbo-tasks-memory/src/task.rs @@ -307,6 +307,16 @@ impl MaybeCollectibles { } } +struct InProgressState { + event: Event, + count_as_finished: bool, + /// Dependencies and children that need to be disconnected once leaving + /// this state + outdated_edges: TaskEdgesSet, + new_children: TaskIdSet, + outdated_collectibles: MaybeCollectibles, +} + enum TaskStateType { /// Ready /// @@ -343,15 +353,7 @@ enum TaskStateType { /// on finish this will move to Done /// /// on invalidation this will move to InProgressDirty - InProgress { - event: Event, - count_as_finished: bool, - /// Dependencies and children that need to be disconnected once leaving - /// this state - outdated_edges: Box, - new_children: TaskIdSet, - outdated_collectibles: MaybeCollectibles, - }, + InProgress(Box), /// Invalid execution is happening /// @@ -367,11 +369,11 @@ impl TaskStateType { fn children(&self) -> impl Iterator + '_ { match self { TaskStateType::Done { edges, .. } => Either::Left(edges.children()), - TaskStateType::InProgress { + TaskStateType::InProgress(box InProgressState { outdated_edges, new_children, .. - } => Either::Right(Either::Left( + }) => Either::Right(Either::Left( outdated_edges .children() .chain(new_children.iter().copied()), @@ -395,12 +397,12 @@ impl TaskStateType { let children = edges.drain_children(); (edges, children) } - TaskStateType::InProgress { + TaskStateType::InProgress(box InProgressState { outdated_edges, new_children, .. - } => { - let mut edges = *outdated_edges; + }) => { + let mut edges = outdated_edges; let mut children = edges.drain_children(); children.extend(new_children.iter().copied()); (edges, children) @@ -669,15 +671,15 @@ impl Task { ref mut outdated_edges, } => { let event = event.take(); - let outdated_edges = take(outdated_edges); + let outdated_edges = *take(outdated_edges); let outdated_collectibles = take(&mut state.collectibles); - state.state_type = InProgress { + state.state_type = InProgress(Box::new(InProgressState { event, count_as_finished: false, outdated_edges, outdated_collectibles, new_children: Default::default(), - }; + })); } Dirty { .. } => { let state_type = Task::state_string(&state); @@ -761,12 +763,12 @@ impl Task { let TaskMetaStateWriteGuard::Full(mut state) = self.state_mut() else { return; }; - let TaskStateType::InProgress { + let TaskStateType::InProgress(box InProgressState { ref mut count_as_finished, ref mut outdated_collectibles, ref mut outdated_edges, .. - } = state.state_type + }) = state.state_type else { return; }; @@ -881,15 +883,15 @@ impl Task { .gc .execution_completed(duration, memory_usage, generation); match state.state_type { - InProgress { + InProgress(box InProgressState { ref mut event, count_as_finished, ref mut outdated_edges, ref mut outdated_collectibles, ref mut new_children, - } => { + }) => { let event = event.take(); - let mut outdated_edges = *take(outdated_edges); + let mut outdated_edges = take(outdated_edges); let outdated_collectibles = outdated_collectibles.take_collectibles(); let mut new_edges = take(&mut dependencies); outdated_edges.remove_all(&new_edges); @@ -1082,13 +1084,13 @@ impl Task { change_job.apply(&aggregation_context); } } - InProgress { + InProgress(box InProgressState { ref mut event, count_as_finished, ref mut outdated_edges, ref mut outdated_collectibles, ref mut new_children, - } => { + }) => { let event = event.take(); let mut outdated_edges = take(outdated_edges); let children_count = new_children.len(); @@ -1125,7 +1127,7 @@ impl Task { }); state.state_type = InProgressDirty { event, - outdated_edges, + outdated_edges: Box::new(outdated_edges), children_count, }; drop(state); @@ -1279,14 +1281,14 @@ impl Task { fn state_string(state: &TaskState) -> &'static str { match state.state_type { Scheduled { .. } => "scheduled", - InProgress { + InProgress(box InProgressState { count_as_finished: false, .. - } => "in progress", - InProgress { + }) => "in progress", + InProgress(box InProgressState { count_as_finished: true, .. - } => "in progress (marked as finished)", + }) => "in progress (marked as finished)", InProgressDirty { .. } => "in progress (dirty)", Done { .. } => "done", Dirty { .. } => "dirty", @@ -1305,11 +1307,11 @@ impl Task { { let mut state = self.full_state_mut(); match &mut state.state_type { - TaskStateType::InProgress { + TaskStateType::InProgress(box InProgressState { outdated_edges, new_children, .. - } => { + }) => { if new_children.insert(child_id) { if outdated_edges.remove(TaskEdge::Child(child_id)) { drop(state); @@ -1436,7 +1438,7 @@ impl Task { Ok(Err(listener)) } Scheduled { ref event, .. } - | InProgress { ref event, .. } + | InProgress(box InProgressState { ref event, .. }) | InProgressDirty { ref event, .. } => { let listener = event.listen_with_note(note); drop(state); diff --git a/crates/turbo-tasks-memory/src/task/aggregation.rs b/crates/turbo-tasks-memory/src/task/aggregation.rs index 9c62119f84523..08dc917a32912 100644 --- a/crates/turbo-tasks-memory/src/task/aggregation.rs +++ b/crates/turbo-tasks-memory/src/task/aggregation.rs @@ -14,7 +14,7 @@ use turbo_tasks::{event::Event, RawVc, TaskId, TaskIdSet, TraitTypeId, TurboTask use super::{ meta_state::{FullTaskWriteGuard, TaskMetaStateWriteGuard}, - TaskStateType, + InProgressState, TaskStateType, }; use crate::{ aggregation::{ @@ -474,10 +474,10 @@ impl<'l> AggregationNodeGuard for TaskGuard<'l> { if !matches!( guard.state_type, TaskStateType::Done { .. } - | TaskStateType::InProgress { + | TaskStateType::InProgress (box InProgressState{ count_as_finished: true, .. - } + }) ) { change.unfinished = 1; #[cfg(feature = "track_unfinished")] @@ -491,10 +491,10 @@ impl<'l> AggregationNodeGuard for TaskGuard<'l> { change.collectibles.push((trait_type_id, collectible, 1)); } } - if let TaskStateType::InProgress { + if let TaskStateType::InProgress(box InProgressState { outdated_collectibles, .. - } = &guard.state_type + }) = &guard.state_type { if let Some(collectibles) = outdated_collectibles.as_ref() { for (&(trait_type_id, collectible), _) in collectibles.iter() { @@ -520,10 +520,10 @@ impl<'l> AggregationNodeGuard for TaskGuard<'l> { if !matches!( guard.state_type, TaskStateType::Done { .. } - | TaskStateType::InProgress { + | TaskStateType::InProgress (box InProgressState{ count_as_finished: true, .. - } + }) ) { change.unfinished = -1; #[cfg(feature = "track_unfinished")] @@ -537,10 +537,10 @@ impl<'l> AggregationNodeGuard for TaskGuard<'l> { change.collectibles.push((trait_type_id, collectible, -1)); } } - if let TaskStateType::InProgress { + if let TaskStateType::InProgress(box InProgressState { outdated_collectibles, .. - } = &guard.state_type + }) = &guard.state_type { if let Some(collectibles) = outdated_collectibles.as_ref() { for (&(trait_type_id, collectible), _) in collectibles.iter() {