From 0084ab78ac0b53c8c7192318a27fd4c9a1cb8435 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Thu, 9 Jan 2025 08:54:41 +0100 Subject: [PATCH] box InProgressState to avoid larger enum --- .../turbo-tasks-backend/src/backend/mod.rs | 34 +++++++++++-------- .../src/backend/operation/connect_child.rs | 4 +-- .../src/backend/operation/invalidate.rs | 9 +++-- .../src/backend/operation/update_output.rs | 9 +++-- .../crates/turbo-tasks-backend/src/data.rs | 29 ++++++++-------- .../crates/turbo-tasks-backend/src/lib.rs | 1 + 6 files changed, 50 insertions(+), 36 deletions(-) diff --git a/turbopack/crates/turbo-tasks-backend/src/backend/mod.rs b/turbopack/crates/turbo-tasks-backend/src/backend/mod.rs index 4d4b6389fff65f..cb8d68eed30102 100644 --- a/turbopack/crates/turbo-tasks-backend/src/backend/mod.rs +++ b/turbopack/crates/turbo-tasks-backend/src/backend/mod.rs @@ -51,7 +51,8 @@ use crate::{ data::{ ActivenessState, AggregationNumber, CachedDataItem, CachedDataItemKey, CachedDataItemType, CachedDataItemValue, CachedDataItemValueRef, CachedDataUpdate, CellRef, CollectibleRef, - CollectiblesRef, DirtyState, InProgressCellState, InProgressState, OutputValue, RootType, + CollectiblesRef, DirtyState, InProgressCellState, InProgressState, InProgressStateInner, + OutputValue, RootType, }, utils::{bi_map::BiMap, chunked_vec::ChunkedVec, ptr_eq_arc::PtrEqArc, sharded::Sharded}, }; @@ -405,7 +406,9 @@ impl TurboTasksBackendInner { if let Some(in_progress) = get!(task, InProgress) { match in_progress { InProgressState::Scheduled { done_event, .. } - | InProgressState::InProgress { done_event, .. } => { + | InProgressState::InProgress(box InProgressStateInner { + done_event, .. + }) => { let reader_desc = reader.map(|r| this.get_task_desc_fn(r)); let listener = done_event.listen_with_note(move || { if let Some(reader_desc) = reader_desc.as_ref() { @@ -1005,14 +1008,14 @@ impl TurboTasksBackendInner { return None; }; task.add_new(CachedDataItem::InProgress { - value: InProgressState::InProgress { + value: InProgressState::InProgress(Box::new(InProgressStateInner { stale: false, once_task, done_event, session_dependent: false, marked_as_completed: false, new_children: Default::default(), - }, + })), }); if self.should_track_children() { @@ -1185,22 +1188,22 @@ impl TurboTasksBackendInner { let Some(in_progress) = get_mut!(task, InProgress) else { panic!("Task execution completed, but task is not in progress: {task:#?}"); }; - let &mut InProgressState::InProgress { + let &mut InProgressState::InProgress(box InProgressStateInner { stale, ref mut new_children, .. - } = in_progress + }) = in_progress else { panic!("Task execution completed, but task is not in progress: {task:#?}"); }; // If the task is stale, reschedule it if stale { - let Some(InProgressState::InProgress { + let Some(InProgressState::InProgress(box InProgressStateInner { done_event, new_children, .. - }) = remove!(task, InProgress) + })) = remove!(task, InProgress) else { unreachable!(); }; @@ -1335,14 +1338,14 @@ impl TurboTasksBackendInner { let Some(in_progress) = remove!(task, InProgress) else { panic!("Task execution completed, but task is not in progress: {task:#?}"); }; - let InProgressState::InProgress { + let InProgressState::InProgress(box InProgressStateInner { done_event, once_task: _, stale, session_dependent, marked_as_completed: _, new_children, - } = in_progress + }) = in_progress else { panic!("Task execution completed, but task is not in progress: {task:#?}"); }; @@ -1686,9 +1689,10 @@ impl TurboTasksBackendInner { ) { let mut ctx = self.execute_context(turbo_tasks); let mut task = ctx.task(task, TaskDataCategory::Data); - if let Some(InProgressState::InProgress { - session_dependent, .. - }) = get_mut!(task, InProgress) + if let Some(InProgressState::InProgress(box InProgressStateInner { + session_dependent, + .. + })) = get_mut!(task, InProgress) { *session_dependent = true; } @@ -1701,10 +1705,10 @@ impl TurboTasksBackendInner { ) { let mut ctx = self.execute_context(turbo_tasks); let mut task = ctx.task(task, TaskDataCategory::Data); - if let Some(InProgressState::InProgress { + if let Some(InProgressState::InProgress(box InProgressStateInner { marked_as_completed, .. - }) = get_mut!(task, InProgress) + })) = get_mut!(task, InProgress) { *marked_as_completed = true; // TODO this should remove the dirty state (also check session_dependent) diff --git a/turbopack/crates/turbo-tasks-backend/src/backend/operation/connect_child.rs b/turbopack/crates/turbo-tasks-backend/src/backend/operation/connect_child.rs index d4420fe37ad2b9..4dfc70df715a15 100644 --- a/turbopack/crates/turbo-tasks-backend/src/backend/operation/connect_child.rs +++ b/turbopack/crates/turbo-tasks-backend/src/backend/operation/connect_child.rs @@ -10,7 +10,7 @@ use crate::{ }, TaskDataCategory, }, - data::{CachedDataItem, CachedDataItemKey, InProgressState}, + data::{CachedDataItem, CachedDataItemKey, InProgressState, InProgressStateInner}, }; #[derive(Serialize, Deserialize, Clone, Default)] @@ -38,7 +38,7 @@ impl ConnectChildOperation { return; } let mut parent_task = ctx.task(parent_task_id, TaskDataCategory::Meta); - let Some(InProgressState::InProgress { new_children, .. }) = + let Some(InProgressState::InProgress(box InProgressStateInner { new_children, .. })) = get_mut!(parent_task, InProgress) else { panic!("Task is not in progress while calling another task"); diff --git a/turbopack/crates/turbo-tasks-backend/src/backend/operation/invalidate.rs b/turbopack/crates/turbo-tasks-backend/src/backend/operation/invalidate.rs index 1693d0c81b3156..fb836b39f04ac7 100644 --- a/turbopack/crates/turbo-tasks-backend/src/backend/operation/invalidate.rs +++ b/turbopack/crates/turbo-tasks-backend/src/backend/operation/invalidate.rs @@ -15,7 +15,10 @@ use crate::{ storage::{get, get_mut}, TaskDataCategory, }, - data::{CachedDataItem, CachedDataItemKey, CachedDataItemValue, DirtyState, InProgressState}, + data::{ + CachedDataItem, CachedDataItemKey, CachedDataItemValue, DirtyState, InProgressState, + InProgressStateInner, + }, }; #[derive(Serialize, Deserialize, Clone, Default)] @@ -162,7 +165,9 @@ pub fn make_task_dirty_internal( ctx: &impl ExecuteContext, ) { if make_stale { - if let Some(InProgressState::InProgress { stale, .. }) = get_mut!(task, InProgress) { + if let Some(InProgressState::InProgress(box InProgressStateInner { stale, .. })) = + get_mut!(task, InProgress) + { if !*stale { let _span = tracing::trace_span!( "make task stale", diff --git a/turbopack/crates/turbo-tasks-backend/src/backend/operation/update_output.rs b/turbopack/crates/turbo-tasks-backend/src/backend/operation/update_output.rs index a6aef93d5d914c..96d3d58ab734fc 100644 --- a/turbopack/crates/turbo-tasks-backend/src/backend/operation/update_output.rs +++ b/turbopack/crates/turbo-tasks-backend/src/backend/operation/update_output.rs @@ -13,7 +13,10 @@ use crate::{ storage::{get, get_many}, TaskDataCategory, }, - data::{CachedDataItem, CachedDataItemKey, CellRef, InProgressState, OutputValue}, + data::{ + CachedDataItem, CachedDataItemKey, CellRef, InProgressState, InProgressStateInner, + OutputValue, + }, }; #[derive(Serialize, Deserialize, Clone, Default)] @@ -42,11 +45,11 @@ impl UpdateOutputOperation { mut ctx: impl ExecuteContext, ) { let mut task = ctx.task(task_id, TaskDataCategory::Meta); - let Some(InProgressState::InProgress { + let Some(InProgressState::InProgress(box InProgressStateInner { stale, new_children, .. - }) = get!(task, InProgress) + })) = get!(task, InProgress) else { panic!("Task is not in progress while updating the output"); }; diff --git a/turbopack/crates/turbo-tasks-backend/src/data.rs b/turbopack/crates/turbo-tasks-backend/src/data.rs index 6f817d472cd789..d10cb63ede96c8 100644 --- a/turbopack/crates/turbo-tasks-backend/src/data.rs +++ b/turbopack/crates/turbo-tasks-backend/src/data.rs @@ -300,22 +300,23 @@ pub enum RootType { OnceTask, } +#[derive(Debug)] +pub struct InProgressStateInner { + pub stale: bool, + #[allow(dead_code)] + pub once_task: bool, + pub session_dependent: bool, + pub marked_as_completed: bool, + pub done_event: Event, + /// Children that should be connected to the task and have their active_count decremented + /// once the task completes. + pub new_children: FxHashSet, +} + #[derive(Debug)] pub enum InProgressState { - Scheduled { - done_event: Event, - }, - InProgress { - stale: bool, - #[allow(dead_code)] - once_task: bool, - session_dependent: bool, - marked_as_completed: bool, - done_event: Event, - /// Children that should be connected to the task and have their active_count decremented - /// once the task completes. - new_children: FxHashSet, - }, + Scheduled { done_event: Event }, + InProgress(Box), } transient_traits!(InProgressState); diff --git a/turbopack/crates/turbo-tasks-backend/src/lib.rs b/turbopack/crates/turbo-tasks-backend/src/lib.rs index 1d3fef0f365aef..d41dce80a55a13 100644 --- a/turbopack/crates/turbo-tasks-backend/src/lib.rs +++ b/turbopack/crates/turbo-tasks-backend/src/lib.rs @@ -1,6 +1,7 @@ #![feature(anonymous_lifetime_in_impl_trait)] #![feature(associated_type_defaults)] #![feature(iter_collect_into)] +#![feature(box_patterns)] mod backend; mod backing_storage;