@@ -10,12 +10,15 @@ use turbo_tasks::{run_once, trace::TraceRawVcs, TurboTasksApi};
10
10
pub struct Registration {
11
11
execution_lock : OnceLock < ( ) > ,
12
12
func : fn ( ) ,
13
- create_turbo_tasks : fn ( bool ) -> Arc < dyn TurboTasksApi > ,
13
+ create_turbo_tasks : fn ( & str , bool ) -> Arc < dyn TurboTasksApi > ,
14
14
}
15
15
16
16
impl Registration {
17
17
#[ doc( hidden) ]
18
- pub const fn new ( create_turbo_tasks : fn ( bool ) -> Arc < dyn TurboTasksApi > , func : fn ( ) ) -> Self {
18
+ pub const fn new (
19
+ create_turbo_tasks : fn ( & str , bool ) -> Arc < dyn TurboTasksApi > ,
20
+ func : fn ( ) ,
21
+ ) -> Self {
19
22
Registration {
20
23
execution_lock : OnceLock :: new ( ) ,
21
24
func,
@@ -30,8 +33,8 @@ impl Registration {
30
33
self . execution_lock . get_or_init ( self . func ) ;
31
34
}
32
35
33
- pub fn create_turbo_tasks ( & self , initial : bool ) -> Arc < dyn TurboTasksApi > {
34
- ( self . create_turbo_tasks ) ( initial)
36
+ pub fn create_turbo_tasks ( & self , name : & str , initial : bool ) -> Arc < dyn TurboTasksApi > {
37
+ ( self . create_turbo_tasks ) ( name , initial)
35
38
}
36
39
}
37
40
@@ -40,12 +43,12 @@ macro_rules! register {
40
43
( $( $other_register_fns: expr) ,* $( , ) ?) => { {
41
44
use turbo_tasks:: TurboTasksApi ;
42
45
use std:: sync:: Arc ;
43
- fn create_turbo_tasks( initial: bool ) -> Arc <dyn TurboTasksApi > {
46
+ fn create_turbo_tasks( name : & str , initial: bool ) -> Arc <dyn TurboTasksApi > {
44
47
let inner = include!( concat!(
45
48
env!( "CARGO_MANIFEST_DIR" ) ,
46
49
"/tests/test_config.trs"
47
50
) ) ;
48
- ( inner) ( initial)
51
+ ( inner) ( name , initial)
49
52
}
50
53
fn register_impl( ) {
51
54
$( $other_register_fns( ) ; ) *
@@ -69,10 +72,16 @@ where
69
72
T : TraceRawVcs + Send + ' static ,
70
73
{
71
74
registration. ensure_registered ( ) ;
72
- let tt = registration. create_turbo_tasks ( true ) ;
75
+ let name = closure_to_name ( & fut) ;
76
+ let tt = registration. create_turbo_tasks ( & name, true ) ;
73
77
run_once ( tt, async move { Ok ( fut. await ) } ) . await . unwrap ( )
74
78
}
75
79
80
+ fn closure_to_name < T > ( value : & T ) -> String {
81
+ let name = std:: any:: type_name_of_val ( value) ;
82
+ name. replace ( "::{{closure}}" , "" ) . replace ( "::" , "_" )
83
+ }
84
+
76
85
pub async fn run < T , F > (
77
86
registration : & Registration ,
78
87
fut : impl Fn ( ) -> F + Send + ' static ,
@@ -82,14 +91,16 @@ where
82
91
T : Debug + PartialEq + Eq + TraceRawVcs + Send + ' static ,
83
92
{
84
93
registration. ensure_registered ( ) ;
85
- let tt = registration. create_turbo_tasks ( true ) ;
94
+
95
+ let name = closure_to_name ( & fut) ;
96
+ let tt = registration. create_turbo_tasks ( & name, true ) ;
86
97
println ! ( "Run #1 (without cache)" ) ;
87
98
let first = run_once ( tt. clone ( ) , fut ( ) ) . await ?;
88
99
println ! ( "Run #2 (with memory cache, same TurboTasks instance)" ) ;
89
100
let second = run_once ( tt. clone ( ) , fut ( ) ) . await ?;
90
101
tt. stop_and_wait ( ) . await ;
91
102
assert_eq ! ( first, second) ;
92
- let tt = registration. create_turbo_tasks ( false ) ;
103
+ let tt = registration. create_turbo_tasks ( & name , false ) ;
93
104
println ! ( "Run #3 (with persistent cache if available, new TurboTasks instance)" ) ;
94
105
let third = run_once ( tt. clone ( ) , fut ( ) ) . await ?;
95
106
tt. stop_and_wait ( ) . await ;
0 commit comments