@@ -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,46 @@ 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+ match key {
1278+ & CachedDataItemKey :: CellData { cell }
1279+ if cell_counters
1280+ . get ( & cell. type_id )
1281+ . map_or ( true , |start_index| cell. index >= * start_index) =>
1282+ {
1283+ true
1284+ }
1285+ _ => false ,
1286+ }
1287+ } ) ) ;
12741288 if self . should_track_children ( ) {
12751289 old_edges. extend ( task. iter ( CachedDataItemIndex :: Children ) . filter_map (
12761290 |( key, _) | match * key {
@@ -1306,9 +1320,9 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
13061320 |( key, _) | {
13071321 match * key {
13081322 CachedDataItemKey :: CellDependent { cell, task }
1309- if removed_cells
1323+ if cell_counters
13101324 . get ( & cell. type_id )
1311- . map_or ( false , |range| range . contains ( & cell. index ) ) =>
1325+ . map_or ( true , |start_index| cell. index >= * start_index ) =>
13121326 {
13131327 Some ( OutdatedEdge :: RemovedCellDependent ( task, cell. type_id ) )
13141328 }
@@ -1317,36 +1331,53 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
13171331 } ,
13181332 ) ) ;
13191333 }
1320- old_edges
13211334 } 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) )
1335+ removed_data. extend ( task. extract_if_all ( |key, value| {
1336+ match ( key, value) {
1337+ (
1338+ & CachedDataItemKey :: InProgressCell { cell } ,
1339+ CachedDataItemValue :: InProgressCell { value } ,
1340+ ) if cell_counters
1341+ . get ( & cell. type_id )
1342+ . map_or ( true , |start_index| cell. index >= * start_index) =>
1343+ {
1344+ value. event . notify ( usize:: MAX ) ;
1345+ return true ;
13301346 }
1331- CachedDataItemKey :: OutdatedCellDependency { target } => {
1332- Some ( OutdatedEdge :: CellDependency ( target) )
1347+ ( & CachedDataItemKey :: CellData { cell } , _)
1348+ if cell_counters
1349+ . get ( & cell. type_id )
1350+ . map_or ( true , |start_index| cell. index >= * start_index) =>
1351+ {
1352+ return true ;
1353+ }
1354+ ( & CachedDataItemKey :: OutdatedChild { task } , _) => {
1355+ old_edges. push ( OutdatedEdge :: Child ( task) ) ;
1356+ }
1357+ (
1358+ & CachedDataItemKey :: OutdatedCollectible { collectible } ,
1359+ & CachedDataItemValue :: OutdatedCollectible { value } ,
1360+ ) => old_edges. push ( OutdatedEdge :: Collectible ( collectible, value) ) ,
1361+ ( & CachedDataItemKey :: OutdatedCellDependency { target } , _) => {
1362+ old_edges. push ( OutdatedEdge :: CellDependency ( target) ) ;
13331363 }
1334- CachedDataItemKey :: OutdatedOutputDependency { target } => {
1335- Some ( OutdatedEdge :: OutputDependency ( target) )
1364+ ( & CachedDataItemKey :: OutdatedOutputDependency { target } , _ ) => {
1365+ old_edges . push ( OutdatedEdge :: OutputDependency ( target) ) ;
13361366 }
1337- CachedDataItemKey :: OutdatedCollectiblesDependency { target } => {
1338- Some ( OutdatedEdge :: CollectiblesDependency ( target) )
1367+ ( & CachedDataItemKey :: OutdatedCollectiblesDependency { target } , _ ) => {
1368+ old_edges . push ( OutdatedEdge :: CollectiblesDependency ( target) ) ;
13391369 }
1340- CachedDataItemKey :: CellDependent { cell, task }
1341- if removed_cells
1370+ ( & CachedDataItemKey :: CellDependent { cell, task } , _ )
1371+ if cell_counters
13421372 . get ( & cell. type_id )
1343- . map_or ( false , |range| range . contains ( & cell. index ) ) =>
1373+ . map_or ( true , |start_index| cell. index >= * start_index ) =>
13441374 {
1345- Some ( OutdatedEdge :: RemovedCellDependent ( task, cell. type_id ) )
1375+ old_edges . push ( OutdatedEdge :: RemovedCellDependent ( task, cell. type_id ) ) ;
13461376 }
1347- _ => None ,
1348- } )
1349- . collect :: < Vec < _ > > ( )
1377+ _ => { }
1378+ }
1379+ false
1380+ } ) ) ;
13501381 } ;
13511382 drop ( task) ;
13521383
0 commit comments