diff options
Diffstat (limited to 'ops/optimizer.rs')
-rw-r--r-- | ops/optimizer.rs | 92 |
1 files changed, 90 insertions, 2 deletions
diff --git a/ops/optimizer.rs b/ops/optimizer.rs index ae3175511..a3ccd51b3 100644 --- a/ops/optimizer.rs +++ b/ops/optimizer.rs @@ -45,6 +45,7 @@ enum TransformKind { SliceU8(bool), SliceF64(bool), PtrU8, + PtrVoid, WasmMemory, } @@ -90,6 +91,13 @@ impl Transform { index, } } + + fn void_ptr(index: usize) -> Self { + Transform { + kind: TransformKind::PtrVoid, + index, + } + } } #[derive(Debug, PartialEq)] @@ -195,19 +203,25 @@ impl Transform { .as_ptr(); }) } + TransformKind::PtrVoid => { + *ty = parse_quote! { *mut ::std::ffi::c_void }; + + q!(Vars {}, {}) + } } } } fn get_fast_scalar(s: &str) -> Option<FastValue> { match s { + "bool" => Some(FastValue::Bool), "u32" => Some(FastValue::U32), "i32" => Some(FastValue::I32), "u64" => Some(FastValue::U64), "i64" => Some(FastValue::I64), "f32" => Some(FastValue::F32), "f64" => Some(FastValue::F64), - "bool" => Some(FastValue::Bool), + "* const c_void" | "* mut c_void" => Some(FastValue::Pointer), "ResourceId" => Some(FastValue::U32), _ => None, } @@ -226,13 +240,14 @@ fn can_return_fast(v: &FastValue) -> bool { #[derive(Debug, PartialEq, Clone)] pub(crate) enum FastValue { Void, + Bool, U32, I32, U64, I64, F32, F64, - Bool, + Pointer, V8Value, Uint8Array, Uint32Array, @@ -414,6 +429,31 @@ impl Optimizer { { self.fast_result = Some(FastValue::Void); } + Some(GenericArgument::Type(Type::Ptr(TypePtr { + mutability: Some(_), + elem, + .. + }))) => { + match &**elem { + Type::Path(TypePath { + path: Path { segments, .. }, + .. + }) => { + // Is `T` a c_void? + let segment = single_segment(segments)?; + match segment { + PathSegment { ident, .. } if ident == "c_void" => { + self.fast_result = Some(FastValue::Pointer); + return Ok(()); + } + _ => { + return Err(BailoutReason::FastUnsupportedParamType) + } + } + } + _ => return Err(BailoutReason::FastUnsupportedParamType), + } + } _ => return Err(BailoutReason::FastUnsupportedParamType), } } @@ -430,6 +470,29 @@ impl Optimizer { } }; } + Type::Ptr(TypePtr { + mutability: Some(_), + elem, + .. + }) => { + match &**elem { + Type::Path(TypePath { + path: Path { segments, .. }, + .. + }) => { + // Is `T` a c_void? + let segment = single_segment(segments)?; + match segment { + PathSegment { ident, .. } if ident == "c_void" => { + self.fast_result = Some(FastValue::Pointer); + return Ok(()); + } + _ => return Err(BailoutReason::FastUnsupportedParamType), + } + } + _ => return Err(BailoutReason::FastUnsupportedParamType), + } + } _ => return Err(BailoutReason::FastUnsupportedParamType), }; @@ -684,6 +747,31 @@ impl Optimizer { } _ => return Err(BailoutReason::FastUnsupportedParamType), }, + // *const T + Type::Ptr(TypePtr { + elem, + mutability: Some(_), + .. + }) => match &**elem { + Type::Path(TypePath { + path: Path { segments, .. }, + .. + }) => { + let segment = single_segment(segments)?; + match segment { + // Is `T` a c_void? + PathSegment { ident, .. } if ident == "c_void" => { + self.fast_parameters.push(FastValue::Pointer); + assert!(self + .transforms + .insert(index, Transform::void_ptr(index)) + .is_none()); + } + _ => return Err(BailoutReason::FastUnsupportedParamType), + } + } + _ => return Err(BailoutReason::FastUnsupportedParamType), + }, _ => return Err(BailoutReason::FastUnsupportedParamType), }, _ => return Err(BailoutReason::FastUnsupportedParamType), |