@@ -333,7 +333,7 @@ fn startup_instance_worker<'scope>(
333333 let module_common = match module_or_mcc {
334334 Either :: Left ( module_common) => Either :: Left ( module_common) ,
335335 Either :: Right ( mcc) => {
336- let def = extract_description ( scope) ?;
336+ let def = extract_description ( scope, & mcc . replica_ctx ) ?;
337337
338338 // Validate and create a common module from the raw definition.
339339 Either :: Right ( build_common_module_from_raw ( mcc, def) ?)
@@ -577,72 +577,84 @@ fn call_reducer<'scope>(
577577) -> ( super :: ReducerCallResult , bool ) {
578578 let mut trapped = false ;
579579
580- let ( res, _) = instance_common. call_reducer_with_tx ( replica_ctx, tx, params, log_traceback, |tx, op, budget| {
581- // TODO(v8): Start the budget timeout and long-running logger.
582- let env = env_on_isolate_unwrap ( scope) ;
583- let mut tx_slot = env. instance_env . tx . clone ( ) ;
584-
585- // Start the timer.
586- // We'd like this tightly around `__call_reducer__`.
587- env. start_reducer ( op. name , op. timestamp ) ;
588-
589- // Call `__call_reducer__` with `tx` provided.
590- // It should not be available before.
591- let ( tx, call_result) = tx_slot. set ( tx, || {
592- catch_exception ( scope, |scope| {
593- let res = call_call_reducer ( scope, fun, op) ?;
594- Ok ( res)
595- } )
596- . map_err ( |( e, can_continue) | {
597- // Convert `can_continue` to whether the isolate has "trapped".
598- // Also cancel execution termination if needed,
599- // that can occur due to terminating long running reducers.
600- trapped = match can_continue {
601- CanContinue :: No => false ,
602- CanContinue :: Yes => true ,
603- CanContinue :: YesCancelTermination => {
604- scope. cancel_terminate_execution ( ) ;
605- true
606- }
607- } ;
608-
609- e
610- } )
611- . map_err ( anyhow:: Error :: from)
612- } ) ;
613-
614- // Finish timings.
615- let timings = env_on_isolate_unwrap ( scope) . finish_reducer ( ) ;
616-
617- // Derive energy stats.
618- let energy = energy_from_elapsed ( budget, timings. total_duration ) ;
619-
620- // Fetch the currently used heap size in V8.
621- // The used size is ostensibly fairer than the total size.
622- let memory_allocation = scope. get_heap_statistics ( ) . used_heap_size ( ) ;
580+ let ( res, _) = instance_common. call_reducer_with_tx (
581+ replica_ctx,
582+ tx,
583+ params,
584+ move |a, b, c| log_traceback ( replica_ctx, a, b, c) ,
585+ |tx, op, budget| {
586+ // TODO(v8): Start the budget timeout and long-running logger.
587+ let env = env_on_isolate_unwrap ( scope) ;
588+ let mut tx_slot = env. instance_env . tx . clone ( ) ;
589+
590+ // Start the timer.
591+ // We'd like this tightly around `__call_reducer__`.
592+ env. start_reducer ( op. name , op. timestamp ) ;
593+
594+ // Call `__call_reducer__` with `tx` provided.
595+ // It should not be available before.
596+ let ( tx, call_result) = tx_slot. set ( tx, || {
597+ catch_exception ( scope, |scope| {
598+ let res = call_call_reducer ( scope, fun, op) ?;
599+ Ok ( res)
600+ } )
601+ . map_err ( |( e, can_continue) | {
602+ // Convert `can_continue` to whether the isolate has "trapped".
603+ // Also cancel execution termination if needed,
604+ // that can occur due to terminating long running reducers.
605+ trapped = match can_continue {
606+ CanContinue :: No => false ,
607+ CanContinue :: Yes => true ,
608+ CanContinue :: YesCancelTermination => {
609+ scope. cancel_terminate_execution ( ) ;
610+ true
611+ }
612+ } ;
623613
624- let exec_result = ExecuteResult {
625- energy,
626- timings,
627- memory_allocation,
628- call_result,
629- } ;
630- ( tx, exec_result)
631- } ) ;
614+ e
615+ } )
616+ . map_err ( anyhow:: Error :: from)
617+ } ) ;
618+
619+ // Finish timings.
620+ let timings = env_on_isolate_unwrap ( scope) . finish_reducer ( ) ;
621+
622+ // Derive energy stats.
623+ let energy = energy_from_elapsed ( budget, timings. total_duration ) ;
624+
625+ // Fetch the currently used heap size in V8.
626+ // The used size is ostensibly fairer than the total size.
627+ let memory_allocation = scope. get_heap_statistics ( ) . used_heap_size ( ) ;
628+
629+ let exec_result = ExecuteResult {
630+ energy,
631+ timings,
632+ memory_allocation,
633+ call_result,
634+ } ;
635+ ( tx, exec_result)
636+ } ,
637+ ) ;
632638
633639 ( res, trapped)
634640}
635641
636642/// Extracts the raw module def by running the registered `__describe_module__` hook.
637- fn extract_description < ' scope > ( scope : & mut PinScope < ' scope , ' _ > ) -> Result < RawModuleDef , DescribeError > {
638- run_describer ( log_traceback, || {
639- catch_exception ( scope, |scope| {
640- let def = call_describe_module ( scope) ?;
641- Ok ( def)
642- } )
643- . map_err ( |( e, _) | e)
644- . map_err ( Into :: into)
645- } )
643+ fn extract_description < ' scope > (
644+ scope : & mut PinScope < ' scope , ' _ > ,
645+ replica_ctx : & ReplicaContext ,
646+ ) -> Result < RawModuleDef , DescribeError > {
647+ run_describer (
648+ |a, b, c| log_traceback ( replica_ctx, a, b, c) ,
649+ || {
650+ catch_exception ( scope, |scope| {
651+ let def = call_describe_module ( scope) ?;
652+ Ok ( def)
653+ } )
654+ . map_err ( |( e, _) | e)
655+ . map_err ( Into :: into)
656+ } ,
657+ )
646658}
647659#[ cfg( test) ]
648660mod test {
0 commit comments