1- use std:: num:: NonZeroU32 ;
1+ use std:: { cmp :: max , num:: NonZeroU32 } ;
22
33use serde:: { Deserialize , Serialize } ;
44use turbo_tasks:: TaskId ;
@@ -59,19 +59,26 @@ impl ConnectChildOperation {
5959 let current_parent_aggregation = get ! ( parent_task, AggregationNumber )
6060 . copied ( )
6161 . unwrap_or_default ( ) ;
62- let parent_aggregation = if is_root_node ( current_parent_aggregation. base ) {
63- u32:: MAX
64- } else {
65- let target_distance = children_count. ilog2 ( ) * 2 ;
66- if target_distance != current_parent_aggregation. distance {
67- queue. push ( AggregationUpdateJob :: UpdateAggregationNumber {
68- task_id : parent_task_id,
69- base_aggregation_number : 0 ,
70- distance : NonZeroU32 :: new ( target_distance) ,
71- } )
72- }
73- current_parent_aggregation. effective
74- } ;
62+ let ( parent_aggregation, future_parent_aggregation) =
63+ if is_root_node ( current_parent_aggregation. base ) {
64+ ( u32:: MAX , u32:: MAX )
65+ } else {
66+ let target_distance = children_count. ilog2 ( ) * 2 ;
67+ if target_distance > current_parent_aggregation. distance {
68+ queue. push ( AggregationUpdateJob :: UpdateAggregationNumber {
69+ task_id : parent_task_id,
70+ base_aggregation_number : 0 ,
71+ distance : NonZeroU32 :: new ( target_distance) ,
72+ } )
73+ }
74+ (
75+ current_parent_aggregation. effective ,
76+ current_parent_aggregation. base . saturating_add ( max (
77+ target_distance,
78+ current_parent_aggregation. distance ,
79+ ) ) ,
80+ )
81+ } ;
7582
7683 // Update child aggregation number based on parent aggregation number
7784 let aggregating_node = is_aggregating_node ( parent_aggregation) ;
@@ -83,7 +90,7 @@ impl ConnectChildOperation {
8390 } ) ;
8491 } else if !aggregating_node {
8592 let base_aggregation_number =
86- parent_aggregation . saturating_add ( AGGREGATION_NUMBER_BUFFER_SPACE ) ;
93+ future_parent_aggregation . saturating_add ( AGGREGATION_NUMBER_BUFFER_SPACE ) ;
8794 queue. push ( AggregationUpdateJob :: UpdateAggregationNumber {
8895 task_id : child_task_id,
8996 base_aggregation_number : if is_aggregating_node (
0 commit comments