From edeccef4990598620bf5595df6fc8c1b1b1a7f73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 7 Oct 2023 17:34:03 +0200 Subject: [PATCH] refactor: migrate more ops to op2 macro (#20808) Getting closer... --- bench_util/README.md | 3 ++- bench_util/benches/op_baseline.rs | 31 +++++++++++++------------------ cli/ops/testing.rs | 5 +---- cli/tools/upgrade.rs | 2 ++ ext/node/ops/http.rs | 13 +++++++------ runtime/ops/os/mod.rs | 4 ++-- runtime/ops/web_worker.rs | 4 ++-- 7 files changed, 29 insertions(+), 33 deletions(-) diff --git a/bench_util/README.md b/bench_util/README.md index 3d507ecae2..0b920223e1 100644 --- a/bench_util/README.md +++ b/bench_util/README.md @@ -9,7 +9,8 @@ use deno_bench_util::bench_js_sync}; use deno_core::Extension; -#[op] +#[op2] +#[number] fn op_nop() -> usize { 9 } diff --git a/bench_util/benches/op_baseline.rs b/bench_util/benches/op_baseline.rs index 4b3bc0203c..c2481d0dd2 100644 --- a/bench_util/benches/op_baseline.rs +++ b/bench_util/benches/op_baseline.rs @@ -6,7 +6,7 @@ use deno_bench_util::bench_or_profile; use deno_bench_util::bencher::benchmark_group; use deno_bench_util::bencher::Bencher; -use deno_core::op; +use deno_core::op2; use deno_core::Extension; deno_core::extension!( @@ -22,25 +22,25 @@ fn setup() -> Vec { vec![bench_setup::init_ops()] } -#[op] +#[op2(fast)] fn op_nop() {} -// TODO(bartlomieju): reenable, currently this op generates a fast function, -// which is wrong, because i64 is not a compatible type for fast call. -// #[op] -// fn op_pi_json() -> i64 { -// 314159 -// } +#[op2(fast)] +#[number] +fn op_pi_json() -> i64 { + 314159 +} // this is a function since async closures aren't stable -#[op] +#[op2(async)] +#[number] async fn op_pi_async() -> i64 { 314159 } -// fn bench_op_pi_json(b: &mut Bencher) { -// bench_js_sync(b, r#"Deno.core.ops.op_pi_json();"#, setup); -// } +fn bench_op_pi_json(b: &mut Bencher) { + bench_js_sync(b, r#"Deno.core.ops.op_pi_json();"#, setup); +} fn bench_op_nop(b: &mut Bencher) { bench_js_sync(b, r#"Deno.core.ops.op_nop();"#, setup); @@ -50,11 +50,6 @@ fn bench_op_async(b: &mut Bencher) { bench_js_async(b, r#"Deno.core.opAsync("op_pi_async");"#, setup); } -benchmark_group!( - benches, - // bench_op_pi_json, - bench_op_nop, - bench_op_async, -); +benchmark_group!(benches, bench_op_pi_json, bench_op_nop, bench_op_async,); bench_or_profile!(benches); diff --git a/cli/ops/testing.rs b/cli/ops/testing.rs index cb3788cdcf..7454670c60 100644 --- a/cli/ops/testing.rs +++ b/cli/ops/testing.rs @@ -1,9 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -// TODO: allow everywhere because `#[allow(clippy::too_many_arguments)]` on -// `#[op(fast)]` does not work. https://github.com/denoland/rusty_v8/issues/1332 -#![allow(clippy::too_many_arguments)] - use crate::tools::test::TestDescription; use crate::tools::test::TestEvent; use crate::tools::test::TestEventSender; @@ -117,6 +113,7 @@ struct TestRegisterResult { static NEXT_ID: AtomicUsize = AtomicUsize::new(0); +#[allow(clippy::too_many_arguments)] #[op2] #[string] fn op_register_test( diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs index 04332f5dfc..d2cb58d28f 100644 --- a/cli/tools/upgrade.rs +++ b/cli/tools/upgrade.rs @@ -372,6 +372,8 @@ pub async fn upgrade( }; let download_url = if upgrade_flags.canary { + // NOTE(bartlomieju): to keep clippy happy on M1 macs. + #[allow(clippy::eq_op)] if env!("TARGET") == "aarch64-apple-darwin" { bail!("Canary builds are not available for M1/M2"); } diff --git a/ext/node/ops/http.rs b/ext/node/ops/http.rs index 2a4d31f50a..40ef6df320 100644 --- a/ext/node/ops/http.rs +++ b/ext/node/ops/http.rs @@ -2,7 +2,7 @@ use deno_core::error::type_error; use deno_core::error::AnyError; -use deno_core::op; +use deno_core::op2; use deno_core::url::Url; use deno_core::AsyncRefCell; use deno_core::ByteString; @@ -23,13 +23,14 @@ use reqwest::header::CONTENT_LENGTH; use reqwest::Body; use reqwest::Method; -#[op] +#[op2] +#[serde] pub fn op_node_http_request

( state: &mut OpState, - method: ByteString, - url: String, - headers: Vec<(ByteString, ByteString)>, - client_rid: Option, + #[serde] method: ByteString, + #[string] url: String, + #[serde] headers: Vec<(ByteString, ByteString)>, + #[smi] client_rid: Option, has_body: bool, ) -> Result where diff --git a/runtime/ops/os/mod.rs b/runtime/ops/os/mod.rs index 166ccb867d..7c61ee0ad1 100644 --- a/runtime/ops/os/mod.rs +++ b/runtime/ops/os/mod.rs @@ -5,7 +5,6 @@ use crate::permissions::PermissionsContainer; use crate::worker::ExitCode; use deno_core::error::type_error; use deno_core::error::AnyError; -use deno_core::op; use deno_core::op2; use deno_core::url::Url; use deno_core::v8; @@ -476,7 +475,8 @@ fn os_uptime(state: &mut OpState) -> Result { Ok(sys_info::os_uptime()) } -#[op] +#[op2(fast)] +#[number] fn op_os_uptime(state: &mut OpState) -> Result { os_uptime(state) } diff --git a/runtime/ops/web_worker.rs b/runtime/ops/web_worker.rs index bdf03d98f8..7fbc0edfae 100644 --- a/runtime/ops/web_worker.rs +++ b/runtime/ops/web_worker.rs @@ -5,7 +5,6 @@ mod sync_fetch; use crate::web_worker::WebWorkerInternalHandle; use crate::web_worker::WebWorkerType; use deno_core::error::AnyError; -use deno_core::op; use deno_core::op2; use deno_core::CancelFuture; @@ -38,7 +37,8 @@ fn op_worker_post_message( Ok(()) } -#[op(deferred)] +#[op2(async(lazy))] +#[serde] async fn op_worker_recv_message( state: Rc>, ) -> Result, AnyError> {