Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 30 additions & 19 deletions turbopack/crates/turbo-tasks-backend/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use tokio::time::{Duration, Instant};
use tracing::{Span, field::Empty, info_span, trace_span};
use turbo_tasks::{
CellId, FxDashMap, FxIndexMap, KeyValuePair, RawVc, ReadCellOptions, ReadConsistency,
SessionId, TRANSIENT_TASK_BIT, TaskExecutionReason, TaskId, TraitTypeId, TurboTasksBackendApi,
ValueTypeId,
ReadOutputOptions, ReadTracking, SessionId, TRANSIENT_TASK_BIT, TaskExecutionReason, TaskId,
TraitTypeId, TurboTasksBackendApi, ValueTypeId,
backend::{
Backend, CachedTaskType, CellContent, TaskExecutionSpec, TransientTaskRoot,
TransientTaskType, TurboTasksExecutionError, TypedCellContent,
Expand Down Expand Up @@ -458,7 +458,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
self: &Arc<Self>,
task_id: TaskId,
reader: Option<TaskId>,
consistency: ReadConsistency,
options: ReadOutputOptions,
turbo_tasks: &dyn TurboTasksBackendApi<TurboTasksBackend<B>>,
) -> Result<Result<RawVc, EventListener>> {
self.assert_not_persistent_calling_transient(reader, task_id, /* cell_id */ None);
Expand All @@ -469,15 +469,16 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
fn listen_to_done_event<B: BackingStorage>(
this: &TurboTasksBackendInner<B>,
reader: Option<TaskId>,
tracking: ReadTracking,
done_event: &Event,
) -> EventListener {
done_event.listen_with_note(move || {
let reader_desc = reader.map(|r| this.get_task_desc_fn(r));
move || {
if let Some(reader_desc) = reader_desc.as_ref() {
format!("try_read_task_output from {}", reader_desc())
format!("try_read_task_output from {} ({})", reader_desc(), tracking)
} else {
"try_read_task_output (untracked)".to_string()
format!("try_read_task_output ({})", tracking)
}
}
})
Expand All @@ -487,16 +488,19 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
this: &TurboTasksBackendInner<B>,
task: &impl TaskGuard,
reader: Option<TaskId>,
tracking: ReadTracking,
ctx: &impl ExecuteContext<'_>,
) -> Option<std::result::Result<std::result::Result<RawVc, EventListener>, anyhow::Error>>
{
match get!(task, InProgress) {
Some(InProgressState::Scheduled { done_event, .. }) => {
Some(Ok(Err(listen_to_done_event(this, reader, done_event))))
}
Some(InProgressState::Scheduled { done_event, .. }) => Some(Ok(Err(
listen_to_done_event(this, reader, tracking, done_event),
))),
Some(InProgressState::InProgress(box InProgressStateInner {
done_event, ..
})) => Some(Ok(Err(listen_to_done_event(this, reader, done_event)))),
})) => Some(Ok(Err(listen_to_done_event(
this, reader, tracking, done_event,
)))),
Some(InProgressState::Canceled) => Some(Err(anyhow::anyhow!(
"{} was canceled",
ctx.get_task_description(task.id())
Expand All @@ -505,7 +509,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
}
}

if matches!(consistency, ReadConsistency::Strong) {
if matches!(options.consistency, ReadConsistency::Strong) {
// Ensure it's an root node
loop {
let aggregation_number = get_aggregation_number(&task);
Expand Down Expand Up @@ -687,7 +691,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
}
}

if let Some(value) = check_in_progress(self, &task, reader, &ctx) {
if let Some(value) = check_in_progress(self, &task, reader, options.tracking, &ctx) {
return value;
}

Expand All @@ -705,6 +709,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
};
if self.should_track_dependencies()
&& let Some(reader) = reader
&& options.tracking.should_track(result.is_err())
&& (!task.is_immutable() || cfg!(feature = "verify_immutable"))
{
let _ = task.add(CachedDataItem::OutputDependent {
Expand Down Expand Up @@ -810,7 +815,9 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
None
};
if let Some(content) = content {
add_cell_dependency(self, task, reader, cell, task_id, &mut ctx);
if options.tracking.should_track(false) {
add_cell_dependency(self, task, reader, cell, task_id, &mut ctx);
}
return Ok(Ok(TypedCellContent(
cell.type_id,
CellContent(Some(content.reference)),
Expand All @@ -835,14 +842,18 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
)
.copied();
let Some(max_id) = max_id else {
add_cell_dependency(self, task, reader, cell, task_id, &mut ctx);
if options.tracking.should_track(true) {
add_cell_dependency(self, task, reader, cell, task_id, &mut ctx);
}
bail!(
"Cell {cell:?} no longer exists in task {} (no cell of this type exists)",
ctx.get_task_description(task_id)
);
};
if cell.index >= max_id {
add_cell_dependency(self, task, reader, cell, task_id, &mut ctx);
if options.tracking.should_track(true) {
add_cell_dependency(self, task, reader, cell, task_id, &mut ctx);
}
bail!(
"Cell {cell:?} no longer exists in task {} (index out of bounds)",
ctx.get_task_description(task_id)
Expand Down Expand Up @@ -2457,7 +2468,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
})
}

fn try_read_own_task_cell_untracked(
fn try_read_own_task_cell(
&self,
task_id: TaskId,
cell: CellId,
Expand Down Expand Up @@ -3139,11 +3150,11 @@ impl<B: BackingStorage> Backend for TurboTasksBackend<B> {
&self,
task_id: TaskId,
reader: Option<TaskId>,
consistency: ReadConsistency,
options: ReadOutputOptions,
turbo_tasks: &dyn TurboTasksBackendApi<Self>,
) -> Result<Result<RawVc, EventListener>> {
self.0
.try_read_task_output(task_id, reader, consistency, turbo_tasks)
.try_read_task_output(task_id, reader, options, turbo_tasks)
}

fn try_read_task_cell(
Expand All @@ -3158,15 +3169,15 @@ impl<B: BackingStorage> Backend for TurboTasksBackend<B> {
.try_read_task_cell(task_id, reader, cell, options, turbo_tasks)
}

fn try_read_own_task_cell_untracked(
fn try_read_own_task_cell(
&self,
task_id: TaskId,
cell: CellId,
options: ReadCellOptions,
turbo_tasks: &dyn TurboTasksBackendApi<Self>,
) -> Result<TypedCellContent> {
self.0
.try_read_own_task_cell_untracked(task_id, cell, options, turbo_tasks)
.try_read_own_task_cell(task_id, cell, options, turbo_tasks)
}

fn read_task_collectibles(
Expand Down
30 changes: 3 additions & 27 deletions turbopack/crates/turbo-tasks-testing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use rustc_hash::FxHashMap;
use tokio::sync::mpsc::Receiver;
use turbo_tasks::{
CellId, ExecutionId, InvalidationReason, LocalTaskId, MagicAny, RawVc, ReadCellOptions,
ReadConsistency, TaskId, TaskPersistence, TraitTypeId, TurboTasksApi, TurboTasksCallApi,
ReadOutputOptions, TaskId, TaskPersistence, TraitTypeId, TurboTasksApi, TurboTasksCallApi,
backend::{CellContent, TaskCollectiblesMap, TypedCellContent},
event::{Event, EventListener},
message_queue::CompilationEvent,
Expand Down Expand Up @@ -176,7 +176,7 @@ impl TurboTasksApi for VcStorage {
fn try_read_task_output(
&self,
id: TaskId,
_consistency: ReadConsistency,
_options: ReadOutputOptions,
) -> Result<Result<RawVc, EventListener>> {
let tasks = self.tasks.lock().unwrap();
let i = *id - 1;
Expand All @@ -190,14 +190,6 @@ impl TurboTasksApi for VcStorage {
}
}

fn try_read_task_output_untracked(
&self,
task: TaskId,
consistency: ReadConsistency,
) -> Result<Result<RawVc, EventListener>> {
self.try_read_task_output(task, consistency)
}

fn try_read_task_cell(
&self,
task: TaskId,
Expand All @@ -212,23 +204,7 @@ impl TurboTasksApi for VcStorage {
}
.into_typed(index.type_id)))
}

fn try_read_task_cell_untracked(
&self,
task: TaskId,
index: CellId,
_options: ReadCellOptions,
) -> Result<Result<TypedCellContent, EventListener>> {
let map = self.cells.lock().unwrap();
Ok(Ok(if let Some(cell) = map.get(&(task, index)) {
cell.to_owned()
} else {
Default::default()
}
.into_typed(index.type_id)))
}

fn try_read_own_task_cell_untracked(
fn try_read_own_task_cell(
&self,
current_task: TaskId,
index: CellId,
Expand Down
19 changes: 7 additions & 12 deletions turbopack/crates/turbo-tasks/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,11 @@ use tracing::Span;
use turbo_rcstr::RcStr;

use crate::{
RawVc, ReadCellOptions, ReadRef, SharedReference, TaskId, TaskIdSet, TraitRef, TraitTypeId,
TurboTasksPanic, ValueTypeId, VcRead, VcValueTrait, VcValueType,
event::EventListener,
macro_helpers::NativeFunction,
magic_any::MagicAny,
manager::{ReadConsistency, TurboTasksBackendApi},
raw_vc::CellId,
registry,
task::shared_reference::TypedSharedReference,
task_statistics::TaskStatisticsApi,
RawVc, ReadCellOptions, ReadOutputOptions, ReadRef, SharedReference, TaskId, TaskIdSet,
TraitRef, TraitTypeId, TurboTasksPanic, ValueTypeId, VcRead, VcValueTrait, VcValueType,
event::EventListener, macro_helpers::NativeFunction, magic_any::MagicAny,
manager::TurboTasksBackendApi, raw_vc::CellId, registry,
task::shared_reference::TypedSharedReference, task_statistics::TaskStatisticsApi,
triomphe_utils::unchecked_sidecast_triomphe_arc,
};

Expand Down Expand Up @@ -564,7 +559,7 @@ pub trait Backend: Sync + Send {
&self,
task: TaskId,
reader: Option<TaskId>,
consistency: ReadConsistency,
options: ReadOutputOptions,
turbo_tasks: &dyn TurboTasksBackendApi<Self>,
) -> Result<Result<RawVc, EventListener>>;

Expand All @@ -581,7 +576,7 @@ pub trait Backend: Sync + Send {

/// INVALIDATION: Be careful with this, it will not track dependencies, so
/// using it could break cache invalidation.
fn try_read_own_task_cell_untracked(
fn try_read_own_task_cell(
&self,
current_task: TaskId,
index: CellId,
Expand Down
4 changes: 2 additions & 2 deletions turbopack/crates/turbo-tasks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ pub use join_iter_ext::{JoinIterExt, TryFlatJoinIterExt, TryJoinIterExt};
pub use key_value_pair::KeyValuePair;
pub use magic_any::MagicAny;
pub use manager::{
CurrentCellRef, ReadConsistency, TaskPersistence, TurboTasks, TurboTasksApi,
CurrentCellRef, ReadConsistency, ReadTracking, TaskPersistence, TurboTasks, TurboTasksApi,
TurboTasksBackendApi, TurboTasksCallApi, Unused, UpdateInfo, dynamic_call, emit, mark_finished,
mark_root, mark_session_dependent, mark_stateful, prevent_gc, run, run_once,
run_once_with_reason, trait_call, turbo_tasks, turbo_tasks_scope,
};
pub use output::OutputContent;
pub use raw_vc::{CellId, RawVc, ReadRawVcFuture, ResolveTypeError};
pub use read_options::ReadCellOptions;
pub use read_options::{ReadCellOptions, ReadOutputOptions};
pub use read_ref::ReadRef;
use rustc_hash::FxHasher;
pub use serialization_invalidation::SerializationInvalidator;
Expand Down
Loading
Loading