Skip to content

Commit 89d496d

Browse files
committed
Turbopack: remove Stateful flag
1 parent 5661e21 commit 89d496d

File tree

7 files changed

+20
-63
lines changed

7 files changed

+20
-63
lines changed

turbopack/crates/turbo-tasks-backend/src/backend/mod.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,7 +1755,6 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
17551755
task_id: TaskId,
17561756
result: Result<RawVc, TurboTasksExecutionError>,
17571757
cell_counters: &AutoMap<ValueTypeId, u32, BuildHasherDefault<FxHasher>, 8>,
1758-
stateful: bool,
17591758
has_invalidator: bool,
17601759
turbo_tasks: &dyn TurboTasksBackendApi<TurboTasksBackend<B>>,
17611760
) -> bool {
@@ -1806,7 +1805,6 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
18061805
task_id,
18071806
result,
18081807
cell_counters,
1809-
stateful,
18101808
has_invalidator,
18111809
)
18121810
else {
@@ -1877,7 +1875,6 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
18771875
task_id: TaskId,
18781876
result: Result<RawVc, TurboTasksExecutionError>,
18791877
cell_counters: &AutoMap<ValueTypeId, u32, BuildHasherDefault<FxHasher>, 8>,
1880-
stateful: bool,
18811878
has_invalidator: bool,
18821879
) -> Option<TaskExecutionCompletePrepareResult> {
18831880
let mut task = ctx.task(task_id, TaskDataCategory::All);
@@ -1943,11 +1940,6 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
19431940
// take the children from the task to process them
19441941
let mut new_children = take(new_children);
19451942

1946-
// handle stateful
1947-
if stateful {
1948-
let _ = task.add(CachedDataItem::Stateful { value: () });
1949-
}
1950-
19511943
// handle has_invalidator
19521944
if has_invalidator {
19531945
let _ = task.add(CachedDataItem::HasInvalidator { value: () });
@@ -2366,8 +2358,8 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
23662358
old_content = task.insert(CachedDataItem::Output { value });
23672359
}
23682360

2369-
// If the task is not stateful and has no mutable children, it does not have a way to be
2370-
// invalidated and we can mark it as immutable.
2361+
// If the task has not invalidator and has no mutable dependencies, it does not have a way
2362+
// to be invalidated and we can mark it as immutable.
23712363
if is_now_immutable {
23722364
let _ = task.add(CachedDataItem::Immutable { value: () });
23732365
}
@@ -3243,15 +3235,13 @@ impl<B: BackingStorage> Backend for TurboTasksBackend<B> {
32433235
task_id: TaskId,
32443236
result: Result<RawVc, TurboTasksExecutionError>,
32453237
cell_counters: &AutoMap<ValueTypeId, u32, BuildHasherDefault<FxHasher>, 8>,
3246-
stateful: bool,
32473238
has_invalidator: bool,
32483239
turbo_tasks: &dyn TurboTasksBackendApi<Self>,
32493240
) -> bool {
32503241
self.0.task_execution_completed(
32513242
task_id,
32523243
result,
32533244
cell_counters,
3254-
stateful,
32553245
has_invalidator,
32563246
turbo_tasks,
32573247
)

turbopack/crates/turbo-tasks-backend/src/data.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,6 @@ pub enum CachedDataItem {
323323
},
324324

325325
// Flags
326-
Stateful {
327-
value: (),
328-
},
329326
HasInvalidator {
330327
value: (),
331328
},
@@ -424,7 +421,6 @@ impl CachedDataItem {
424421
}
425422
CachedDataItem::AggregatedDirtyContainerCount { .. } => true,
426423
CachedDataItem::AggregatedCurrentSessionCleanContainerCount { .. } => false,
427-
CachedDataItem::Stateful { .. } => true,
428424
CachedDataItem::HasInvalidator { .. } => true,
429425
CachedDataItem::Immutable { .. } => true,
430426
CachedDataItem::Activeness { .. } => false,
@@ -495,7 +491,6 @@ impl CachedDataItem {
495491
| Self::AggregatedDirtyContainer { .. }
496492
| Self::AggregatedCollectible { .. }
497493
| Self::AggregatedDirtyContainerCount { .. }
498-
| Self::Stateful { .. }
499494
| Self::HasInvalidator { .. }
500495
| Self::Immutable { .. }
501496
| Self::CollectiblesDependent { .. } => TaskDataCategory::Meta,
@@ -556,7 +551,6 @@ impl CachedDataItemKey {
556551
}
557552
CachedDataItemKey::AggregatedDirtyContainerCount { .. } => true,
558553
CachedDataItemKey::AggregatedCurrentSessionCleanContainerCount { .. } => false,
559-
CachedDataItemKey::Stateful { .. } => true,
560554
CachedDataItemKey::HasInvalidator { .. } => true,
561555
CachedDataItemKey::Immutable { .. } => true,
562556
CachedDataItemKey::Activeness { .. } => false,
@@ -595,7 +589,6 @@ impl CachedDataItemType {
595589
| Self::AggregatedDirtyContainer { .. }
596590
| Self::AggregatedCollectible { .. }
597591
| Self::AggregatedDirtyContainerCount { .. }
598-
| Self::Stateful { .. }
599592
| Self::HasInvalidator { .. }
600593
| Self::Immutable { .. }
601594
| Self::CollectiblesDependent { .. } => TaskDataCategory::Meta,
@@ -634,7 +627,6 @@ impl CachedDataItemType {
634627
| Self::AggregatedDirtyContainer
635628
| Self::AggregatedCollectible
636629
| Self::AggregatedDirtyContainerCount
637-
| Self::Stateful
638630
| Self::HasInvalidator
639631
| Self::Immutable => true,
640632

turbopack/crates/turbo-tasks-fs/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ use turbo_rcstr::{RcStr, rcstr};
6161
use turbo_tasks::{
6262
ApplyEffectsContext, Completion, InvalidationReason, Invalidator, NonLocalValue, ReadRef,
6363
ResolvedVc, TaskInput, ValueToString, Vc, debug::ValueDebugFormat, effect,
64-
mark_session_dependent, mark_stateful, parallel, trace::TraceRawVcs,
64+
mark_session_dependent, parallel, trace::TraceRawVcs,
6565
};
6666
use turbo_tasks_hash::{DeterministicHash, DeterministicHasher, hash_xxh3_hash64};
6767
use turbo_unix_path::{
@@ -637,8 +637,6 @@ impl DiskFileSystem {
637637
impl DiskFileSystem {
638638
#[turbo_tasks::function]
639639
fn new_internal(name: RcStr, root: RcStr, denied_path: Option<RcStr>) -> Vc<Self> {
640-
mark_stateful();
641-
642640
let instance = DiskFileSystem {
643641
inner: Arc::new(DiskFileSystemInner {
644642
name,

turbopack/crates/turbo-tasks/src/backend.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,6 @@ pub trait Backend: Sync + Send {
427427
task: TaskId,
428428
result: Result<RawVc, TurboTasksExecutionError>,
429429
cell_counters: &AutoMap<ValueTypeId, u32, BuildHasherDefault<FxHasher>, 8>,
430-
stateful: bool,
431430
has_invalidator: bool,
432431
turbo_tasks: &dyn TurboTasksBackendApi<Self>,
433432
) -> bool;

turbopack/crates/turbo-tasks/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ pub use crate::{
112112
manager::{
113113
CurrentCellRef, ReadConsistency, ReadTracking, TaskPersistence, TurboTasks, TurboTasksApi,
114114
TurboTasksBackendApi, TurboTasksCallApi, Unused, UpdateInfo, dynamic_call, emit,
115-
mark_finished, mark_root, mark_session_dependent, mark_stateful, prevent_gc, run, run_once,
116-
run_once_with_reason, trait_call, turbo_tasks, turbo_tasks_scope,
115+
get_serialization_invalidator, mark_finished, mark_root, mark_session_dependent,
116+
prevent_gc, run, run_once, run_once_with_reason, trait_call, turbo_tasks,
117+
turbo_tasks_scope,
117118
},
118119
output::OutputContent,
119120
raw_vc::{CellId, RawVc, ReadRawVcFuture, ResolveTypeError},

turbopack/crates/turbo-tasks/src/manager.rs

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,6 @@ struct CurrentTaskState {
377377
task_id: Option<TaskId>,
378378
execution_id: ExecutionId,
379379

380-
/// True if the current task has state in cells
381-
stateful: bool,
382-
383380
/// True if the current task uses an external invalidator
384381
has_invalidator: bool,
385382

@@ -402,7 +399,6 @@ impl CurrentTaskState {
402399
Self {
403400
task_id: Some(task_id),
404401
execution_id,
405-
stateful: false,
406402
has_invalidator: false,
407403
cell_counters: Some(AutoMap::default()),
408404
local_tasks: Vec::new(),
@@ -414,7 +410,6 @@ impl CurrentTaskState {
414410
Self {
415411
task_id: None,
416412
execution_id,
417-
stateful: false,
418413
has_invalidator: false,
419414
cell_counters: None,
420415
local_tasks: Vec::new(),
@@ -732,17 +727,14 @@ impl<B: Backend + 'static> TurboTasks<B> {
732727
Err(err) => Err(TurboTasksExecutionError::Panic(Arc::new(err))),
733728
};
734729

735-
let FinishedTaskState {
736-
stateful,
737-
has_invalidator,
738-
} = this.finish_current_task_state();
730+
let FinishedTaskState { has_invalidator } =
731+
this.finish_current_task_state();
739732
let cell_counters = CURRENT_TASK_STATE
740733
.with(|ts| ts.write().unwrap().cell_counters.take().unwrap());
741734
this.backend.task_execution_completed(
742735
task_id,
743736
result,
744737
&cell_counters,
745-
stateful,
746738
has_invalidator,
747739
&*this,
748740
)
@@ -1129,19 +1121,14 @@ impl<B: Backend + 'static> TurboTasks<B> {
11291121
}
11301122

11311123
fn finish_current_task_state(&self) -> FinishedTaskState {
1132-
let (stateful, has_invalidator) = CURRENT_TASK_STATE.with(|cell| {
1124+
let has_invalidator = CURRENT_TASK_STATE.with(|cell| {
11331125
let CurrentTaskState {
1134-
stateful,
1135-
has_invalidator,
1136-
..
1126+
has_invalidator, ..
11371127
} = &mut *cell.write().unwrap();
1138-
(*stateful, *has_invalidator)
1128+
*has_invalidator
11391129
});
11401130

1141-
FinishedTaskState {
1142-
stateful,
1143-
has_invalidator,
1144-
}
1131+
FinishedTaskState { has_invalidator }
11451132
}
11461133

11471134
pub fn backend(&self) -> &B {
@@ -1150,9 +1137,6 @@ impl<B: Backend + 'static> TurboTasks<B> {
11501137
}
11511138

11521139
struct FinishedTaskState {
1153-
/// True if the task has state in cells
1154-
stateful: bool,
1155-
11561140
/// True if the task uses an external invalidator
11571141
has_invalidator: bool,
11581142
}
@@ -1665,20 +1649,15 @@ pub fn mark_finished() {
16651649
});
16661650
}
16671651

1668-
/// Marks the current task as stateful. This prevents the tasks from being
1669-
/// dropped without persisting the state.
1670-
///
16711652
/// Returns a [`SerializationInvalidator`] that can be used to invalidate the
16721653
/// serialization of the current task cells
1673-
pub fn mark_stateful() -> SerializationInvalidator {
1654+
pub fn get_serialization_invalidator() -> SerializationInvalidator {
16741655
CURRENT_TASK_STATE.with(|cell| {
1675-
let CurrentTaskState {
1676-
stateful, task_id, ..
1677-
} = &mut *cell.write().unwrap();
1678-
*stateful = true;
1656+
let CurrentTaskState { task_id, .. } = &mut *cell.write().unwrap();
16791657
let Some(task_id) = *task_id else {
16801658
panic!(
1681-
"mark_stateful() can only be used in the context of a turbo_tasks task execution"
1659+
"get_serialization_invalidator() can only be used in the context of a turbo_tasks \
1660+
task execution"
16821661
);
16831662
};
16841663
SerializationInvalidator::new(task_id)
@@ -1695,8 +1674,7 @@ pub fn mark_invalidator() {
16951674
}
16961675

16971676
pub fn prevent_gc() {
1698-
// There is a hack in UpdateCellOperation that need to be updated when this is changed.
1699-
mark_stateful();
1677+
// TODO implement garbage collection
17001678
}
17011679

17021680
pub fn emit<T: VcValueTrait + ?Sized>(collectible: ResolvedVc<T>) {

turbopack/crates/turbo-tasks/src/state.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use parking_lot::{Mutex, MutexGuard};
1111
use tracing::trace_span;
1212

1313
use crate::{
14-
Invalidator, OperationValue, SerializationInvalidator, get_invalidator, mark_session_dependent,
15-
mark_stateful, trace::TraceRawVcs,
14+
Invalidator, OperationValue, SerializationInvalidator, get_invalidator,
15+
get_serialization_invalidator, mark_session_dependent, trace::TraceRawVcs,
1616
};
1717

1818
#[derive(Encode, Decode)]
@@ -201,7 +201,7 @@ impl<T> State<T> {
201201
T: OperationValue,
202202
{
203203
Self {
204-
serialization_invalidator: mark_stateful(),
204+
serialization_invalidator: get_serialization_invalidator(),
205205
inner: Mutex::new(StateInner::new(value)),
206206
}
207207
}
@@ -312,7 +312,6 @@ impl<T> Eq for TransientState<T> {}
312312

313313
impl<T> TransientState<T> {
314314
pub fn new() -> Self {
315-
mark_stateful();
316315
Self {
317316
inner: Mutex::new(StateInner::new(None)),
318317
}

0 commit comments

Comments
 (0)