diff options
Diffstat (limited to 'ops/optimizer_tests')
30 files changed, 414 insertions, 0 deletions
diff --git a/ops/optimizer_tests/callback_options.expected b/ops/optimizer_tests/callback_options.expected new file mode 100644 index 000000000..063032bb5 --- /dev/null +++ b/ops/optimizer_tests/callback_options.expected @@ -0,0 +1,8 @@ +=== Optimizer Dump === +returns_result: false +has_ref_opstate: false +has_rc_opstate: false +has_fast_callback_option: false +fast_result: Some(Void) +fast_parameters: [V8Value] +transforms: {} diff --git a/ops/optimizer_tests/callback_options.out b/ops/optimizer_tests/callback_options.out new file mode 100644 index 000000000..426fe0c4a --- /dev/null +++ b/ops/optimizer_tests/callback_options.out @@ -0,0 +1,25 @@ +struct op_fallback_fast { + _phantom: ::std::marker::PhantomData<()>, +} +impl<'scope> deno_core::v8::fast_api::FastFunction for op_fallback_fast { + fn function(&self) -> *const ::std::ffi::c_void { + op_fallback_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] + } + fn return_type(&self) -> deno_core::v8::fast_api::CType { + deno_core::v8::fast_api::CType::Void + } +} +fn op_fallback_fast_fn<'scope>( + _: deno_core::v8::Local<deno_core::v8::Object>, + options: Option<&mut FastApiCallbackOptions>, +) -> () { + use deno_core::v8; + use deno_core::_ops; + let result = op_fallback::call(options); + result +} diff --git a/ops/optimizer_tests/callback_options.rs b/ops/optimizer_tests/callback_options.rs new file mode 100644 index 000000000..c210171d2 --- /dev/null +++ b/ops/optimizer_tests/callback_options.rs @@ -0,0 +1,5 @@ +fn op_fallback(options: Option<&mut FastApiCallbackOptions>) { + if let Some(options) = options { + options.fallback = true; + } +} diff --git a/ops/optimizer_tests/incompatible_1.expected b/ops/optimizer_tests/incompatible_1.expected new file mode 100644 index 000000000..250ff1022 --- /dev/null +++ b/ops/optimizer_tests/incompatible_1.expected @@ -0,0 +1 @@ +FastUnsupportedParamType
\ No newline at end of file diff --git a/ops/optimizer_tests/incompatible_1.rs b/ops/optimizer_tests/incompatible_1.rs new file mode 100644 index 000000000..326189aa1 --- /dev/null +++ b/ops/optimizer_tests/incompatible_1.rs @@ -0,0 +1,9 @@ +fn op_sync_serialize_object_with_numbers_as_keys( + value: serde_json::Value, +) -> Result<(), Error> { + assert_eq!( + value.to_string(), + r#"{"lines":{"100":{"unit":"m"},"200":{"unit":"cm"}}}"# + ); + Ok(()) +} diff --git a/ops/optimizer_tests/op_state.expected b/ops/optimizer_tests/op_state.expected new file mode 100644 index 000000000..f23bf764a --- /dev/null +++ b/ops/optimizer_tests/op_state.expected @@ -0,0 +1,8 @@ +=== Optimizer Dump === +returns_result: false +has_ref_opstate: true +has_rc_opstate: false +has_fast_callback_option: false +fast_result: Some(Void) +fast_parameters: [V8Value, I32] +transforms: {} diff --git a/ops/optimizer_tests/op_state.out b/ops/optimizer_tests/op_state.out new file mode 100644 index 000000000..a98db68d8 --- /dev/null +++ b/ops/optimizer_tests/op_state.out @@ -0,0 +1,34 @@ +struct op_set_exit_code_fast { + _phantom: ::std::marker::PhantomData<()>, +} +impl<'scope> deno_core::v8::fast_api::FastFunction for op_set_exit_code_fast { + fn function(&self) -> *const ::std::ffi::c_void { + op_set_exit_code_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, Int32, CallbackOptions] + } + fn return_type(&self) -> deno_core::v8::fast_api::CType { + deno_core::v8::fast_api::CType::Void + } +} +fn op_set_exit_code_fast_fn<'scope>( + _: deno_core::v8::Local<deno_core::v8::Object>, + code: i32, + 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 __ctx = unsafe { + &*(v8::Local::<v8::External>::cast(unsafe { __opts.data.data }).value() + as *const _ops::OpCtx) + }; + let state = &mut ::std::cell::RefCell::borrow_mut(&__ctx.state); + let result = op_set_exit_code::call(state, code); + result +} diff --git a/ops/optimizer_tests/op_state.rs b/ops/optimizer_tests/op_state.rs new file mode 100644 index 000000000..04e9a886d --- /dev/null +++ b/ops/optimizer_tests/op_state.rs @@ -0,0 +1,3 @@ +fn op_set_exit_code(state: &mut OpState, code: i32) { + state.borrow_mut::<ExitCode>().set(code); +} diff --git a/ops/optimizer_tests/op_state_basic1.expected b/ops/optimizer_tests/op_state_basic1.expected new file mode 100644 index 000000000..3639959b8 --- /dev/null +++ b/ops/optimizer_tests/op_state_basic1.expected @@ -0,0 +1,8 @@ +=== Optimizer Dump === +returns_result: false +has_ref_opstate: true +has_rc_opstate: false +has_fast_callback_option: false +fast_result: Some(U32) +fast_parameters: [V8Value, U32, U32] +transforms: {} diff --git a/ops/optimizer_tests/op_state_basic1.out b/ops/optimizer_tests/op_state_basic1.out new file mode 100644 index 000000000..0f03f2c58 --- /dev/null +++ b/ops/optimizer_tests/op_state_basic1.out @@ -0,0 +1,35 @@ +struct foo_fast { + _phantom: ::std::marker::PhantomData<()>, +} +impl<'scope> deno_core::v8::fast_api::FastFunction for foo_fast { + fn function(&self) -> *const ::std::ffi::c_void { + foo_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, Uint32, Uint32, CallbackOptions] + } + fn return_type(&self) -> deno_core::v8::fast_api::CType { + deno_core::v8::fast_api::CType::Uint32 + } +} +fn foo_fast_fn<'scope>( + _: deno_core::v8::Local<deno_core::v8::Object>, + a: u32, + b: u32, + fast_api_callback_options: *mut deno_core::v8::fast_api::FastApiCallbackOptions, +) -> u32 { + use deno_core::v8; + use deno_core::_ops; + let __opts: &mut v8::fast_api::FastApiCallbackOptions = unsafe { + &mut *fast_api_callback_options + }; + let __ctx = unsafe { + &*(v8::Local::<v8::External>::cast(unsafe { __opts.data.data }).value() + as *const _ops::OpCtx) + }; + let state = &mut ::std::cell::RefCell::borrow_mut(&__ctx.state); + let result = foo::call(state, a, b); + result +} diff --git a/ops/optimizer_tests/op_state_basic1.rs b/ops/optimizer_tests/op_state_basic1.rs new file mode 100644 index 000000000..9c89b41ce --- /dev/null +++ b/ops/optimizer_tests/op_state_basic1.rs @@ -0,0 +1,3 @@ +fn foo(state: &mut OpState, a: u32, b: u32) -> u32 { + a + b +} diff --git a/ops/optimizer_tests/op_state_generics.expected b/ops/optimizer_tests/op_state_generics.expected new file mode 100644 index 000000000..83e938502 --- /dev/null +++ b/ops/optimizer_tests/op_state_generics.expected @@ -0,0 +1,8 @@ +=== Optimizer Dump === +returns_result: false +has_ref_opstate: true +has_rc_opstate: false +has_fast_callback_option: false +fast_result: Some(Void) +fast_parameters: [V8Value] +transforms: {} diff --git a/ops/optimizer_tests/op_state_generics.out b/ops/optimizer_tests/op_state_generics.out new file mode 100644 index 000000000..d141c7445 --- /dev/null +++ b/ops/optimizer_tests/op_state_generics.out @@ -0,0 +1,39 @@ +struct op_foo_fast<SP> { + _phantom: ::std::marker::PhantomData<SP>, +} +impl<'scope, SP> deno_core::v8::fast_api::FastFunction for op_foo_fast<SP> +where + SP: SomePermission + 'static, +{ + fn function(&self) -> *const ::std::ffi::c_void { + op_foo_fast_fn::<SP> 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_foo_fast_fn<'scope, SP>( + _: deno_core::v8::Local<deno_core::v8::Object>, + fast_api_callback_options: *mut deno_core::v8::fast_api::FastApiCallbackOptions, +) -> () +where + SP: SomePermission + 'static, +{ + use deno_core::v8; + use deno_core::_ops; + let __opts: &mut v8::fast_api::FastApiCallbackOptions = unsafe { + &mut *fast_api_callback_options + }; + let __ctx = unsafe { + &*(v8::Local::<v8::External>::cast(unsafe { __opts.data.data }).value() + as *const _ops::OpCtx) + }; + let state = &mut ::std::cell::RefCell::borrow_mut(&__ctx.state); + let result = op_foo::call::<SP>(state); + result +} diff --git a/ops/optimizer_tests/op_state_generics.rs b/ops/optimizer_tests/op_state_generics.rs new file mode 100644 index 000000000..7fa498981 --- /dev/null +++ b/ops/optimizer_tests/op_state_generics.rs @@ -0,0 +1,5 @@ +pub fn op_foo<SP>(state: &mut OpState) +where + SP: SomePermission + 'static, +{ +} diff --git a/ops/optimizer_tests/op_state_result.expected b/ops/optimizer_tests/op_state_result.expected new file mode 100644 index 000000000..16e71c38c --- /dev/null +++ b/ops/optimizer_tests/op_state_result.expected @@ -0,0 +1,8 @@ +=== Optimizer Dump === +returns_result: true +has_ref_opstate: true +has_rc_opstate: false +has_fast_callback_option: false +fast_result: Some(U32) +fast_parameters: [V8Value, U32, U32] +transforms: {} diff --git a/ops/optimizer_tests/op_state_result.out b/ops/optimizer_tests/op_state_result.out new file mode 100644 index 000000000..5174dd7f2 --- /dev/null +++ b/ops/optimizer_tests/op_state_result.out @@ -0,0 +1,42 @@ +struct foo_fast { + _phantom: ::std::marker::PhantomData<()>, +} +impl<'scope> deno_core::v8::fast_api::FastFunction for foo_fast { + fn function(&self) -> *const ::std::ffi::c_void { + foo_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, Uint32, Uint32, CallbackOptions] + } + fn return_type(&self) -> deno_core::v8::fast_api::CType { + deno_core::v8::fast_api::CType::Uint32 + } +} +fn foo_fast_fn<'scope>( + _: deno_core::v8::Local<deno_core::v8::Object>, + a: u32, + b: u32, + fast_api_callback_options: *mut deno_core::v8::fast_api::FastApiCallbackOptions, +) -> u32 { + use deno_core::v8; + use deno_core::_ops; + let __opts: &mut v8::fast_api::FastApiCallbackOptions = unsafe { + &mut *fast_api_callback_options + }; + let __ctx = unsafe { + &*(v8::Local::<v8::External>::cast(unsafe { __opts.data.data }).value() + as *const _ops::OpCtx) + }; + let state = &mut ::std::cell::RefCell::borrow_mut(&__ctx.state); + let result = foo::call(state, a, b); + match result { + Ok(result) => result, + Err(err) => { + state.last_fast_op_error.replace(err); + __opts.fallback = true; + Default::default() + } + } +} diff --git a/ops/optimizer_tests/op_state_result.rs b/ops/optimizer_tests/op_state_result.rs new file mode 100644 index 000000000..331005c08 --- /dev/null +++ b/ops/optimizer_tests/op_state_result.rs @@ -0,0 +1,3 @@ +fn foo(state: &mut OpState, a: u32, b: u32) -> Result<u32, AnyError> { + Ok(a + b) +} diff --git a/ops/optimizer_tests/op_state_with_transforms.expected b/ops/optimizer_tests/op_state_with_transforms.expected new file mode 100644 index 000000000..388d396f5 --- /dev/null +++ b/ops/optimizer_tests/op_state_with_transforms.expected @@ -0,0 +1,8 @@ +=== Optimizer Dump === +returns_result: false +has_ref_opstate: true +has_rc_opstate: false +has_fast_callback_option: true +fast_result: Some(Void) +fast_parameters: [V8Value, Uint8Array] +transforms: {1: Transform { kind: SliceU8(true), index: 1 }} diff --git a/ops/optimizer_tests/op_state_with_transforms.out b/ops/optimizer_tests/op_state_with_transforms.out new file mode 100644 index 000000000..f981748be --- /dev/null +++ b/ops/optimizer_tests/op_state_with_transforms.out @@ -0,0 +1,47 @@ +struct op_now_fast<TP> { + _phantom: ::std::marker::PhantomData<TP>, +} +impl<'scope, TP> deno_core::v8::fast_api::FastFunction for op_now_fast<TP> +where + TP: TimersPermission + 'static, +{ + fn function(&self) -> *const ::std::ffi::c_void { + op_now_fast_fn::<TP> 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, TypedArray(CType::Uint8), CallbackOptions] + } + fn return_type(&self) -> deno_core::v8::fast_api::CType { + deno_core::v8::fast_api::CType::Void + } +} +fn op_now_fast_fn<'scope, TP>( + _: deno_core::v8::Local<deno_core::v8::Object>, + buf: *const deno_core::v8::fast_api::FastApiTypedArray<u8>, + fast_api_callback_options: *mut deno_core::v8::fast_api::FastApiCallbackOptions, +) -> () +where + TP: TimersPermission + 'static, +{ + use deno_core::v8; + use deno_core::_ops; + let __opts: &mut v8::fast_api::FastApiCallbackOptions = unsafe { + &mut *fast_api_callback_options + }; + let __ctx = unsafe { + &*(v8::Local::<v8::External>::cast(unsafe { __opts.data.data }).value() + as *const _ops::OpCtx) + }; + let state = &mut ::std::cell::RefCell::borrow_mut(&__ctx.state); + let buf = match unsafe { &*buf }.get_storage_if_aligned() { + Some(v) => v, + None => { + unsafe { &mut *fast_api_callback_options }.fallback = true; + return Default::default(); + } + }; + let result = op_now::call::<TP>(state, buf); + result +} diff --git a/ops/optimizer_tests/op_state_with_transforms.rs b/ops/optimizer_tests/op_state_with_transforms.rs new file mode 100644 index 000000000..4e7e616f3 --- /dev/null +++ b/ops/optimizer_tests/op_state_with_transforms.rs @@ -0,0 +1,5 @@ +pub fn op_now<TP>(state: &mut OpState, buf: &mut [u8]) +where + TP: TimersPermission + 'static, +{ +} diff --git a/ops/optimizer_tests/opstate_with_arity.expected b/ops/optimizer_tests/opstate_with_arity.expected new file mode 100644 index 000000000..6259f3e28 --- /dev/null +++ b/ops/optimizer_tests/opstate_with_arity.expected @@ -0,0 +1,8 @@ +=== Optimizer Dump === +returns_result: true +has_ref_opstate: false +has_rc_opstate: false +has_fast_callback_option: false +fast_result: Some(U32) +fast_parameters: [V8Value, U32, U32, U32, U32] +transforms: {} diff --git a/ops/optimizer_tests/opstate_with_arity.out b/ops/optimizer_tests/opstate_with_arity.out new file mode 100644 index 000000000..20b7769e7 --- /dev/null +++ b/ops/optimizer_tests/opstate_with_arity.out @@ -0,0 +1,44 @@ +struct op_add_4_fast { + _phantom: ::std::marker::PhantomData<()>, +} +impl<'scope> deno_core::v8::fast_api::FastFunction for op_add_4_fast { + fn function(&self) -> *const ::std::ffi::c_void { + op_add_4_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, Uint32, Uint32, Uint32, Uint32, CallbackOptions] + } + fn return_type(&self) -> deno_core::v8::fast_api::CType { + deno_core::v8::fast_api::CType::Uint32 + } +} +fn op_add_4_fast_fn<'scope>( + _: deno_core::v8::Local<deno_core::v8::Object>, + x1: u32, + x2: u32, + x3: u32, + x4: u32, + fast_api_callback_options: *mut deno_core::v8::fast_api::FastApiCallbackOptions, +) -> u32 { + use deno_core::v8; + use deno_core::_ops; + let __opts: &mut v8::fast_api::FastApiCallbackOptions = unsafe { + &mut *fast_api_callback_options + }; + let __ctx = unsafe { + &*(v8::Local::<v8::External>::cast(unsafe { __opts.data.data }).value() + as *const _ops::OpCtx) + }; + let op_state = &mut ::std::cell::RefCell::borrow_mut(&__ctx.state); + let result = op_add_4::call(x1, x2, x3, x4); + match result { + Ok(result) => result, + Err(err) => { + op_state.last_fast_op_error.replace(err); + __opts.fallback = true; + Default::default() + } + } +} diff --git a/ops/optimizer_tests/opstate_with_arity.rs b/ops/optimizer_tests/opstate_with_arity.rs new file mode 100644 index 000000000..7212ca975 --- /dev/null +++ b/ops/optimizer_tests/opstate_with_arity.rs @@ -0,0 +1,3 @@ +fn op_add_4(x1: u32, x2: u32, x3: u32, x4: u32) -> Result<u32, anyhow::Error> { + Ok(x1 + x2 + x3 + x4) +} diff --git a/ops/optimizer_tests/param_mut_binding_warning.expected b/ops/optimizer_tests/param_mut_binding_warning.expected new file mode 100644 index 000000000..250ff1022 --- /dev/null +++ b/ops/optimizer_tests/param_mut_binding_warning.expected @@ -0,0 +1 @@ +FastUnsupportedParamType
\ No newline at end of file diff --git a/ops/optimizer_tests/param_mut_binding_warning.rs b/ops/optimizer_tests/param_mut_binding_warning.rs new file mode 100644 index 000000000..c47122728 --- /dev/null +++ b/ops/optimizer_tests/param_mut_binding_warning.rs @@ -0,0 +1,11 @@ +fn op_read_sync( + state: &mut OpState, + rid: ResourceId, + mut buf: ZeroCopyBuf, +) -> Result<u32, AnyError> { + // Should not warn about unused `mut buf` binding. + // + // This was caused due to incorrect codegen by fast_call.rs + // on an incompatible op function. + Ok(23) +} diff --git a/ops/optimizer_tests/serde_v8_value.expected b/ops/optimizer_tests/serde_v8_value.expected new file mode 100644 index 000000000..5acd38655 --- /dev/null +++ b/ops/optimizer_tests/serde_v8_value.expected @@ -0,0 +1,8 @@ +=== Optimizer Dump === +returns_result: false +has_ref_opstate: false +has_rc_opstate: false +has_fast_callback_option: false +fast_result: Some(Bool) +fast_parameters: [V8Value, V8Value] +transforms: {0: Transform { kind: V8Value, index: 0 }} diff --git a/ops/optimizer_tests/serde_v8_value.out b/ops/optimizer_tests/serde_v8_value.out new file mode 100644 index 000000000..8c7630547 --- /dev/null +++ b/ops/optimizer_tests/serde_v8_value.out @@ -0,0 +1,26 @@ +struct op_is_proxy_fast { + _phantom: ::std::marker::PhantomData<()>, +} +impl<'scope> deno_core::v8::fast_api::FastFunction for op_is_proxy_fast { + fn function(&self) -> *const ::std::ffi::c_void { + op_is_proxy_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, V8Value] + } + fn return_type(&self) -> deno_core::v8::fast_api::CType { + deno_core::v8::fast_api::CType::Bool + } +} +fn op_is_proxy_fast_fn<'scope>( + _: deno_core::v8::Local<deno_core::v8::Object>, + value: deno_core::v8::Local<v8::Value>, +) -> bool { + use deno_core::v8; + use deno_core::_ops; + let value = serde_v8::Value { v8_value: value }; + let result = op_is_proxy::call(value); + result +} diff --git a/ops/optimizer_tests/serde_v8_value.rs b/ops/optimizer_tests/serde_v8_value.rs new file mode 100644 index 000000000..c986930d9 --- /dev/null +++ b/ops/optimizer_tests/serde_v8_value.rs @@ -0,0 +1,3 @@ +fn op_is_proxy(value: serde_v8::Value) -> bool { + value.v8_value.is_proxy() +} diff --git a/ops/optimizer_tests/u64_result.expected b/ops/optimizer_tests/u64_result.expected new file mode 100644 index 000000000..250ff1022 --- /dev/null +++ b/ops/optimizer_tests/u64_result.expected @@ -0,0 +1 @@ +FastUnsupportedParamType
\ No newline at end of file diff --git a/ops/optimizer_tests/u64_result.rs b/ops/optimizer_tests/u64_result.rs new file mode 100644 index 000000000..1cc783db8 --- /dev/null +++ b/ops/optimizer_tests/u64_result.rs @@ -0,0 +1,5 @@ +fn op_bench_now(state: &mut OpState) -> Result<u64, AnyError> { + let ns = state.borrow::<time::Instant>().elapsed().as_nanos(); + let ns_u64 = u64::try_from(ns)?; + Ok(ns_u64) +} |