Skip to content

Commit 009e30d

Browse files
authored
Turbopack: remove lazy invalidated tasks (#83845)
### What? Lazy invalidation is no longer used with the new backend
1 parent f6b9857 commit 009e30d

File tree

4 files changed

+8
-97
lines changed

4 files changed

+8
-97
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,6 @@ impl TurboTasksApi for VcStorage {
157157
// ignore
158158
}
159159

160-
fn notify_scheduled_tasks(&self) {
161-
// ignore
162-
}
163-
164160
fn try_read_task_output(
165161
&self,
166162
id: TaskId,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
pub use crate::{
1515
global_name, inventory_submit,
1616
magic_any::MagicAny,
17-
manager::{find_cell_by_type, notify_scheduled_tasks, spawn_detached_for_testing},
17+
manager::{find_cell_by_type, spawn_detached_for_testing},
1818
native_function::{
1919
CollectableFunction, FunctionMeta, NativeFunction, downcast_args_owned, downcast_args_ref,
2020
},

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

Lines changed: 7 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@ use anyhow::{Result, anyhow};
1515
use auto_hash_map::AutoMap;
1616
use rustc_hash::FxHasher;
1717
use serde::{Deserialize, Serialize};
18-
use smallvec::SmallVec;
1918
use tokio::{select, sync::mpsc::Receiver, task_local};
2019
use tokio_util::task::TaskTracker;
21-
use tracing::{Instrument, Level, instrument, trace_span};
20+
use tracing::{Instrument, Level, instrument};
2221

2322
use crate::{
2423
Completion, InvalidationReason, InvalidationReasonSet, OutputContent, ReadCellOptions,
25-
ResolvedVc, SharedReference, TaskId, TaskIdSet, TraitMethod, ValueTypeId, Vc, VcRead,
26-
VcValueTrait, VcValueType,
24+
ResolvedVc, SharedReference, TaskId, TraitMethod, ValueTypeId, Vc, VcRead, VcValueTrait,
25+
VcValueType,
2726
backend::{
2827
Backend, CachedTaskType, CellContent, TaskCollectiblesMap, TaskExecutionSpec,
2928
TransientTaskType, TurboTasksExecutionError, TypedCellContent,
@@ -102,10 +101,6 @@ pub trait TurboTasksApi: TurboTasksCallApi + Sync + Send {
102101

103102
fn invalidate_serialization(&self, task: TaskId);
104103

105-
/// Eagerly notifies all tasks that were scheduled for notifications via
106-
/// `schedule_notify_tasks_set()`
107-
fn notify_scheduled_tasks(&self);
108-
109104
fn try_read_task_output(
110105
&self,
111106
task: TaskId,
@@ -264,14 +259,6 @@ pub trait TurboTasksBackendApi<B: Backend + 'static>: TurboTasksCallApi + Sync +
264259
/// idle even with active background jobs.
265260
fn schedule_backend_background_job(&self, job: B::BackendJob);
266261

267-
/// Enqueues tasks for notification of changed dependencies. This will
268-
/// eventually call `invalidate_tasks()` on all tasks.
269-
fn schedule_notify_tasks(&self, tasks: &[TaskId]);
270-
271-
/// Enqueues tasks for notification of changed dependencies. This will
272-
/// eventually call `invalidate_tasks()` on all tasks.
273-
fn schedule_notify_tasks_set(&self, tasks: &TaskIdSet);
274-
275262
/// Returns the duration from the start of the program to the given instant.
276263
fn program_duration_until(&self, instant: Instant) -> Duration;
277264

@@ -403,11 +390,6 @@ struct CurrentTaskState {
403390
task_id: TaskId,
404391
execution_id: ExecutionId,
405392

406-
/// Affected tasks, that are tracked during task execution. These tasks will
407-
/// be invalidated when the execution finishes or before reading a cell
408-
/// value.
409-
tasks_to_notify: SmallVec<[TaskId; 4]>,
410-
411393
/// True if the current task has state in cells
412394
stateful: bool,
413395

@@ -439,7 +421,6 @@ impl CurrentTaskState {
439421
Self {
440422
task_id,
441423
execution_id,
442-
tasks_to_notify: SmallVec::new(),
443424
stateful: false,
444425
has_invalidator: false,
445426
cell_counters: Some(AutoMap::default()),
@@ -749,18 +730,15 @@ impl<B: Backend + 'static> TurboTasks<B> {
749730
} = this.finish_current_task_state();
750731
let cell_counters = CURRENT_TASK_STATE
751732
.with(|ts| ts.write().unwrap().cell_counters.take().unwrap());
752-
let schedule_again = this.backend.task_execution_completed(
733+
this.backend.task_execution_completed(
753734
task_id,
754735
duration,
755736
alloc_info.memory_usage(),
756737
&cell_counters,
757738
stateful,
758739
has_invalidator,
759740
&*this,
760-
);
761-
// task_execution_completed might need to notify tasks
762-
this.notify_scheduled_tasks();
763-
schedule_again
741+
)
764742
}
765743
.instrument(span)
766744
.await
@@ -1123,19 +1101,15 @@ impl<B: Backend + 'static> TurboTasks<B> {
11231101
}
11241102

11251103
fn finish_current_task_state(&self) -> FinishedTaskState {
1126-
let (stateful, has_invalidator, tasks) = CURRENT_TASK_STATE.with(|cell| {
1104+
let (stateful, has_invalidator) = CURRENT_TASK_STATE.with(|cell| {
11271105
let CurrentTaskState {
1128-
tasks_to_notify,
11291106
stateful,
11301107
has_invalidator,
11311108
..
11321109
} = &mut *cell.write().unwrap();
1133-
(*stateful, *has_invalidator, take(tasks_to_notify))
1110+
(*stateful, *has_invalidator)
11341111
});
11351112

1136-
if !tasks.is_empty() {
1137-
self.backend.invalidate_tasks(&tasks, self);
1138-
}
11391113
FinishedTaskState {
11401114
stateful,
11411115
has_invalidator,
@@ -1245,21 +1219,6 @@ impl<B: Backend + 'static> TurboTasksApi for TurboTasks<B> {
12451219
self.backend.invalidate_serialization(task, self);
12461220
}
12471221

1248-
fn notify_scheduled_tasks(&self) {
1249-
let _ = CURRENT_TASK_STATE.try_with(|cell| {
1250-
let tasks = {
1251-
let CurrentTaskState {
1252-
tasks_to_notify, ..
1253-
} = &mut *cell.write().unwrap();
1254-
take(tasks_to_notify)
1255-
};
1256-
if tasks.is_empty() {
1257-
return;
1258-
}
1259-
self.backend.invalidate_tasks(&tasks, self);
1260-
});
1261-
}
1262-
12631222
fn try_read_task_output(
12641223
&self,
12651224
task: TaskId,
@@ -1475,36 +1434,6 @@ impl<B: Backend + 'static> TurboTasksBackendApi<B> for TurboTasks<B> {
14751434
})
14761435
}
14771436

1478-
/// Enqueues tasks for notification of changed dependencies. This will
1479-
/// eventually call `dependent_cell_updated()` on all tasks.
1480-
fn schedule_notify_tasks(&self, tasks: &[TaskId]) {
1481-
let result = CURRENT_TASK_STATE.try_with(|cell| {
1482-
let CurrentTaskState {
1483-
tasks_to_notify, ..
1484-
} = &mut *cell.write().unwrap();
1485-
tasks_to_notify.extend(tasks.iter().copied());
1486-
});
1487-
if result.is_err() {
1488-
let _guard = trace_span!("schedule_notify_tasks", count = tasks.len()).entered();
1489-
self.backend.invalidate_tasks(tasks, self);
1490-
}
1491-
}
1492-
1493-
/// Enqueues tasks for notification of changed dependencies. This will
1494-
/// eventually call `dependent_cell_updated()` on all tasks.
1495-
fn schedule_notify_tasks_set(&self, tasks: &TaskIdSet) {
1496-
let result = CURRENT_TASK_STATE.try_with(|cell| {
1497-
let CurrentTaskState {
1498-
tasks_to_notify, ..
1499-
} = &mut *cell.write().unwrap();
1500-
tasks_to_notify.extend(tasks.iter().copied());
1501-
});
1502-
if result.is_err() {
1503-
let _guard = trace_span!("schedule_notify_tasks_set", count = tasks.len()).entered();
1504-
self.backend.invalidate_tasks_set(tasks, self);
1505-
};
1506-
}
1507-
15081437
#[track_caller]
15091438
fn schedule(&self, task: TaskId) {
15101439
self.schedule(task)
@@ -1730,11 +1659,6 @@ pub fn prevent_gc() {
17301659
mark_stateful();
17311660
}
17321661

1733-
/// Notifies scheduled tasks for execution.
1734-
pub fn notify_scheduled_tasks() {
1735-
with_turbo_tasks(|tt| tt.notify_scheduled_tasks())
1736-
}
1737-
17381662
pub fn emit<T: VcValueTrait + ?Sized>(collectible: ResolvedVc<T>) {
17391663
with_turbo_tasks(|tt| {
17401664
let raw_vc = collectible.node.node;

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ impl RawVc {
166166
conditional: impl FnOnce(ValueTypeId) -> (bool, Option<&'static ValueType>),
167167
) -> Result<Option<RawVc>, ResolveTypeError> {
168168
let tt = turbo_tasks();
169-
tt.notify_scheduled_tasks();
170169
let mut current = self;
171170
loop {
172171
match current {
@@ -211,14 +210,9 @@ impl RawVc {
211210
async fn resolve_inner(self, mut consistency: ReadConsistency) -> Result<RawVc> {
212211
let tt = turbo_tasks();
213212
let mut current = self;
214-
let mut notified = false;
215213
loop {
216214
match current {
217215
RawVc::TaskOutput(task) => {
218-
if !notified {
219-
tt.notify_scheduled_tasks();
220-
notified = true;
221-
}
222216
current = read_task_output(&*tt, task, consistency).await?;
223217
// We no longer need to read strongly consistent, as any Vc returned
224218
// from the first task will be inside of the scope of the first
@@ -302,7 +296,6 @@ impl CollectiblesSource for RawVc {
302296
);
303297
};
304298
let tt = turbo_tasks();
305-
tt.notify_scheduled_tasks();
306299
let map = tt.read_task_collectibles(task_id, T::get_trait_type_id());
307300
map.into_iter()
308301
.filter_map(|(raw, count)| (count > 0).then_some(raw.try_into().unwrap()))
@@ -317,7 +310,6 @@ impl CollectiblesSource for RawVc {
317310
);
318311
};
319312
let tt = turbo_tasks();
320-
tt.notify_scheduled_tasks();
321313
let map = tt.read_task_collectibles(task_id, T::get_trait_type_id());
322314
tt.unemit_collectibles(T::get_trait_type_id(), &map);
323315
map.into_iter()
@@ -368,7 +360,6 @@ impl Future for ReadRawVcFuture {
368360

369361
fn poll(self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Self::Output> {
370362
with_turbo_tasks(|tt| {
371-
tt.notify_scheduled_tasks();
372363
// SAFETY: we are not moving this
373364
let this = unsafe { self.get_unchecked_mut() };
374365
'outer: loop {

0 commit comments

Comments
 (0)