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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 32 additions & 18 deletions turbopack/crates/turbo-tasks-backend/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use smallvec::{SmallVec, smallvec};
use tokio::time::{Duration, Instant};
use tracing::{Span, trace_span};
use turbo_tasks::{
CellId, FxDashMap, KeyValuePair, RawVc, ReadCellOptions, ReadConsistency, ReadOutputOptions,
ReadTracking, TRANSIENT_TASK_BIT, TaskExecutionReason, TaskId, TraitTypeId,
CellId, FxDashMap, KeyValuePair, RawVc, ReadCellOptions, ReadCellTracking, ReadConsistency,
ReadOutputOptions, ReadTracking, TRANSIENT_TASK_BIT, TaskExecutionReason, TaskId, TraitTypeId,
TurboTasksBackendApi, ValueTypeId,
backend::{
Backend, CachedTaskType, CellContent, TaskExecutionSpec, TransientTaskRoot,
Expand Down Expand Up @@ -791,12 +791,14 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
reader: Option<TaskId>,
reader_task: Option<impl TaskGuard>,
cell: CellId,
key: Option<u64>,
) {
if let Some(mut reader_task) = reader_task
&& (!task.is_immutable() || cfg!(feature = "verify_immutable"))
{
let _ = task.add(CachedDataItem::CellDependent {
cell,
key,
task: reader.unwrap(),
value: (),
});
Expand All @@ -812,10 +814,14 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
cell,
};
if reader_task
.remove(&CachedDataItemKey::OutdatedCellDependency { target })
.remove(&CachedDataItemKey::OutdatedCellDependency { target, key })
.is_none()
{
let _ = reader_task.add(CachedDataItem::CellDependency { target, value: () });
let _ = reader_task.add(CachedDataItem::CellDependency {
target,
key,
value: (),
});
}
}
}
Expand All @@ -828,7 +834,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {

let mut ctx = self.execute_context(turbo_tasks);
let (mut task, reader_task) = if self.should_track_dependencies()
&& !matches!(tracking, ReadTracking::Untracked)
&& !matches!(tracking, ReadCellTracking::Untracked)
&& let Some(reader_id) = reader
&& reader_id != task_id
{
Expand All @@ -848,7 +854,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
};
if let Some(content) = content {
if tracking.should_track(false) {
add_cell_dependency(task_id, task, reader, reader_task, cell);
add_cell_dependency(task_id, task, reader, reader_task, cell, tracking.key());
}
return Ok(Ok(TypedCellContent(
cell.type_id,
Expand All @@ -875,7 +881,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
.copied();
let Some(max_id) = max_id else {
if tracking.should_track(true) {
add_cell_dependency(task_id, task, reader, reader_task, cell);
add_cell_dependency(task_id, task, reader, reader_task, cell, tracking.key());
}
bail!(
"Cell {cell:?} no longer exists in task {} (no cell of this type exists)",
Expand All @@ -884,7 +890,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
};
if cell.index >= max_id {
if tracking.should_track(true) {
add_cell_dependency(task_id, task, reader, reader_task, cell);
add_cell_dependency(task_id, task, reader, reader_task, cell, tracking.key());
}
bail!(
"Cell {cell:?} no longer exists in task {} (index out of bounds)",
Expand Down Expand Up @@ -1684,22 +1690,26 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
if self.should_track_dependencies() {
// Make all dependencies outdated
let outdated_cell_dependencies_to_add =
iter_many!(task, CellDependency { target } => target)
iter_many!(task, CellDependency { target, key } => (target, key))
.collect::<SmallVec<[_; 8]>>();
let outdated_cell_dependencies_to_remove =
iter_many!(task, OutdatedCellDependency { target } => target)
.filter(|&target| {
!task.has_key(&CachedDataItemKey::CellDependency { target })
iter_many!(task, OutdatedCellDependency { target, key } => (target, key))
.filter(|&(target, key)| {
!task.has_key(&CachedDataItemKey::CellDependency { target, key })
})
.collect::<SmallVec<[_; 8]>>();
task.extend(
CachedDataItemType::OutdatedCellDependency,
outdated_cell_dependencies_to_add
.into_iter()
.map(|target| CachedDataItem::OutdatedCellDependency { target, value: () }),
.map(|(target, key)| CachedDataItem::OutdatedCellDependency {
target,
key,
value: (),
}),
);
for target in outdated_cell_dependencies_to_remove {
task.remove(&CachedDataItemKey::OutdatedCellDependency { target });
for (target, key) in outdated_cell_dependencies_to_remove {
task.remove(&CachedDataItemKey::OutdatedCellDependency { target, key });
}

let outdated_output_dependencies_to_add =
Expand Down Expand Up @@ -2000,7 +2010,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
Some(
// Collect all dependencies on tasks to check if all dependencies are immutable
iter_many!(task, OutputDependency { target } => target)
.chain(iter_many!(task, CellDependency { target } => target.task))
.chain(iter_many!(task, CellDependency { target, key: _ } => target.task))
.collect::<FxHashSet<_>>(),
)
} else {
Expand Down Expand Up @@ -2054,10 +2064,10 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
);

if self.should_track_dependencies() {
old_edges.extend(iter_many!(task, OutdatedCellDependency { target } => OutdatedEdge::CellDependency(target)));
old_edges.extend(iter_many!(task, OutdatedCellDependency { target, key } => OutdatedEdge::CellDependency(target, key)));
old_edges.extend(iter_many!(task, OutdatedOutputDependency { target } => OutdatedEdge::OutputDependency(target)));
old_edges.extend(
iter_many!(task, CellDependent { cell, task } => (cell, task)).filter_map(
iter_many!(task, CellDependent { cell, task, key: _ } => (cell, task)).filter_map(
|(cell, task)| {
if cell_counters
.get(&cell.type_id)
Expand Down Expand Up @@ -2742,6 +2752,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
cell: CellId,
is_serializable_cell_content: bool,
content: CellContent,
updated_key_hashes: Option<SmallVec<[u64; 2]>>,
verification_mode: VerificationMode,
turbo_tasks: &dyn TurboTasksBackendApi<TurboTasksBackend<B>>,
) {
Expand All @@ -2750,6 +2761,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
cell,
content,
is_serializable_cell_content,
updated_key_hashes,
verification_mode,
self.execute_context(turbo_tasks),
);
Expand Down Expand Up @@ -3337,6 +3349,7 @@ impl<B: BackingStorage> Backend for TurboTasksBackend<B> {
cell: CellId,
is_serializable_cell_content: bool,
content: CellContent,
updated_key_hashes: Option<SmallVec<[u64; 2]>>,
verification_mode: VerificationMode,
turbo_tasks: &dyn TurboTasksBackendApi<Self>,
) {
Expand All @@ -3345,6 +3358,7 @@ impl<B: BackingStorage> Backend for TurboTasksBackend<B> {
cell,
is_serializable_cell_content,
content,
updated_key_hashes,
verification_mode,
turbo_tasks,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub enum CleanupOldEdgesOperation {
pub enum OutdatedEdge {
Child(TaskId),
Collectible(CollectibleRef, i32),
CellDependency(CellRef),
CellDependency(CellRef, Option<u64>),
OutputDependency(TaskId),
CollectiblesDependency(CollectiblesRef),
RemovedCellDependent {
Expand Down Expand Up @@ -160,14 +160,18 @@ impl Operation for CleanupOldEdgesOperation {
AggregatedDataUpdate::new().collectibles_update(collectibles),
));
}
OutdatedEdge::CellDependency(CellRef {
task: cell_task_id,
cell,
}) => {
OutdatedEdge::CellDependency(
CellRef {
task: cell_task_id,
cell,
},
key,
) => {
{
let mut task = ctx.task(cell_task_id, TaskDataCategory::Data);
task.remove(&CachedDataItemKey::CellDependent {
cell,
key,
task: task_id,
});
}
Expand All @@ -178,6 +182,7 @@ impl Operation for CleanupOldEdgesOperation {
task: cell_task_id,
cell,
},
key,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Operation for InvalidateOperation {
make_task_dirty(
task_id,
#[cfg(feature = "trace_task_dirty")]
cause,
cause.clone(),
&mut queue,
ctx,
);
Expand All @@ -90,11 +90,12 @@ impl Operation for InvalidateOperation {
}

#[cfg(feature = "trace_task_dirty")]
#[derive(Serialize, Deserialize, Clone, Copy, Debug)]
#[derive(Encode, Decode, Clone, Debug)]
pub enum TaskDirtyCause {
InitialDirty,
CellChange {
value_type: turbo_tasks::ValueTypeId,
keys: SmallVec<[Option<u64>; 2]>,
},
CellRemoved {
value_type: turbo_tasks::ValueTypeId,
Expand Down Expand Up @@ -132,12 +133,27 @@ impl<'e, E: ExecuteContext<'e>> std::fmt::Display for TaskDirtyCauseInContext<'_
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.cause {
TaskDirtyCause::InitialDirty => write!(f, "initial dirty"),
TaskDirtyCause::CellChange { value_type } => {
write!(
f,
"{} cell changed",
turbo_tasks::registry::get_value_type(*value_type).name
)
TaskDirtyCause::CellChange { value_type, keys } => {
if keys.is_empty() {
write!(
f,
"{} cell changed",
turbo_tasks::registry::get_value_type(*value_type).name
)
} else {
write!(
f,
"{} cell changed (keys: {})",
turbo_tasks::registry::get_value_type(*value_type).name,
keys.iter()
.map(|key| match key {
Some(k) => k.to_string(),
None => "*".to_string(),
})
.collect::<Vec<_>>()
.join(", ")
)
}
}
TaskDirtyCause::CellRemoved { value_type } => {
write!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ where
if id.is_transient() {
if call_prepared_task_callback_for_transient_tasks {
let mut task = self.backend.storage.access_mut(id);
// TODO add is_restoring and avoid concurrent restores and duplicates tasks
// ids in `task_ids`
if !task.state().is_restored(category) {
task.state_mut().set_restored(TaskDataCategory::All);
}
Expand Down Expand Up @@ -1003,7 +1005,7 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> {
}
self.task.state_mut().set_prefetched(true);
let map = iter_many!(self, OutputDependency { target } => (target, TaskDataCategory::Meta))
.chain(iter_many!(self, CellDependency { target } => (target.task, TaskDataCategory::All)))
.chain(iter_many!(self, CellDependency { target, key: _ } => (target.task, TaskDataCategory::All)))
.chain(iter_many!(self, CollectiblesDependency { target } => (target.task, TaskDataCategory::All)))
.chain(iter_many!(self, Child { task } => (task, TaskDataCategory::All)))
.collect::<FxIndexMap<_, _>>();
Expand Down
Loading
Loading