@@ -604,7 +604,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
604604 ctx. get_task_description( task_id)
605605 ) ;
606606 } ;
607- if cell. index > * max_id {
607+ if cell. index >= * max_id {
608608 add_cell_dependency ( self , task, reader, cell, task_id, & mut ctx) ;
609609 bail ! (
610610 "Cell {cell:?} no longer exists in task {} (index out of bounds)" ,
@@ -1228,7 +1228,6 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
12281228 let _ = stateful;
12291229
12301230 // handle cell counters: update max index and remove cells that are no longer used
1231- let mut removed_cells = HashMap :: new ( ) ;
12321231 let mut old_counters: HashMap < _ , _ > =
12331232 get_many ! ( task, CellTypeMaxIndex { cell_type } max_index => ( * cell_type, * max_index) ) ;
12341233 for ( & cell_type, & max_index) in cell_counters. iter ( ) {
@@ -1238,9 +1237,6 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
12381237 cell_type,
12391238 value : max_index,
12401239 } ) ;
1241- if old_max_index > max_index {
1242- removed_cells. insert ( cell_type, max_index + 1 ..=old_max_index) ;
1243- }
12441240 }
12451241 } else {
12461242 task. add_new ( CachedDataItem :: CellTypeMaxIndex {
@@ -1249,28 +1245,39 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
12491245 } ) ;
12501246 }
12511247 }
1252- for ( cell_type, old_max_index ) in old_counters {
1248+ for ( cell_type, _ ) in old_counters {
12531249 task. remove ( & CachedDataItemKey :: CellTypeMaxIndex { cell_type } ) ;
1254- removed_cells. insert ( cell_type, 0 ..=old_max_index) ;
12551250 }
1251+
12561252 let mut removed_data = Vec :: new ( ) ;
1257- for ( & cell_type, range) in removed_cells. iter ( ) {
1258- for index in range. clone ( ) {
1259- removed_data. extend (
1260- task. remove ( & CachedDataItemKey :: CellData {
1261- cell : CellId {
1262- type_id : cell_type,
1263- index,
1264- } ,
1265- } )
1266- . into_iter ( ) ,
1267- ) ;
1268- }
1269- }
1253+ let mut old_edges = Vec :: new ( ) ;
12701254
1255+ // Remove no longer existing cells and notify in progress cells
12711256 // find all outdated data items (removed cells, outdated edges)
1272- let old_edges = if task. is_indexed ( ) {
1273- let mut old_edges = Vec :: new ( ) ;
1257+ if task. is_indexed ( ) {
1258+ removed_data. extend ( task. extract_if (
1259+ CachedDataItemIndex :: InProgressCell ,
1260+ |key, value| {
1261+ match ( key, value) {
1262+ (
1263+ & CachedDataItemKey :: InProgressCell { cell } ,
1264+ CachedDataItemValue :: InProgressCell { value } ,
1265+ ) if cell_counters
1266+ . get ( & cell. type_id )
1267+ . map_or ( true , |start_index| cell. index >= * start_index) =>
1268+ {
1269+ value. event . notify ( usize:: MAX ) ;
1270+ true
1271+ }
1272+ _ => false ,
1273+ }
1274+ } ,
1275+ ) ) ;
1276+ removed_data. extend ( task. extract_if ( CachedDataItemIndex :: CellData , |key, _| {
1277+ matches ! ( key, & CachedDataItemKey :: CellData { cell } if cell_counters
1278+ . get( & cell. type_id)
1279+ . map_or( true , |start_index| cell. index >= * start_index) )
1280+ } ) ) ;
12741281 if self . should_track_children ( ) {
12751282 old_edges. extend ( task. iter ( CachedDataItemIndex :: Children ) . filter_map (
12761283 |( key, _) | match * key {
@@ -1306,9 +1313,9 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
13061313 |( key, _) | {
13071314 match * key {
13081315 CachedDataItemKey :: CellDependent { cell, task }
1309- if removed_cells
1316+ if cell_counters
13101317 . get ( & cell. type_id )
1311- . map_or ( false , |range| range . contains ( & cell. index ) ) =>
1318+ . map_or ( true , |start_index| cell. index >= * start_index ) =>
13121319 {
13131320 Some ( OutdatedEdge :: RemovedCellDependent ( task, cell. type_id ) )
13141321 }
@@ -1317,36 +1324,53 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
13171324 } ,
13181325 ) ) ;
13191326 }
1320- old_edges
13211327 } else {
1322- task. iter_all ( )
1323- . filter_map ( |( key, value) | match * key {
1324- CachedDataItemKey :: OutdatedChild { task } => Some ( OutdatedEdge :: Child ( task) ) ,
1325- CachedDataItemKey :: OutdatedCollectible { collectible } => {
1326- let CachedDataItemValue :: OutdatedCollectible { value } = * value else {
1327- unreachable ! ( ) ;
1328- } ;
1329- Some ( OutdatedEdge :: Collectible ( collectible, value) )
1328+ removed_data. extend ( task. extract_if_all ( |key, value| {
1329+ match ( key, value) {
1330+ (
1331+ & CachedDataItemKey :: InProgressCell { cell } ,
1332+ CachedDataItemValue :: InProgressCell { value } ,
1333+ ) if cell_counters
1334+ . get ( & cell. type_id )
1335+ . map_or ( true , |start_index| cell. index >= * start_index) =>
1336+ {
1337+ value. event . notify ( usize:: MAX ) ;
1338+ return true ;
13301339 }
1331- CachedDataItemKey :: OutdatedCellDependency { target } => {
1332- Some ( OutdatedEdge :: CellDependency ( target) )
1340+ ( & CachedDataItemKey :: CellData { cell } , _)
1341+ if cell_counters
1342+ . get ( & cell. type_id )
1343+ . map_or ( true , |start_index| cell. index >= * start_index) =>
1344+ {
1345+ return true ;
13331346 }
1334- CachedDataItemKey :: OutdatedOutputDependency { target } => {
1335- Some ( OutdatedEdge :: OutputDependency ( target ) )
1347+ ( & CachedDataItemKey :: OutdatedChild { task } , _ ) => {
1348+ old_edges . push ( OutdatedEdge :: Child ( task ) ) ;
13361349 }
1337- CachedDataItemKey :: OutdatedCollectiblesDependency { target } => {
1338- Some ( OutdatedEdge :: CollectiblesDependency ( target) )
1350+ (
1351+ & CachedDataItemKey :: OutdatedCollectible { collectible } ,
1352+ & CachedDataItemValue :: OutdatedCollectible { value } ,
1353+ ) => old_edges. push ( OutdatedEdge :: Collectible ( collectible, value) ) ,
1354+ ( & CachedDataItemKey :: OutdatedCellDependency { target } , _) => {
1355+ old_edges. push ( OutdatedEdge :: CellDependency ( target) ) ;
1356+ }
1357+ ( & CachedDataItemKey :: OutdatedOutputDependency { target } , _) => {
1358+ old_edges. push ( OutdatedEdge :: OutputDependency ( target) ) ;
1359+ }
1360+ ( & CachedDataItemKey :: OutdatedCollectiblesDependency { target } , _) => {
1361+ old_edges. push ( OutdatedEdge :: CollectiblesDependency ( target) ) ;
13391362 }
1340- CachedDataItemKey :: CellDependent { cell, task }
1341- if removed_cells
1363+ ( & CachedDataItemKey :: CellDependent { cell, task } , _ )
1364+ if cell_counters
13421365 . get ( & cell. type_id )
1343- . map_or ( false , |range| range . contains ( & cell. index ) ) =>
1366+ . map_or ( true , |start_index| cell. index >= * start_index ) =>
13441367 {
1345- Some ( OutdatedEdge :: RemovedCellDependent ( task, cell. type_id ) )
1368+ old_edges . push ( OutdatedEdge :: RemovedCellDependent ( task, cell. type_id ) ) ;
13461369 }
1347- _ => None ,
1348- } )
1349- . collect :: < Vec < _ > > ( )
1370+ _ => { }
1371+ }
1372+ false
1373+ } ) ) ;
13501374 } ;
13511375 drop ( task) ;
13521376
0 commit comments