[m-rev.] diff: Add get_ctor_arg_types predicate.

Peter Wang novalazy at gmail.com
Wed May 5 17:56:13 AEST 2021


compiler/prog_data.m:
    Add get_ctor_arg_types predicate.

compiler/check_typeclass.m:
compiler/modecheck_coerce.m:
compiler/old_type_constraints.m:
    Use get_ctor_arg_types instead of similar predicates or functions.

diff --git a/compiler/check_typeclass.m b/compiler/check_typeclass.m
index 0592248cd..3475f5a45 100644
--- a/compiler/check_typeclass.m
+++ b/compiler/check_typeclass.m
@@ -1840,7 +1840,7 @@ check_typeclass_constraints_on_data_ctor(ModuleInfo, TypeCtor, TypeDefn,
             %
             % Any ambiguity errors can be reported *after* the programmer
             % fixes the references to nonexistent typeclasses.
-            ArgTypes = list.map(func(ctor_arg(_, T, _)) = T, CtorArgs),
+            get_ctor_arg_types(CtorArgs, ArgTypes),
             type_vars_list(ArgTypes, ArgTVars),
             list.filter((pred(V::in) is semidet :- list.member(V, ExistQVars)),
                 ArgTVars, ExistQArgTVars),
diff --git a/compiler/modecheck_coerce.m b/compiler/modecheck_coerce.m
index 24d7e8b8d..c73a2bf66 100644
--- a/compiler/modecheck_coerce.m
+++ b/compiler/modecheck_coerce.m
@@ -655,7 +655,7 @@ modecheck_coerce_from_ground_make_bound_functor(ModuleInfo, TVarSet,
     % Get the argument types for the constructors of both types,
     % with type arguments substituted in.
     % type_constructors already substituted type args into CtorArgsX.
-    list.map(get_ctor_arg_type, CtorArgsX, ArgTypesX),
+    get_ctor_arg_types(CtorArgsX, ArgTypesX),
     ( if
         get_ctor_arg_types_do_subst(ModuleInfo, TypeY, ConsIdY, ArgTypesY0)
     then
@@ -715,7 +715,7 @@ get_ctor_arg_types_do_subst(ModuleInfo, Type, ConsId, CtorArgTypes) :-
     search_cons_table_of_type_ctor(ConsTable, TypeCtor, ConsId, ConsDefn),
     ConsDefn = hlds_cons_defn(_TypeCtor, _TVarSet, TypeParams, _KindMap,
         _MaybeExistConstraints, CtorArgs, _Context),
-    list.map(get_ctor_arg_type, CtorArgs, CtorArgTypes0),
+    get_ctor_arg_types(CtorArgs, CtorArgTypes0),
     (
         TypeParams = [],
         CtorArgTypes = CtorArgTypes0
@@ -725,11 +725,6 @@ get_ctor_arg_types_do_subst(ModuleInfo, Type, ConsId, CtorArgTypes) :-
         apply_subst_to_type_list(Subst, CtorArgTypes0, CtorArgTypes)
     ).
 
-    % XXX move this to prog_data.m and reuse in other modules
-:- pred get_ctor_arg_type(constructor_arg::in, mer_type::out) is det.
-
-get_ctor_arg_type(ctor_arg(_, Type, _), Type).
-
 %---------------------------------------------------------------------------%
 
 :- type types_comparison
diff --git a/compiler/old_type_constraints.m b/compiler/old_type_constraints.m
index 3204445f6..d4a846a1f 100644
--- a/compiler/old_type_constraints.m
+++ b/compiler/old_type_constraints.m
@@ -692,7 +692,7 @@ functor_unif_constraint(LTVar, ArgTVars, Info, ConsDefn, Constraints,
     GoalId = goal_info_get_goal_id(Info),
     % Find the types of each argument and the result type, given a renaming
     % of type variables.
-    list.map(get_ctor_arg_type, FuncArgs, FuncArgTypes0),
+    get_ctor_arg_types(FuncArgs, FuncArgTypes0),
     prog_data.tvarset_merge_renaming(!.TCInfo ^ tconstr_tvarset,
         FunctorTVarSet, NewTVarSet, TVarRenaming),
     !TCInfo ^ tconstr_tvarset := NewTVarSet,
@@ -1126,10 +1126,6 @@ create_stconstr(TVar, Type) = stconstr(TVar, Type).
 
 get_case_goal(Case, Case ^ case_goal).
 
-:- pred get_ctor_arg_type(constructor_arg::in, mer_type::out) is det.
-
-get_ctor_arg_type(ctor_arg(_, Type, _), Type).
-
 :- func tvar_to_type(tvar) = mer_type.
 
 tvar_to_type(TVar) = type_variable(TVar, kind_star).
diff --git a/compiler/prog_data.m b/compiler/prog_data.m
index 7ac83717a..6f4a547fd 100644
--- a/compiler/prog_data.m
+++ b/compiler/prog_data.m
@@ -516,6 +516,9 @@ cons_id_is_const_struct(ConsId, ConstNum) :-
                 prog_context        % The context of the name in the source.
             ).
 
+:- pred get_ctor_arg_types(list(constructor_arg)::in, list(mer_type)::out)
+    is det.
+
     % The arg_pos_width type and its components specify how much space
     % does a constructor argument occupy in the memory that represents
     % a term with that constructor, and where. This memory will usually be
@@ -911,6 +914,13 @@ ctors_are_all_constants([Ctor | Ctors], [Name | Names]) :-
     ctor_is_constant(Ctor, Name),
     ctors_are_all_constants(Ctors, Names).
 
+get_ctor_arg_types(CtorArgs, CtorArgTypes) :-
+    list.map(get_ctor_arg_type, CtorArgs, CtorArgTypes).
+
+:- pred get_ctor_arg_type(constructor_arg::in, mer_type::out) is det.
+
+get_ctor_arg_type(ctor_arg(_, Type, _), Type).
+
 fill_kind_string(fill_enum, "fill_enum").
 fill_kind_string(fill_int8, "fill_int8").
 fill_kind_string(fill_int16, "fill_int16").
-- 
2.30.0



More information about the reviews mailing list