Unverified Commit 1ee20b5d authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

Bind concrete task guards to execution contexts

Co-authored-by: 's avatarLuke Sandberg <210140+lukesandberg@users.noreply.github.com>
parent 8d8c0cd5
......@@ -250,7 +250,7 @@ impl TurboTasksBackend {
GcJob::Collect(task_id) => task_id,
};
let collector = |child_id| spawner.spawn(GcJob::Collect(child_id));
let mut ctx = ExecuteContext::new_for_gc(self, turbo_tasks, phase, &collector);
let ctx = ExecuteContext::new_for_gc(self, turbo_tasks, phase, &collector);
// `All` restores Data so `capture_all_edges` below can read the
// Data-category dependency sets. The recheck itself only needs Meta.
let mut task = ctx.task(task_id, TaskDataCategory::All);
......@@ -287,7 +287,7 @@ impl TurboTasksBackend {
// Delete outgoing edges but don't update the aggregation graph yet.
// To avoid accidentally rebalancing on deleted tasks due to racing deletions,
// we defer all rebalancing to the end
let deferred = cleanup_old_edges_deletions_only(task_id, old_edges, &mut ctx);
let deferred = cleanup_old_edges_deletions_only(task_id, old_edges, &ctx);
result.deferred_balance_edges.extend(deferred.balance_edges);
ControlFlow::Continue(())
},
......@@ -306,10 +306,10 @@ impl TurboTasksBackend {
let deferred = std::mem::take(&mut result.deferred_balance_edges);
if !deferred.is_empty() {
let noop_collector = |_task_id| {};
let mut ctx = ExecuteContext::new_for_gc(self, turbo_tasks, phase, &noop_collector);
let ctx = ExecuteContext::new_for_gc(self, turbo_tasks, phase, &noop_collector);
let mut queue = AggregationUpdateQueue::new();
queue.extend_balance_edges(deferred, &mut ctx);
while !queue.process(&mut ctx) {}
queue.extend_balance_edges(deferred, &ctx);
while !queue.process(&ctx) {}
}
// Collect all active roots
......@@ -398,7 +398,7 @@ impl TurboTasksBackend {
// We expect this call to come from outside a turbo-task context, at least sometimes
// So be defensive about conostructing a context. If we get none then we are shutting down
// and it is too late for ref-counting.
let Some(mut ctx) = self.try_execute_context(turbo_tasks) else {
let Some(ctx) = self.try_execute_context(turbo_tasks) else {
return;
};
// Technically we only need to manipulate transient data so meta is overkill. But the task
......
......@@ -112,7 +112,7 @@ pub fn get_uppers(task: &TaskGuard<'_>) -> TaskIdVec {
/// Acquires a `Meta`-category guard for `task_id` and sets `optimization_pending`. Used in
/// the optimize-queue drop paths when the caller doesn't already hold a guard for the task.
fn lock_and_mark_optimization_pending(ctx: &mut ExecuteContext<'_>, task_id: TaskId) {
fn lock_and_mark_optimization_pending(ctx: &ExecuteContext<'_>, task_id: TaskId) {
let mut task = ctx.task(task_id, TaskDataCategory::Meta);
task.set_optimization_pending(true);
}
......@@ -1028,7 +1028,7 @@ impl AggregationUpdateQueue {
/// Only called from `optimize_task`'s self re-enqueue, which has just cleared the flag at
/// entry, so the enqueued job carries `optimization_pending_flag_already_set = false`. The
/// `Meta`-category guard is acquired only when the push has to be dropped.
fn push_optimize_task_by_id(&mut self, ctx: &mut ExecuteContext<'_>, task_id: TaskId) {
fn push_optimize_task_by_id(&mut self, ctx: &ExecuteContext<'_>, task_id: TaskId) {
if !self.try_enqueue_optimize_job(task_id, false) {
lock_and_mark_optimization_pending(ctx, task_id);
}
......@@ -1055,7 +1055,7 @@ impl AggregationUpdateQueue {
}
/// Runs the job and all dependent jobs until it's done.
pub fn run(job: AggregationUpdateJob, ctx: &mut ExecuteContext<'_>) {
pub fn run(job: AggregationUpdateJob, ctx: &ExecuteContext<'_>) {
let mut queue = Self::new();
queue.push(job);
queue.execute(ctx);
......@@ -1114,7 +1114,7 @@ impl AggregationUpdateQueue {
pub fn extend_balance_edges(
&mut self,
edges: impl IntoIterator<Item = (TaskId, TaskId)>,
ctx: &mut ExecuteContext<'_>,
ctx: &ExecuteContext<'_>,
) {
for (upper_id, task_id) in edges {
// structure as 2 if statements to ensure the first guard is dropped before the second
......@@ -1130,7 +1130,7 @@ impl AggregationUpdateQueue {
}
/// Executes a single step of the queue. Returns true, when the queue is empty.
pub fn process(&mut self, ctx: &mut ExecuteContext<'_>) -> bool {
pub fn process(&mut self, ctx: &ExecuteContext<'_>) -> bool {
if let Some(job) = self.jobs.pop_front() {
let job: AggregationUpdateJobGuard = job.entered();
match job.job {
......@@ -1612,7 +1612,7 @@ impl AggregationUpdateQueue {
/// triggers more changes to the structure.
///
/// It locks both tasks simultaneously to atomically change the edges.
fn balance_edge(&mut self, ctx: &mut ExecuteContext<'_>, upper_id: TaskId, task_id: TaskId) {
fn balance_edge(&mut self, ctx: &ExecuteContext<'_>, upper_id: TaskId, task_id: TaskId) {
#[cfg(feature = "trace_aggregation_update")]
let _span = trace_span!("process balance edge").entered();
......@@ -1784,7 +1784,7 @@ impl AggregationUpdateQueue {
fn find_and_schedule_dirty(
&mut self,
jobs: SmallVec<[FindAndScheduleJob; 4]>,
ctx: &mut ExecuteContext<'_>,
ctx: &ExecuteContext<'_>,
) {
#[cfg(feature = "trace_find_and_schedule")]
let mut spans: FxHashMap<TaskId, Option<Span>> = jobs
......@@ -1814,7 +1814,7 @@ impl AggregationUpdateQueue {
&mut self,
task_id: TaskId,
mut task: TaskGuard<'_>,
ctx: &mut ExecuteContext<'_>,
ctx: &ExecuteContext<'_>,
) {
// Task need to be scheduled if it's dirty or doesn't have output
let dirty = task.is_dirty();
......@@ -1855,7 +1855,7 @@ impl AggregationUpdateQueue {
fn aggregated_data_update(
&mut self,
upper_ids: TaskIdVec,
ctx: &mut ExecuteContext<'_>,
ctx: &ExecuteContext<'_>,
update: AggregatedDataUpdate,
) {
// For performance reasons this should stay `Meta` and not `All`
......@@ -1883,7 +1883,7 @@ impl AggregationUpdateQueue {
fn inner_of_upper_lost_follower(
&mut self,
ctx: &mut ExecuteContext<'_>,
ctx: &ExecuteContext<'_>,
lost_follower_id: TaskId,
upper_id: TaskId,
mut retry: u16,
......@@ -2061,7 +2061,7 @@ impl AggregationUpdateQueue {
fn inner_of_uppers_lost_follower(
&mut self,
ctx: &mut ExecuteContext<'_>,
ctx: &ExecuteContext<'_>,
lost_follower_id: TaskId,
mut upper_ids: TaskIdVec,
mut retry: u16,
......@@ -2254,7 +2254,7 @@ impl AggregationUpdateQueue {
fn inner_of_upper_lost_followers(
&mut self,
ctx: &mut ExecuteContext<'_>,
ctx: &ExecuteContext<'_>,
mut lost_follower_ids: TaskIdVec,
upper_id: TaskId,
mut retry: u16,
......@@ -2450,7 +2450,7 @@ impl AggregationUpdateQueue {
/// See detailed comments in that function, follow the STEP numbers.
fn inner_of_uppers_has_new_follower<T: TaskIdWithOptionalCount + Clone, const N: usize>(
&mut self,
ctx: &mut ExecuteContext<'_>,
ctx: &ExecuteContext<'_>,
new_follower_id: TaskId,
mut upper_ids: SmallVec<[T; N]>,
) {
......@@ -2696,7 +2696,7 @@ impl AggregationUpdateQueue {
/// See detailed comments in that function, follow the STEP numbers.
fn inner_of_upper_has_new_followers<T: TaskIdWithOptionalCount, const N: usize>(
&mut self,
ctx: &mut ExecuteContext<'_>,
ctx: &ExecuteContext<'_>,
new_follower_ids: SmallVec<[T; N]>,
upper_id: TaskId,
) {
......@@ -2957,7 +2957,7 @@ impl AggregationUpdateQueue {
fn inner_of_upper_has_new_follower(
&mut self,
ctx: &mut ExecuteContext<'_>,
ctx: &ExecuteContext<'_>,
new_follower_id: TaskId,
upper_id: TaskId,
count: u32,
......@@ -3139,7 +3139,7 @@ impl AggregationUpdateQueue {
/// Decreases the active count of a task.
///
/// Only used when activeness is tracked.
fn decrease_active_count(&mut self, ctx: &mut ExecuteContext<'_>, task_id: TaskId) {
fn decrease_active_count(&mut self, ctx: &ExecuteContext<'_>, task_id: TaskId) {
#[cfg(feature = "trace_aggregation_update")]
let _span = trace_span!("decrease active count").entered();
......@@ -3186,7 +3186,7 @@ impl AggregationUpdateQueue {
/// Only used when activeness is tracked.
fn increase_active_count(
&mut self,
ctx: &mut ExecuteContext<'_>,
ctx: &ExecuteContext<'_>,
task_id: TaskId,
release_construction_ref: bool,
) {
......@@ -3238,7 +3238,7 @@ impl AggregationUpdateQueue {
fn update_aggregation_number(
&mut self,
ctx: &mut ExecuteContext<'_>,
ctx: &ExecuteContext<'_>,
task_id: TaskId,
base_effective_distance: Option<std::num::NonZero<u32>>,
base_aggregation_number: u32,
......@@ -3342,7 +3342,7 @@ impl AggregationUpdateQueue {
/// does so); when `false`, the flag is known to be unset already and we can skip the write.
fn optimize_task(
&mut self,
ctx: &mut ExecuteContext<'_>,
ctx: &ExecuteContext<'_>,
task_id: TaskId,
optimization_pending_flag_already_set: bool,
) {
......@@ -3485,17 +3485,14 @@ impl AggregationUpdateQueue {
}
#[cfg(feature = "trace_aggregation_update_stats")]
pub fn execute_with_stats(
&mut self,
ctx: &mut ExecuteContext<'_>,
) -> AggregationUpdateQueueStats {
pub fn execute_with_stats(&mut self, ctx: &ExecuteContext<'_>) -> AggregationUpdateQueueStats {
while !self.process(ctx) {}
take(&mut self.stats)
}
}
impl AggregationUpdateQueue {
pub fn execute(&mut self, ctx: &mut ExecuteContext<'_>) {
pub fn execute(&mut self, ctx: &ExecuteContext<'_>) {
while !self.process(ctx) {}
}
}
......
......@@ -88,7 +88,7 @@ pub fn cleanup_old_edges(
task_id: TaskId,
outdated: Vec<OutdatedEdge>,
queue: AggregationUpdateQueue,
ctx: &mut ExecuteContext<'_>,
ctx: &ExecuteContext<'_>,
) -> Stats {
cleanup_old_edges_inner(task_id, outdated, queue, ctx, false).0
}
......@@ -101,7 +101,7 @@ pub fn cleanup_old_edges(
pub fn cleanup_old_edges_deletions_only(
task_id: TaskId,
outdated: Vec<OutdatedEdge>,
ctx: &mut ExecuteContext<'_>,
ctx: &ExecuteContext<'_>,
) -> DeferredCleanup {
let (_, stopped) = cleanup_old_edges_inner(
task_id,
......@@ -118,7 +118,7 @@ fn cleanup_old_edges_inner(
task_id: TaskId,
mut outdated: Vec<OutdatedEdge>,
mut queue: AggregationUpdateQueue,
ctx: &mut ExecuteContext<'_>,
ctx: &ExecuteContext<'_>,
stop_when_only_rebalance_remains: bool,
) -> (Stats, Option<DeferredCleanup>) {
while let Some(edge) = outdated.pop() {
......
......@@ -20,12 +20,12 @@ use crate::{
/// connect handshake.
///
/// GC destructively mutates tasks so mark resurrected tasks as dirty to get them re-scheduled.
pub(super) fn resurrect_deleted<'e>(
guard: TaskGuard<'e>,
pub(super) fn resurrect_deleted<'ctx>(
guard: TaskGuard<'ctx>,
task_id: TaskId,
queue: &mut AggregationUpdateQueue,
ctx: &mut ExecuteContext<'e>,
) -> TaskGuard<'e> {
ctx: &'ctx ExecuteContext<'_>,
) -> TaskGuard<'ctx> {
if !guard.deleted() {
return guard;
}
......@@ -64,7 +64,7 @@ pub(super) fn resurrect_deleted<'e>(
task
}
fn release_construction_ref(task_id: TaskId, ctx: &mut ExecuteContext<'_>) {
fn release_construction_ref(task_id: TaskId, ctx: &ExecuteContext<'_>) {
let mut task = ctx.task(task_id, TaskDataCategory::Meta);
task.update_and_get_transient_ref_count(-1);
}
......@@ -73,7 +73,7 @@ pub fn connect_child(
parent_task_id: Option<TaskId>,
child_task_id: TaskId,
release_construction_ref: bool,
mut ctx: ExecuteContext<'_>,
ctx: ExecuteContext<'_>,
) {
if parent_task_id.is_none() {
// All parentless tasks receive a transient ref when connected: their lifetime cannot be
......@@ -95,7 +95,7 @@ pub fn connect_child(
if new_children.contains(&child_task_id) {
drop(parent_task);
if release_construction_ref {
self::release_construction_ref(child_task_id, &mut ctx);
self::release_construction_ref(child_task_id, &ctx);
}
return;
}
......@@ -111,7 +111,7 @@ pub fn connect_child(
new_children.insert(child_task_id);
drop(parent_task);
if release_construction_ref {
self::release_construction_ref(child_task_id, &mut ctx);
self::release_construction_ref(child_task_id, &ctx);
}
return;
}
......@@ -142,7 +142,7 @@ pub fn connect_child(
// Revive the child if GC soft-deleted it. This can happen in a rare race between a
// cache hit on a task and snapshotting actually performing the delete.
let mut child_task = resurrect_deleted(child_task, child_task_id, &mut queue, &mut ctx);
let mut child_task = resurrect_deleted(child_task, child_task_id, &mut queue, &ctx);
let has_output = child_task.has_output();
// An already constructed top-level task was made a root when it was first connected.
......@@ -174,7 +174,7 @@ pub fn connect_child(
}
if !queue.is_empty() {
queue.execute(&mut ctx);
queue.execute(&ctx);
}
if let Some(parent_task_id) = parent_task_id {
......@@ -195,7 +195,7 @@ pub fn connect_child(
AggregationUpdateJob::DecreaseActiveCount {
task: child_task_id,
},
&mut ctx,
&ctx,
);
}
}
......
......@@ -18,7 +18,7 @@ use crate::backend::{
};
pub fn connect_children(
ctx: &mut ExecuteContext<'_>,
ctx: &ExecuteContext<'_>,
parent_task_id: TaskId,
mut parent_task: TaskGuard<'_>,
new_children: FxHashSet<TaskId>,
......@@ -46,7 +46,7 @@ pub fn connect_children(
drop(parent_task);
fn process_new_children(
ctx: &mut ExecuteContext<'_>,
ctx: &ExecuteContext<'_>,
new_follower_ids: SmallVec<[TaskId; 4]>,
upper_ids: Option<SmallVec<[TaskId; 4]>>,
parent_task_id: TaskId,
......@@ -183,10 +183,10 @@ pub fn connect_children(
let upper_ids = &upper_ids;
let child_ctx = ctx.child_context();
scope.spawn(move || {
let mut ctx = child_ctx.create();
let ctx = child_ctx.create();
let new_follower_ids = chunk.collect::<SmallVec<[_; 4]>>();
process_new_children(
&mut ctx,
&ctx,
new_follower_ids,
upper_ids.clone(),
parent_task_id,
......
......@@ -20,7 +20,7 @@ use crate::{
pub fn invalidate(
task_ids: SmallVec<[TaskId; 4]>,
#[cfg(feature = "task_dirty_cause")] cause: TaskDirtyCause,
mut ctx: ExecuteContext<'_>,
ctx: ExecuteContext<'_>,
) {
let mut queue = AggregationUpdateQueue::new();
for task_id in task_ids {
......@@ -29,10 +29,10 @@ pub fn invalidate(
#[cfg(feature = "task_dirty_cause")]
cause.clone(),
&mut queue,
&mut ctx,
&ctx,
);
}
queue.execute(&mut ctx);
queue.execute(&ctx);
}
/// Marks a task dirty, doing nothing if it no longer exists.
......@@ -42,7 +42,7 @@ pub fn try_make_task_dirty(
task_id: TaskId,
#[cfg(feature = "task_dirty_cause")] cause: TaskDirtyCause,
queue: &mut AggregationUpdateQueue,
ctx: &mut ExecuteContext<'_>,
ctx: &ExecuteContext<'_>,
) {
let Some(mut task) = ctx.try_task(task_id, TaskDataCategory::All) else {
return;
......@@ -63,7 +63,7 @@ pub fn make_task_dirty_internal(
make_stale: bool,
#[cfg(feature = "task_dirty_cause")] cause: TaskDirtyCause,
queue: &mut AggregationUpdateQueue,
ctx: &mut ExecuteContext<'_>,
ctx: &ExecuteContext<'_>,
) {
// There must be no way to invalidate immutable tasks. If there would be a way the task is not
// immutable.
......
......@@ -85,7 +85,7 @@ impl LeafDistanceUpdateQueue {
}
/// Executes a single step of the queue. Returns true, when the queue is empty.
pub fn process(&mut self, ctx: &mut ExecuteContext<'_>) -> bool {
pub fn process(&mut self, ctx: &ExecuteContext<'_>) -> bool {
let mut remaining = MAX_COUNT_BEFORE_YIELD;
while remaining > 0 {
if let Some((Reverse(queue_dependencies_distance), task_id)) = self.queue.pop() {
......@@ -121,7 +121,7 @@ impl LeafDistanceUpdateQueue {
fn update_leaf_distance(
&mut self,
ctx: &mut ExecuteContext<'_>,
ctx: &ExecuteContext<'_>,
task_id: TaskId,
dependencies_distance: u32,
dependencies_max_distance_in_buffer: u32,
......@@ -169,7 +169,7 @@ impl LeafDistanceUpdateQueue {
task.set_leaf_distance(leaf_distance);
}
pub fn execute(&mut self, ctx: &mut ExecuteContext<'_>) {
pub fn execute(&mut self, ctx: &ExecuteContext<'_>) {
if self.is_empty() {
return;
}
......
......@@ -29,7 +29,7 @@ pub fn update_cell(
content_hash: Option<CellHash>,
#[cfg(feature = "verify_determinism")] verification_mode: VerificationMode,
#[cfg(not(feature = "verify_determinism"))] _verification_mode: VerificationMode,
mut ctx: ExecuteContext<'_>,
ctx: ExecuteContext<'_>,
) {
let value_type = registry::get_value_type(cell.type_id());
// `content_hash` is only ever supplied for `HashOnly` cells — only the
......@@ -186,7 +186,7 @@ pub fn update_cell(
#[cfg(feature = "task_dirty_cause")]
has_updated_key_hashes,
content.map(|r| r.into_typed(cell.type_id())),
&mut ctx,
&ctx,
);
return;
}
......@@ -235,7 +235,7 @@ fn invalidate_cell_dependents(
mut dependent_tasks: FxIndexMap<TaskId, SmallVec<[Option<u64>; 2]>>,
#[cfg(feature = "task_dirty_cause")] has_updated_key_hashes: bool,
content: Option<TypedSharedReference>,
ctx: &mut ExecuteContext<'_>,
ctx: &ExecuteContext<'_>,
) {
let mut queue = AggregationUpdateQueue::new();
while let Some((dependent_task_id, keys)) = dependent_tasks.pop() {
......
......@@ -21,7 +21,7 @@ impl UpdateCollectibleOperation {
task_id: TaskId,
collectible: CollectibleRef,
mut count: i32,
mut ctx: ExecuteContext<'_>,
ctx: ExecuteContext<'_>,
) {
let mut task = ctx.task(task_id, TaskDataCategory::All);
if count < 0
......@@ -75,6 +75,6 @@ impl UpdateCollectibleOperation {
drop(task);
queue.execute(&mut ctx);
queue.execute(&ctx);
}
}
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