From dab0e4b758ecc80439f2e40c4130635087b72b10 Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Sun, 30 Apr 2023 10:00:46 +0300 Subject: [PATCH] Move opposite_variance to type utils --- src/aeso_ast_infer_types.erl | 9 ++++----- src/aeso_tc_type_utils.erl | 6 ++++++ src/aeso_tc_unify.erl | 7 ++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/aeso_ast_infer_types.erl b/src/aeso_ast_infer_types.erl index 86b1269..260f6a8 100644 --- a/src/aeso_ast_infer_types.erl +++ b/src/aeso_ast_infer_types.erl @@ -124,6 +124,10 @@ unify(A, B, C, D) -> aeso_tc_unify:unify(A, B, C, D). unfold_types_in_type(A, B) -> aeso_tc_type_unfolding:unfold_types_in_type(A, B). unfold_record_types(A, B) -> aeso_tc_type_unfolding:unfold_record_types(A, B). +%% ------- + +opposite_variance(A) -> aeso_tc_type_utils:opposite_variance(A). + %% -- The rest --------------------------------------------------------------- map_t(As, K, V) -> {app_t, As, {id, As, "map"}, [K, V]}. @@ -510,11 +514,6 @@ infer_type_vars_variance({fun_t, _, [], Args, Res}) -> FlippedArgsVariance ++ ResVariance; infer_type_vars_variance(_) -> []. -opposite_variance(invariant) -> invariant; -opposite_variance(covariant) -> contravariant; -opposite_variance(contravariant) -> covariant; -opposite_variance(bivariant) -> bivariant. - -spec check_constants(env(), [aeso_syntax:decl()]) -> {env(), [aeso_syntax:decl()]}. check_constants(Env, Consts) -> HasValidId = fun({letval, _, {id, _, _}, _}) -> true; diff --git a/src/aeso_tc_type_utils.erl b/src/aeso_tc_type_utils.erl index fbbaa60..9eebffb 100644 --- a/src/aeso_tc_type_utils.erl +++ b/src/aeso_tc_type_utils.erl @@ -7,6 +7,7 @@ , fun_arity/1 , ensure_first_order/2 , ensure_monomorphic/2 + , opposite_variance/1 ]). typesig_to_fun_t({type_sig, Ann, _Constr, Named, Args, Res}) -> @@ -80,3 +81,8 @@ is_first_order({fun_t, _, _, _, _}) -> false; is_first_order(Ts) when is_list(Ts) -> lists:all(fun is_first_order/1, Ts); is_first_order(Tup) when is_tuple(Tup) -> is_first_order(tuple_to_list(Tup)); is_first_order(_) -> true. + +opposite_variance(invariant) -> invariant; +opposite_variance(covariant) -> contravariant; +opposite_variance(contravariant) -> covariant; +opposite_variance(bivariant) -> bivariant. diff --git a/src/aeso_tc_unify.erl b/src/aeso_tc_unify.erl index 045134a..45034ca 100644 --- a/src/aeso_tc_unify.erl +++ b/src/aeso_tc_unify.erl @@ -2,9 +2,6 @@ -export([unify/4]). -%% -- Circular dependency ---------------------------------------------------- - -opposite_variance(A) -> aeso_ast_infer_types:opposite_variance(A). %% -- Moved functions -------------------------------------------------------- @@ -15,6 +12,10 @@ unfold_types_in_type(A, B, C) -> aeso_tc_type_unfolding:unfold_types_in_type(A, type_error(A) -> aeso_tc_errors:type_error(A). cannot_unify(A, B, C, D) -> aeso_tc_errors:cannot_unify(A, B, C, D). +%% ------- + +opposite_variance(A) -> aeso_tc_type_utils:opposite_variance(A). + %% --------------------------------------------------------------------------- unify(Env, A, B, When) -> unify0(Env, A, B, covariant, When).