Unverified Commit ab75f649 authored by Luke Sandberg's avatar Luke Sandberg Committed by GitHub

Simplify turbo-tasks-backend guards and execution contexts (#99599)

### What?

Simplify the task guard and execution context abstractions in
`turbo-tasks-backend`, including the companion child context used for
parallel work.

Followup from #99249

### Why?

Each trait has a single implementation, with no alternate
implementations or mocks using the abstraction. The trait layer adds
duplicate declarations, associated types, and generic plumbing without
providing a useful extension point today. This is a simplicity refactor,
not a performance optimization.


<!-- fleet 22e7fce7-cf14-4d21-9cb9-d77f674cb241 -->
Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: 's avatarLuke Sandberg <210140+lukesandberg@users.noreply.github.com>
parent 2d5a45a5
...@@ -31,8 +31,8 @@ use crate::{ ...@@ -31,8 +31,8 @@ use crate::{
backend::{ backend::{
TurboTasksBackend, TurboTasksBackend,
operation::{ operation::{
AggregationUpdateJob, AggregationUpdateQueue, ExecuteContext, ExecuteContextImpl, AggregationUpdateJob, AggregationUpdateQueue, ExecuteContext, capture_all_edges,
TaskGuard, capture_all_edges, cleanup_old_edges_deletions_only, cleanup_old_edges_deletions_only,
}, },
snapshot_coordinator::SnapshotPhase, snapshot_coordinator::SnapshotPhase,
storage::{SpecificTaskDataCategory, TaskDataCategory}, storage::{SpecificTaskDataCategory, TaskDataCategory},
...@@ -262,7 +262,7 @@ impl TurboTasksBackend { ...@@ -262,7 +262,7 @@ impl TurboTasksBackend {
GcJob::Collect(task_id) => task_id, GcJob::Collect(task_id) => task_id,
}; };
let collector = |child_id| spawner.spawn(GcJob::Collect(child_id)); let collector = |child_id| spawner.spawn(GcJob::Collect(child_id));
let mut ctx = ExecuteContextImpl::new_for_gc(self, turbo_tasks, phase, &collector); let mut ctx = ExecuteContext::new_for_gc(self, turbo_tasks, phase, &collector);
// `All` restores Data so `capture_all_edges` below can read the // `All` restores Data so `capture_all_edges` below can read the
// Data-category dependency sets. The recheck itself only needs Meta. // Data-category dependency sets. The recheck itself only needs Meta.
let mut task = ctx.task(task_id, TaskDataCategory::All); let mut task = ctx.task(task_id, TaskDataCategory::All);
...@@ -321,7 +321,7 @@ impl TurboTasksBackend { ...@@ -321,7 +321,7 @@ impl TurboTasksBackend {
let deferred = std::mem::take(&mut result.deferred_balance_edges); let deferred = std::mem::take(&mut result.deferred_balance_edges);
if !deferred.is_empty() { if !deferred.is_empty() {
let noop_collector = |_task_id| {}; let noop_collector = |_task_id| {};
let mut ctx = ExecuteContextImpl::new_for_gc(self, turbo_tasks, phase, &noop_collector); let mut ctx = ExecuteContext::new_for_gc(self, turbo_tasks, phase, &noop_collector);
let mut queue = AggregationUpdateQueue::new(); let mut queue = AggregationUpdateQueue::new();
queue.extend_balance_edges(deferred, &mut ctx); queue.extend_balance_edges(deferred, &mut ctx);
while !queue.process(&mut ctx) {} while !queue.process(&mut ctx) {}
...@@ -333,7 +333,7 @@ impl TurboTasksBackend { ...@@ -333,7 +333,7 @@ impl TurboTasksBackend {
let dirty_dependents = std::mem::take(&mut result.deferred_dirty_dependents); let dirty_dependents = std::mem::take(&mut result.deferred_dirty_dependents);
if !dirty_dependents.is_empty() { if !dirty_dependents.is_empty() {
let noop_collector = |_task_id| {}; let noop_collector = |_task_id| {};
let mut ctx = ExecuteContextImpl::new_for_gc(self, turbo_tasks, phase, &noop_collector); let mut ctx = ExecuteContext::new_for_gc(self, turbo_tasks, phase, &noop_collector);
let mut queue = AggregationUpdateQueue::new(); let mut queue = AggregationUpdateQueue::new();
// A dependent collected by this same pass is skipped: the job is weak by construction. // A dependent collected by this same pass is skipped: the job is weak by construction.
queue.push(AggregationUpdateJob::InvalidateDueToDependencyTornDown { queue.push(AggregationUpdateJob::InvalidateDueToDependencyTornDown {
......
...@@ -64,11 +64,10 @@ pub use self::{ ...@@ -64,11 +64,10 @@ pub use self::{
use crate::{ use crate::{
backend::{ backend::{
operation::{ operation::{
AggregationUpdateJob, AggregationUpdateQueue, ChildExecuteContext, ExecuteContext, AggregationUpdateJob, AggregationUpdateQueue, ExecuteContext, LeafDistanceUpdateQueue,
ExecuteContextImpl, LeafDistanceUpdateQueue, OutdatedEdge, TaskGuard, TaskType, OutdatedEdge, TaskGuard, TaskType, TaskTypeRef, capture_all_edges, cleanup_old_edges,
TaskTypeRef, capture_all_edges, cleanup_old_edges, connect_child, connect_children, connect_child, connect_children, get_aggregation_number, get_uppers, invalidate,
get_aggregation_number, get_uppers, invalidate, make_task_dirty_internal, make_task_dirty_internal, prepare_new_children, update_cell,
prepare_new_children, update_cell,
}, },
snapshot_coordinator::{OperationGuard, SlowSettle, SnapshotCoordinator}, snapshot_coordinator::{OperationGuard, SlowSettle, SnapshotCoordinator},
storage::Storage, storage::Storage,
...@@ -104,7 +103,7 @@ const GC_MIN_PROGRESS: Duration = Duration::from_millis(100); ...@@ -104,7 +103,7 @@ const GC_MIN_PROGRESS: Duration = Duration::from_millis(100);
/// than the (likely higher) priority of the original schedule. We use invalidation priority /// than the (likely higher) priority of the original schedule. We use invalidation priority
/// based on the task's leaf distance, parented under either the task's current dirty priority /// based on the task's leaf distance, parented under either the task's current dirty priority
/// or `leaf()` if it is no longer dirty. /// or `leaf()` if it is no longer dirty.
fn compute_stale_priority(task: &impl TaskGuard) -> TaskPriority { fn compute_stale_priority(task: &TaskGuard<'_>) -> TaskPriority {
TaskPriority::invalidation( TaskPriority::invalidation(
task.get_leaf_distance() task.get_leaf_distance()
.copied() .copied()
...@@ -371,8 +370,8 @@ impl TurboTasksBackend { ...@@ -371,8 +370,8 @@ impl TurboTasksBackend {
fn execute_context<'a>( fn execute_context<'a>(
&'a self, &'a self,
turbo_tasks: &'a TurboTasks<TurboTasksBackend>, turbo_tasks: &'a TurboTasks<TurboTasksBackend>,
) -> impl ExecuteContext<'a> { ) -> ExecuteContext<'a> {
ExecuteContextImpl::new(self, turbo_tasks) ExecuteContext::new(self, turbo_tasks)
} }
/// Like [`TurboTasksBackend::execute_context`], but refuses to hand out a context once /// Like [`TurboTasksBackend::execute_context`], but refuses to hand out a context once
...@@ -385,12 +384,12 @@ impl TurboTasksBackend { ...@@ -385,12 +384,12 @@ impl TurboTasksBackend {
fn try_execute_context<'a>( fn try_execute_context<'a>(
&'a self, &'a self,
turbo_tasks: &'a TurboTasks<TurboTasksBackend>, turbo_tasks: &'a TurboTasks<TurboTasksBackend>,
) -> Option<impl ExecuteContext<'a>> { ) -> Option<ExecuteContext<'a>> {
let stopping = self.stopping.read(); let stopping = self.stopping.read();
if *stopping { if *stopping {
return None; return None;
} }
Some(ExecuteContextImpl::new_with_shutdown_guard( Some(ExecuteContext::new_with_shutdown_guard(
self, self,
turbo_tasks, turbo_tasks,
stopping, stopping,
...@@ -513,7 +512,7 @@ impl TurboTasksBackend { ...@@ -513,7 +512,7 @@ impl TurboTasksBackend {
fn task_error_to_turbo_tasks_execution_error( fn task_error_to_turbo_tasks_execution_error(
&self, &self,
error: &TaskError, error: &TaskError,
ctx: &mut impl ExecuteContext<'_>, ctx: &mut ExecuteContext<'_>,
) -> TurboTasksExecutionError { ) -> TurboTasksExecutionError {
match error { match error {
TaskError::Panic(panic) => TurboTasksExecutionError::Panic(panic.clone()), TaskError::Panic(panic) => TurboTasksExecutionError::Panic(panic.clone()),
...@@ -584,11 +583,11 @@ struct TaskExecutionCompletePrepareResult { ...@@ -584,11 +583,11 @@ struct TaskExecutionCompletePrepareResult {
pub is_session_dependent: bool, pub is_session_dependent: bool,
} }
fn lock_task_and_optional_reader<'e, C: ExecuteContext<'e>>( fn lock_task_and_optional_reader<'e>(
ctx: &mut C, ctx: &mut ExecuteContext<'e>,
task_id: TaskId, task_id: TaskId,
reader_id: Option<TaskId>, reader_id: Option<TaskId>,
) -> (C::TaskGuardImpl, Option<C::TaskGuardImpl>) { ) -> (TaskGuard<'e>, Option<TaskGuard<'e>>) {
let Some(reader_id) = reader_id else { let Some(reader_id) = reader_id else {
return (ctx.task(task_id, TaskDataCategory::All), None); return (ctx.task(task_id, TaskDataCategory::All), None);
}; };
...@@ -663,7 +662,7 @@ impl TurboTasksBackend { ...@@ -663,7 +662,7 @@ impl TurboTasksBackend {
/// whether a worker has actually started it. A task that is only `Scheduled` can be taken /// whether a worker has actually started it. A task that is only `Scheduled` can be taken
/// over and executed by the reader; one that is `InProgress` can only be waited for. /// over and executed by the reader; one that is `InProgress` can only be waited for.
fn check_in_progress<T>( fn check_in_progress<T>(
task: &impl TaskGuard, task: &TaskGuard<'_>,
reader_description: Option<EventDescription>, reader_description: Option<EventDescription>,
tracking: ReadTracking, tracking: ReadTracking,
) -> Option<Result<ReadOutcome<T>>> { ) -> Option<Result<ReadOutcome<T>>> {
...@@ -749,7 +748,7 @@ impl TurboTasksBackend { ...@@ -749,7 +748,7 @@ impl TurboTasksBackend {
.collect::<String>() .collect::<String>()
} }
fn get_info( fn get_info(
ctx: &mut impl ExecuteContext<'_>, ctx: &mut ExecuteContext<'_>,
task_id: TaskId, task_id: TaskId,
parent_and_count: Option<(TaskId, i32)>, parent_and_count: Option<(TaskId, i32)>,
visited: &mut FxHashSet<TaskId>, visited: &mut FxHashSet<TaskId>,
...@@ -963,9 +962,9 @@ impl TurboTasksBackend { ...@@ -963,9 +962,9 @@ impl TurboTasksBackend {
fn add_cell_dependency( fn add_cell_dependency(
task_id: TaskId, task_id: TaskId,
mut task: impl TaskGuard, mut task: TaskGuard<'_>,
reader: Option<TaskId>, reader: Option<TaskId>,
reader_task: Option<impl TaskGuard>, reader_task: Option<TaskGuard<'_>>,
cell: CellId, cell: CellId,
key: Option<u64>, key: Option<u64>,
) { ) {
...@@ -1104,10 +1103,10 @@ impl TurboTasksBackend { ...@@ -1104,10 +1103,10 @@ impl TurboTasksBackend {
fn listen_to_cell( fn listen_to_cell(
&self, &self,
task: &mut impl TaskGuard, task: &mut TaskGuard<'_>,
task_id: TaskId, task_id: TaskId,
reader: Option<TaskId>, reader: Option<TaskId>,
reader_task: &Option<impl TaskGuard>, reader_task: &Option<TaskGuard<'_>>,
cell: CellId, cell: CellId,
) -> (EventListener, bool) { ) -> (EventListener, bool) {
let note = || { let note = || {
...@@ -2298,7 +2297,7 @@ impl TurboTasksBackend { ...@@ -2298,7 +2297,7 @@ impl TurboTasksBackend {
fn task_execution_completed_prepare( fn task_execution_completed_prepare(
&self, &self,
ctx: &mut impl ExecuteContext<'_>, ctx: &mut ExecuteContext<'_>,
#[cfg(feature = "trace_task_details")] span: &Span, #[cfg(feature = "trace_task_details")] span: &Span,
task_id: TaskId, task_id: TaskId,
result: Result<RawVc, TurboTasksExecutionError>, result: Result<RawVc, TurboTasksExecutionError>,
...@@ -2603,7 +2602,7 @@ impl TurboTasksBackend { ...@@ -2603,7 +2602,7 @@ impl TurboTasksBackend {
fn task_execution_completed_invalidate_output_dependent( fn task_execution_completed_invalidate_output_dependent(
&self, &self,
ctx: &mut impl ExecuteContext<'_>, ctx: &mut ExecuteContext<'_>,
task_id: TaskId, task_id: TaskId,
#[cfg(feature = "task_dirty_cause")] function_id: Option<FunctionId>, #[cfg(feature = "task_dirty_cause")] function_id: Option<FunctionId>,
output_dependent_tasks: SmallVec<[TaskId; 4]>, output_dependent_tasks: SmallVec<[TaskId; 4]>,
...@@ -2626,7 +2625,7 @@ impl TurboTasksBackend { ...@@ -2626,7 +2625,7 @@ impl TurboTasksBackend {
} }
fn process_output_dependents( fn process_output_dependents(
ctx: &mut impl ExecuteContext<'_>, ctx: &mut ExecuteContext<'_>,
task_id: TaskId, task_id: TaskId,
#[cfg(feature = "task_dirty_cause")] cause: &TaskDirtyCause, #[cfg(feature = "task_dirty_cause")] cause: &TaskDirtyCause,
dependent_task_id: TaskId, dependent_task_id: TaskId,
...@@ -2719,7 +2718,7 @@ impl TurboTasksBackend { ...@@ -2719,7 +2718,7 @@ impl TurboTasksBackend {
fn task_execution_completed_connect( fn task_execution_completed_connect(
&self, &self,
ctx: &mut impl ExecuteContext<'_>, ctx: &mut ExecuteContext<'_>,
task_id: TaskId, task_id: TaskId,
new_children: FxHashSet<TaskId>, new_children: FxHashSet<TaskId>,
) -> Option<TaskPriority> { ) -> Option<TaskPriority> {
...@@ -2789,7 +2788,7 @@ impl TurboTasksBackend { ...@@ -2789,7 +2788,7 @@ impl TurboTasksBackend {
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
fn task_execution_completed_finish( fn task_execution_completed_finish(
&self, &self,
ctx: &mut impl ExecuteContext<'_>, ctx: &mut ExecuteContext<'_>,
task_id: TaskId, task_id: TaskId,
#[cfg(feature = "verify_determinism")] no_output_set: bool, #[cfg(feature = "verify_determinism")] no_output_set: bool,
new_output: Option<OutputValue>, new_output: Option<OutputValue>,
...@@ -2897,7 +2896,7 @@ impl TurboTasksBackend { ...@@ -2897,7 +2896,7 @@ impl TurboTasksBackend {
fn task_execution_completed_cleanup( fn task_execution_completed_cleanup(
&self, &self,
ctx: &mut impl ExecuteContext<'_>, ctx: &mut ExecuteContext<'_>,
task_id: TaskId, task_id: TaskId,
cell_counters: &AutoMap<ValueTypeId, u32, BuildHasherDefault<FxHasher>, 8>, cell_counters: &AutoMap<ValueTypeId, u32, BuildHasherDefault<FxHasher>, 8>,
is_error: bool, is_error: bool,
......
...@@ -91,7 +91,7 @@ pub fn cleanup_old_edges( ...@@ -91,7 +91,7 @@ pub fn cleanup_old_edges(
task_id: TaskId, task_id: TaskId,
outdated: Vec<OutdatedEdge>, outdated: Vec<OutdatedEdge>,
queue: AggregationUpdateQueue, queue: AggregationUpdateQueue,
ctx: &mut impl ExecuteContext<'_>, ctx: &mut ExecuteContext<'_>,
) -> Stats { ) -> Stats {
cleanup_old_edges_inner(task_id, outdated, queue, ctx, false).0 cleanup_old_edges_inner(task_id, outdated, queue, ctx, false).0
} }
...@@ -102,10 +102,10 @@ pub fn cleanup_old_edges( ...@@ -102,10 +102,10 @@ pub fn cleanup_old_edges(
/// parallel collect is quiescent. Deletion is safe to run concurrently; the deferred work is /// parallel collect is quiescent. Deletion is safe to run concurrently; the deferred work is
/// not. `balance_edge` *adds* edges, and dirtying propagates through the aggregation graph -- /// not. `balance_edge` *adds* edges, and dirtying propagates through the aggregation graph --
/// neither is safe while other workers are still collecting. /// neither is safe while other workers are still collecting.
pub fn cleanup_old_edges_deletions_only<'a, C: ExecuteContext<'a>>( pub fn cleanup_old_edges_deletions_only(
task_id: TaskId, task_id: TaskId,
outdated: Vec<OutdatedEdge>, outdated: Vec<OutdatedEdge>,
ctx: &mut C, ctx: &mut ExecuteContext<'_>,
) -> DeferredCleanup { ) -> DeferredCleanup {
let (_, stopped) = cleanup_old_edges_inner( let (_, stopped) = cleanup_old_edges_inner(
task_id, task_id,
...@@ -122,7 +122,7 @@ fn cleanup_old_edges_inner( ...@@ -122,7 +122,7 @@ fn cleanup_old_edges_inner(
task_id: TaskId, task_id: TaskId,
mut outdated: Vec<OutdatedEdge>, mut outdated: Vec<OutdatedEdge>,
mut queue: AggregationUpdateQueue, mut queue: AggregationUpdateQueue,
ctx: &mut impl ExecuteContext<'_>, ctx: &mut ExecuteContext<'_>,
stop_when_only_rebalance_remains: bool, stop_when_only_rebalance_remains: bool,
) -> (Stats, Option<DeferredCleanup>) { ) -> (Stats, Option<DeferredCleanup>) {
let mut dirty_dependents = AutoSet::default(); let mut dirty_dependents = AutoSet::default();
......
...@@ -20,12 +20,12 @@ use crate::{ ...@@ -20,12 +20,12 @@ use crate::{
/// connect handshake. /// connect handshake.
/// ///
/// GC destructively mutates tasks so mark resurrected tasks as dirty to get them re-scheduled. /// GC destructively mutates tasks so mark resurrected tasks as dirty to get them re-scheduled.
pub(super) fn resurrect_deleted<'e, C: ExecuteContext<'e>>( pub(super) fn resurrect_deleted<'e>(
guard: C::TaskGuardImpl, guard: TaskGuard<'e>,
task_id: TaskId, task_id: TaskId,
queue: &mut AggregationUpdateQueue, queue: &mut AggregationUpdateQueue,
ctx: &mut C, ctx: &mut ExecuteContext<'e>,
) -> C::TaskGuardImpl { ) -> TaskGuard<'e> {
if !guard.deleted() { if !guard.deleted() {
return guard; return guard;
} }
...@@ -64,7 +64,7 @@ pub(super) fn resurrect_deleted<'e, C: ExecuteContext<'e>>( ...@@ -64,7 +64,7 @@ pub(super) fn resurrect_deleted<'e, C: ExecuteContext<'e>>(
task task
} }
fn release_construction_ref<'e, C: ExecuteContext<'e>>(task_id: TaskId, ctx: &mut C) { fn release_construction_ref(task_id: TaskId, ctx: &mut ExecuteContext<'_>) {
let mut task = ctx.task(task_id, TaskDataCategory::Meta); let mut task = ctx.task(task_id, TaskDataCategory::Meta);
task.update_and_get_transient_ref_count(-1); task.update_and_get_transient_ref_count(-1);
} }
...@@ -73,7 +73,7 @@ pub fn connect_child( ...@@ -73,7 +73,7 @@ pub fn connect_child(
parent_task_id: Option<TaskId>, parent_task_id: Option<TaskId>,
child_task_id: TaskId, child_task_id: TaskId,
release_construction_ref: bool, release_construction_ref: bool,
mut ctx: impl ExecuteContext<'_>, mut ctx: ExecuteContext<'_>,
) { ) {
if parent_task_id.is_none() { if parent_task_id.is_none() {
// All parentless tasks receive a transient ref when connected: their lifetime cannot be // All parentless tasks receive a transient ref when connected: their lifetime cannot be
......
...@@ -10,17 +10,17 @@ use turbo_tasks::{ ...@@ -10,17 +10,17 @@ use turbo_tasks::{
use crate::backend::{ use crate::backend::{
operation::{ operation::{
AggregationUpdateJob, AggregationUpdateQueue, ChildExecuteContext, ExecuteContext, AggregationUpdateJob, AggregationUpdateQueue, ExecuteContext, TaskGuard,
TaskGuard, aggregation_update::InnerOfUppersHasNewFollowersJob, get_aggregation_number, aggregation_update::InnerOfUppersHasNewFollowersJob, get_aggregation_number, get_uppers,
get_uppers, invalidate::make_task_dirty_internal, is_aggregating_node, invalidate::make_task_dirty_internal, is_aggregating_node,
}, },
storage_schema::TaskStorageAccessors, storage_schema::TaskStorageAccessors,
}; };
pub fn connect_children( pub fn connect_children(
ctx: &mut impl ExecuteContext<'_>, ctx: &mut ExecuteContext<'_>,
parent_task_id: TaskId, parent_task_id: TaskId,
mut parent_task: impl TaskGuard, mut parent_task: TaskGuard<'_>,
new_children: FxHashSet<TaskId>, new_children: FxHashSet<TaskId>,
parent_has_active_count: bool, parent_has_active_count: bool,
should_track_activeness: bool, should_track_activeness: bool,
...@@ -46,7 +46,7 @@ pub fn connect_children( ...@@ -46,7 +46,7 @@ pub fn connect_children(
drop(parent_task); drop(parent_task);
fn process_new_children( fn process_new_children(
ctx: &mut impl ExecuteContext<'_>, ctx: &mut ExecuteContext<'_>,
new_follower_ids: SmallVec<[TaskId; 4]>, new_follower_ids: SmallVec<[TaskId; 4]>,
upper_ids: Option<SmallVec<[TaskId; 4]>>, upper_ids: Option<SmallVec<[TaskId; 4]>>,
parent_task_id: TaskId, parent_task_id: TaskId,
......
...@@ -20,7 +20,7 @@ use crate::{ ...@@ -20,7 +20,7 @@ use crate::{
pub fn invalidate( pub fn invalidate(
task_ids: SmallVec<[TaskId; 4]>, task_ids: SmallVec<[TaskId; 4]>,
#[cfg(feature = "task_dirty_cause")] cause: TaskDirtyCause, #[cfg(feature = "task_dirty_cause")] cause: TaskDirtyCause,
mut ctx: impl ExecuteContext<'_>, mut ctx: ExecuteContext<'_>,
) { ) {
let mut queue = AggregationUpdateQueue::new(); let mut queue = AggregationUpdateQueue::new();
for task_id in task_ids { for task_id in task_ids {
...@@ -42,7 +42,7 @@ pub fn try_make_task_dirty( ...@@ -42,7 +42,7 @@ pub fn try_make_task_dirty(
task_id: TaskId, task_id: TaskId,
#[cfg(feature = "task_dirty_cause")] cause: TaskDirtyCause, #[cfg(feature = "task_dirty_cause")] cause: TaskDirtyCause,
queue: &mut AggregationUpdateQueue, queue: &mut AggregationUpdateQueue,
ctx: &mut impl ExecuteContext<'_>, ctx: &mut ExecuteContext<'_>,
) { ) {
let Some(mut task) = ctx.try_task(task_id, TaskDataCategory::All) else { let Some(mut task) = ctx.try_task(task_id, TaskDataCategory::All) else {
return; return;
...@@ -58,12 +58,12 @@ pub fn try_make_task_dirty( ...@@ -58,12 +58,12 @@ pub fn try_make_task_dirty(
} }
/// Requires the guard to be allocated with [TaskDataCategory::All] /// Requires the guard to be allocated with [TaskDataCategory::All]
pub fn make_task_dirty_internal<'e, E: ExecuteContext<'e>>( pub fn make_task_dirty_internal(
task: &mut E::TaskGuardImpl, task: &mut TaskGuard<'_>,
make_stale: bool, make_stale: bool,
#[cfg(feature = "task_dirty_cause")] cause: TaskDirtyCause, #[cfg(feature = "task_dirty_cause")] cause: TaskDirtyCause,
queue: &mut AggregationUpdateQueue, queue: &mut AggregationUpdateQueue,
ctx: &mut E, ctx: &mut ExecuteContext<'_>,
) { ) {
// There must be no way to invalidate immutable tasks. If there would be a way the task is not // There must be no way to invalidate immutable tasks. If there would be a way the task is not
// immutable. // immutable.
......
...@@ -85,7 +85,7 @@ impl LeafDistanceUpdateQueue { ...@@ -85,7 +85,7 @@ impl LeafDistanceUpdateQueue {
} }
/// Executes a single step of the queue. Returns true, when the queue is empty. /// Executes a single step of the queue. Returns true, when the queue is empty.
pub fn process(&mut self, ctx: &mut impl ExecuteContext) -> bool { pub fn process(&mut self, ctx: &mut ExecuteContext<'_>) -> bool {
let mut remaining = MAX_COUNT_BEFORE_YIELD; let mut remaining = MAX_COUNT_BEFORE_YIELD;
while remaining > 0 { while remaining > 0 {
if let Some((Reverse(queue_dependencies_distance), task_id)) = self.queue.pop() { if let Some((Reverse(queue_dependencies_distance), task_id)) = self.queue.pop() {
...@@ -121,7 +121,7 @@ impl LeafDistanceUpdateQueue { ...@@ -121,7 +121,7 @@ impl LeafDistanceUpdateQueue {
fn update_leaf_distance( fn update_leaf_distance(
&mut self, &mut self,
ctx: &mut impl ExecuteContext, ctx: &mut ExecuteContext<'_>,
task_id: TaskId, task_id: TaskId,
dependencies_distance: u32, dependencies_distance: u32,
dependencies_max_distance_in_buffer: u32, dependencies_max_distance_in_buffer: u32,
...@@ -169,7 +169,7 @@ impl LeafDistanceUpdateQueue { ...@@ -169,7 +169,7 @@ impl LeafDistanceUpdateQueue {
task.set_leaf_distance(leaf_distance); task.set_leaf_distance(leaf_distance);
} }
pub fn execute(&mut self, ctx: &mut impl ExecuteContext<'_>) { pub fn execute(&mut self, ctx: &mut ExecuteContext<'_>) {
if self.is_empty() { if self.is_empty() {
return; return;
} }
......
...@@ -3,15 +3,18 @@ use std::{cmp::max, num::NonZeroU32}; ...@@ -3,15 +3,18 @@ use std::{cmp::max, num::NonZeroU32};
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;
use turbo_tasks::TaskId; use turbo_tasks::TaskId;
use crate::backend::operation::{ use crate::backend::{
AggregationUpdateJob, AggregationUpdateQueue, TaskGuard, is_aggregating_node, is_root_node, operation::{
AggregationUpdateJob, AggregationUpdateQueue, TaskGuard, is_aggregating_node, is_root_node,
},
storage_schema::TaskStorageAccessors,
}; };
const AGGREGATION_NUMBER_BUFFER_SPACE: u32 = 3; const AGGREGATION_NUMBER_BUFFER_SPACE: u32 = 3;
pub fn prepare_new_children( pub fn prepare_new_children(
parent_task_id: TaskId, parent_task_id: TaskId,
parent_task: &mut impl TaskGuard, parent_task: &mut TaskGuard<'_>,
new_children: &FxHashSet<TaskId>, new_children: &FxHashSet<TaskId>,
queue: &mut AggregationUpdateQueue, queue: &mut AggregationUpdateQueue,
) -> u32 { ) -> u32 {
......
...@@ -29,7 +29,7 @@ pub fn update_cell( ...@@ -29,7 +29,7 @@ pub fn update_cell(
content_hash: Option<CellHash>, content_hash: Option<CellHash>,
#[cfg(feature = "verify_determinism")] verification_mode: VerificationMode, #[cfg(feature = "verify_determinism")] verification_mode: VerificationMode,
#[cfg(not(feature = "verify_determinism"))] _verification_mode: VerificationMode, #[cfg(not(feature = "verify_determinism"))] _verification_mode: VerificationMode,
mut ctx: impl ExecuteContext<'_>, mut ctx: ExecuteContext<'_>,
) { ) {
let value_type = registry::get_value_type(cell.type_id()); let value_type = registry::get_value_type(cell.type_id());
// `content_hash` is only ever supplied for `HashOnly` cells — only the // `content_hash` is only ever supplied for `HashOnly` cells — only the
...@@ -219,7 +219,7 @@ pub fn update_cell( ...@@ -219,7 +219,7 @@ pub fn update_cell(
/// Updates the stored cell_data_hash, which only `serialization = "hash"` /// Updates the stored cell_data_hash, which only `serialization = "hash"`
/// cells consult (on eviction + recompute). Skips the update for all other /// cells consult (on eviction + recompute). Skips the update for all other
/// persistence modes and when the hash hasn't changed. /// persistence modes and when the hash hasn't changed.
fn update_cell_data_hash(task: &mut impl TaskGuard, cell: &CellId, content_hash: Option<CellHash>) { fn update_cell_data_hash(task: &mut TaskGuard<'_>, cell: &CellId, content_hash: Option<CellHash>) {
let old_hash = task.get_cell_data_hash(cell).copied(); let old_hash = task.get_cell_data_hash(cell).copied();
if old_hash != content_hash { if old_hash != content_hash {
if let Some(hash) = content_hash { if let Some(hash) = content_hash {
...@@ -235,7 +235,7 @@ fn invalidate_cell_dependents( ...@@ -235,7 +235,7 @@ fn invalidate_cell_dependents(
mut dependent_tasks: FxIndexMap<TaskId, SmallVec<[Option<u64>; 2]>>, mut dependent_tasks: FxIndexMap<TaskId, SmallVec<[Option<u64>; 2]>>,
#[cfg(feature = "task_dirty_cause")] has_updated_key_hashes: bool, #[cfg(feature = "task_dirty_cause")] has_updated_key_hashes: bool,
content: Option<TypedSharedReference>, content: Option<TypedSharedReference>,
ctx: &mut impl ExecuteContext<'_>, ctx: &mut ExecuteContext<'_>,
) { ) {
let mut queue = AggregationUpdateQueue::new(); let mut queue = AggregationUpdateQueue::new();
while let Some((dependent_task_id, keys)) = dependent_tasks.pop() { while let Some((dependent_task_id, keys)) = dependent_tasks.pop() {
......
...@@ -21,7 +21,7 @@ impl UpdateCollectibleOperation { ...@@ -21,7 +21,7 @@ impl UpdateCollectibleOperation {
task_id: TaskId, task_id: TaskId,
collectible: CollectibleRef, collectible: CollectibleRef,
mut count: i32, mut count: i32,
mut ctx: impl ExecuteContext<'_>, mut ctx: ExecuteContext<'_>,
) { ) {
let mut task = ctx.task(task_id, TaskDataCategory::All); let mut task = ctx.task(task_id, TaskDataCategory::All);
if count < 0 if count < 0
......
#![feature(anonymous_lifetime_in_impl_trait)]
#![feature(deref_patterns)] #![feature(deref_patterns)]
mod backend; mod backend;
......
...@@ -335,7 +335,7 @@ async fn mutating_a_state_read_by_a_collected_task_does_not_panic() { ...@@ -335,7 +335,7 @@ async fn mutating_a_state_read_by_a_collected_task_does_not_panic() {
// GC only soft-deletes, leaving the task resident, and a weak open of a resident-but-deleted // GC only soft-deletes, leaving the task resident, and a weak open of a resident-but-deleted
// task returns early on the `deleted` flag. Evicting drops it from memory (and tombstones it on // task returns early on the `deleted` flag. Evicting drops it from memory (and tombstones it on
// disk), so the open below instead reaches the exists-nowhere case in // disk), so the open below instead reaches the exists-nowhere case in
// `ExecuteContextImpl::open_task` -- nothing restored, nothing found on disk -- which is the // `ExecuteContext::open_task` -- nothing restored, nothing found on disk -- which is the
// one that would panic under `MustExist`. Drop this line and the test still passes, but it // one that would panic under `MustExist`. Drop this line and the test still passes, but it
// stops covering that path. // stops covering that path.
tt2.backend().snapshot_and_evict_for_testing(&tt2); tt2.backend().snapshot_and_evict_for_testing(&tt2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment