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

Align ExecuteContext task accessor names (#99258)

### What?

Align `ExecuteContext` task accessors around their behavior when a task
is absent: keep the frequently used `task`, use `try_task` for optional
access, and `task_or_create` where storage may need to be materialized.

### Why?

The three operations had inconsistent names despite sharing the same
task-access mechanism. In addition, the diagnostic `get_task_name` path
could create storage merely to name a missing task.

### How?

Keep the shared private task-opening logic and its existing access
policies; rename the public context methods and their callers.
`get_task_name` now takes the optional path and returns `"unknown"` if
the task is absent, without creating storage. The separate
`Backend::get_or_create_task` API is unchanged.

### Verification

- `cargo fmt --all -- --check`
- `cargo test -p turbo-tasks-backend --test basic --test errors --test
invalidation` (19 passed)
- `git diff --check`


<!-- fleet 8ec6f3d1-8af4-46e7-9a88-fd25742f533d -->

---------
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 238fe941
...@@ -1946,13 +1946,17 @@ impl TurboTasksBackend { ...@@ -1946,13 +1946,17 @@ impl TurboTasksBackend {
) -> String { ) -> String {
let mut ctx = self.execute_context(turbo_tasks); let mut ctx = self.execute_context(turbo_tasks);
// Diagnostic path: the caller may name any id, including one that no longer exists, so this // Diagnostic path: the caller may name any id, including one that no longer exists, so this
// must not assert existence. A nonexistent task falls through to the "unknown" case below. // must not assert existence or create storage for a missing task.
let task = ctx.open_or_create_task_storage(task_id, TaskDataCategory::Data); let Some(task) = ctx.try_task(task_id, TaskDataCategory::Data) else {
return "unknown".to_string();
};
if let Some(value) = task.get_persistent_task_type() { if let Some(value) = task.get_persistent_task_type() {
value.to_string() value.to_string()
} else if let Some(value) = task.get_transient_task_type() { } else if let Some(value) = task.get_transient_task_type() {
value.to_string() value.to_string()
} else { } else {
// A stale transient id may open a blank task without a type; diagnostics should not
// panic.
"unknown".to_string() "unknown".to_string()
} }
} }
......
...@@ -91,8 +91,7 @@ impl ConnectChildOperation { ...@@ -91,8 +91,7 @@ impl ConnectChildOperation {
// 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
// constrained by turbo-tasks and needs to be managed by the caller. If the caller // constrained by turbo-tasks and needs to be managed by the caller. If the caller
// doesn't manage it, the GC root TTL handles it in a later session. // doesn't manage it, the GC root TTL handles it in a later session.
let mut child_task = let mut child_task = ctx.task_or_create(child_task_id, TaskDataCategory::Meta);
ctx.open_or_create_task_storage(child_task_id, TaskDataCategory::Meta);
child_task.update_and_get_transient_ref_count(1); child_task.update_and_get_transient_ref_count(1);
} }
if let Some(parent_task_id) = parent_task_id { if let Some(parent_task_id) = parent_task_id {
...@@ -152,7 +151,7 @@ impl ConnectChildOperation { ...@@ -152,7 +151,7 @@ impl ConnectChildOperation {
} else { } else {
// First connect of this child: its id is minted but the storage entry may not exist // First connect of this child: its id is minted but the storage entry may not exist
// yet, and concurrent connects race to be the one that first touches it. // yet, and concurrent connects race to be the one that first touches it.
let child_task = ctx.open_or_create_task_storage(child_task_id, TaskDataCategory::Meta); let child_task = ctx.task_or_create(child_task_id, TaskDataCategory::Meta);
// Revive the child if GC soft-deleted it. This can happen in a rare race between a // 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. // cache hit on a task and snapshotting actually performing the delete.
......
...@@ -115,7 +115,7 @@ pub fn try_make_task_dirty( ...@@ -115,7 +115,7 @@ pub fn try_make_task_dirty(
queue: &mut AggregationUpdateQueue, queue: &mut AggregationUpdateQueue,
ctx: &mut impl ExecuteContext<'_>, ctx: &mut impl ExecuteContext<'_>,
) { ) {
let Some(mut task) = ctx.try_get_task(task_id, TaskDataCategory::All) else { let Some(mut task) = ctx.try_task(task_id, TaskDataCategory::All) else {
return; return;
}; };
make_task_dirty_internal( make_task_dirty_internal(
......
...@@ -77,8 +77,8 @@ impl DerefMut for OpenedTask<'_> { ...@@ -77,8 +77,8 @@ impl DerefMut for OpenedTask<'_> {
/// Whether an [`ExecuteContext`] task open may create the task, requires it to already exist, or /// Whether an [`ExecuteContext`] task open may create the task, requires it to already exist, or
/// tolerates its absence. A private impl detail behind the three public methods /// tolerates its absence. A private impl detail behind the three public methods
/// ([`ExecuteContext::task`] = `MustExist`, [`ExecuteContext::open_or_create_task_storage`] = /// ([`ExecuteContext::task`] = `MustExist`, [`ExecuteContext::task_or_create`] =
/// `MaybeCreate`, [`ExecuteContext::try_get_task`] = `AllowMissing`). /// `MaybeCreate`, [`ExecuteContext::try_task`] = `AllowMissing`).
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
enum TaskAccess { enum TaskAccess {
/// Open the task, creating it if it does not exist: `access_mut` inserts a blank entry, then /// Open the task, creating it if it does not exist: `access_mut` inserts a blank entry, then
...@@ -105,7 +105,7 @@ pub trait ExecuteContext<'e>: Sized { ...@@ -105,7 +105,7 @@ pub trait ExecuteContext<'e>: Sized {
/// Opens a task that must **already exist**, restoring the requested `category` if needed. A /// Opens a task that must **already exist**, restoring the requested `category` if needed. A
/// task that exists in neither memory nor persistent storage is a stale reference, so this /// task that exists in neither memory nor persistent storage is a stale reference, so this
/// panics rather than fabricate a blank. This is the common case; use /// panics rather than fabricate a blank. This is the common case; use
/// [`Self::open_or_create_task_storage`] only where the task may be getting materialized for /// [`Self::task_or_create`] only where the task may be getting materialized for
/// the first time. /// the first time.
/// ///
/// The check applies only to persistent tasks; a `MustExist` open of a transient id falls /// The check applies only to persistent tasks; a `MustExist` open of a transient id falls
...@@ -115,7 +115,7 @@ pub trait ExecuteContext<'e>: Sized { ...@@ -115,7 +115,7 @@ pub trait ExecuteContext<'e>: Sized {
/// ///
/// Gone covers both a task that exists nowhere and one that is soft-deleted: the caller cannot /// Gone covers both a task that exists nowhere and one that is soft-deleted: the caller cannot
/// tell those apart, since only the timing of the next eviction separates them. /// tell those apart, since only the timing of the next eviction separates them.
fn try_get_task( fn try_task(
&mut self, &mut self,
task_id: TaskId, task_id: TaskId,
category: TaskDataCategory, category: TaskDataCategory,
...@@ -127,8 +127,8 @@ pub trait ExecuteContext<'e>: Sized { ...@@ -127,8 +127,8 @@ pub trait ExecuteContext<'e>: Sized {
/// ///
/// This creates *storage for* an already-minted `TaskId`; it does not mint one. Compare /// This creates *storage for* an already-minted `TaskId`; it does not mint one. Compare
/// `TurboTasksBackend::get_or_create_task`, which takes a function and arguments and returns a /// `TurboTasksBackend::get_or_create_task`, which takes a function and arguments and returns a
/// new `TaskId`. /// `TaskId` (reusing one if the task is already cached).
fn open_or_create_task_storage( fn task_or_create(
&mut self, &mut self,
task_id: TaskId, task_id: TaskId,
category: TaskDataCategory, category: TaskDataCategory,
...@@ -1102,7 +1102,7 @@ impl<'e> ExecuteContext<'e> for ExecuteContextImpl<'e> { ...@@ -1102,7 +1102,7 @@ impl<'e> ExecuteContext<'e> for ExecuteContextImpl<'e> {
.expect("a MustExist open either yields a task or panics") .expect("a MustExist open either yields a task or panics")
} }
fn try_get_task( fn try_task(
&mut self, &mut self,
task_id: TaskId, task_id: TaskId,
category: TaskDataCategory, category: TaskDataCategory,
...@@ -1110,7 +1110,7 @@ impl<'e> ExecuteContext<'e> for ExecuteContextImpl<'e> { ...@@ -1110,7 +1110,7 @@ impl<'e> ExecuteContext<'e> for ExecuteContextImpl<'e> {
self.open_task(task_id, category, TaskAccess::AllowMissing) self.open_task(task_id, category, TaskAccess::AllowMissing)
} }
fn open_or_create_task_storage( fn task_or_create(
&mut self, &mut self,
task_id: TaskId, task_id: TaskId,
category: TaskDataCategory, category: TaskDataCategory,
......
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