Skip to content

Commit

Permalink
Merge branch 'main' of github.com:denoland/deno into fastops_utf8_val…
Browse files Browse the repository at this point in the history
…idate
  • Loading branch information
littledivy committed Mar 31, 2023
2 parents 096bef7 + b9a3790 commit be81112
Show file tree
Hide file tree
Showing 41 changed files with 763 additions and 921 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ license = "MIT"
repository = "https://github.com/denoland/deno"

[workspace.dependencies]
v8 = { version = "0.66.0", default-features = false }
v8 = { version = "0.67.0", default-features = false }
deno_ast = { version = "0.25.0", features = ["transpiling"] }

deno_core = { version = "0.177.0", path = "./core" }
Expand Down
4 changes: 2 additions & 2 deletions core/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub(crate) fn external_references(ops: &[OpCtx]) -> v8::ExternalReferences {
});
if let Some(fast_fn) = &ctx.decl.fast_fn {
references.push(v8::ExternalReference {
pointer: fast_fn.function() as _,
pointer: fast_fn.function as _,
});
references.push(v8::ExternalReference {
pointer: ctx.fast_fn_c_info.unwrap().as_ptr() as _,
Expand Down Expand Up @@ -218,7 +218,7 @@ fn add_op_to_deno_core_ops(
let templ = if let Some(fast_function) = &op_ctx.decl.fast_fn {
builder.build_fast(
scope,
&**fast_function,
fast_function,
Some(op_ctx.fast_fn_c_info.unwrap().as_ptr()),
None,
None,
Expand Down
2 changes: 1 addition & 1 deletion core/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ pub struct OpDecl {
pub is_async: bool,
pub is_unstable: bool,
pub is_v8: bool,
pub fast_fn: Option<Box<dyn FastFunction>>,
pub force_registration: bool,
pub fast_fn: Option<FastFunction>,
}

impl OpDecl {
Expand Down
6 changes: 3 additions & 3 deletions core/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ impl OpCtx {
let mut fast_fn_c_info = None;

if let Some(fast_fn) = &decl.fast_fn {
let args = CTypeInfo::new_from_slice(fast_fn.args());
let ret = CTypeInfo::new(fast_fn.return_type());
let args = CTypeInfo::new_from_slice(fast_fn.args);
let ret = CTypeInfo::new(fast_fn.return_type);

// SAFETY: all arguments are coming from the trait and they have
// static lifetime
let c_fn = unsafe {
CFunctionInfo::new(args.as_ptr(), fast_fn.args().len(), ret.as_ptr())
CFunctionInfo::new(args.as_ptr(), fast_fn.args.len(), ret.as_ptr())
};
fast_fn_c_info = Some(c_fn);
}
Expand Down
4 changes: 2 additions & 2 deletions core/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,8 @@ impl JsRuntime {
true => op,
false => OpDecl {
v8_fn_ptr: match op.is_async {
true => op_void_async::v8_fn_ptr(),
false => op_void_sync::v8_fn_ptr(),
true => op_void_async::v8_fn_ptr as _,
false => op_void_sync::v8_fn_ptr as _,
},
..op
},
Expand Down
41 changes: 12 additions & 29 deletions ext/ffi/turbocall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,29 @@ pub(crate) fn compile_trampoline(sym: &Symbol) -> Trampoline {
}
}

pub(crate) fn make_template(sym: &Symbol, trampoline: &Trampoline) -> Template {
pub(crate) fn make_template(
sym: &Symbol,
trampoline: &Trampoline,
) -> fast_api::FastFunction {
let mut params = once(fast_api::Type::V8Value) // Receiver
.chain(sym.parameter_types.iter().map(|t| t.into()))
.collect::<Vec<_>>();

let ret = if needs_unwrap(&sym.result_type) {
params.push(fast_api::Type::TypedArray(fast_api::CType::Int32));
fast_api::Type::Void
fast_api::CType::Void
} else if sym.result_type == NativeType::Buffer {
// Buffer can be used as a return type and converts differently than in parameters.
fast_api::Type::Pointer
fast_api::CType::Pointer
} else {
fast_api::Type::from(&sym.result_type)
fast_api::CType::from(&fast_api::Type::from(&sym.result_type))
};

Template {
args: params.into_boxed_slice(),
ret: (&ret).into(),
symbol_ptr: trampoline.ptr(),
}
fast_api::FastFunction::new(
Box::leak(params.into_boxed_slice()),
ret,
trampoline.ptr(),
)
}

/// Trampoline for fast-call FFI functions
Expand All @@ -73,26 +76,6 @@ impl Trampoline {
}
}

pub(crate) struct Template {
pub args: Box<[fast_api::Type]>,
pub ret: fast_api::CType,
pub symbol_ptr: *const c_void,
}

impl fast_api::FastFunction for Template {
fn function(&self) -> *const c_void {
self.symbol_ptr
}

fn args(&self) -> &'static [fast_api::Type] {
Box::leak(self.args.clone())
}

fn return_type(&self) -> fast_api::CType {
self.ret
}
}

impl From<&NativeType> for fast_api::Type {
fn from(native_type: &NativeType) -> Self {
match native_type {
Expand Down
76 changes: 23 additions & 53 deletions ext/flash/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,26 +316,16 @@ async fn op_flash_write_resource(
Ok(())
}

pub struct RespondFast;

impl fast_api::FastFunction for RespondFast {
fn function(&self) -> *const c_void {
op_flash_respond_fast as *const c_void
}

fn args(&self) -> &'static [fast_api::Type] {
&[
fast_api::Type::V8Value,
fast_api::Type::Uint32,
fast_api::Type::TypedArray(fast_api::CType::Uint8),
fast_api::Type::Bool,
]
}

fn return_type(&self) -> fast_api::CType {
fast_api::CType::Uint32
}
}
pub const RESPOND_FAST: fast_api::FastFunction = fast_api::FastFunction::new(
&[
fast_api::Type::V8Value,
fast_api::Type::Uint32,
fast_api::Type::TypedArray(fast_api::CType::Uint8),
fast_api::Type::Bool,
],
fast_api::CType::Uint32,
op_flash_respond_fast as *const c_void,
);

fn flash_respond(
ctx: &mut ServerContext,
Expand Down Expand Up @@ -468,21 +458,11 @@ fn next_request_sync(ctx: &mut ServerContext) -> u32 {
ctx.next_token - offset
}

pub struct NextRequestFast;

impl fast_api::FastFunction for NextRequestFast {
fn function(&self) -> *const c_void {
op_flash_next_fast as *const c_void
}

fn args(&self) -> &'static [fast_api::Type] {
&[fast_api::Type::V8Value]
}

fn return_type(&self) -> fast_api::CType {
fast_api::CType::Uint32
}
}
const NEXT_REQUEST_FAST: fast_api::FastFunction = fast_api::FastFunction::new(
&[fast_api::Type::V8Value],
fast_api::CType::Uint32,
op_flash_next_fast as *const c_void,
);

unsafe fn op_flash_next_fast(recv: v8::Local<v8::Object>) -> u32 {
let ptr =
Expand All @@ -491,21 +471,11 @@ unsafe fn op_flash_next_fast(recv: v8::Local<v8::Object>) -> u32 {
next_request_sync(ctx)
}

pub struct GetMethodFast;

impl fast_api::FastFunction for GetMethodFast {
fn function(&self) -> *const c_void {
op_flash_get_method_fast as *const c_void
}

fn args(&self) -> &'static [fast_api::Type] {
&[fast_api::Type::V8Value, fast_api::Type::Uint32]
}

fn return_type(&self) -> fast_api::CType {
fast_api::CType::Uint32
}
}
const GET_METHOD_FAST: fast_api::FastFunction = fast_api::FastFunction::new(
&[fast_api::Type::V8Value, fast_api::Type::Uint32],
fast_api::CType::Uint32,
op_flash_get_method_fast as *const c_void,
);

unsafe fn op_flash_get_method_fast(
recv: v8::Local<v8::Object>,
Expand Down Expand Up @@ -549,7 +519,7 @@ fn op_flash_make_request<'scope>(
)
.data(v8::External::new(scope, ctx as *mut _).into());

let func = builder.build_fast(scope, &NextRequestFast, None, None, None);
let func = builder.build_fast(scope, &NEXT_REQUEST_FAST, None, None, None);
let func: v8::Local<v8::Value> = func.get_function(scope).unwrap().into();

let key = v8::String::new(scope, "nextRequest").unwrap();
Expand All @@ -572,7 +542,7 @@ fn op_flash_make_request<'scope>(
)
.data(v8::External::new(scope, ctx as *mut _).into());

let func = builder.build_fast(scope, &GetMethodFast, None, None, None);
let func = builder.build_fast(scope, &GET_METHOD_FAST, None, None, None);
let func: v8::Local<v8::Value> = func.get_function(scope).unwrap().into();

let key = v8::String::new(scope, "getMethod").unwrap();
Expand Down Expand Up @@ -610,7 +580,7 @@ fn op_flash_make_request<'scope>(
)
.data(v8::External::new(scope, ctx as *mut _).into());

let func = builder.build_fast(scope, &RespondFast, None, None, None);
let func = builder.build_fast(scope, &RESPOND_FAST, None, None, None);
let func: v8::Local<v8::Value> = func.get_function(scope).unwrap().into();

let key = v8::String::new(scope, "respond").unwrap();
Expand Down
Loading

0 comments on commit be81112

Please sign in to comment.