1
1
use std:: {
2
- any:: Any ,
3
2
future:: Future ,
4
3
hash:: BuildHasherDefault ,
5
4
mem:: take,
@@ -262,54 +261,13 @@ pub trait TurboTasksBackendApi<B: Backend + 'static>: TurboTasksCallApi + Sync +
262
261
/// Returns the duration from the start of the program to the given instant.
263
262
fn program_duration_until ( & self , instant : Instant ) -> Duration ;
264
263
265
- /// An untyped object-safe version of [`TurboTasksBackendApiExt::read_task_state`]. Callers
266
- /// should prefer the extension trait's version of this method.
267
- fn read_task_state_dyn ( & self , func : & mut dyn FnMut ( & B :: TaskState ) ) ;
268
-
269
- /// An untyped object-safe version of [`TurboTasksBackendApiExt::write_task_state`]. Callers
270
- /// should prefer the extension trait's version of this method.
271
- fn write_task_state_dyn ( & self , func : & mut dyn FnMut ( & mut B :: TaskState ) ) ;
272
-
273
264
/// Returns true if the system is idle.
274
265
fn is_idle ( & self ) -> bool ;
275
266
276
267
/// Returns a reference to the backend.
277
268
fn backend ( & self ) -> & B ;
278
269
}
279
270
280
- /// An extension trait for methods of [`TurboTasksBackendApi`] that are not object-safe. This is
281
- /// automatically implemented for all [`TurboTasksBackendApi`]s using a blanket impl.
282
- pub trait TurboTasksBackendApiExt < B : Backend + ' static > : TurboTasksBackendApi < B > {
283
- /// Allows modification of the [`Backend::TaskState`].
284
- ///
285
- /// This function holds open a non-exclusive read lock that blocks writes, so `func` is expected
286
- /// to execute quickly in order to release the lock.
287
- fn read_task_state < T > ( & self , func : impl FnOnce ( & B :: TaskState ) -> T ) -> T {
288
- let mut func = Some ( func) ;
289
- let mut out = None ;
290
- self . read_task_state_dyn ( & mut |ts| out = Some ( ( func. take ( ) . unwrap ( ) ) ( ts) ) ) ;
291
- out. expect ( "read_task_state_dyn must call `func`" )
292
- }
293
-
294
- /// Allows modification of the [`Backend::TaskState`].
295
- ///
296
- /// This function holds open a write lock, so `func` is expected to execute quickly in order to
297
- /// release the lock.
298
- fn write_task_state < T > ( & self , func : impl FnOnce ( & mut B :: TaskState ) -> T ) -> T {
299
- let mut func = Some ( func) ;
300
- let mut out = None ;
301
- self . write_task_state_dyn ( & mut |ts| out = Some ( ( func. take ( ) . unwrap ( ) ) ( ts) ) ) ;
302
- out. expect ( "write_task_state_dyn must call `func`" )
303
- }
304
- }
305
-
306
- impl < TT , B > TurboTasksBackendApiExt < B > for TT
307
- where
308
- TT : TurboTasksBackendApi < B > + ?Sized ,
309
- B : Backend + ' static ,
310
- {
311
- }
312
-
313
271
#[ allow( clippy:: manual_non_exhaustive) ]
314
272
pub struct UpdateInfo {
315
273
pub duration : Duration ,
@@ -408,16 +366,10 @@ struct CurrentTaskState {
408
366
/// Tracks currently running local tasks, and defers cleanup of the global task until those
409
367
/// complete. Also used by `detached_for_testing`.
410
368
local_task_tracker : TaskTracker ,
411
-
412
- backend_state : Box < dyn Any + Send + Sync > ,
413
369
}
414
370
415
371
impl CurrentTaskState {
416
- fn new (
417
- task_id : TaskId ,
418
- execution_id : ExecutionId ,
419
- backend_state : Box < dyn Any + Send + Sync > ,
420
- ) -> Self {
372
+ fn new ( task_id : TaskId , execution_id : ExecutionId ) -> Self {
421
373
Self {
422
374
task_id,
423
375
execution_id,
@@ -426,7 +378,6 @@ impl CurrentTaskState {
426
378
cell_counters : Some ( AutoMap :: default ( ) ) ,
427
379
local_tasks : Vec :: new ( ) ,
428
380
local_task_tracker : TaskTracker :: new ( ) ,
429
- backend_state,
430
381
}
431
382
}
432
383
@@ -688,14 +639,10 @@ impl<B: Backend + 'static> TurboTasks<B> {
688
639
let future = async move {
689
640
let mut schedule_again = true ;
690
641
while schedule_again {
691
- let backend_state = this. backend . new_task_state ( task_id) ;
692
642
// it's okay for execution ids to overflow and wrap, they're just used for an assert
693
643
let execution_id = this. execution_id_factory . wrapping_get ( ) ;
694
- let current_task_state = Arc :: new ( RwLock :: new ( CurrentTaskState :: new (
695
- task_id,
696
- execution_id,
697
- Box :: new ( backend_state) ,
698
- ) ) ) ;
644
+ let current_task_state =
645
+ Arc :: new ( RwLock :: new ( CurrentTaskState :: new ( task_id, execution_id) ) ) ;
699
646
let single_execution_future = async {
700
647
if this. stopped . load ( Ordering :: Acquire ) {
701
648
this. backend . task_execution_canceled ( task_id, & * this) ;
@@ -1461,16 +1408,6 @@ impl<B: Backend + 'static> TurboTasksBackendApi<B> for TurboTasks<B> {
1461
1408
unsafe { self . transient_task_id_factory . reuse ( id. into ( ) ) }
1462
1409
}
1463
1410
1464
- fn read_task_state_dyn ( & self , func : & mut dyn FnMut ( & B :: TaskState ) ) {
1465
- CURRENT_TASK_STATE
1466
- . with ( move |ts| func ( ts. read ( ) . unwrap ( ) . backend_state . downcast_ref ( ) . unwrap ( ) ) )
1467
- }
1468
-
1469
- fn write_task_state_dyn ( & self , func : & mut dyn FnMut ( & mut B :: TaskState ) ) {
1470
- CURRENT_TASK_STATE
1471
- . with ( move |ts| func ( ts. write ( ) . unwrap ( ) . backend_state . downcast_mut ( ) . unwrap ( ) ) )
1472
- }
1473
-
1474
1411
fn is_idle ( & self ) -> bool {
1475
1412
self . currently_scheduled_foreground_jobs
1476
1413
. load ( Ordering :: Acquire )
@@ -1588,7 +1525,6 @@ pub fn with_turbo_tasks_for_testing<T>(
1588
1525
Arc :: new ( RwLock :: new ( CurrentTaskState :: new (
1589
1526
current_task,
1590
1527
execution_id,
1591
- Box :: new ( ( ) ) ,
1592
1528
) ) ) ,
1593
1529
f,
1594
1530
) ,
0 commit comments