[m-dev.] for review: change typeclass_info structure

David Glen JEFFERY dgj at cs.mu.OZ.AU
Tue Apr 4 14:49:52 AEST 2000


On 03-Apr-2000, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> On 31-Mar-2000, David Glen JEFFERY <dgj at cs.mu.OZ.AU> wrote:
> > Index: compiler/polymorphism.m
> > @@ -2134,10 +2025,14 @@
> >                                  % already been reversed, so lets
> >                                  % reverse them back.
> >                          list__reverse(TypeInfoGoals, RevTypeInfoGoals),
> > +                        list__reverse(UnconstrainedTypeInfoGoals, 
> > +                                RevUnconstrainedTypeInfoGoals),
> >  
> >                          list__append(ExtraGoals1, RevTypeInfoGoals,
> >                                  ExtraGoals2),
> > -                        list__append(NewGoals, ExtraGoals2, ExtraGoals)
> > +                        list__append(NewGoals, ExtraGoals2, ExtraGoals3),
> > +                        list__append(RevUnconstrainedTypeInfoGoals,
> > +                                ExtraGoals3, ExtraGoals)
> 
> Hmm, the order of the goals there looks a little strange.
> Why do the RevTypeInfoGoals get put at the end, whereas
> the RevUnconstraintTypeInfoGoals get put at the start?

The goals are in the same order as the values that they generate appear in
the type class info.

> >          arity = MR_typeclass_info_instance_arity(typeclass_info);
> > +        num_unconstrained = 
> > +                MR_typeclass_info_num_extra_instance_args(typeclass_info) 
> > +                - arity;
> 
> The name `arity' here is a bit confusing to me.  What does the
> `instance_arity' field of the typeclass_info actually represent?
> 
> I think perhaps `MR_typeclass_info_num_instance_constraints()' might be a
> better name for that macro, and likewise `num_instance_constraints' might be a
> better name for the `arity' variable here.

Done.

> > +                /* First, copy typeinfos for unconstrained tvars from */
> > +                /* the instance declaration */
> 
> That comment is not using the format for a multi-line C comment
> specified in the Mercury C coding guidelines.

Fixed.

> I think it would be a good idea to explain that in a little bit
> more detail:
> 
>                 /*
> 		** Next, copy all the typeclass infos: both the ones for
> 		** constraints on the instance declaration (instance
> 		** constraints), and the ones for constraints on the
> 		** typeclass declaration (superclass constraints).
> 		*/
> 
> > +                /* Then, copy the type infos */
> 
> Likewise here:
> 
>                 /*
> 		** Then, copy all the type infos for types in the
> 		** head of the type class declaration.
> 		*/

I have added both those comments.

Here is the new diff for mercury_deep_copy_body.h:

Index: mercury_deep_copy_body.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_deep_copy_body.h,v
retrieving revision 1.21
diff -u -t -r1.21 mercury_deep_copy_body.h
--- mercury_deep_copy_body.h	2000/03/24 10:27:47	1.21
+++ mercury_deep_copy_body.h	2000/04/04 04:43:48
@@ -680,7 +680,8 @@
         Word    *new_typeclass_info;
         int     num_arg_typeinfos;
         int     num_super;
-        int     arity;
+        int     num_instance_constraints;
+        int     num_unconstrained;
         int     i;
 
         /*
@@ -690,22 +691,47 @@
 
         base_typeclass_info = (Word *) *typeclass_info;
 
-        arity = MR_typeclass_info_instance_arity(typeclass_info);
+        num_instance_constraints = 
+                MR_typeclass_info_num_instance_constraints(typeclass_info);
+        num_unconstrained = 
+                MR_typeclass_info_num_extra_instance_args(typeclass_info) 
+                - num_instance_constraints;
         num_super = MR_typeclass_info_num_superclasses(typeclass_info);
         num_arg_typeinfos = MR_typeclass_info_num_type_infos(typeclass_info);
         incr_saved_hp(LVALUE_CAST(Word, new_typeclass_info),
-            arity + num_super + num_arg_typeinfos + 1);
+            num_instance_constraints + num_super + num_arg_typeinfos + 1);
 
         new_typeclass_info[0] = (Word) base_typeclass_info;
 
-                /* First, copy all the typeclass infos */
-        for (i = 1; i < arity + num_super + 1; i++) {
+                /* 
+                ** First, copy typeinfos for unconstrained tvars from
+                ** the instance declaration 
+                */
+        for (i = 1; i < num_unconstrained + 1; i++) {
+            new_typeclass_info[i] = (Word) copy_type_info(
+                (MR_TypeInfo *)(&typeclass_info[i]), lower_limit, upper_limit);
+        }
+                /*
+                ** Next, copy all the typeclass infos: both the ones for
+                ** constraints on the instance declaration (instance
+                ** constraints), and the ones for constraints on the
+                ** typeclass declaration (superclass constraints).  
+                */
+        for (i = num_unconstrained + 1; 
+                i < num_unconstrained + num_instance_constraints + num_super + 1; 
+                i++) 
+        {
             new_typeclass_info[i] = (Word) copy_typeclass_info(
                 &typeclass_info[i], lower_limit, upper_limit);
         }
-                /* Then, copy all the type infos */
-        for (i = arity + num_super + 1;
-            i < arity + num_super + num_arg_typeinfos + 1;
+
+                /*
+                ** Then, copy all the type infos for types in the
+                ** head of the type class declaration.
+                */
+        for (i = num_unconstrained + num_instance_constraints + num_super + 1;
+            i < num_unconstrained + num_instance_constraints + 
+                        num_super + num_arg_typeinfos + 1;
             i++)
         {
             new_typeclass_info[i] = (Word) copy_type_info(


dgj
-- 
David Jeffery (dgj at cs.mu.oz.au) | If your thesis is utterly vacuous
PhD student,                    | Use first-order predicate calculus.
Dept. of Comp. Sci. & Soft. Eng.|     With sufficient formality
The University of Melbourne     |     The sheerist banality
Australia                       | Will be hailed by the critics: "Miraculous!"
                                |     -- Anon.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list