[m-rev.] for review: method_infos

Julien Fischer jfischer at opturion.com
Mon Nov 21 16:36:40 AEDT 2022


On Mon, 21 Nov 2022, Zoltan Somogyi wrote:

> Record more than a pred_proc_id for each method.
> 
> Class and instance definitions both contain lists of methods,
> predicates and/or functions, that each have one or more procedures.
> Until now, we represented the methods in class and instance definitions
> as lists of nothing more than pred_proc_ids. This fact complicated
> several operations,
> 
> - partly because there was no simple way to tell which procedures
>   were part of the same predicate or function, and
> 
> - partly because the order of the list is important (we identify
>   each method procedure in our equivalent of vtables with a number,
>   which is simply the procedure's position in this list), but there was
>   absolutely no information about recorded this.

    ... recorded about this.

> compiler/check_typeclass.m:
>     Significantly simplify the code for that generates the pred_infos and
>     proc_infos implementing all the methods of an instances definition,
>     and construct lists of method_infos instead of lists of pred_proc_ids.
>
>     Give some predicates better names.
>
>     Some error messages about problems in instance definitions started with
>
>         In instance declaration for class/arity:
>
>     while others started with
>
>         In instance declaration for class(module_a.foo, module_b.bar):
>
>     Replace both with
>
>         In instance declaration for class(foo, bar):

That's fine for type classes with *small* numbers of arguments; it's going be
(arguably) less readable than just class/arity for those with larger numbers of
arguments; for example, the following:

     :- instance fd_solver(fdsolver, fd_bool_solver, fd_int_solver, fd_set_solver,
         fdbool, fdvar, fdset).

...


> diff --git a/compiler/check_typeclass.m b/compiler/check_typeclass.m
> index 29361e47e..e8ac05751 100644
> --- a/compiler/check_typeclass.m
> +++ b/compiler/check_typeclass.m

...

> @@ -304,12 +309,11 @@ is_valid_instance_orig_type(ModuleInfo, ClassId, InstanceDefn, Type,
>          )
>      ;
>          Type = kinded_type(_, _),
> -        unexpected("check_typeclass", "kinded_type")
> +        unexpected($pred, "kinded_type")
>      ).
> 
> -    % Each of these types in the instance declaration must be either
> -    % (a) a type with no arguments, or (b) a polymorphic type whose arguments
> -    % are all distinct type variables.
> +    % Each of these types in the instance declaration must be
> +    % a type constructor applied to zero or more distinct type variables.
>      %
>  :- pred is_valid_instance_type(module_info::in,
>      class_id::in, hlds_instance_defn::in, mer_type::in,

That comment is out-of-date: there is no requirement that the type variables
be distinct any more.

That looks fine otherwise.

Julien.


More information about the reviews mailing list