diff --git a/third_party/move/move-compiler-v2/src/env_pipeline/function_checker.rs b/third_party/move/move-compiler-v2/src/env_pipeline/function_checker.rs index 8085c408fb6c1f..d7dbcc3cfce2b3 100644 --- a/third_party/move/move-compiler-v2/src/env_pipeline/function_checker.rs +++ b/third_party/move/move-compiler-v2/src/env_pipeline/function_checker.rs @@ -15,21 +15,13 @@ use std::{collections::BTreeSet, iter::Iterator, ops::Deref, vec::Vec}; type QualifiedFunId = QualifiedId; -fn type_has_function(ty: &Type) -> bool { - match ty { - Type::Tuple(tys) => tys.iter().any(|ty| ty.is_function()), - Type::Fun(..) => true, - _ => false, - } -} - // Takes a list of function types, returns those which have a function type in their argument type -fn identify_function_types_with_functions_in_args(func_returns: Vec) -> Vec { - func_returns +fn identify_function_types_with_functions_in_args(func_types: Vec) -> Vec { + func_types .into_iter() .filter_map(|ty| { if let Type::Fun(argt, _) = &ty { - if type_has_function(argt.deref()) { + if argt.deref().has_function() { Some(ty) } else { None @@ -44,14 +36,14 @@ fn identify_function_types_with_functions_in_args(func_returns: Vec) -> Ve // Takes a list of function-typed parameters, along with argument and result type // Returns a list of any parameters whose result type has a function value, along with that result type. fn identify_function_typed_params_with_functions_in_rets( - func_params: Vec<&Parameter>, + func_types: Vec<&Parameter>, ) -> Vec<(&Parameter, &Type)> { - func_params + func_types .iter() .filter_map(|param| { if let Type::Fun(_argt, rest) = ¶m.1 { let rest_unboxed = rest.deref(); - if type_has_function(rest_unboxed) { + if rest_unboxed.has_function() { Some((*param, rest_unboxed)) } else { None diff --git a/third_party/move/move-model/src/ty.rs b/third_party/move/move-model/src/ty.rs index 9fc0002f44ece0..158c26dd3ea9c4 100644 --- a/third_party/move/move-model/src/ty.rs +++ b/third_party/move/move-model/src/ty.rs @@ -819,16 +819,26 @@ impl Type { matches!(self, Type::Primitive(_)) } - /// Determines whether this is a reference. - pub fn is_reference(&self) -> bool { - matches!(self, Type::Reference(_, _)) - } - /// Determines whether this is a function. pub fn is_function(&self) -> bool { matches!(self, Type::Fun(..)) } + /// Determines whether this is a function or a tuple with a function; + /// this is useful to test a function parameter/return type for function values. + pub fn has_function(&self) -> bool { + match self { + Type::Tuple(tys) => tys.iter().any(|ty| ty.is_function()), + Type::Fun(..) => true, + _ => false, + } + } + + /// Determines whether this is a reference. + pub fn is_reference(&self) -> bool { + matches!(self, Type::Reference(_, _)) + } + /// If this is a reference, return the kind of the reference, otherwise None. pub fn ref_kind(&self) -> Option { if let Type::Reference(kind, _) = self {