Skip to content

Commit

Permalink
move type_has_function into Type as has_function, as suggested by Vin…
Browse files Browse the repository at this point in the history
…eeth.
  • Loading branch information
brmataptos committed Oct 3, 2024
1 parent fda421e commit e8a6216
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,13 @@ use std::{collections::BTreeSet, iter::Iterator, ops::Deref, vec::Vec};

type QualifiedFunId = QualifiedId<FunId>;

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<Type>) -> Vec<Type> {
func_returns
fn identify_function_types_with_functions_in_args(func_types: Vec<Type>) -> Vec<Type> {
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)

Check warning on line 25 in third_party/move/move-compiler-v2/src/env_pipeline/function_checker.rs

View check run for this annotation

Codecov / codecov/patch

third_party/move/move-compiler-v2/src/env_pipeline/function_checker.rs#L25

Added line #L25 was not covered by tests
} else {
None
Expand All @@ -44,14 +36,14 @@ fn identify_function_types_with_functions_in_args(func_returns: Vec<Type>) -> 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) = &param.1 {
let rest_unboxed = rest.deref();
if type_has_function(rest_unboxed) {
if rest_unboxed.has_function() {
Some((*param, rest_unboxed))
} else {
None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,12 @@ impl<'a> RecursiveStructChecker<'a> {
struct_name,
struct_name,
);
self.mod_env.env.error_with_labels(
&struct_env.get_loc(),
"cyclic data",
vec![(field_env.get_loc().clone(), note)],
);
self.mod_env
.env
.error_with_labels(&struct_env.get_loc(), "cyclic data", vec![(
field_env.get_loc().clone(),
note,
)]);
}

/// Report cyclic dependency of structs
Expand Down
20 changes: 15 additions & 5 deletions third_party/move/move-model/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReferenceKind> {
if let Type::Reference(kind, _) = self {
Expand Down

0 comments on commit e8a6216

Please sign in to comment.