1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

chore(core): remove argc field from OpDecl (#18024)

https://github.com/denoland/deno/pull/18023#discussion_r1125611859
This commit is contained in:
Divy Srivastava 2023-03-05 16:46:43 +05:30 committed by GitHub
parent da201d9ea5
commit d4807f458e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 54 additions and 96 deletions

View file

@ -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<Box<dyn FastFunction>>,
}

View file

@ -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::<TokenStream2>();
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<TokenStream2> {
@ -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::<Vec<_>>();
let rust_i0 = special_args.len();
let args_head = special_args.into_iter().collect::<TokenStream2>();
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)

View file

@ -26,7 +26,6 @@ impl op_void_async {
is_async: true,
is_unstable: false,
is_v8: false,
argc: 0usize,
}
}
#[inline]

View file

@ -26,7 +26,6 @@ impl op_async_result {
is_async: true,
is_unstable: false,
is_v8: false,
argc: 1usize,
}
}
#[inline]

View file

@ -26,7 +26,6 @@ impl op_fallback {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 1usize,
}
}
#[inline]

View file

@ -26,7 +26,6 @@ impl op_cow_str {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 1usize,
}
}
#[inline]

View file

@ -26,7 +26,6 @@ impl op_f64_buf {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 1usize,
}
}
#[inline]

View file

@ -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]

View file

@ -22,7 +22,6 @@ impl send_stdin {
is_async: true,
is_unstable: false,
is_v8: false,
argc: 1usize,
}
}
#[inline]

View file

@ -22,7 +22,6 @@ impl send_stdin {
is_async: true,
is_unstable: false,
is_v8: false,
argc: 1usize,
}
}
#[inline]

View file

@ -22,7 +22,6 @@ impl op_blob_revoke_object_url {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 1usize,
}
}
#[inline]

View file

@ -26,7 +26,6 @@ impl op_ffi_ptr_value {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 2usize,
}
}
#[inline]

View file

@ -22,7 +22,6 @@ impl op_print {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 2usize,
}
}
#[inline]

View file

@ -26,7 +26,6 @@ impl op_set_exit_code {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 1usize,
}
}
#[inline]

View file

@ -26,7 +26,6 @@ impl foo {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 2usize,
}
}
#[inline]

View file

@ -32,7 +32,6 @@ impl op_foo {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 0usize,
}
}
#[inline]

View file

@ -26,7 +26,6 @@ impl foo {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 2usize,
}
}
#[inline]

View file

@ -26,7 +26,6 @@ impl op_listen {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 0usize,
}
}
#[inline]

View file

@ -32,7 +32,6 @@ impl op_now {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 1usize,
}
}
#[inline]

View file

@ -26,7 +26,6 @@ impl op_add_4 {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 4usize,
}
}
#[inline]

View file

@ -22,7 +22,6 @@ impl op_try_close {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 1usize,
}
}
#[inline]

View file

@ -26,7 +26,6 @@ impl op_string_length {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 1usize,
}
}
#[inline]

View file

@ -22,7 +22,6 @@ impl op_read_sync {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 2usize,
}
}
#[inline]

View file

@ -32,7 +32,6 @@ impl op_ffi_ptr_of {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 2usize,
}
}
#[inline]

View file

@ -26,7 +26,6 @@ impl op_is_proxy {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 1usize,
}
}
#[inline]

View file

@ -26,7 +26,6 @@ impl op_string_length {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 1usize,
}
}
#[inline]

View file

@ -22,7 +22,6 @@ impl op_string_length {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 1usize,
}
}
#[inline]

View file

@ -22,7 +22,6 @@ impl op_bench_now {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 0usize,
}
}
#[inline]

View file

@ -26,7 +26,6 @@ impl op_import_spki_x25519 {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 2usize,
}
}
#[inline]

View file

@ -26,7 +26,6 @@ impl op_unit_result {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 0usize,
}
}
#[inline]

View file

@ -26,7 +26,6 @@ impl op_set_nodelay {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 2usize,
}
}
#[inline]

View file

@ -26,7 +26,6 @@ impl op_unit {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 0usize,
}
}
#[inline]

View file

@ -26,7 +26,6 @@ impl op_wasm {
is_async: false,
is_unstable: false,
is_v8: false,
argc: 1usize,
}
}
#[inline]