Skip to content

Commit 82acf13

Browse files
committed
count as dirty when self dirty or container dirty
1 parent c807112 commit 82acf13

File tree

3 files changed

+63
-72
lines changed

3 files changed

+63
-72
lines changed

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

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,32 +2347,31 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
23472347

23482348
// Grab the old dirty state
23492349
let old_dirtyness = get!(task, Dirty).cloned();
2350-
let (was_dirty, was_current_session_clean, old_clean_in_session) = match old_dirtyness {
2351-
None => (false, false, None),
2352-
Some(Dirtyness::Dirty) => (true, false, None),
2353-
Some(Dirtyness::SessionDependent) => {
2354-
let clean_in_session = get!(task, CleanInSession).copied();
2355-
(
2356-
true,
2357-
clean_in_session == Some(self.session_id),
2358-
clean_in_session,
2359-
)
2360-
}
2361-
};
2362-
let old_dirty_value = if was_dirty { 1 } else { 0 };
2363-
let old_current_session_clean_value = if was_current_session_clean { 1 } else { 0 };
2350+
let (old_self_dirty, old_current_session_self_clean, old_clean_in_session) =
2351+
match old_dirtyness {
2352+
None => (false, false, None),
2353+
Some(Dirtyness::Dirty) => (true, false, None),
2354+
Some(Dirtyness::SessionDependent) => {
2355+
let clean_in_session = get!(task, CleanInSession).copied();
2356+
(
2357+
true,
2358+
clean_in_session == Some(self.session_id),
2359+
clean_in_session,
2360+
)
2361+
}
2362+
};
23642363

23652364
// Compute the new dirty state
2366-
let (new_dirtyness, new_clean_in_session, new_dirty_value, new_current_session_clean_value) =
2365+
let (new_dirtyness, new_clean_in_session, new_self_dirty, new_current_session_self_clean) =
23672366
if session_dependent {
23682367
(
23692368
Some(Dirtyness::SessionDependent),
23702369
Some(self.session_id),
2371-
1,
2372-
1,
2370+
true,
2371+
true,
23732372
)
23742373
} else {
2375-
(None, None, 0, 0)
2374+
(None, None, false, false)
23762375
};
23772376

23782377
// Update the dirty state
@@ -2392,8 +2391,8 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
23922391
}
23932392

23942393
// Propagate dirtyness changes
2395-
let data_update = if old_dirty_value != new_dirty_value
2396-
|| old_current_session_clean_value != new_current_session_clean_value
2394+
let data_update = if old_self_dirty != new_self_dirty
2395+
|| old_current_session_self_clean != new_current_session_self_clean
23972396
{
23982397
let dirty_container_count = get!(task, AggregatedDirtyContainerCount)
23992398
.cloned()
@@ -2411,10 +2410,10 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
24112410
new_dirty_container_count: dirty_container_count,
24122411
old_current_session_clean_container_count: current_session_clean_container_count,
24132412
new_current_session_clean_container_count: current_session_clean_container_count,
2414-
old_dirty_value,
2415-
new_dirty_value,
2416-
old_current_session_clean_value,
2417-
new_current_session_clean_value,
2413+
old_self_dirty,
2414+
new_self_dirty,
2415+
old_current_session_self_clean,
2416+
new_current_session_self_clean,
24182417
}
24192418
.compute();
24202419
result

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

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ pub struct ComputeDirtyAndCleanUpdate {
9999
pub new_dirty_container_count: i32,
100100
pub old_current_session_clean_container_count: i32,
101101
pub new_current_session_clean_container_count: i32,
102-
pub old_dirty_value: i32,
103-
pub new_dirty_value: i32,
104-
pub old_current_session_clean_value: i32,
105-
pub new_current_session_clean_value: i32,
102+
pub old_self_dirty: bool,
103+
pub new_self_dirty: bool,
104+
pub old_current_session_self_clean: bool,
105+
pub new_current_session_self_clean: bool,
106106
}
107107

108108
pub struct ComputeDirtyAndCleanUpdateResult {
@@ -117,23 +117,19 @@ impl ComputeDirtyAndCleanUpdate {
117117
new_dirty_container_count,
118118
old_current_session_clean_container_count,
119119
new_current_session_clean_container_count,
120-
old_dirty_value,
121-
new_dirty_value,
122-
old_current_session_clean_value,
123-
new_current_session_clean_value,
120+
old_self_dirty,
121+
new_self_dirty,
122+
old_current_session_self_clean,
123+
new_current_session_self_clean,
124124
} = self;
125-
let was_dirty_without_clean = old_dirty_container_count + old_dirty_value > 0;
126-
let is_dirty_without_clean = new_dirty_container_count + new_dirty_value > 0;
127-
let was_dirty = was_dirty_without_clean
128-
&& old_dirty_container_count + old_dirty_value
129-
- old_current_session_clean_container_count
130-
- old_current_session_clean_value
131-
> 0;
132-
let is_dirty = is_dirty_without_clean
133-
&& new_dirty_container_count + new_dirty_value
134-
- new_current_session_clean_container_count
135-
- new_current_session_clean_value
136-
> 0;
125+
let was_dirty_without_clean = old_self_dirty || old_dirty_container_count > 0;
126+
let is_dirty_without_clean = new_self_dirty || new_dirty_container_count > 0;
127+
let was_dirty = old_self_dirty && !old_current_session_self_clean
128+
|| old_dirty_container_count > 0
129+
&& old_dirty_container_count > old_current_session_clean_container_count;
130+
let is_dirty = new_self_dirty && !new_current_session_self_clean
131+
|| new_dirty_container_count > 0
132+
&& new_dirty_container_count > new_current_session_clean_container_count;
137133
let was_flagged_clean = was_dirty_without_clean && !was_dirty;
138134
let is_flagged_clean = is_dirty_without_clean && !is_dirty;
139135

@@ -501,9 +497,7 @@ impl AggregatedDataUpdate {
501497
before_after_to_diff_value(was_single_container_clean, is_single_container_clean);
502498

503499
if dirty_container_count_update != 0 || current_session_clean_update != 0 {
504-
let (is_dirty, current_session_clean) = task.dirty(current_session_id);
505-
let dirty_value = if is_dirty { 1 } else { 0 };
506-
let clean_value = if current_session_clean { 1 } else { 0 };
500+
let (is_self_dirty, current_session_self_clean) = task.dirty(current_session_id);
507501

508502
let task_id = task.id();
509503

@@ -525,8 +519,8 @@ impl AggregatedDataUpdate {
525519
old_dirty_container_count = new_dirty_container_count;
526520
};
527521

528-
let was_dirty_without_clean = old_dirty_container_count + dirty_value > 0;
529-
let is_dirty_without_clean = new_dirty_container_count + dirty_value > 0;
522+
let was_dirty_without_clean = is_self_dirty || old_dirty_container_count > 0;
523+
let is_dirty_without_clean = is_self_dirty || new_dirty_container_count > 0;
530524

531525
let upper_count_update =
532526
before_after_to_diff_value(was_dirty_without_clean, is_dirty_without_clean);
@@ -557,16 +551,14 @@ impl AggregatedDataUpdate {
557551
new_current_session_clean_container_count;
558552
};
559553

560-
let was_dirty = was_dirty_without_clean
561-
&& old_dirty_container_count + dirty_value
562-
- old_current_session_clean_container_count
563-
- clean_value
564-
> 0;
565-
let is_dirty = is_dirty_without_clean
566-
&& new_dirty_container_count + dirty_value
567-
- new_current_session_clean_container_count
568-
- clean_value
569-
> 0;
554+
let was_dirty = is_self_dirty && !current_session_self_clean
555+
|| old_dirty_container_count > 0
556+
&& old_dirty_container_count - old_current_session_clean_container_count
557+
> 0;
558+
let is_dirty = is_self_dirty && !current_session_self_clean
559+
|| new_dirty_container_count > 0
560+
&& new_dirty_container_count - new_current_session_clean_container_count
561+
> 0;
570562

571563
let was_flagged_clean = was_dirty_without_clean && !was_dirty;
572564
let is_flagged_clean = is_dirty_without_clean && !is_dirty;
@@ -578,10 +570,10 @@ impl AggregatedDataUpdate {
578570
new_dirty_container_count,
579571
old_current_session_clean_container_count,
580572
new_current_session_clean_container_count,
581-
old_dirty_value: dirty_value,
582-
new_dirty_value: dirty_value,
583-
old_current_session_clean_value: clean_value,
584-
new_current_session_clean_value: clean_value,
573+
old_self_dirty: is_self_dirty,
574+
new_self_dirty: is_self_dirty,
575+
old_current_session_self_clean: current_session_self_clean,
576+
new_current_session_self_clean: current_session_self_clean,
585577
}
586578
.compute();
587579
assert_eq!(compute_result.dirty_count_update, upper_count_update);

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ pub fn make_task_dirty_internal(
234234
let old = task.insert(CachedDataItem::Dirty {
235235
value: Dirtyness::Dirty,
236236
});
237-
let (old_dirty_value, old_current_session_clean_value) = match old {
237+
let (old_self_dirty, old_current_session_self_clean) = match old {
238238
Some(CachedDataItemValue::Dirty {
239239
value: Dirtyness::Dirty,
240240
}) => {
@@ -259,7 +259,7 @@ pub fn make_task_dirty_internal(
259259
{
260260
// There was a clean count for a session. If it was the current session, we need to
261261
// propagate that change.
262-
(1, 1)
262+
(true, true)
263263
} else {
264264
#[cfg(feature = "trace_task_dirty")]
265265
let _span = tracing::trace_span!(
@@ -274,13 +274,13 @@ pub fn make_task_dirty_internal(
274274
}
275275
None => {
276276
// It was clean before, so we need to increase the dirty count
277-
(0, 0)
277+
(false, false)
278278
}
279279
_ => unreachable!(),
280280
};
281281

282-
let new_dirty_value = 1;
283-
let new_current_session_clean_value = 0;
282+
let new_self_dirty = true;
283+
let new_current_session_self_clean = false;
284284

285285
let dirty_container_count = get!(task, AggregatedDirtyContainerCount)
286286
.copied()
@@ -308,10 +308,10 @@ pub fn make_task_dirty_internal(
308308
new_dirty_container_count: dirty_container_count,
309309
old_current_session_clean_container_count: current_session_clean_container_count,
310310
new_current_session_clean_container_count: current_session_clean_container_count,
311-
old_dirty_value,
312-
new_dirty_value,
313-
old_current_session_clean_value,
314-
new_current_session_clean_value,
311+
old_self_dirty,
312+
new_self_dirty,
313+
old_current_session_self_clean,
314+
new_current_session_self_clean,
315315
}
316316
.compute();
317317

0 commit comments

Comments
 (0)