Skip to content

Commit 75ab6b0

Browse files
authored
chore(turbo-tasks): Clean up consistency/untracked APIs around local outputs and cells (#75171)
We only read data owned by the the currently-executing task when reading from a local Vc, so: - A separate "untracked" API doesn't make sense. There's never any tracking needed for reading local outputs or cells. (would we mark the current task as dependent on itself?) - Allowing a `consistency` argument isn't useful because you can't strongly consistently await your own task. - We don't need to call `notify_scheduled_tasks`, we're not adding any new task dependencies.
1 parent 66d3b9a commit 75ab6b0

File tree

3 files changed

+25
-73
lines changed

3 files changed

+25
-73
lines changed

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,19 +228,9 @@ impl TurboTasksApi for VcStorage {
228228
}
229229

230230
fn try_read_local_output(
231-
&self,
232-
parent_task_id: TaskId,
233-
local_task_id: LocalTaskId,
234-
consistency: ReadConsistency,
235-
) -> Result<Result<RawVc, EventListener>> {
236-
self.try_read_local_output_untracked(parent_task_id, local_task_id, consistency)
237-
}
238-
239-
fn try_read_local_output_untracked(
240231
&self,
241232
_parent_task_id: TaskId,
242233
_local_task_id: LocalTaskId,
243-
_consistency: ReadConsistency,
244234
) -> Result<Result<RawVc, EventListener>> {
245235
unimplemented!()
246236
}

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

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,13 @@ pub trait TurboTasksApi: TurboTasksCallApi + Sync + Send {
137137
index: CellId,
138138
) -> Result<Result<TypedCellContent, EventListener>>;
139139

140+
/// This does not accept a consistency argument, as you cannot control consistency of a read of
141+
/// an operation owned by your own task. Strongly consistent reads are only allowed on
142+
/// `OperationVc`s, which should never be local tasks.
140143
fn try_read_local_output(
141144
&self,
142145
parent_task_id: TaskId,
143146
local_task_id: LocalTaskId,
144-
consistency: ReadConsistency,
145-
) -> Result<Result<RawVc, EventListener>>;
146-
147-
/// INVALIDATION: Be careful with this, it will not track dependencies, so
148-
/// using it could break cache invalidation.
149-
fn try_read_local_output_untracked(
150-
&self,
151-
parent_task_id: TaskId,
152-
local_task_id: LocalTaskId,
153-
consistency: ReadConsistency,
154147
) -> Result<Result<RawVc, EventListener>>;
155148

156149
fn read_task_collectibles(&self, task: TaskId, trait_id: TraitTypeId) -> TaskCollectiblesMap;
@@ -335,7 +328,7 @@ pub enum TaskPersistence {
335328
LocalCells,
336329
}
337330

338-
#[derive(Clone, Copy, Eq, PartialEq)]
331+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
339332
pub enum ReadConsistency {
340333
/// The default behavior for most APIs. Reads are faster, but may return stale values, which
341334
/// may later trigger re-computation.
@@ -1323,26 +1316,16 @@ impl<B: Backend + 'static> TurboTasksApi for TurboTasks<B> {
13231316
&self,
13241317
parent_task_id: TaskId,
13251318
local_task_id: LocalTaskId,
1326-
consistency: ReadConsistency,
1327-
) -> Result<Result<RawVc, EventListener>> {
1328-
// we don't currently support reading a local output outside of it's own task, so
1329-
// tracked/untracked is currently irrelevant
1330-
self.try_read_local_output_untracked(parent_task_id, local_task_id, consistency)
1331-
}
1332-
1333-
/// INVALIDATION: Be careful with this, it will not track dependencies, so
1334-
/// using it could break cache invalidation.
1335-
fn try_read_local_output_untracked(
1336-
&self,
1337-
parent_task_id: TaskId,
1338-
local_task_id: LocalTaskId,
1339-
// we don't currently support reading a local output outside of it's own task, so
1340-
// consistency is currently irrelevant
1341-
_consistency: ReadConsistency,
13421319
) -> Result<Result<RawVc, EventListener>> {
13431320
CURRENT_GLOBAL_TASK_STATE.with(|gts| {
13441321
let gts_read = gts.read().unwrap();
1322+
1323+
// Local Vcs are local to their parent task, and do not exist outside of it. This is
1324+
// weakly enforced at compile time using the `NonLocalValue` marker trait. This
1325+
// assertion exists to handle any potential escapes that the compile-time checks cannot
1326+
// capture.
13451327
gts_read.assert_task_id(parent_task_id);
1328+
13461329
match gts_read.get_local_task(local_task_id) {
13471330
LocalTask::Scheduled { done_event } => Ok(Err(done_event.listen())),
13481331
LocalTask::Done { output } => Ok(Ok(output.as_read_result()?)),
@@ -2051,10 +2034,9 @@ pub(crate) async fn read_local_output(
20512034
this: &dyn TurboTasksApi,
20522035
parent_task_id: TaskId,
20532036
local_task_id: LocalTaskId,
2054-
consistency: ReadConsistency,
20552037
) -> Result<RawVc> {
20562038
loop {
2057-
match this.try_read_local_output(parent_task_id, local_task_id, consistency)? {
2039+
match this.try_read_local_output(parent_task_id, local_task_id)? {
20582040
Ok(raw_vc) => return Ok(raw_vc),
20592041
Err(event_listener) => event_listener.await,
20602042
}

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

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,9 @@ impl RawVc {
178178
}
179179
}
180180
RawVc::LocalOutput(task_id, local_cell_id) => {
181-
current =
182-
read_local_output(&*tt, task_id, local_cell_id, ReadConsistency::Eventual)
183-
.await
184-
.map_err(|source| ResolveTypeError::TaskError { source })?;
181+
current = read_local_output(&*tt, task_id, local_cell_id)
182+
.await
183+
.map_err(|source| ResolveTypeError::TaskError { source })?;
185184
}
186185
RawVc::LocalCell(execution_id, local_cell_id) => {
187186
let shared_reference = read_local_cell(execution_id, local_cell_id);
@@ -214,24 +213,22 @@ impl RawVc {
214213
let tt = turbo_tasks();
215214
let mut current = self;
216215
let mut notified = false;
217-
let mut lazily_notify = || {
218-
if !notified {
219-
tt.notify_scheduled_tasks();
220-
notified = true;
221-
}
222-
};
223216
loop {
224217
match current {
225218
RawVc::TaskOutput(task) => {
226-
lazily_notify();
219+
if !notified {
220+
tt.notify_scheduled_tasks();
221+
notified = true;
222+
}
227223
current = read_task_output(&*tt, task, consistency).await?;
228224
}
229225
RawVc::TaskCell(_, _) => return Ok(current),
230226
RawVc::LocalOutput(task_id, local_cell_id) => {
231-
lazily_notify();
232-
current = read_local_output(&*tt, task_id, local_cell_id, consistency).await?;
227+
debug_assert_eq!(consistency, ReadConsistency::Eventual);
228+
current = read_local_output(&*tt, task_id, local_cell_id).await?;
233229
}
234230
RawVc::LocalCell(execution_id, local_cell_id) => {
231+
debug_assert_eq!(consistency, ReadConsistency::Eventual);
235232
let shared_reference = read_local_cell(execution_id, local_cell_id);
236233
let value_type = get_value_type(shared_reference.0);
237234
return Ok((value_type.raw_cell)(shared_reference));
@@ -245,20 +242,10 @@ impl RawVc {
245242
pub(crate) async fn to_non_local(self) -> Result<RawVc> {
246243
let tt = turbo_tasks();
247244
let mut current = self;
248-
let mut notified = false;
249-
let mut lazily_notify = || {
250-
if !notified {
251-
tt.notify_scheduled_tasks();
252-
notified = true;
253-
}
254-
};
255245
loop {
256246
match current {
257247
RawVc::LocalOutput(task_id, local_cell_id) => {
258-
lazily_notify();
259-
current =
260-
read_local_output(&*tt, task_id, local_cell_id, ReadConsistency::Eventual)
261-
.await?;
248+
current = read_local_output(&*tt, task_id, local_cell_id).await?;
262249
}
263250
RawVc::LocalCell(execution_id, local_cell_id) => {
264251
let shared_reference = read_local_cell(execution_id, local_cell_id);
@@ -435,18 +422,10 @@ impl Future for ReadRawVcFuture {
435422
}
436423
}
437424
RawVc::LocalOutput(task_id, local_output_id) => {
438-
let read_result = if this.untracked {
439-
tt.try_read_local_output_untracked(
440-
task_id,
441-
local_output_id,
442-
this.consistency,
443-
)
444-
} else {
445-
tt.try_read_local_output(task_id, local_output_id, this.consistency)
446-
};
425+
debug_assert_eq!(this.consistency, ReadConsistency::Eventual);
426+
let read_result = tt.try_read_local_output(task_id, local_output_id);
447427
match read_result {
448428
Ok(Ok(vc)) => {
449-
this.consistency = ReadConsistency::Eventual;
450429
this.current = vc;
451430
continue 'outer;
452431
}
@@ -455,6 +434,7 @@ impl Future for ReadRawVcFuture {
455434
}
456435
}
457436
RawVc::LocalCell(execution_id, local_cell_id) => {
437+
debug_assert_eq!(this.consistency, ReadConsistency::Eventual);
458438
return Poll::Ready(
459439
Ok(read_local_cell(execution_id, local_cell_id).into()),
460440
);

0 commit comments

Comments
 (0)