diff --git a/core/extensions.rs b/core/extensions.rs index 4f68ecf6c2..ead1fa3546 100644 --- a/core/extensions.rs +++ b/core/extensions.rs @@ -51,9 +51,6 @@ pub struct OpDecl { pub enabled: bool, pub is_async: bool, pub is_unstable: bool, - /// V8 argument count. Used as an optimization - /// hint by `core.initalizeAsyncOps`. - pub argc: usize, pub is_v8: bool, pub fast_fn: Option>, } diff --git a/ops/lib.rs b/ops/lib.rs index 21812f6053..f7c69ec8a4 100644 --- a/ops/lib.rs +++ b/ops/lib.rs @@ -145,7 +145,6 @@ impl Op { is_async: #is_async, is_unstable: #is_unstable, is_v8: #is_v8, - argc: 0, } } @@ -160,7 +159,7 @@ impl Op { let has_fallible_fast_call = active && optimizer.returns_result; - let (v8_body, argc) = if is_async { + let v8_body = if is_async { let deferred = attrs.deferred; codegen_v8_async( &core, @@ -202,7 +201,6 @@ impl Op { is_async: #is_async, is_unstable: #is_unstable, is_v8: #is_v8, - argc: #argc, } } @@ -239,7 +237,7 @@ fn codegen_v8_async( margs: Attributes, asyncness: bool, deferred: bool, -) -> (TokenStream2, usize) { +) -> TokenStream2 { let Attributes { is_v8, .. } = margs; let special_args = f .sig @@ -253,7 +251,7 @@ fn codegen_v8_async( let rust_i0 = special_args.len(); let args_head = special_args.into_iter().collect::(); - let (arg_decls, args_tail, argc) = codegen_args(core, f, rust_i0, 1, true); + let (arg_decls, args_tail, _) = codegen_args(core, f, rust_i0, 1, true); let type_params = exclude_lifetime_params(&f.sig.generics.params); let (pre_result, mut result_fut) = match asyncness { @@ -284,48 +282,45 @@ fn codegen_v8_async( false => quote! { let result = Ok(result); }, }; - ( - quote! { - use #core::futures::FutureExt; - // SAFETY: #core guarantees args.data() is a v8 External pointing to an OpCtx for the isolates lifetime - let ctx = unsafe { - &*(#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; + quote! { + use #core::futures::FutureExt; + // SAFETY: #core guarantees args.data() is a v8 External pointing to an OpCtx for the isolates lifetime + let ctx = unsafe { + &*(#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) - .map(|l| l.value() as #core::PromiseId) - .map_err(#core::anyhow::Error::from); - // Fail if promise id invalid (not an int) - let promise_id: #core::PromiseId = match promise_id { - Ok(promise_id) => promise_id, - Err(err) => { - #core::_ops::throw_type_error(scope, format!("invalid promise id: {}", err)); - return; - } - }; + let promise_id = args.get(0); + let promise_id = #core::v8::Local::<#core::v8::Integer>::try_from(promise_id) + .map(|l| l.value() as #core::PromiseId) + .map_err(#core::anyhow::Error::from); + // Fail if promise id invalid (not an int) + let promise_id: #core::PromiseId = match promise_id { + Ok(promise_id) => promise_id, + Err(err) => { + #core::_ops::throw_type_error(scope, format!("invalid promise id: {}", err)); + return; + } + }; - #arg_decls + #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 - }; + // 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 - #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)) - }); - }, - argc, - ) + #pre_result + #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)) + }); + } } fn scope_arg(arg: &FnArg) -> Option { @@ -362,7 +357,7 @@ fn codegen_v8_sync( f: &syn::ItemFn, margs: Attributes, has_fallible_fast_call: bool, -) -> (TokenStream2, usize) { +) -> TokenStream2 { let Attributes { is_v8, .. } = margs; let special_args = f .sig @@ -374,7 +369,7 @@ fn codegen_v8_sync( .collect::>(); let rust_i0 = special_args.len(); let args_head = special_args.into_iter().collect::(); - let (arg_decls, args_tail, argc) = codegen_args(core, f, rust_i0, 0, false); + let (arg_decls, args_tail, _) = codegen_args(core, f, rust_i0, 0, false); let ret = codegen_sync_ret(core, &f.sig.output); let type_params = exclude_lifetime_params(&f.sig.generics.params); @@ -393,27 +388,24 @@ fn codegen_v8_sync( quote! {} }; - ( - quote! { - // SAFETY: #core guarantees args.data() is a v8 External pointing to an OpCtx for the isolates lifetime - let ctx = unsafe { - &*(#core::v8::Local::<#core::v8::External>::cast(args.data()).value() - as *const #core::_ops::OpCtx) - }; + quote! { + // SAFETY: #core guarantees args.data() is a v8 External pointing to an OpCtx for the isolates lifetime + let ctx = unsafe { + &*(#core::v8::Local::<#core::v8::External>::cast(args.data()).value() + as *const #core::_ops::OpCtx) + }; - #fast_error_handler - #arg_decls + #fast_error_handler + #arg_decls - let result = Self::call::<#type_params>(#args_head #args_tail); + let result = Self::call::<#type_params>(#args_head #args_tail); - // use RefCell::borrow instead of state.borrow to avoid clash with std::borrow::Borrow - let op_state = ::std::cell::RefCell::borrow(&*ctx.state); - op_state.tracker.track_sync(ctx.id); + // use RefCell::borrow instead of state.borrow to avoid clash with std::borrow::Borrow + let op_state = ::std::cell::RefCell::borrow(&*ctx.state); + op_state.tracker.track_sync(ctx.id); - #ret - }, - argc, - ) + #ret + } } /// (full declarations, idents, v8 argument count) diff --git a/ops/optimizer_tests/async_nop.out b/ops/optimizer_tests/async_nop.out index b59eedf9b2..1fed63735d 100644 --- a/ops/optimizer_tests/async_nop.out +++ b/ops/optimizer_tests/async_nop.out @@ -26,7 +26,6 @@ impl op_void_async { is_async: true, is_unstable: false, is_v8: false, - argc: 0usize, } } #[inline] diff --git a/ops/optimizer_tests/async_result.out b/ops/optimizer_tests/async_result.out index b812e4cef3..7270ca3d52 100644 --- a/ops/optimizer_tests/async_result.out +++ b/ops/optimizer_tests/async_result.out @@ -26,7 +26,6 @@ impl op_async_result { is_async: true, is_unstable: false, is_v8: false, - argc: 1usize, } } #[inline] diff --git a/ops/optimizer_tests/callback_options.out b/ops/optimizer_tests/callback_options.out index 81745375d3..be84d686a4 100644 --- a/ops/optimizer_tests/callback_options.out +++ b/ops/optimizer_tests/callback_options.out @@ -26,7 +26,6 @@ impl op_fallback { is_async: false, is_unstable: false, is_v8: false, - argc: 1usize, } } #[inline] diff --git a/ops/optimizer_tests/cow_str.out b/ops/optimizer_tests/cow_str.out index da405f451d..c1c4917f65 100644 --- a/ops/optimizer_tests/cow_str.out +++ b/ops/optimizer_tests/cow_str.out @@ -26,7 +26,6 @@ impl op_cow_str { is_async: false, is_unstable: false, is_v8: false, - argc: 1usize, } } #[inline] diff --git a/ops/optimizer_tests/f64_slice.out b/ops/optimizer_tests/f64_slice.out index 88ccd232ad..9526d988a5 100644 --- a/ops/optimizer_tests/f64_slice.out +++ b/ops/optimizer_tests/f64_slice.out @@ -26,7 +26,6 @@ impl op_f64_buf { is_async: false, is_unstable: false, is_v8: false, - argc: 1usize, } } #[inline] diff --git a/ops/optimizer_tests/incompatible_1.out b/ops/optimizer_tests/incompatible_1.out index 92cf4a5764..cedfb1a8f9 100644 --- a/ops/optimizer_tests/incompatible_1.out +++ b/ops/optimizer_tests/incompatible_1.out @@ -22,7 +22,6 @@ impl op_sync_serialize_object_with_numbers_as_keys { is_async: false, is_unstable: false, is_v8: false, - argc: 1usize, } } #[inline] diff --git a/ops/optimizer_tests/issue16934.out b/ops/optimizer_tests/issue16934.out index b823b5d533..2b8df30d29 100644 --- a/ops/optimizer_tests/issue16934.out +++ b/ops/optimizer_tests/issue16934.out @@ -22,7 +22,6 @@ impl send_stdin { is_async: true, is_unstable: false, is_v8: false, - argc: 1usize, } } #[inline] diff --git a/ops/optimizer_tests/issue16934_fast.out b/ops/optimizer_tests/issue16934_fast.out index 8ff9bad4f2..cf1e416800 100644 --- a/ops/optimizer_tests/issue16934_fast.out +++ b/ops/optimizer_tests/issue16934_fast.out @@ -22,7 +22,6 @@ impl send_stdin { is_async: true, is_unstable: false, is_v8: false, - argc: 1usize, } } #[inline] diff --git a/ops/optimizer_tests/op_blob_revoke_object_url.out b/ops/optimizer_tests/op_blob_revoke_object_url.out index ac51c0de7e..8c5a569a50 100644 --- a/ops/optimizer_tests/op_blob_revoke_object_url.out +++ b/ops/optimizer_tests/op_blob_revoke_object_url.out @@ -22,7 +22,6 @@ impl op_blob_revoke_object_url { is_async: false, is_unstable: false, is_v8: false, - argc: 1usize, } } #[inline] diff --git a/ops/optimizer_tests/op_ffi_ptr_value.out b/ops/optimizer_tests/op_ffi_ptr_value.out index bfbbd5ae75..5ef91e21f0 100644 --- a/ops/optimizer_tests/op_ffi_ptr_value.out +++ b/ops/optimizer_tests/op_ffi_ptr_value.out @@ -26,7 +26,6 @@ impl op_ffi_ptr_value { is_async: false, is_unstable: false, is_v8: false, - argc: 2usize, } } #[inline] diff --git a/ops/optimizer_tests/op_print.out b/ops/optimizer_tests/op_print.out index bafa0b9f83..f22553c767 100644 --- a/ops/optimizer_tests/op_print.out +++ b/ops/optimizer_tests/op_print.out @@ -22,7 +22,6 @@ impl op_print { is_async: false, is_unstable: false, is_v8: false, - argc: 2usize, } } #[inline] diff --git a/ops/optimizer_tests/op_state.out b/ops/optimizer_tests/op_state.out index 5b273960a6..520d41e1a0 100644 --- a/ops/optimizer_tests/op_state.out +++ b/ops/optimizer_tests/op_state.out @@ -26,7 +26,6 @@ impl op_set_exit_code { is_async: false, is_unstable: false, is_v8: false, - argc: 1usize, } } #[inline] diff --git a/ops/optimizer_tests/op_state_basic1.out b/ops/optimizer_tests/op_state_basic1.out index ab3404a429..7d803ac398 100644 --- a/ops/optimizer_tests/op_state_basic1.out +++ b/ops/optimizer_tests/op_state_basic1.out @@ -26,7 +26,6 @@ impl foo { is_async: false, is_unstable: false, is_v8: false, - argc: 2usize, } } #[inline] diff --git a/ops/optimizer_tests/op_state_generics.out b/ops/optimizer_tests/op_state_generics.out index bd5e40afe8..28315eb261 100644 --- a/ops/optimizer_tests/op_state_generics.out +++ b/ops/optimizer_tests/op_state_generics.out @@ -32,7 +32,6 @@ impl op_foo { is_async: false, is_unstable: false, is_v8: false, - argc: 0usize, } } #[inline] diff --git a/ops/optimizer_tests/op_state_result.out b/ops/optimizer_tests/op_state_result.out index 76070b5363..0b7301bfc3 100644 --- a/ops/optimizer_tests/op_state_result.out +++ b/ops/optimizer_tests/op_state_result.out @@ -26,7 +26,6 @@ impl foo { is_async: false, is_unstable: false, is_v8: false, - argc: 2usize, } } #[inline] diff --git a/ops/optimizer_tests/op_state_warning.out b/ops/optimizer_tests/op_state_warning.out index 9917fbf79d..1942a6376d 100644 --- a/ops/optimizer_tests/op_state_warning.out +++ b/ops/optimizer_tests/op_state_warning.out @@ -26,7 +26,6 @@ impl op_listen { is_async: false, is_unstable: false, is_v8: false, - argc: 0usize, } } #[inline] diff --git a/ops/optimizer_tests/op_state_with_transforms.out b/ops/optimizer_tests/op_state_with_transforms.out index b2ded3c5a4..ecd56ceeb3 100644 --- a/ops/optimizer_tests/op_state_with_transforms.out +++ b/ops/optimizer_tests/op_state_with_transforms.out @@ -32,7 +32,6 @@ impl op_now { is_async: false, is_unstable: false, is_v8: false, - argc: 1usize, } } #[inline] diff --git a/ops/optimizer_tests/opstate_with_arity.out b/ops/optimizer_tests/opstate_with_arity.out index 132e54aeff..7c831ccfec 100644 --- a/ops/optimizer_tests/opstate_with_arity.out +++ b/ops/optimizer_tests/opstate_with_arity.out @@ -26,7 +26,6 @@ impl op_add_4 { is_async: false, is_unstable: false, is_v8: false, - argc: 4usize, } } #[inline] diff --git a/ops/optimizer_tests/option_arg.out b/ops/optimizer_tests/option_arg.out index 9f647765f4..14dca54877 100644 --- a/ops/optimizer_tests/option_arg.out +++ b/ops/optimizer_tests/option_arg.out @@ -22,7 +22,6 @@ impl op_try_close { is_async: false, is_unstable: false, is_v8: false, - argc: 1usize, } } #[inline] diff --git a/ops/optimizer_tests/owned_string.out b/ops/optimizer_tests/owned_string.out index 4892221f81..56d3cbfdca 100644 --- a/ops/optimizer_tests/owned_string.out +++ b/ops/optimizer_tests/owned_string.out @@ -26,7 +26,6 @@ impl op_string_length { is_async: false, is_unstable: false, is_v8: false, - argc: 1usize, } } #[inline] diff --git a/ops/optimizer_tests/param_mut_binding_warning.out b/ops/optimizer_tests/param_mut_binding_warning.out index daccc28abb..3a93a738f7 100644 --- a/ops/optimizer_tests/param_mut_binding_warning.out +++ b/ops/optimizer_tests/param_mut_binding_warning.out @@ -22,7 +22,6 @@ impl op_read_sync { is_async: false, is_unstable: false, is_v8: false, - argc: 2usize, } } #[inline] diff --git a/ops/optimizer_tests/raw_ptr.out b/ops/optimizer_tests/raw_ptr.out index cf678ddb9d..2b4e8c0b4a 100644 --- a/ops/optimizer_tests/raw_ptr.out +++ b/ops/optimizer_tests/raw_ptr.out @@ -32,7 +32,6 @@ impl op_ffi_ptr_of { is_async: false, is_unstable: false, is_v8: false, - argc: 2usize, } } #[inline] diff --git a/ops/optimizer_tests/serde_v8_value.out b/ops/optimizer_tests/serde_v8_value.out index d4f2c0321d..3ea0aacb31 100644 --- a/ops/optimizer_tests/serde_v8_value.out +++ b/ops/optimizer_tests/serde_v8_value.out @@ -26,7 +26,6 @@ impl op_is_proxy { is_async: false, is_unstable: false, is_v8: false, - argc: 1usize, } } #[inline] diff --git a/ops/optimizer_tests/strings.out b/ops/optimizer_tests/strings.out index 41f09c4f8d..8aa93a37a0 100644 --- a/ops/optimizer_tests/strings.out +++ b/ops/optimizer_tests/strings.out @@ -26,7 +26,6 @@ impl op_string_length { is_async: false, is_unstable: false, is_v8: false, - argc: 1usize, } } #[inline] diff --git a/ops/optimizer_tests/strings_result.out b/ops/optimizer_tests/strings_result.out index 8446a603bc..fd847d9ca8 100644 --- a/ops/optimizer_tests/strings_result.out +++ b/ops/optimizer_tests/strings_result.out @@ -22,7 +22,6 @@ impl op_string_length { is_async: false, is_unstable: false, is_v8: false, - argc: 1usize, } } #[inline] diff --git a/ops/optimizer_tests/u64_result.out b/ops/optimizer_tests/u64_result.out index 0039c75751..efe6c9d23f 100644 --- a/ops/optimizer_tests/u64_result.out +++ b/ops/optimizer_tests/u64_result.out @@ -22,7 +22,6 @@ impl op_bench_now { is_async: false, is_unstable: false, is_v8: false, - argc: 0usize, } } #[inline] diff --git a/ops/optimizer_tests/uint8array.out b/ops/optimizer_tests/uint8array.out index bd7fa4d87e..06e50ce662 100644 --- a/ops/optimizer_tests/uint8array.out +++ b/ops/optimizer_tests/uint8array.out @@ -26,7 +26,6 @@ impl op_import_spki_x25519 { is_async: false, is_unstable: false, is_v8: false, - argc: 2usize, } } #[inline] diff --git a/ops/optimizer_tests/unit_result.out b/ops/optimizer_tests/unit_result.out index f4e87ffa3f..082d29a453 100644 --- a/ops/optimizer_tests/unit_result.out +++ b/ops/optimizer_tests/unit_result.out @@ -26,7 +26,6 @@ impl op_unit_result { is_async: false, is_unstable: false, is_v8: false, - argc: 0usize, } } #[inline] diff --git a/ops/optimizer_tests/unit_result2.out b/ops/optimizer_tests/unit_result2.out index d1df0e0415..6f5a5915d7 100644 --- a/ops/optimizer_tests/unit_result2.out +++ b/ops/optimizer_tests/unit_result2.out @@ -26,7 +26,6 @@ impl op_set_nodelay { is_async: false, is_unstable: false, is_v8: false, - argc: 2usize, } } #[inline] diff --git a/ops/optimizer_tests/unit_ret.out b/ops/optimizer_tests/unit_ret.out index c18fa19152..3924beb537 100644 --- a/ops/optimizer_tests/unit_ret.out +++ b/ops/optimizer_tests/unit_ret.out @@ -26,7 +26,6 @@ impl op_unit { is_async: false, is_unstable: false, is_v8: false, - argc: 0usize, } } #[inline] diff --git a/ops/optimizer_tests/wasm_op.out b/ops/optimizer_tests/wasm_op.out index a40beb158e..219537f607 100644 --- a/ops/optimizer_tests/wasm_op.out +++ b/ops/optimizer_tests/wasm_op.out @@ -26,7 +26,6 @@ impl op_wasm { is_async: false, is_unstable: false, is_v8: false, - argc: 1usize, } } #[inline]