diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-11-26 20:48:17 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-27 04:48:17 +0000 |
commit | 9ffc6acdbb3326dde74c803332547b0ae33e483a (patch) | |
tree | e3d45392c1f6d41fac66f59c2f216f81b9a86c6e /ops/optimizer.rs | |
parent | 0012484f4f194664bea87879ab9f4f20f4ee86c6 (diff) |
perf(ops): Reenable fast unit result optimization (#16827)
The optimization was missed in the optimizer rewrite
https://github.com/denoland/deno/pull/16514
Diffstat (limited to 'ops/optimizer.rs')
-rw-r--r-- | ops/optimizer.rs | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/ops/optimizer.rs b/ops/optimizer.rs index cf2c71ae4..8fa2ab1f5 100644 --- a/ops/optimizer.rs +++ b/ops/optimizer.rs @@ -9,7 +9,7 @@ use syn::{ parse_quote, punctuated::Punctuated, token::Colon2, AngleBracketedGenericArguments, FnArg, GenericArgument, PatType, Path, PathArguments, PathSegment, ReturnType, Signature, Type, TypePath, TypePtr, - TypeReference, TypeSlice, + TypeReference, TypeSlice, TypeTuple, }; #[derive(Debug)] @@ -196,7 +196,10 @@ pub(crate) struct Optimizer { pub(crate) has_rc_opstate: bool, + // Do we need an explict FastApiCallbackOptions argument? pub(crate) has_fast_callback_option: bool, + // Do we depend on FastApiCallbackOptions? + pub(crate) needs_fast_callback_option: bool, pub(crate) fast_result: Option<FastValue>, pub(crate) fast_parameters: Vec<FastValue>, @@ -218,6 +221,11 @@ impl Debug for Optimizer { "has_fast_callback_option: {}", self.has_fast_callback_option )?; + writeln!( + f, + "needs_fast_callback_option: {}", + self.needs_fast_callback_option + )?; writeln!(f, "fast_result: {:?}", self.fast_result)?; writeln!(f, "fast_parameters: {:?}", self.fast_parameters)?; writeln!(f, "transforms: {:?}", self.transforms)?; @@ -298,6 +306,9 @@ impl Optimizer { fn analyze_return_type(&mut self, ty: &Type) -> Result<(), BailoutReason> { match ty { + Type::Tuple(TypeTuple { elems, .. }) if elems.is_empty() => { + self.fast_result = Some(FastValue::Void); + } Type::Path(TypePath { path: Path { segments, .. }, .. @@ -333,6 +344,14 @@ impl Optimizer { self.fast_compatible = false; return Err(BailoutReason::FastUnsupportedParamType); } + Some(GenericArgument::Type(Type::Tuple(TypeTuple { + elems, + .. + }))) + if elems.is_empty() => + { + self.fast_result = Some(FastValue::Void); + } _ => return Err(BailoutReason::FastUnsupportedParamType), } } @@ -407,15 +426,19 @@ impl Optimizer { { let segment = single_segment(segments)?; match segment { - // Is `T` a FastApiCallbackOption? + // Is `T` a FastApiCallbackOptions? PathSegment { ident, .. } - if ident == "FastApiCallbackOption" => + if ident == "FastApiCallbackOptions" => { self.has_fast_callback_option = true; } - _ => {} + _ => return Err(BailoutReason::FastUnsupportedParamType), } + } else { + return Err(BailoutReason::FastUnsupportedParamType); } + } else { + return Err(BailoutReason::FastUnsupportedParamType); } } } @@ -517,7 +540,7 @@ impl Optimizer { match segment { // Is `T` a u8? PathSegment { ident, .. } if ident == "u8" => { - self.has_fast_callback_option = true; + self.needs_fast_callback_option = true; self.fast_parameters.push(FastValue::Uint8Array); assert!(self .transforms @@ -526,7 +549,7 @@ impl Optimizer { } // Is `T` a u32? PathSegment { ident, .. } if ident == "u32" => { - self.has_fast_callback_option = true; + self.needs_fast_callback_option = true; self.fast_parameters.push(FastValue::Uint32Array); assert!(self .transforms @@ -554,7 +577,7 @@ impl Optimizer { match segment { // Is `T` a u8? PathSegment { ident, .. } if ident == "u8" => { - self.has_fast_callback_option = true; + self.needs_fast_callback_option = true; self.fast_parameters.push(FastValue::Uint8Array); assert!(self .transforms |