Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Sep 4, 2024
1 parent 5ec33db commit 67ba486
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
4 changes: 3 additions & 1 deletion turbopack/crates/turbo-tasks-backend/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ impl Backend for TurboTasksBackend {

let task_type = Arc::new(task_type);
let task_id = self.transient_task_id_factory.get();
if let Err(existing_task_id) = self.task_cache.try_insert(task_type, task_id) {
if let Err(existing_task_id) = self.task_cache.try_insert(task_type.clone(), task_id) {
// Safety: We just created the id and failed to insert it.
unsafe {
self.transient_task_id_factory.reuse(task_id);
Expand All @@ -618,6 +618,8 @@ impl Backend for TurboTasksBackend {
return existing_task_id;
}

println!("{task_id} {task_type:?}");

self.connect_child(parent_task, task_id, turbo_tasks);

task_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ impl AggregatedDataUpdate {
dirty_task_count,
dirty_tasks_update,
} = self;
println!("apply {:?} {dirty_tasks_update:?}", task.id());
let mut result = Self::default();
if *dirty_task_count != 0 {
update!(task, AggregatedDirtyTaskCount, |old: Option<i32>| {
Expand Down Expand Up @@ -268,6 +269,7 @@ impl AggregationUpdateQueue {

pub fn process(&mut self, ctx: &ExecuteContext<'_>) -> bool {
if let Some(job) = self.jobs.pop_front() {
println!("process {:?}", job);
match job {
AggregationUpdateJob::UpdateAggregationNumber {
task_id,
Expand All @@ -276,6 +278,10 @@ impl AggregationUpdateQueue {
let mut task = ctx.task(task_id);
let old = get_aggregation_number(&task);
if old < aggregation_number {
println!(
"UpdateAggregationNumber {:?} {} -> {}",
task_id, old, aggregation_number
);
task.insert(CachedDataItem::AggregationNumber {
value: aggregation_number,
});
Expand Down Expand Up @@ -565,6 +571,11 @@ impl AggregationUpdateQueue {
let (mut upper, mut task) = ctx.task_pair(upper_id, task_id);
let upper_aggregation_number = get_aggregation_number(&upper);
let task_aggregation_number = get_aggregation_number(&task);
println!(
"BalanceEdge {:?} {upper_aggregation_number} {:?} \
{task_aggregation_number}",
upper_id, task_id
);

let should_be_inner = is_root_node(upper_aggregation_number)
|| upper_aggregation_number > task_aggregation_number;
Expand Down Expand Up @@ -675,7 +686,12 @@ impl AggregationUpdateQueue {
}
}

self.jobs.is_empty()
if self.jobs.is_empty() {
println!("done");
true
} else {
false
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,14 @@ impl Operation for InvalidateOperation {
pub fn make_task_dirty(task_id: TaskId, queue: &mut AggregationUpdateQueue, ctx: &ExecuteContext) {
let mut task = ctx.task(task_id);

println!("make_task_dirty {:?}", task_id);

if task.add(CachedDataItem::Dirty { value: () }) {
queue.push(AggregationUpdateJob::DataUpdate {
task_id,
update: AggregatedDataUpdate::dirty_task(task_id),
})
} else {
println!("already dirty");
}
}
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-backend/tests/scope_stress.rs
3 changes: 3 additions & 0 deletions turbopack/crates/turbo-tasks-testing/tests/emptied_cells.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ struct ChangingInput {
#[turbo_tasks::function]
async fn compute(input: Vc<ChangingInput>) -> Result<Vc<u32>> {
let value = *inner_compute(input).await?;
println!("compute {value}");
Ok(Vc::cell(value))
}

#[turbo_tasks::function]
async fn inner_compute(input: Vc<ChangingInput>) -> Result<Vc<u32>> {
let state_value = *input.await?.state.get();
println!("inner_compute {state_value}");
let mut last = None;
for i in 0..=state_value {
last = Some(compute2(Vc::cell(i)));
Expand All @@ -66,5 +68,6 @@ async fn inner_compute(input: Vc<ChangingInput>) -> Result<Vc<u32>> {
#[turbo_tasks::function]
async fn compute2(input: Vc<u32>) -> Result<Vc<u32>> {
let value = *input.await?;
println!("compute2 {value}");
Ok(Vc::cell(value))
}

0 comments on commit 67ba486

Please sign in to comment.