diff options
Diffstat (limited to 'ops')
-rw-r--r-- | ops/fast_call.rs | 35 | ||||
-rw-r--r-- | ops/lib.rs | 88 | ||||
-rw-r--r-- | ops/optimizer_tests/async_nop.out | 30 | ||||
-rw-r--r-- | ops/optimizer_tests/async_result.out | 35 | ||||
-rw-r--r-- | ops/optimizer_tests/issue16934.out | 29 | ||||
-rw-r--r-- | ops/optimizer_tests/issue16934_fast.out | 29 |
6 files changed, 83 insertions, 163 deletions
diff --git a/ops/fast_call.rs b/ops/fast_call.rs index 2485b6083..ebbb1927b 100644 --- a/ops/fast_call.rs +++ b/ops/fast_call.rs @@ -245,41 +245,16 @@ pub(crate) fn generate( } if optimizer.is_async { - // Referenced variables are declared in parent block. - let track_async = q!({ - let __op_id = __ctx.id; - let __state = ::std::cell::RefCell::borrow(&__ctx.state); - __state.tracker.track_async(__op_id); - }); - - output_transforms.push_tokens(&track_async); - let queue_future = if optimizer.returns_result { q!({ - let realm_idx = __ctx.realm_idx; - let __get_class = __state.get_error_class_fn; - let result = _ops::queue_fast_async_op(__ctx, async move { - let result = result.await; - ( - realm_idx, - __promise_id, - __op_id, - _ops::to_op_result(__get_class, result), - ) - }); + let result = _ops::queue_fast_async_op(__ctx, __promise_id, result); }) } else { q!({ - let realm_idx = __ctx.realm_idx; - let result = _ops::queue_fast_async_op(__ctx, async move { - let result = result.await; - ( - realm_idx, - __promise_id, - __op_id, - _ops::OpResult::Ok(result.into()), - ) - }); + let result = + _ops::queue_fast_async_op(__ctx, __promise_id, async move { + Ok(result.await) + }); }) }; diff --git a/ops/lib.rs b/ops/lib.rs index 7bf962091..5a192537f 100644 --- a/ops/lib.rs +++ b/ops/lib.rs @@ -258,32 +258,55 @@ fn codegen_v8_async( let (arg_decls, args_tail, _) = codegen_args(core, f, rust_i0, 1, asyncness); let type_params = exclude_lifetime_params(&f.sig.generics.params); - let (pre_result, mut result_fut) = match asyncness { - true => ( - quote! {}, - quote! { Self::call::<#type_params>(#args_head #args_tail).await; }, - ), - false => ( - quote! { let result_fut = Self::call::<#type_params>(#args_head #args_tail); }, - quote! { result_fut.await; }, - ), - }; - let result_wrapper = match is_result(&f.sig.output) { - true => { - // Support `Result<impl Future<Output = Result<T, AnyError>> + 'static, AnyError>` - if !asyncness { - result_fut = quote! { result_fut; }; - quote! { - let result = match result { - Ok(fut) => fut.await, - Err(e) => return (realm_idx, promise_id, op_id, #core::_ops::to_op_result::<()>(get_class, Err(e))), - }; - } - } else { - quote! {} + let wrapper = match (asyncness, is_result(&f.sig.output)) { + (true, true) => { + quote! { + let fut = #core::_ops::map_async_op1(ctx, Self::call::<#type_params>(#args_head #args_tail)); + let maybe_response = #core::_ops::queue_async_op( + ctx, + scope, + #deferred, + promise_id, + fut, + ); + } + } + (true, false) => { + quote! { + let fut = #core::_ops::map_async_op2(ctx, Self::call::<#type_params>(#args_head #args_tail)); + let maybe_response = #core::_ops::queue_async_op( + ctx, + scope, + #deferred, + promise_id, + fut, + ); + } + } + (false, true) => { + quote! { + let fut = #core::_ops::map_async_op3(ctx, Self::call::<#type_params>(#args_head #args_tail)); + let maybe_response = #core::_ops::queue_async_op( + ctx, + scope, + #deferred, + promise_id, + fut, + ); + } + } + (false, false) => { + quote! { + let fut = #core::_ops::map_async_op4(ctx, Self::call::<#type_params>(#args_head #args_tail)); + let maybe_response = #core::_ops::queue_async_op( + ctx, + scope, + #deferred, + promise_id, + fut, + ); } } - false => quote! { let result = Ok(result); }, }; quote! { @@ -293,8 +316,6 @@ fn codegen_v8_async( &*(#core::v8::Local::<#core::v8::External>::cast(args.data()).value() as *const #core::_ops::OpCtx) }; - let op_id = ctx.id; - let realm_idx = ctx.realm_idx; let promise_id = args.get(0); let promise_id = #core::v8::Local::<#core::v8::Integer>::try_from(promise_id) @@ -310,20 +331,7 @@ fn codegen_v8_async( }; #arg_decls - - // Track async call & get copy of get_error_class_fn - let get_class = { - let state = ::std::cell::RefCell::borrow(&ctx.state); - state.tracker.track_async(op_id); - state.get_error_class_fn - }; - - #pre_result - let maybe_response = #core::_ops::queue_async_op(ctx, scope, #deferred, async move { - let result = #result_fut - #result_wrapper - (realm_idx, promise_id, op_id, #core::_ops::to_op_result(get_class, result)) - }); + #wrapper if let Some(response) = maybe_response { rv.set(response); diff --git a/ops/optimizer_tests/async_nop.out b/ops/optimizer_tests/async_nop.out index 7782b5970..d26733825 100644 --- a/ops/optimizer_tests/async_nop.out +++ b/ops/optimizer_tests/async_nop.out @@ -56,8 +56,6 @@ impl op_void_async { &*(deno_core::v8::Local::<deno_core::v8::External>::cast(args.data()).value() as *const deno_core::_ops::OpCtx) }; - let op_id = ctx.id; - let realm_idx = ctx.realm_idx; let promise_id = args.get(0); let promise_id = deno_core::v8::Local::< deno_core::v8::Integer, @@ -74,25 +72,13 @@ impl op_void_async { return; } }; - let get_class = { - let state = ::std::cell::RefCell::borrow(&ctx.state); - state.tracker.track_async(op_id); - state.get_error_class_fn - }; + let fut = deno_core::_ops::map_async_op2(ctx, Self::call()); let maybe_response = deno_core::_ops::queue_async_op( ctx, scope, false, - async move { - let result = Self::call().await; - let result = Ok(result); - ( - realm_idx, - promise_id, - op_id, - deno_core::_ops::to_op_result(get_class, result), - ) - }, + promise_id, + fut, ); if let Some(response) = maybe_response { rv.set(response); @@ -116,16 +102,10 @@ fn op_void_async_fast_fn<'scope>( }; let op_state = __ctx.state.clone(); let result = op_void_async::call(); - let __op_id = __ctx.id; - let __state = ::std::cell::RefCell::borrow(&__ctx.state); - __state.tracker.track_async(__op_id); - let realm_idx = __ctx.realm_idx; let result = _ops::queue_fast_async_op( __ctx, - async move { - let result = result.await; - (realm_idx, __promise_id, __op_id, _ops::OpResult::Ok(result.into())) - }, + __promise_id, + async move { Ok(result.await) }, ); result } diff --git a/ops/optimizer_tests/async_result.out b/ops/optimizer_tests/async_result.out index c3bb433f1..4494bf22a 100644 --- a/ops/optimizer_tests/async_result.out +++ b/ops/optimizer_tests/async_result.out @@ -56,8 +56,6 @@ impl op_async_result { &*(deno_core::v8::Local::<deno_core::v8::External>::cast(args.data()).value() as *const deno_core::_ops::OpCtx) }; - let op_id = ctx.id; - let realm_idx = ctx.realm_idx; let promise_id = args.get(0); let promise_id = deno_core::v8::Local::< deno_core::v8::Integer, @@ -85,24 +83,16 @@ impl op_async_result { return deno_core::_ops::throw_type_error(scope, msg); } }; - let get_class = { - let state = ::std::cell::RefCell::borrow(&ctx.state); - state.tracker.track_async(op_id); - state.get_error_class_fn - }; + let fut = deno_core::_ops::map_async_op1( + ctx, + Self::call(ctx.state.clone(), arg_0), + ); let maybe_response = deno_core::_ops::queue_async_op( ctx, scope, false, - async move { - let result = Self::call(ctx.state.clone(), arg_0).await; - ( - realm_idx, - promise_id, - op_id, - deno_core::_ops::to_op_result(get_class, result), - ) - }, + promise_id, + fut, ); if let Some(response) = maybe_response { rv.set(response); @@ -127,16 +117,5 @@ fn op_async_result_fast_fn<'scope>( }; let state = __ctx.state.clone(); let result = op_async_result::call(state, rid); - let __op_id = __ctx.id; - let __state = ::std::cell::RefCell::borrow(&__ctx.state); - __state.tracker.track_async(__op_id); - let realm_idx = __ctx.realm_idx; - let __get_class = __state.get_error_class_fn; - let result = _ops::queue_fast_async_op( - __ctx, - async move { - let result = result.await; - (realm_idx, __promise_id, __op_id, _ops::to_op_result(__get_class, result)) - }, - ); + let result = _ops::queue_fast_async_op(__ctx, __promise_id, result); } diff --git a/ops/optimizer_tests/issue16934.out b/ops/optimizer_tests/issue16934.out index 68f59ef43..e92510038 100644 --- a/ops/optimizer_tests/issue16934.out +++ b/ops/optimizer_tests/issue16934.out @@ -50,8 +50,6 @@ impl send_stdin { &*(deno_core::v8::Local::<deno_core::v8::External>::cast(args.data()).value() as *const deno_core::_ops::OpCtx) }; - let op_id = ctx.id; - let realm_idx = ctx.realm_idx; let promise_id = args.get(0); let promise_id = deno_core::v8::Local::< deno_core::v8::Integer, @@ -79,28 +77,19 @@ impl send_stdin { ); } }; - let get_class = { - let state = ::std::cell::RefCell::borrow(&ctx.state); - state.tracker.track_async(op_id); - state.get_error_class_fn - }; + let fut = deno_core::_ops::map_async_op1( + ctx, + Self::call( + compile_error!("mutable opstate is not supported in async ops"), + arg_0, + ), + ); let maybe_response = deno_core::_ops::queue_async_op( ctx, scope, false, - async move { - let result = Self::call( - compile_error!("mutable opstate is not supported in async ops"), - arg_0, - ) - .await; - ( - realm_idx, - promise_id, - op_id, - deno_core::_ops::to_op_result(get_class, result), - ) - }, + promise_id, + fut, ); if let Some(response) = maybe_response { rv.set(response); diff --git a/ops/optimizer_tests/issue16934_fast.out b/ops/optimizer_tests/issue16934_fast.out index 7a4a39f34..2a16d1b62 100644 --- a/ops/optimizer_tests/issue16934_fast.out +++ b/ops/optimizer_tests/issue16934_fast.out @@ -48,8 +48,6 @@ impl send_stdin { &*(deno_core::v8::Local::<deno_core::v8::External>::cast(args.data()).value() as *const deno_core::_ops::OpCtx) }; - let op_id = ctx.id; - let realm_idx = ctx.realm_idx; let promise_id = args.get(0); let promise_id = deno_core::v8::Local::< deno_core::v8::Integer, @@ -77,28 +75,19 @@ impl send_stdin { return deno_core::_ops::throw_type_error(scope, msg); } }; - let get_class = { - let state = ::std::cell::RefCell::borrow(&ctx.state); - state.tracker.track_async(op_id); - state.get_error_class_fn - }; + let fut = deno_core::_ops::map_async_op1( + ctx, + Self::call( + compile_error!("mutable opstate is not supported in async ops"), + arg_0, + ), + ); let maybe_response = deno_core::_ops::queue_async_op( ctx, scope, false, - async move { - let result = Self::call( - compile_error!("mutable opstate is not supported in async ops"), - arg_0, - ) - .await; - ( - realm_idx, - promise_id, - op_id, - deno_core::_ops::to_op_result(get_class, result), - ) - }, + promise_id, + fut, ); if let Some(response) = maybe_response { rv.set(response); |