summaryrefslogtreecommitdiff
path: root/ops/optimizer_tests
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2022-11-27 05:54:28 -0800
committerGitHub <noreply@github.com>2022-11-27 19:24:28 +0530
commitca66978a5aadddf7895b49b44076c574e7e6a0b0 (patch)
tree65d93f524bc5fea23cef4e75b02de275833158e1 /ops/optimizer_tests
parent9ffc6acdbb3326dde74c803332547b0ae33e483a (diff)
feat(ops): fast calls for Wasm (#16776)
This PR introduces Wasm ops. These calls are optimized for entry from Wasm land. The `#[op(wasm)]` attribute is opt-in. Last parameter `Option<&mut [u8]>` is the memory slice of the Wasm module *when entered from a Fast API call*. Otherwise, the user is expected to implement logic to obtain the memory if `None` ```rust #[op(wasm)] pub fn op_args_get( offset: i32, buffer_offset: i32, memory: Option<&mut [u8]>, ) { // ... } ```
Diffstat (limited to 'ops/optimizer_tests')
-rw-r--r--ops/optimizer_tests/wasm_op.expected11
-rw-r--r--ops/optimizer_tests/wasm_op.out81
-rw-r--r--ops/optimizer_tests/wasm_op.rs3
3 files changed, 95 insertions, 0 deletions
diff --git a/ops/optimizer_tests/wasm_op.expected b/ops/optimizer_tests/wasm_op.expected
new file mode 100644
index 000000000..98cfb4e7d
--- /dev/null
+++ b/ops/optimizer_tests/wasm_op.expected
@@ -0,0 +1,11 @@
+=== Optimizer Dump ===
+returns_result: false
+has_ref_opstate: false
+has_rc_opstate: false
+has_fast_callback_option: false
+needs_fast_callback_option: true
+fast_result: Some(Void)
+fast_parameters: [V8Value]
+transforms: {0: Transform { kind: WasmMemory, index: 0 }}
+is_async: false
+fast_compatible: true
diff --git a/ops/optimizer_tests/wasm_op.out b/ops/optimizer_tests/wasm_op.out
new file mode 100644
index 000000000..a40beb158
--- /dev/null
+++ b/ops/optimizer_tests/wasm_op.out
@@ -0,0 +1,81 @@
+#[allow(non_camel_case_types)]
+///Auto-generated by `deno_ops`, i.e: `#[op]`
+///
+///Use `op_wasm::decl()` to get an op-declaration
+///you can include in a `deno_core::Extension`.
+pub struct op_wasm;
+#[doc(hidden)]
+impl op_wasm {
+ pub fn name() -> &'static str {
+ stringify!(op_wasm)
+ }
+ pub fn v8_fn_ptr<'scope>() -> deno_core::v8::FunctionCallback {
+ use deno_core::v8::MapFnTo;
+ Self::v8_func.map_fn_to()
+ }
+ pub fn decl<'scope>() -> deno_core::OpDecl {
+ deno_core::OpDecl {
+ name: Self::name(),
+ v8_fn_ptr: Self::v8_fn_ptr(),
+ enabled: true,
+ fast_fn: Some(
+ Box::new(op_wasm_fast {
+ _phantom: ::std::marker::PhantomData,
+ }),
+ ),
+ is_async: false,
+ is_unstable: false,
+ is_v8: false,
+ argc: 1usize,
+ }
+ }
+ #[inline]
+ #[allow(clippy::too_many_arguments)]
+ fn call(memory: Option<&mut [u8]>) {}
+ pub fn v8_func<'scope>(
+ scope: &mut deno_core::v8::HandleScope<'scope>,
+ args: deno_core::v8::FunctionCallbackArguments,
+ mut rv: deno_core::v8::ReturnValue,
+ ) {
+ let ctx = unsafe {
+ &*(deno_core::v8::Local::<deno_core::v8::External>::cast(args.data()).value()
+ as *const deno_core::_ops::OpCtx)
+ };
+ let arg_0 = None;
+ let result = Self::call(arg_0);
+ let op_state = ::std::cell::RefCell::borrow(&*ctx.state);
+ op_state.tracker.track_sync(ctx.id);
+ }
+}
+struct op_wasm_fast {
+ _phantom: ::std::marker::PhantomData<()>,
+}
+impl<'scope> deno_core::v8::fast_api::FastFunction for op_wasm_fast {
+ fn function(&self) -> *const ::std::ffi::c_void {
+ op_wasm_fast_fn as *const ::std::ffi::c_void
+ }
+ fn args(&self) -> &'static [deno_core::v8::fast_api::Type] {
+ use deno_core::v8::fast_api::Type::*;
+ use deno_core::v8::fast_api::CType;
+ &[V8Value, CallbackOptions]
+ }
+ fn return_type(&self) -> deno_core::v8::fast_api::CType {
+ deno_core::v8::fast_api::CType::Void
+ }
+}
+fn op_wasm_fast_fn<'scope>(
+ _: deno_core::v8::Local<deno_core::v8::Object>,
+ fast_api_callback_options: *mut deno_core::v8::fast_api::FastApiCallbackOptions,
+) -> () {
+ use deno_core::v8;
+ use deno_core::_ops;
+ let __opts: &mut v8::fast_api::FastApiCallbackOptions = unsafe {
+ &mut *fast_api_callback_options
+ };
+ let memory = unsafe {
+ &*(__opts.wasm_memory as *const deno_core::v8::fast_api::FastApiTypedArray<u8>)
+ }
+ .get_storage_if_aligned();
+ let result = op_wasm::call(memory);
+ result
+}
diff --git a/ops/optimizer_tests/wasm_op.rs b/ops/optimizer_tests/wasm_op.rs
new file mode 100644
index 000000000..b18f32fd1
--- /dev/null
+++ b/ops/optimizer_tests/wasm_op.rs
@@ -0,0 +1,3 @@
+fn op_wasm(memory: Option<&mut [u8]>) {
+ // @test-attr:wasm
+}