Commit 77285690 authored by Tobias Koppers's avatar Tobias Koppers

turbo-tasks-backend: add Argument edge type to track task argument relationships

Add `argument_of: AutoSet<TaskId>` field (data category, filter_transient) to
TaskStorageSchema. Add `task_execution_completed_arguments` method that runs
after `task_execution_completed_connect` and before `task_execution_completed_finish`,
only on first execution (when output is not yet set). It uses TraceRawVcs on
both `this` and `arg` of the task's CachedTaskType to collect all referenced
tasks and records the consumer task ID in each argument task's `argument_of` set.
These edges are permanent and never cleaned up.
Co-Authored-By: 's avatarClaude <noreply@anthropic.com>
parent c53f5863
...@@ -464,6 +464,9 @@ struct TaskExecutionCompletePrepareResult { ...@@ -464,6 +464,9 @@ struct TaskExecutionCompletePrepareResult {
pub is_now_immutable: bool, pub is_now_immutable: bool,
#[cfg(feature = "verify_determinism")] #[cfg(feature = "verify_determinism")]
pub no_output_set: bool, pub no_output_set: bool,
/// True when the task's output was not set before this execution (i.e. first run).
/// Used to populate the `argument_of` edge exactly once.
pub is_first_execution: bool,
pub new_output: Option<OutputValue>, pub new_output: Option<OutputValue>,
pub output_dependent_tasks: SmallVec<[TaskId; 4]>, pub output_dependent_tasks: SmallVec<[TaskId; 4]>,
} }
...@@ -1955,6 +1958,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> { ...@@ -1955,6 +1958,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
is_now_immutable, is_now_immutable,
#[cfg(feature = "verify_determinism")] #[cfg(feature = "verify_determinism")]
no_output_set, no_output_set,
is_first_execution,
new_output, new_output,
output_dependent_tasks, output_dependent_tasks,
}) = self.task_execution_completed_prepare( }) = self.task_execution_completed_prepare(
...@@ -2008,6 +2012,10 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> { ...@@ -2008,6 +2012,10 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
return true; return true;
} }
if is_first_execution {
self.task_execution_completed_arguments(&mut ctx, task_id);
}
let (stale, in_progress_cells) = self.task_execution_completed_finish( let (stale, in_progress_cells) = self.task_execution_completed_finish(
&mut ctx, &mut ctx,
task_id, task_id,
...@@ -2053,6 +2061,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> { ...@@ -2053,6 +2061,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
is_now_immutable: false, is_now_immutable: false,
#[cfg(feature = "verify_determinism")] #[cfg(feature = "verify_determinism")]
no_output_set: false, no_output_set: false,
is_first_execution: false,
new_output: None, new_output: None,
output_dependent_tasks: Default::default(), output_dependent_tasks: Default::default(),
}); });
...@@ -2202,6 +2211,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> { ...@@ -2202,6 +2211,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
let current_output = task.get_output(); let current_output = task.get_output();
#[cfg(feature = "verify_determinism")] #[cfg(feature = "verify_determinism")]
let no_output_set = current_output.is_none(); let no_output_set = current_output.is_none();
let is_first_execution = current_output.is_none();
let new_output = match result { let new_output = match result {
Ok(RawVc::TaskOutput(output_task_id)) => { Ok(RawVc::TaskOutput(output_task_id)) => {
if let Some(OutputValue::Output(current_task_id)) = current_output if let Some(OutputValue::Output(current_task_id)) = current_output
...@@ -2275,6 +2285,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> { ...@@ -2275,6 +2285,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
is_now_immutable, is_now_immutable,
#[cfg(feature = "verify_determinism")] #[cfg(feature = "verify_determinism")]
no_output_set, no_output_set,
is_first_execution,
new_output, new_output,
output_dependent_tasks, output_dependent_tasks,
}) })
...@@ -2471,6 +2482,36 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> { ...@@ -2471,6 +2482,36 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
false false
} }
fn task_execution_completed_arguments(
&self,
ctx: &mut impl ExecuteContext<'_>,
task_id: TaskId,
) {
// Record this task as a consumer ("argument user") on each task that appears as
// an argument in this task's CachedTaskType. This is done exactly once — on the
// first execution — and never cleaned up, so the edges are permanent.
let task = ctx.task(task_id, TaskDataCategory::Data);
let Some(task_type) = task.get_persistent_task_type().cloned() else {
// Transient tasks have no persistent_task_type; nothing to record.
return;
};
drop(task);
// Collect all RawVcs referenced by `this` and `arg`.
let mut raw_vcs: Vec<RawVc> = Vec::new();
if let Some(this) = task_type.this {
raw_vcs.extend(this.get_raw_vcs());
}
raw_vcs.extend(task_type.arg.get_raw_vcs());
for raw_vc in raw_vcs {
if let Some(arg_task_id) = raw_vc.try_get_task_id() {
let mut arg_task = ctx.task(arg_task_id, TaskDataCategory::Data);
let _ = arg_task.add_argument_of(task_id);
}
}
}
fn task_execution_completed_finish( fn task_execution_completed_finish(
&self, &self,
ctx: &mut impl ExecuteContext<'_>, ctx: &mut impl ExecuteContext<'_>,
......
...@@ -258,6 +258,11 @@ struct TaskStorageSchema { ...@@ -258,6 +258,11 @@ struct TaskStorageSchema {
)] )]
cell_dependents: AutoSet<(CellId, Option<u64>, TaskId)>, cell_dependents: AutoSet<(CellId, Option<u64>, TaskId)>,
/// Tasks that use this task as an argument (Argument edges).
/// Populated once on first execution and never cleaned up — edges are permanent.
#[field(storage = "auto_set", category = "data", filter_transient)]
argument_of: AutoSet<TaskId>,
/// Tasks that depend on collectibles of a specific type from this task. /// Tasks that depend on collectibles of a specific type from this task.
/// Maps TraitTypeId -> Set<TaskId> /// Maps TraitTypeId -> Set<TaskId>
......
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