@@ -43,13 +43,13 @@ use crate::{
43
43
AggregationUpdateQueue , CleanupOldEdgesOperation , ConnectChildOperation ,
44
44
ExecuteContext , OutdatedEdge ,
45
45
} ,
46
- storage:: { get, get_many, remove, Storage } ,
46
+ storage:: { get, get_many, iter_many , remove, Storage } ,
47
47
} ,
48
48
backing_storage:: { BackingStorage , ReadTransaction } ,
49
49
data:: {
50
50
ActiveType , AggregationNumber , CachedDataItem , CachedDataItemIndex , CachedDataItemKey ,
51
- CachedDataItemValue , CachedDataUpdate , CellRef , InProgressCellState , InProgressState ,
52
- OutputValue , RootState ,
51
+ CachedDataItemValue , CachedDataUpdate , CellRef , CollectibleRef , CollectiblesRef ,
52
+ InProgressCellState , InProgressState , OutputValue , RootState ,
53
53
} ,
54
54
utils:: { bi_map:: BiMap , chunked_vec:: ChunkedVec , ptr_eq_arc:: PtrEqArc , sharded:: Sharded } ,
55
55
} ;
@@ -361,7 +361,7 @@ impl TurboTasksBackendInner {
361
361
// active and this task won't stale. CachedActiveUntilClean
362
362
// is automatically removed when this task is clean.
363
363
task. add_new ( CachedDataItem :: AggregateRoot {
364
- value : RootState :: new ( ActiveType :: CachedActiveUntilClean ) ,
364
+ value : RootState :: new ( ActiveType :: CachedActiveUntilClean , task_id ) ,
365
365
} ) ;
366
366
get ! ( task, AggregateRoot ) . unwrap ( )
367
367
} ;
@@ -845,6 +845,38 @@ impl TurboTasksBackendInner {
845
845
}
846
846
}
847
847
848
+ // Make all current collectibles outdated (remove left-over outdated collectibles)
849
+ enum Collectible {
850
+ Current ( CollectibleRef , i32 ) ,
851
+ Outdated ( CollectibleRef ) ,
852
+ }
853
+ let collectibles = task
854
+ . iter ( CachedDataItemIndex :: Collectibles )
855
+ . filter_map ( |( key, value) | match ( key, value) {
856
+ (
857
+ & CachedDataItemKey :: Collectible { collectible } ,
858
+ & CachedDataItemValue :: Collectible { value } ,
859
+ ) => Some ( Collectible :: Current ( collectible, value) ) ,
860
+ ( & CachedDataItemKey :: OutdatedCollectible { collectible } , _) => {
861
+ Some ( Collectible :: Outdated ( collectible) )
862
+ }
863
+ _ => None ,
864
+ } )
865
+ . collect :: < Vec < _ > > ( ) ;
866
+ for collectible in collectibles {
867
+ match collectible {
868
+ Collectible :: Current ( collectible, value) => {
869
+ let _ =
870
+ task. insert ( CachedDataItem :: OutdatedCollectible { collectible, value } ) ;
871
+ }
872
+ Collectible :: Outdated ( collectible) => {
873
+ if !task. has_key ( & CachedDataItemKey :: Collectible { collectible } ) {
874
+ task. remove ( & CachedDataItemKey :: OutdatedCollectible { collectible } ) ;
875
+ }
876
+ }
877
+ }
878
+ }
879
+
848
880
// Make all dependencies outdated
849
881
enum Dep {
850
882
CurrentCell ( CellRef ) ,
@@ -898,8 +930,6 @@ impl TurboTasksBackendInner {
898
930
}
899
931
}
900
932
}
901
-
902
- // TODO: Make all collectibles outdated
903
933
}
904
934
905
935
let ( span, future) = match task_type {
@@ -1096,16 +1126,25 @@ impl TurboTasksBackendInner {
1096
1126
. collect :: < Vec < _ > > ( )
1097
1127
} else {
1098
1128
task. iter_all ( )
1099
- . filter_map ( |( key, _ ) | match * key {
1129
+ . filter_map ( |( key, value ) | match * key {
1100
1130
CachedDataItemKey :: OutdatedChild { task } => {
1101
1131
Some ( OutdatedEdge :: Child ( task) )
1102
1132
}
1133
+ CachedDataItemKey :: OutdatedCollectible { collectible } => {
1134
+ let CachedDataItemValue :: OutdatedCollectible { value } = * value else {
1135
+ unreachable ! ( ) ;
1136
+ } ;
1137
+ Some ( OutdatedEdge :: Collectible ( collectible, value) )
1138
+ }
1103
1139
CachedDataItemKey :: OutdatedCellDependency { target } => {
1104
1140
Some ( OutdatedEdge :: CellDependency ( target) )
1105
1141
}
1106
1142
CachedDataItemKey :: OutdatedOutputDependency { target } => {
1107
1143
Some ( OutdatedEdge :: OutputDependency ( target) )
1108
1144
}
1145
+ CachedDataItemKey :: OutdatedCollectiblesDependency { target } => {
1146
+ Some ( OutdatedEdge :: CollectiblesDependency ( target) )
1147
+ }
1109
1148
CachedDataItemKey :: CellDependent { cell, task }
1110
1149
if removed_cells
1111
1150
. get ( & cell. type_id )
@@ -1132,7 +1171,7 @@ impl TurboTasksBackendInner {
1132
1171
}
1133
1172
AggregationUpdateJob :: data_update (
1134
1173
& mut task,
1135
- AggregatedDataUpdate :: no_longer_dirty_container ( task_id) ,
1174
+ AggregatedDataUpdate :: new ( ) . no_longer_dirty_container ( task_id) ,
1136
1175
)
1137
1176
} else {
1138
1177
None
@@ -1246,6 +1285,116 @@ impl TurboTasksBackendInner {
1246
1285
}
1247
1286
}
1248
1287
1288
+ fn read_task_collectibles (
1289
+ & self ,
1290
+ task_id : TaskId ,
1291
+ collectible_type : TraitTypeId ,
1292
+ reader_id : TaskId ,
1293
+ turbo_tasks : & dyn TurboTasksBackendApi < TurboTasksBackend > ,
1294
+ ) -> AutoMap < RawVc , i32 , BuildHasherDefault < FxHasher > , 1 > {
1295
+ let mut ctx = self . execute_context ( turbo_tasks) ;
1296
+ let mut collectibles = AutoMap :: default ( ) ;
1297
+ {
1298
+ let mut task = ctx. task ( task_id, TaskDataCategory :: Data ) ;
1299
+ // Ensure it's an root node
1300
+ loop {
1301
+ let aggregation_number = get_aggregation_number ( & task) ;
1302
+ if is_root_node ( aggregation_number) {
1303
+ break ;
1304
+ }
1305
+ drop ( task) ;
1306
+ AggregationUpdateQueue :: run (
1307
+ AggregationUpdateJob :: UpdateAggregationNumber {
1308
+ task_id,
1309
+ base_aggregation_number : u32:: MAX ,
1310
+ distance : None ,
1311
+ } ,
1312
+ & mut ctx,
1313
+ ) ;
1314
+ task = ctx. task ( task_id, TaskDataCategory :: All ) ;
1315
+ }
1316
+ for collectible in iter_many ! ( task, AggregatedCollectible { collectible } count if collectible. collectible_type == collectible_type && count > 0 => collectible. cell)
1317
+ {
1318
+ * collectibles
1319
+ . entry ( RawVc :: TaskCell ( collectible. task , collectible. cell ) )
1320
+ . or_insert ( 0 ) += 1 ;
1321
+ }
1322
+ for ( collectible, count) in iter_many ! ( task, Collectible { collectible } count if collectible. collectible_type == collectible_type => ( collectible. cell, count) )
1323
+ {
1324
+ * collectibles
1325
+ . entry ( RawVc :: TaskCell ( collectible. task , collectible. cell ) )
1326
+ . or_insert ( 0 ) += count;
1327
+ }
1328
+ task. insert ( CachedDataItem :: CollectiblesDependent {
1329
+ collectible_type,
1330
+ task : reader_id,
1331
+ value : ( ) ,
1332
+ } ) ;
1333
+ }
1334
+ {
1335
+ let mut reader = ctx. task ( reader_id, TaskDataCategory :: Data ) ;
1336
+ let target = CollectiblesRef {
1337
+ task : task_id,
1338
+ collectible_type,
1339
+ } ;
1340
+ if reader. add ( CachedDataItem :: CollectiblesDependency { target, value : ( ) } ) {
1341
+ reader. remove ( & CachedDataItemKey :: OutdatedCollectiblesDependency { target } ) ;
1342
+ }
1343
+ }
1344
+ collectibles
1345
+ }
1346
+
1347
+ fn emit_collectible (
1348
+ & self ,
1349
+ collectible_type : TraitTypeId ,
1350
+ collectible : RawVc ,
1351
+ task_id : TaskId ,
1352
+ turbo_tasks : & dyn TurboTasksBackendApi < TurboTasksBackend > ,
1353
+ ) {
1354
+ let RawVc :: TaskCell ( collectible_task, cell) = collectible else {
1355
+ panic ! ( "Collectibles need to be resolved" ) ;
1356
+ } ;
1357
+ let cell = CellRef {
1358
+ task : collectible_task,
1359
+ cell,
1360
+ } ;
1361
+ operation:: UpdateCollectibleOperation :: run (
1362
+ task_id,
1363
+ CollectibleRef {
1364
+ collectible_type,
1365
+ cell,
1366
+ } ,
1367
+ 1 ,
1368
+ self . execute_context ( turbo_tasks) ,
1369
+ ) ;
1370
+ }
1371
+
1372
+ fn unemit_collectible (
1373
+ & self ,
1374
+ collectible_type : TraitTypeId ,
1375
+ collectible : RawVc ,
1376
+ count : u32 ,
1377
+ task_id : TaskId ,
1378
+ turbo_tasks : & dyn TurboTasksBackendApi < TurboTasksBackend > ,
1379
+ ) {
1380
+ let RawVc :: TaskCell ( collectible_task, cell) = collectible else {
1381
+ panic ! ( "Collectibles need to be resolved" ) ;
1382
+ } ;
1383
+ let cell = CellRef {
1384
+ task : collectible_task,
1385
+ cell,
1386
+ } ;
1387
+ operation:: UpdateCollectibleOperation :: run (
1388
+ task_id,
1389
+ CollectibleRef {
1390
+ collectible_type,
1391
+ cell,
1392
+ } ,
1393
+ -( i32:: try_from ( count) . unwrap ( ) ) ,
1394
+ self . execute_context ( turbo_tasks) ,
1395
+ ) ;
1396
+ }
1397
+
1249
1398
fn update_task_cell (
1250
1399
& self ,
1251
1400
task_id : TaskId ,
@@ -1293,7 +1442,7 @@ impl TurboTasksBackendInner {
1293
1442
} ,
1294
1443
} ) ;
1295
1444
task. add ( CachedDataItem :: AggregateRoot {
1296
- value : RootState :: new ( root_type) ,
1445
+ value : RootState :: new ( root_type, task_id ) ,
1297
1446
} ) ;
1298
1447
task. add ( CachedDataItem :: new_scheduled ( move || match root_type {
1299
1448
ActiveType :: RootTask => "Root Task" . to_string ( ) ,
@@ -1474,33 +1623,36 @@ impl Backend for TurboTasksBackend {
1474
1623
1475
1624
fn read_task_collectibles (
1476
1625
& self ,
1477
- _ : TaskId ,
1478
- _ : TraitTypeId ,
1479
- _ : TaskId ,
1480
- _ : & dyn TurboTasksBackendApi < Self > ,
1626
+ task_id : TaskId ,
1627
+ collectible_type : TraitTypeId ,
1628
+ reader : TaskId ,
1629
+ turbo_tasks : & dyn TurboTasksBackendApi < Self > ,
1481
1630
) -> AutoMap < RawVc , i32 , BuildHasherDefault < FxHasher > , 1 > {
1482
- todo ! ( )
1631
+ self . 0
1632
+ . read_task_collectibles ( task_id, collectible_type, reader, turbo_tasks)
1483
1633
}
1484
1634
1485
1635
fn emit_collectible (
1486
1636
& self ,
1487
- _ : TraitTypeId ,
1488
- _ : RawVc ,
1489
- _ : TaskId ,
1490
- _ : & dyn TurboTasksBackendApi < Self > ,
1637
+ collectible_type : TraitTypeId ,
1638
+ collectible : RawVc ,
1639
+ task_id : TaskId ,
1640
+ turbo_tasks : & dyn TurboTasksBackendApi < Self > ,
1491
1641
) {
1492
- todo ! ( )
1642
+ self . 0
1643
+ . emit_collectible ( collectible_type, collectible, task_id, turbo_tasks)
1493
1644
}
1494
1645
1495
1646
fn unemit_collectible (
1496
1647
& self ,
1497
- _ : TraitTypeId ,
1498
- _ : RawVc ,
1499
- _ : u32 ,
1500
- _ : TaskId ,
1501
- _ : & dyn TurboTasksBackendApi < Self > ,
1648
+ collectible_type : TraitTypeId ,
1649
+ collectible : RawVc ,
1650
+ count : u32 ,
1651
+ task_id : TaskId ,
1652
+ turbo_tasks : & dyn TurboTasksBackendApi < Self > ,
1502
1653
) {
1503
- todo ! ( )
1654
+ self . 0
1655
+ . unemit_collectible ( collectible_type, collectible, count, task_id, turbo_tasks)
1504
1656
}
1505
1657
1506
1658
fn update_task_cell (
0 commit comments