[m-dev.] for review: cleanup of type_ctor_infos, part 4

Zoltan Somogyi zs at cs.mu.OZ.AU
Fri Feb 25 16:10:45 AEDT 2000


cvs diff: Diffing profiler
cvs diff: Diffing runtime
Index: runtime/mercury_deep_copy_body.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_deep_copy_body.h,v
retrieving revision 1.18
diff -u -b -r1.18 mercury_deep_copy_body.h
--- runtime/mercury_deep_copy_body.h	2000/01/19 09:45:21	1.18
+++ runtime/mercury_deep_copy_body.h	2000/02/24 04:25:07
@@ -16,10 +16,10 @@
 ** Prototypes.
 */
 static  Word    copy_arg(maybeconst Word *data_ptr, 
-                        maybeconst Word *parent_data_ptr, 
-                        const Word *functor_descriptor, const Word *type_info,
-                        const Word *arg_type_info, const Word *lower_limit,
-                        const Word *upper_limit);
+                        maybeconst Word *parent_data_ptr, int rtti_version,
+                        const MR_DuFunctorDesc *functor_descriptor,
+                        const Word *type_info, const Word *arg_type_info,
+                        const Word *lower_limit, const Word *upper_limit);
 static  Word    *copy_type_info(maybeconst Word *type_info,
                         const Word *lower_limit, const Word *upper_limit);
 static Word     copy_typeclass_info(maybeconst Word *typeclass_info_ptr, 
@@ -29,24 +29,15 @@
 copy(maybeconst Word *data_ptr, const Word *type_info, 
          const Word *lower_limit, const Word *upper_limit)
 {
+    Word                data;
+    Word                new_data;
     MR_TypeCtorInfo type_ctor_info;
-    MR_TypeCtorLayout type_ctor_layout;
-    MR_TypeCtorFunctors type_ctor_functors;
-
-    Word functors_indicator;
-    Word layout_entry, *entry_value, *data_value;
-    MR_DiscUnionTagRepresentation tag_rep;
-    int data_tag; 
-    Word new_data, data;
 
     data = *data_ptr;
-
-    data_tag = MR_tag(data);
-    data_value = (Word *) MR_body(data, data_tag);
-
     type_ctor_info = MR_TYPEINFO_GET_TYPE_CTOR_INFO(type_info);
 
     switch (type_ctor_info->type_ctor_rep) {
+
         case MR_TYPECTOR_REP_ENUM:
         case MR_TYPECTOR_REP_ENUM_USEREQ:
             new_data = data;    /* just a copy of the actual item */
@@ -54,10 +45,18 @@
 
         case MR_TYPECTOR_REP_DU:
         case MR_TYPECTOR_REP_DU_USEREQ:
+        if (type_ctor_info->type_ctor_version <= MR_RTTI_VERSION__USEREQ) {
+            Word    layout_entry;
+            Word    *entry_value;
+            Word    *data_value;
+            int     data_tag; 
+
+            data_tag = MR_tag(data);
+            data_value = (Word *) MR_body(data, data_tag);
+
             layout_entry = type_ctor_info->type_ctor_layout[data_tag];
             entry_value = (Word *) MR_strip_tag(layout_entry);
-            tag_rep = MR_get_tag_representation(layout_entry);
-            switch (tag_rep) {
+            switch (MR_get_tag_representation(layout_entry)) {
 
             case MR_DISCUNIONTAG_SHARED_LOCAL:
                 new_data = data;        /* just a copy of the actual item */
@@ -100,7 +99,7 @@
 
                     /* copy typeinfo arguments */
                     for (i = 0; i < num_extra_typeinfos; i++) {
-                        MR_field(0, new_data, i + 1) = (Word)copy_type_info(
+                        MR_field(0, new_data, i + 1) = (Word) copy_type_info(
                                 &argument_vector[i],
                                 lower_limit, upper_limit);
                     }
@@ -117,6 +116,8 @@
                         MR_field(0, new_data, i + num_extra_args + 1) 
                             = copy_arg(data_value,
                                     &argument_vector[i + num_extra_args], 
+                                    type_ctor_info->type_ctor_version,
+                                    (const MR_DuFunctorDesc *)
                                     functor_descriptor, type_info,
                                     (Word *) type_info_vector[i], lower_limit,
                                     upper_limit);
@@ -129,6 +130,7 @@
                     new_data = data;
                     found_forwarding_pointer(data);
                 }
+
             break;
             }
 
@@ -178,8 +180,10 @@
                         MR_field(0, new_data, i + num_extra_args) 
                             = copy_arg(data_value,
                                     &argument_vector[i + num_extra_args],
-                                    entry_value,
-                                    type_info, (Word *) type_info_vector[i],
+                                    type_ctor_info->type_ctor_version,
+                                    (const MR_DuFunctorDesc *)
+                                    functor_descriptor, type_info,
+                                    (Word *) type_info_vector[i],
                                     lower_limit, upper_limit);
                     }
                     /* tag this pointer */
@@ -189,33 +193,291 @@
                     new_data = data;
                     found_forwarding_pointer(data);
                 }
+
+                break;
+                }
+            }
+        } else {
+            /* XXX CHECKME */
+            MR_DuPtagLayout     *ptag_layout;
+            int                 ptag; 
+            Word                *data_value;
+
+            ptag = MR_tag(data);
+            ptag_layout = type_ctor_info->type_layout.layout_du[ptag];
+
+            switch (ptag_layout->MR_sectag_locn) {
+            case MR_SECTAG_LOCAL:
+                new_data = data;    /* just a copy of the actual item */
                 break;
+
+                /*
+                ** The code we want to execute for the MR_SECTAG_REMOTE
+                ** and MR_SECTAG_NONE cases is the following. However,
+                ** this code checks the secondary tag location several times
+                ** and also checks whether exist_info is NULL several times.
+                ** Since speed is important, we duplicate the code downstream
+                ** of the first test of each kind. To avoid double maintenance
+                ** problems, the stuff that is duplicated is macro invocations;
+                ** each macro is of course defined only once. Note that the
+                ** initial and final macros have unbalanced parentheses.
+                */
+
+/*
+**          case MR_SECTAG_REMOTE:
+**          case MR_SECTAG_NONE:
+**
+**              data_value = (Word *) MR_body(data, ptag);
+**              if (in_range(data_value)) {
+**                  const MR_DuFunctorDesc  *functor_desc;
+**                  const MR_DuExistInfo    *exist_info;
+**                  int                     sectag;
+**                  int                     cell_size;
+**                  int                     cur_slot;
+**                  int                     arity;
+**                  int                     num_ti_plain;
+**                  int                     num_tci;
+**                  int                     i;
+**
+**                  if (ptag_layout->MR_sectag_locn == MR_SECTAG_NONE) {
+**                      sectag = 0;
+**                  } else {
+**                      sectag = data_value[0];
+**                  }
+**
+**                  functor_desc = ptag_layout->MR_sectag_alternatives[sectag];
+**                  arity = functor_desc->MR_du_functor_orig_arity;
+**                  exist_info = functor_desc->MR_du_functor_exist_info;
+**
+**                  if (ptag_layout->MR_sectag_locn == MR_SECTAG_NONE) {
+**                      cell_size = arity;
+**                  } else {
+**                      cell_size = 1 + arity;
+**                  }
+**
+**                  if (exist_info == NULL) {
+**                      num_ti_plain = 0;
+**                      num_tci = 0;
+**                  } else {
+**                      num_ti_plain = exist_info->MR_exist_typeinfos_plain;
+**                      num_tci = exist_info->MR_exist_tcis;
+**                      cell_size += num_ti_plain + num_tci;
+**                  }
+**
+**                  incr_saved_hp(new_data, cell_size);
+**
+**                  if (ptag_layout->MR_sectag_locn == MR_SECTAG_NONE) {
+**                      cur_slot = 0;
+**                  } else {
+**                      MR_field(0, new_data, 0) = sectag;
+**                      cur_slot = 1;
+**                  }
+**
+**                  for (i = 0; i < num_ti_plain; i++) {
+**                      MR_field(0, new_data, cur_slot) = (Word)
+**                          copy_type_info(&data_value[cur_slot],
+**                              lower_limit, upper_limit);
+**                      cur_slot++;
+**                  }
+**
+**                  for (i = 0; i < num_tci; i++) {
+**                      MR_field(0, new_data, cur_slot) = (Word)
+**                          copy_typeclass_info(&data_value[cur_slot],
+**                              lower_limit, upper_limit);
+**                      cur_slot++;
+**                  }
+**
+**                  for (i = 0; i < arity; i++) {
+**                      MR_field(0, new_data, cur_slot) =
+**                          copy_arg(data_value, &data_value[cur_slot],
+**                              type_ctor_info->type_ctor_version,
+**                              functor_desc, type_info, (const Word *)
+**                              functor_desc->MR_du_functor_arg_types[i],
+**                              lower_limit, upper_limit);
+**                      cur_slot++;
+**                  }
+**
+**                  new_data = (Word) MR_mkword(ptag, new_data);
+**                  leave_forwarding_pointer(data_ptr, new_data);
+**              } else {
+**                  new_data = data;
+**                  found_forwarding_pointer(data);
+**              }
+**              break;
+*/
+
+#define MR_DC_initial                                                   \
+                data_value = (Word *) MR_body(data, ptag);              \
+                if (in_range(data_value)) {                             \
+                    const MR_DuFunctorDesc  *functor_desc;              \
+                    const MR_DuExistInfo    *exist_info;                \
+                    int                     sectag;                     \
+                    int                     cell_size;                  \
+                    int                     cur_slot;                   \
+                    int                     arity;                      \
+                    int                     num_ti_plain;               \
+                    int                     num_tci;                    \
+                    int                     i;
+
+#define MR_DC_functor_desc                                              \
+                    functor_desc = ptag_layout->MR_sectag_alternatives  \
+                        [sectag];                                       \
+                    arity = functor_desc->MR_du_functor_orig_arity;     \
+                    exist_info = functor_desc->MR_du_functor_exist_info;
+
+#define MR_DC_setup_exist_info                                          \
+                        num_ti_plain = exist_info->MR_exist_typeinfos_plain;\
+                        num_tci = exist_info->MR_exist_tcis;            \
+                        cell_size += num_ti_plain + num_tci;
+
+#define MR_DC_copy_exist_info                                           \
+                    for (i = 0; i < num_ti_plain; i++) {                \
+                        MR_field(0, new_data, cur_slot) = (Word)        \
+                            copy_type_info(&data_value[cur_slot],       \
+                                lower_limit, upper_limit);              \
+                        cur_slot++;                                     \
+                    }                                                   \
+                                                                        \
+                    for (i = 0; i < num_tci; i++) {                     \
+                        MR_field(0, new_data, cur_slot) = (Word)        \
+                            copy_typeclass_info(&data_value[cur_slot],  \
+                                lower_limit, upper_limit);              \
+                        cur_slot++;                                     \
+                    }
+
+#define MR_DC_copy_plain_args                                           \
+                    for (i = 0; i < arity; i++) {                       \
+                        MR_field(0, new_data, cur_slot) =               \
+                            copy_arg(data_value, &data_value[cur_slot], \
+                                type_ctor_info->type_ctor_version,      \
+                                functor_desc, type_info, (const Word *) \
+                                functor_desc->MR_du_functor_arg_types[i],\
+                                lower_limit, upper_limit);              \
+                        cur_slot++;                                     \
+                    }
+
+#define MR_DC_final                                                     \
+                    new_data = (Word) MR_mkword(ptag, new_data);        \
+                    leave_forwarding_pointer(data_ptr, new_data);       \
+                } else {                                                \
+                    new_data = data;                                    \
+                    found_forwarding_pointer(data);                     \
+                }                                                       \
+                break;
+
+            case MR_SECTAG_REMOTE:
+                MR_DC_initial
+                sectag = data_value[0];
+                MR_DC_functor_desc
+                cell_size = 1 + arity;
+                if (exist_info != NULL) {
+                    MR_DC_setup_exist_info
+                    incr_saved_hp(new_data, cell_size);
+                    MR_field(0, new_data, 0) = sectag;
+                    cur_slot = 1;
+                    MR_DC_copy_exist_info
+                    MR_DC_copy_exist_info
+                } else {
+                    incr_saved_hp(new_data, cell_size);
+                    MR_field(0, new_data, 0) = sectag;
+                    cur_slot = 1;
+                }
+                MR_DC_copy_plain_args
+                MR_DC_final
+
+            case MR_SECTAG_NONE:
+                MR_DC_initial
+                sectag = 0;
+                MR_DC_functor_desc
+                cell_size = arity;
+                if (exist_info != NULL) {
+                    MR_DC_setup_exist_info
+                    incr_saved_hp(new_data, cell_size);
+                    cur_slot = 0;
+                    MR_DC_copy_exist_info
+                } else {
+                    incr_saved_hp(new_data, cell_size);
+                    cur_slot = 0;
+                }
+                MR_DC_copy_plain_args
+                MR_DC_final
             }
         }
         break;
+
         case MR_TYPECTOR_REP_NOTAG:
         case MR_TYPECTOR_REP_NOTAG_USEREQ:
+        if (type_ctor_info->type_ctor_version <= MR_RTTI_VERSION__USEREQ) {
+            Word    layout_entry;
+            Word    *entry_value;
+            Word    *data_value;
+            int     data_tag; 
+
+            data_tag = MR_tag(data);
+            data_value = (Word *) MR_body(data, data_tag);
+
             layout_entry = type_ctor_info->type_ctor_layout[data_tag];
             entry_value = (Word *) MR_strip_tag(layout_entry);
-            new_data = copy_arg(NULL, data_ptr, NULL, type_info, 
+            new_data = copy_arg(NULL, data_ptr,
+                    type_ctor_info->type_ctor_version, NULL, type_info,
                     (Word *) *MR_TYPE_CTOR_LAYOUT_NO_TAG_VECTOR_ARGS(
                      entry_value), lower_limit, upper_limit);
+        } else {
+            /* XXX CHECKME */
+            new_data = copy_arg(NULL, data_ptr,
+                type_ctor_info->type_ctor_version, NULL, type_info,
+                (const Word *) type_ctor_info->type_layout.layout_notag->
+                MR_notag_functor_arg_type, lower_limit, upper_limit);
+        }
             break;
 
         case MR_TYPECTOR_REP_EQUIV: 
+        if (type_ctor_info->type_ctor_version <= MR_RTTI_VERSION__USEREQ) {
+            Word    layout_entry;
+            Word    *entry_value;
+            Word    *data_value;
+            int     data_tag; 
+
+            data_tag = MR_tag(data);
+            data_value = (Word *) MR_body(data, data_tag);
+
             layout_entry = type_ctor_info->type_ctor_layout[data_tag];
             entry_value = (Word *) MR_strip_tag(layout_entry);
-            new_data = copy_arg(NULL, data_ptr, NULL, type_info,
+            new_data = copy_arg(NULL, data_ptr,
+                    type_ctor_info->type_ctor_version, NULL, type_info,
                 (const Word *) MR_TYPE_CTOR_LAYOUT_EQUIV_TYPE((Word *)
                         entry_value), lower_limit, upper_limit);
+        } else {
+            /* XXX CHECKME */
+            new_data = copy_arg(NULL, data_ptr,
+                    type_ctor_info->type_ctor_version, NULL, type_info,
+                    (const Word *) type_ctor_info->type_layout.layout_equiv,
+                    lower_limit, upper_limit);
+        }
             break;
 
         case MR_TYPECTOR_REP_EQUIV_VAR:
+        if (type_ctor_info->type_ctor_version <= MR_RTTI_VERSION__USEREQ) {
+            Word    layout_entry;
+            Word    *entry_value;
+            Word    *data_value;
+            int     data_tag; 
+
+            data_tag = MR_tag(data);
+            data_value = (Word *) MR_body(data, data_tag);
+
             layout_entry = type_ctor_info->type_ctor_layout[data_tag];
             entry_value = (Word *) MR_strip_tag(layout_entry);
             new_data = copy(data_ptr,
                     (Word *) type_info[(Word) entry_value],
                     lower_limit, upper_limit);
+        } else {
+            /*
+            ** The current version of the RTTI gives all equivalence types
+            ** the EQUIV type_ctor_rep, not EQUIV_VAR.
+            */
+            fatal_error("unexpected EQUIV_VAR type_ctor_rep");
+        }
             break;
 
         case MR_TYPECTOR_REP_INT:  /* fallthru */
@@ -225,6 +487,14 @@
 
         case MR_TYPECTOR_REP_FLOAT:
             #ifdef BOXED_FLOAT
+            {
+                Word    *data_value;
+                int     data_tag;
+
+                /* XXX simplify: tag should be zero */
+                data_tag = MR_tag(data);
+                data_value = (Word *) MR_body(data, data_tag);
+
                 if (in_range(data_value)) {
                     restore_transient_hp();
                     new_data = word_to_float(float_to_word(data));
@@ -234,12 +504,21 @@
                     new_data = data;
                     found_forwarding_pointer(data);
                 }
+            }
             #else
                 new_data = data;
             #endif
             break;
 
         case MR_TYPECTOR_REP_STRING:
+        {
+            Word    *data_value;
+            int     data_tag; 
+
+            /* XXX simplify: tag should be zero */
+            data_tag = MR_tag(data);
+            data_value = (Word *) MR_body(data, data_tag);
+
             if (in_range(data_value)) {
                 incr_saved_hp_atomic(new_data, 
                     (strlen((String) data) + sizeof(Word)) / sizeof(Word));
@@ -249,9 +528,18 @@
                 new_data = data;
                 found_forwarding_pointer(data);
             }
+        }
             break;
 
         case MR_TYPECTOR_REP_PRED:
+        {
+            Word    *data_value;
+            int     data_tag; 
+
+            /* XXX simplify: tag should be zero */
+            data_tag = MR_tag(data);
+            data_value = (Word *) MR_body(data, data_tag);
+
             /*
             ** predicate closures store the number of curried arguments
             ** as their first argument, the Code * as their second, and
@@ -285,7 +573,7 @@
                     new_closure->MR_closure_hidden_args_0[i] =
                         copy_arg(NULL,
                             &old_closure->MR_closure_hidden_args_0[i],
-                            NULL,
+                            type_ctor_info->type_ctor_version, NULL,
                             type_info + TYPEINFO_OFFSET_FOR_PRED_ARGS - 1,
                             arg_pseudo_type_info,
                             lower_limit, upper_limit
@@ -298,9 +586,18 @@
                 new_data = data;
                 found_forwarding_pointer(data);
             }
+        }
             break;
 
         case MR_TYPECTOR_REP_UNIV: 
+        {
+            Word    *data_value;
+            int     data_tag; 
+
+            /* XXX simplify: tag should be zero */
+            data_tag = MR_tag(data);
+            data_value = (Word *) MR_body(data, data_tag);
+
             /* if the univ is stored in range, copy it */ 
             if (in_range(data_value)) {
                 Word *new_data_ptr;
@@ -328,15 +625,23 @@
                 new_data = data;
                 found_forwarding_pointer(data);
             }
+        }
             break;
 
         case MR_TYPECTOR_REP_VOID:
             fatal_error("Cannot copy a void type");
             break;
 
-        case MR_TYPECTOR_REP_ARRAY: {
+    case MR_TYPECTOR_REP_ARRAY:
+        {
+            Word    *data_value;
+            int     data_tag; 
             int i;
 
+            /* XXX simplify: tag should be zero */
+            data_tag = MR_tag(data);
+            data_value = (Word *) MR_body(data, data_tag);
+
             if (in_range(data_value)) {
                 MR_ArrayType *new_array;
                 MR_ArrayType *old_array;
@@ -348,7 +653,8 @@
                 new_array->size = array_size;
                 for (i = 0; i < array_size; i++) {
                     new_array->elements[i] = copy_arg(NULL,
-                        &old_array->elements[i], NULL, type_info, 
+                        &old_array->elements[i],
+                        type_ctor_info->type_ctor_version, NULL, type_info, 
                         (const Word *) 1, lower_limit, upper_limit);
                 }
                 new_data = (Word) new_array;
@@ -357,8 +663,8 @@
                 new_data = data;
                 found_forwarding_pointer(data);
             }
-            break;
         }
+        break;
 
         case MR_TYPECTOR_REP_TYPEINFO:
             new_data = (Word) copy_type_info(data_ptr,
@@ -366,6 +672,14 @@
             break;
 
         case MR_TYPECTOR_REP_C_POINTER:
+        {
+            Word    *data_value;
+            int     data_tag; 
+
+            /* XXX simplify: tag should be zero */
+            data_tag = MR_tag(data);
+            data_value = (Word *) MR_body(data, data_tag);
+
             if (in_range(data_value)) {
                 /*
                 ** This error occurs if we try to copy() a
@@ -376,6 +690,7 @@
             } else {
                 new_data = data;
             }
+        }
             break;
 
         case MR_TYPECTOR_REP_SUCCIP: /* fallthru */
@@ -414,21 +729,21 @@
 }
 
 /*
-** copy_arg is like copy() except that it takes a
-** pseudo_type_info (namely arg_pseudo_type_info) rather than
-** a type_info.  The pseudo_type_info may contain type variables,
+** copy_arg is like copy() except that it takes a pseudo_type_info
+** (namely arg_pseudo_type_info) rather than a type_info.
+** The pseudo_type_info may contain type variables,
 ** which refer to arguments of the term_type_info.
 **
 ** It also takes a pointer to the data of the parent of this piece of data
 ** and a functor descriptor for the parent in case the data being copied is
 ** existentially quantified.
 */
+
 static Word
 copy_arg(maybeconst Word *parent_data_ptr, maybeconst Word *data_ptr, 
-                const Word *functor_descriptor,
-                const Word *term_type_info,
-                const Word *arg_pseudo_type_info, const Word *lower_limit,
-                const Word *upper_limit)
+        int rtti_version, const MR_DuFunctorDesc *functor_descriptor,
+        const Word *term_type_info, const Word *arg_pseudo_type_info,
+        const Word *lower_limit, const Word *upper_limit)
 {
         MR_MemoryList allocated_memory_cells;
         Word *new_type_info;
@@ -436,7 +751,7 @@
 
         allocated_memory_cells = NULL;
         new_type_info = MR_make_type_info_maybe_existq(term_type_info, 
-                        arg_pseudo_type_info, parent_data_ptr,
+                        arg_pseudo_type_info, parent_data_ptr, rtti_version,
                         functor_descriptor, &allocated_memory_cells);
 
         new_data = copy(data_ptr, new_type_info, lower_limit, upper_limit);
@@ -506,7 +821,7 @@
         if (in_range(typeclass_info)) {
                 Word *base_typeclass_info;
                 Word *new_typeclass_info;
-                Integer arity, num_super, num_arg_typeinfos, offset, i;
+                Integer arity, num_super, num_arg_typeinfos, i;
 
                 /*
                 ** Note that we assume base_typeclass_infos will always be
@@ -526,14 +841,16 @@
 
                         /* First, copy all the typeclass infos */
                 for (i = 1; i < arity + num_super + 1; i++) {
-                        new_typeclass_info[i] = (Word) copy_typeclass_info(&typeclass_info[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; 
                                 i++) {
-                        new_typeclass_info[i] = (Word) copy_type_info(&typeclass_info[i],
+                        new_typeclass_info[i] = (Word)
+                                copy_type_info(&typeclass_info[i],
                                 lower_limit, upper_limit);
                 }
                 leave_forwarding_pointer(typeclass_info_ptr, 
@@ -544,4 +861,3 @@
                 return (Word) typeclass_info;
         }
 }
-
Index: runtime/mercury_std.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_std.h,v
retrieving revision 1.9
diff -u -b -r1.9 mercury_std.h
--- runtime/mercury_std.h	2000/01/19 09:45:22	1.9
+++ runtime/mercury_std.h	2000/02/21 09:32:01
@@ -85,7 +85,7 @@
 ** At the moment, we use variable length arrays that are indexed by
 ** closure argument numbers or by type parameter numbers. We therefore
 ** use a default MR_VARIABLE_SIZED value that is at least as big as
-** both MAX_VIRTUAL_REG and TYPE_CTOR_LAYOUT_MAX_VARINT.
+** both MAX_VIRTUAL_REG and MR_PSEUDOTYPEINFO_MAX_VAR.
 */
 
 #if __STDC_VERSION__ >= 199901	/* January 1999 */
Index: runtime/mercury_tabling.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_tabling.c,v
retrieving revision 1.21
diff -u -b -r1.21 mercury_tabling.c
--- runtime/mercury_tabling.c	2000/02/16 09:17:34	1.21
+++ runtime/mercury_tabling.c	2000/02/24 02:41:59
@@ -585,6 +585,13 @@
 	return node;
 }
 
+MR_TrieNode
+MR_type_class_info_lookup_or_add(MR_TrieNode table, Word *type_class_info)
+{
+	fatal_error("tabling of typeclass_infos not yet implemented");
+	return NULL;
+}
+
 /*---------------------------------------------------------------------------*/
 
 /*
@@ -598,29 +605,15 @@
 ** Due to the depth of the control here, we'll use 4 space indentation.
 **
 ** NOTE: changes to this function will probably also have to be reflected
-** in mercury_deep_copy.c and std_util::ML_expand().
+** in the places listed in mercury_type_info.h.
 */
 
 MR_TrieNode
 MR_table_type(MR_TrieNode table, Word *type_info, Word data)
 {
     MR_TypeCtorInfo	type_ctor_info;
-    MR_TypeCtorLayout	type_ctor_layout;
-    MR_TypeCtorFunctors	type_ctor_functors;
-    MR_DiscUnionTagRepresentation tag_rep;
-    MR_MemoryList	allocated_memory_cells = NULL;
 
-    Word		layout_for_tag;
-    Word		*layout_vector_for_tag;
-    Word		*data_value;
-    int			data_tag;
-
-    data_tag = MR_tag(data);
-    data_value = (Word *) MR_body(data, data_tag);
-
     type_ctor_info = MR_TYPEINFO_GET_TYPE_CTOR_INFO(type_info);
-    type_ctor_layout = type_ctor_info->type_ctor_layout;
-    type_ctor_functors = type_ctor_info->type_ctor_functors;
 
 #ifdef  MR_TABLE_DEBUG
     if (MR_tabledebug) {
@@ -632,22 +625,43 @@
     switch (type_ctor_info->type_ctor_rep) {
         case MR_TYPECTOR_REP_ENUM: 
         case MR_TYPECTOR_REP_ENUM_USEREQ: 
-	{
+            if (type_ctor_info->type_ctor_version <= MR_RTTI_VERSION__USEREQ) {
+                MR_TypeCtorLayout   type_ctor_layout;
+                Word                layout_for_tag;
+                Word                *layout_vector_for_tag;
+                int                 data_tag;
             int functors;
 
+                data_tag = MR_tag(data);
+                type_ctor_layout = type_ctor_info->type_ctor_layout;
+
             layout_for_tag = type_ctor_layout[data_tag];
             layout_vector_for_tag = (Word *) MR_strip_tag(layout_for_tag);
             functors = MR_TYPE_CTOR_LAYOUT_ENUM_VECTOR_NUM_FUNCTORS(
                                 layout_vector_for_tag);
             MR_DEBUG_TABLE_ENUM(table, functors, data);
-            break;
+            } else {
+                MR_DEBUG_TABLE_ENUM(table,
+                        type_ctor_info->type_ctor_num_functors, data);
         }
+            break;
+
         case MR_TYPECTOR_REP_DU: 
         case MR_TYPECTOR_REP_DU_USEREQ: 
-	{
+            if (type_ctor_info->type_ctor_version <= MR_RTTI_VERSION__USEREQ) {
+                MR_DiscUnionTagRepresentation tag_rep;
+                MR_TypeCtorLayout   type_ctor_layout;
+                MR_MemoryList       allocated_memory_cells = NULL;
+                Word                layout_for_tag;
+                Word                *layout_vector_for_tag;
+                Word                *data_value;
+                int                 data_tag;
+
+                data_tag = MR_tag(data);
             layout_for_tag = type_ctor_layout[data_tag];
             layout_vector_for_tag = (Word *) MR_strip_tag(layout_for_tag);
             tag_rep = MR_get_tag_representation((Word) layout_for_tag);
+
             switch(tag_rep) {
             case MR_DISCUNIONTAG_SHARED_LOCAL: {
                 int functors = MR_TYPE_CTOR_LAYOUT_ENUM_VECTOR_NUM_FUNCTORS(
@@ -657,10 +671,13 @@
                 break;
             }
             case MR_DISCUNIONTAG_UNSHARED: {
-                int arity, i;
-                Word *argument_vector, *type_info_vector, *new_type_info;
+                    Word    *argument_vector;
+                    Word    *type_info_vector;
+                    Word    *new_type_info;
+                    int     arity;
+                    int     i;
     
-                argument_vector = data_value;
+                    argument_vector = (Word *) MR_body(data, data_tag);
     
                 arity = layout_vector_for_tag[
                             TYPE_CTOR_LAYOUT_UNSHARED_ARITY_OFFSET];
@@ -672,7 +689,8 @@
                      /* copy arguments */
                 for (i = 0; i < arity; i++) {
                     new_type_info = MR_make_type_info(type_info,
-                        (Word *) type_info_vector[i], &allocated_memory_cells);
+                            (Word *) type_info_vector[i],
+                            &allocated_memory_cells);
 
                     MR_DEBUG_TABLE_ANY(table, new_type_info,
                         argument_vector[i]);
@@ -688,38 +706,118 @@
                 Word    num_sharers;
                 Word    *new_layout_vector;
 
+                    data_value = (Word *) MR_body(data, data_tag);
                 secondary_tag = *data_value;
                 argument_vector = data_value + 1;
 
-                num_sharers = MR_TYPE_CTOR_LAYOUT_SHARED_REMOTE_VECTOR_NUM_SHARERS(
+                    num_sharers =
+                        MR_TYPE_CTOR_LAYOUT_SHARED_REMOTE_VECTOR_NUM_SHARERS(
                                 layout_vector_for_tag);
                 new_layout_vector =
                     MR_TYPE_CTOR_LAYOUT_SHARED_REMOTE_VECTOR_GET_FUNCTOR_DESCRIPTOR(
                     layout_vector_for_tag, secondary_tag);
-                arity = new_layout_vector[TYPE_CTOR_LAYOUT_UNSHARED_ARITY_OFFSET];
-                type_info_vector =
-                    &new_layout_vector[TYPE_CTOR_LAYOUT_UNSHARED_ARGS_OFFSET];
+                    arity = new_layout_vector[
+                        TYPE_CTOR_LAYOUT_UNSHARED_ARITY_OFFSET];
+                    type_info_vector = &new_layout_vector[
+                        TYPE_CTOR_LAYOUT_UNSHARED_ARGS_OFFSET];
 
                 MR_DEBUG_TABLE_TAG(table, data_tag);
                 MR_DEBUG_TABLE_ENUM(table, num_sharers, secondary_tag);
 
                 for (i = 0; i < arity; i++) {
                     new_type_info = MR_make_type_info(type_info,
-                        (Word *) type_info_vector[i], &allocated_memory_cells);
+                            (Word *) type_info_vector[i],
+                            &allocated_memory_cells);
 
                     MR_DEBUG_TABLE_ANY(table, new_type_info,
                         argument_vector[i]);
                 }
                 break;
             }
+
+                MR_deallocate(allocated_memory_cells);
             }
+            } else {
+                /* XXX CHECKME */
+                MR_MemoryList           allocated_memory_cells = NULL;
+                const MR_DuPtagLayout   *ptag_layout;
+                const MR_DuFunctorDesc  *functor_desc;
+                const MR_DuExistInfo    *exist_info;
+                Word                    *arg_type_info;
+                int                     ptag;
+                int                     sectag;
+                Word                    *arg_vector;
+                int                     meta_args;
+                int                     i;
+
+                ptag = MR_tag(data);
+                ptag_layout = type_ctor_info->type_layout.layout_du[ptag];
+
+                switch (ptag_layout->MR_sectag_locn) {
+                case MR_SECTAG_NONE:
+                    functor_desc = ptag_layout->MR_sectag_alternatives[0];
+                    arg_vector = (Word *) MR_body(data, ptag);
+                    break;
+                case MR_SECTAG_LOCAL:
+                    sectag = MR_unmkbody(data);
+                    functor_desc = ptag_layout->MR_sectag_alternatives[sectag];
+                    assert(functor_desc->MR_du_functor_orig_arity == 0);
+                    assert(functor_desc->MR_du_functor_exist_info == NULL);
+                    arg_vector = NULL;
+                    break;
+                case MR_SECTAG_REMOTE:
+                    sectag = MR_field(ptag, data, 0);
+                    functor_desc = ptag_layout->MR_sectag_alternatives[sectag];
+                    arg_vector = (Word *) MR_body(data, ptag) + 1;
             break;
         }
+
+                MR_DEBUG_TABLE_ENUM(table,
+                        type_ctor_info->type_ctor_num_functors,
+                        functor_desc->MR_du_functor_ordinal);
+
+                exist_info = functor_desc->MR_du_functor_exist_info;
+                if (exist_info != NULL) {
+                    for (i = 0; i < exist_info->MR_exist_typeinfos_plain; i++)
+                    {
+                        MR_DEBUG_TABLE_TYPEINFO(table, (Word *) arg_vector[i]);
+                    }
+                    meta_args = exist_info->MR_exist_typeinfos_plain;
+                    for (i = 0; i < exist_info->MR_exist_tcis; i++) {
+                        MR_DEBUG_TABLE_TYPECLASSINFO(table,
+                            (Word *) arg_vector[meta_args + i]);
+                    }
+                    meta_args += exist_info->MR_exist_tcis;
+                } else {
+                    meta_args = 0;
+                }
+
+                for (i = 0; i < functor_desc->MR_du_functor_orig_arity; i++) {
+                    arg_type_info = MR_make_type_info_maybe_existq(type_info,
+                        (Word *) functor_desc->MR_du_functor_arg_types[i],
+                        (Word *) MR_body(data, ptag),
+                        type_ctor_info->type_ctor_version,
+                        functor_desc, &allocated_memory_cells);
+
+                    MR_DEBUG_TABLE_ANY(table, arg_type_info,
+                        arg_vector[meta_args + i]);
+                }
+
+                MR_deallocate(allocated_memory_cells);
+            }
+            break;
+
         case MR_TYPECTOR_REP_NOTAG: 
         case MR_TYPECTOR_REP_NOTAG_USEREQ:
-	{
+            if (type_ctor_info->type_ctor_version <= MR_RTTI_VERSION__USEREQ) {
+                MR_TypeCtorLayout   type_ctor_layout;
+                MR_MemoryList       allocated_memory_cells = NULL;
+                Word                layout_for_tag;
+                Word                *layout_vector_for_tag;
+                int                 data_tag;
             Word *new_type_info;
 
+                data_tag = MR_tag(data);
             layout_for_tag = type_ctor_layout[data_tag];
             layout_vector_for_tag = (Word *) MR_strip_tag(layout_for_tag);
             new_type_info = MR_make_type_info(type_info,
@@ -727,24 +825,69 @@
                     layout_vector_for_tag),
                 &allocated_memory_cells);
             MR_DEBUG_TABLE_ANY(table, new_type_info, data);
-            break;
+                MR_deallocate(allocated_memory_cells);
+            } else {
+                /* XXX CHECKME */
+                MR_MemoryList       allocated_memory_cells = NULL;
+                Word                *eqv_type_info;
+
+                eqv_type_info = MR_make_type_info(type_info,
+                    (Word *) type_ctor_info->type_layout.layout_notag->
+                        MR_notag_functor_arg_type, &allocated_memory_cells);
+                MR_DEBUG_TABLE_ANY(table, eqv_type_info, data);
+                MR_deallocate(allocated_memory_cells);
         }
-        case MR_TYPECTOR_REP_EQUIV: {
+            break;
+
+        case MR_TYPECTOR_REP_EQUIV:
+            if (type_ctor_info->type_ctor_version <= MR_RTTI_VERSION__USEREQ) {
+                MR_TypeCtorLayout   type_ctor_layout;
+                MR_MemoryList       allocated_memory_cells = NULL;
+                Word                layout_for_tag;
+                Word                *layout_vector_for_tag;
+                int                 data_tag;
             Word *new_type_info;
 
+                data_tag = MR_tag(data);
             layout_for_tag = type_ctor_layout[data_tag];
             layout_vector_for_tag = (Word *) MR_strip_tag(layout_for_tag);
-            new_type_info = MR_make_type_info(type_info,
-                (Word *) MR_TYPE_CTOR_LAYOUT_EQUIV_TYPE(layout_vector_for_tag),
+                new_type_info = MR_make_type_info(type_info, (Word *)
+                    MR_TYPE_CTOR_LAYOUT_EQUIV_TYPE(layout_vector_for_tag),
                 &allocated_memory_cells);
             MR_DEBUG_TABLE_ANY(table, new_type_info, data);
-            break;
+                MR_deallocate(allocated_memory_cells);
+            } else {
+                /* XXX CHECKME */
+                MR_MemoryList       allocated_memory_cells = NULL;
+                Word                *eqv_type_info;
+
+                eqv_type_info = MR_make_type_info(type_info,
+                    (Word *) type_ctor_info->type_layout.layout_equiv,
+                    &allocated_memory_cells);
+                MR_DEBUG_TABLE_ANY(table, eqv_type_info, data);
+                MR_deallocate(allocated_memory_cells);
         }
+            break;
+
         case MR_TYPECTOR_REP_EQUIV_VAR:
+            if (type_ctor_info->type_ctor_version <= MR_RTTI_VERSION__USEREQ) {
+                MR_TypeCtorLayout   type_ctor_layout;
+                Word                layout_for_tag;
+                Word                *layout_vector_for_tag;
+                int                 data_tag;
+
+                data_tag = MR_tag(data);
             layout_for_tag = type_ctor_layout[data_tag];
             layout_vector_for_tag = (Word *) MR_strip_tag(layout_for_tag);
             MR_DEBUG_TABLE_ANY(table,
                 (Word *) type_info[(Word) layout_vector_for_tag], data);
+            } else {
+                /*
+                ** The current version of the RTTI gives all equivalence types
+                ** the EQUIV type_ctor_rep, not EQUIV_VAR.
+                */
+                fatal_error("unexpected EQUIV_VAR type_ctor_rep");
+            }
             break;
 
         case MR_TYPECTOR_REP_INT:
@@ -780,21 +923,34 @@
                     <type_info for hidden closure argument number i>,
                     closure->MR_closure_hidden_args(i));
             }
-            break;
-	#endif
+    #else
 	    /*
 	    ** Instead, we use the following rather simplistic means of
 	    ** tabling closures: we just table based on the closure address.
 	    */
+            Word    *data_value;
+            int     data_tag;
+
+            data_tag = MR_tag(data);
+            data_value = (Word *) MR_body(data, data_tag);
             MR_DEBUG_TABLE_INT(table, (Word) data_value);
+    #endif
+            break;
         }
-        case MR_TYPECTOR_REP_UNIV:
+        case MR_TYPECTOR_REP_UNIV: {
+            Word    *data_value;
+            int     data_tag;
+
+            data_tag = MR_tag(data);
+            data_value = (Word *) MR_body(data, data_tag);
+
             MR_DEBUG_TABLE_TYPEINFO(table,
                 (Word *) data_value[UNIV_OFFSET_FOR_TYPEINFO]);
             MR_DEBUG_TABLE_ANY(table,
                 (Word *) data_value[UNIV_OFFSET_FOR_TYPEINFO],
                 data_value[UNIV_OFFSET_FOR_DATA]);
             break;
+        }
 
         case MR_TYPECTOR_REP_VOID:
             fatal_error("Cannot table a void type");
@@ -804,15 +960,23 @@
             fatal_error("Attempt to table a C_POINTER");
             break;
 
-        case MR_TYPECTOR_REP_TYPEINFO:
+        case MR_TYPECTOR_REP_TYPEINFO: {
+            Word    *data_value;
+            int     data_tag;
+
+            data_tag = MR_tag(data);
+            data_value = (Word *) MR_body(data, data_tag);
             MR_DEBUG_TABLE_TYPEINFO(table, (Word *) data_value);
             break;
+        }
 
         case MR_TYPECTOR_REP_TYPECLASSINFO:
             fatal_error("Attempt to table a type_class_info");
             break;
 
         case MR_TYPECTOR_REP_ARRAY: {
+            MR_MemoryList   allocated_memory_cells = NULL;
+            Word            *data_value;
             int i;
             MR_ArrayType *array;
             Word *new_type_info;
@@ -827,6 +991,8 @@
             for (i = 0; i < array_size; i++) {
                 MR_DEBUG_TABLE_ANY(table, new_type_info, array->elements[i]);
             }
+
+            MR_deallocate(allocated_memory_cells);
             break;
         }
 
@@ -867,8 +1033,6 @@
             fatal_error("Unknown layout tag in table_any");
             break;
     }
-
-    MR_deallocate(allocated_memory_cells);
 
     return table;
 } /* end table_any() */
Index: runtime/mercury_tabling.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_tabling.h,v
retrieving revision 1.17
diff -u -b -r1.17 mercury_tabling.h
--- runtime/mercury_tabling.h	2000/01/03 08:53:08	1.17
+++ runtime/mercury_tabling.h	2000/02/21 09:32:01
@@ -308,6 +308,13 @@
 				Word *type_info);
 
 /*
+** This function tables typeclass_infos in a hash table.
+*/
+
+extern	MR_TrieNode	MR_type_class_info_lookup_or_add(MR_TrieNode table,
+				Word *type_class_info);
+
+/*
 ** This function tables values of arbitrary types; the form of the data
 ** structure depends on the actual type of the value.
 */
Index: runtime/mercury_tabling_macros.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_tabling_macros.h,v
retrieving revision 1.2
diff -u -b -r1.2 mercury_tabling_macros.h
--- runtime/mercury_tabling_macros.h	2000/01/11 07:51:12	1.2
+++ runtime/mercury_tabling_macros.h	2000/02/21 09:32:01
@@ -43,6 +43,9 @@
 #define MR_RAW_TABLE_TYPEINFO(table, type_info)				\
 	MR_type_info_lookup_or_add((table), (type_info))
 
+#define MR_RAW_TABLE_TYPECLASSINFO(table, typeclass_info)		\
+	MR_type_info_lookup_or_add((table), (typeclass_info))
+
 #ifdef	MR_TABLE_DEBUG
 
 #define	MR_DEBUG_NEW_TABLE_ANY(table, table0, type_info, value)		\
@@ -212,6 +215,24 @@
 		}							\
 	} while (0)
 
+#define	MR_DEBUG_NEW_TABLE_TYPECLASSINFO(table, table0, value)		\
+	do {								\
+		(table) = MR_RAW_TABLE_TYPECLASSINFO((table0), (value));\
+		if (MR_tabledebug) {					\
+			printf("TABLE %p: typeclassinfo %p => %p\n",	\
+				(table), (value), (table));		\
+		}							\
+	} while (0)
+#define	MR_DEBUG_TABLE_TYPECLASSINFO(table, value)			\
+	do {								\
+		MR_TrieNode prev_table = (table);			\
+		(table) = MR_RAW_TABLE_TYPECLASSINFO((table), (value));	\
+		if (MR_tabledebug) {					\
+			printf("TABLE %p: typeclassinfo %p => %p\n",	\
+				prev_table, (value), (table));		\
+		}							\
+	} while (0)
+
 #else	/* not MR_TABLE_DEBUG */
 
 #define	MR_DEBUG_NEW_TABLE_ANY(table, table0, type_info, value)		\
@@ -293,6 +314,15 @@
 #define	MR_DEBUG_TABLE_TYPEINFO(table, value)				\
 	do {								\
 		(table) = MR_RAW_TABLE_TYPEINFO((table), (value));	\
+	} while (0)
+
+#define	MR_DEBUG_NEW_TABLE_TYPECLASSINFO(table, table0, value)		\
+	do {								\
+		(table) = MR_RAW_TABLE_TYPECLASSINFO((table0), (value));\
+	} while (0)
+#define	MR_DEBUG_TABLE_TYPECLASSINFO(table, value)			\
+	do {								\
+		(table) = MR_RAW_TABLE_TYPECLASSINFO((table), (value));	\
 	} while (0)
 
 #endif	/* MR_TABLE_DEBUG */
Index: runtime/mercury_type_info.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_type_info.c,v
retrieving revision 1.32
diff -u -b -r1.32 mercury_type_info.c
--- runtime/mercury_type_info.c	2000/01/19 09:45:22	1.32
+++ runtime/mercury_type_info.c	2000/02/24 13:30:39
@@ -18,7 +18,7 @@
 static Word *
 MR_get_arg_type_info(const Word *term_type_info, 
 	const Word *arg_pseudo_type_info, const Word *data_value, 
-	const Word *functor_descriptor);
+	int rtti_version, const MR_DuFunctorDesc *functor_desc);
 
 /*---------------------------------------------------------------------------*/
 
@@ -66,7 +66,8 @@
 MR_create_type_info(const Word *term_type_info, const Word *arg_pseudo_type_info)
 {
 	return MR_create_type_info_maybe_existq(term_type_info, 
-		arg_pseudo_type_info, NULL, NULL);
+		arg_pseudo_type_info, NULL,
+		MR_RTTI_VERSION__CLEAN_LAYOUT, NULL);
 }
 
 	/*
@@ -81,18 +82,20 @@
 	** If the term_type_info has a NULL type_ctor_info,
 	** or if the arg_pseudo_type_info does not contain any
 	** existentially typed type variables, then it is OK
-	** for the data_value and functor_descriptor to be NULL.
+	** for the data_value and functor_desc to be NULL.
 	*/
 
 Word * 
 MR_create_type_info_maybe_existq(const Word *term_type_info, 
 	const Word *arg_pseudo_type_info, const Word *data_value, 
-	const Word *functor_descriptor)
+	int rtti_version, const MR_DuFunctorDesc *functor_desc)
 {
-	int i, arity, extra_args;
 	MR_TypeCtorInfo type_ctor_info;
 	Word *arg_type_info;
 	Word *type_info;
+	int		arity;
+	int		extra_args;
+	int		i;
 
 	/* 
 	** The arg_pseudo_type_info might be a polymorphic variable.
@@ -101,7 +104,8 @@
 	if (TYPEINFO_IS_VARIABLE(arg_pseudo_type_info)) {
 
 		arg_type_info = MR_get_arg_type_info(term_type_info, 
-			arg_pseudo_type_info, data_value, functor_descriptor);
+			arg_pseudo_type_info, data_value,
+			rtti_version, functor_desc);
 
 		if (TYPEINFO_IS_VARIABLE(arg_type_info)) {
 			fatal_error("MR_create_type_info: "
@@ -136,7 +140,7 @@
 	for (i = extra_args; i < arity + extra_args; i++) {
 		arg_type_info = MR_create_type_info_maybe_existq(term_type_info,
 				(Word *) arg_pseudo_type_info[i],
-				data_value, functor_descriptor);
+				data_value, rtti_version, functor_desc);
 		if (TYPEINFO_IS_VARIABLE(arg_type_info)) {
 			fatal_error("MR_create_type_info_maybe_existq: "
 				"unbound type variable");
@@ -166,7 +170,7 @@
 static Word *
 MR_get_arg_type_info(const Word *term_type_info, 
 	const Word *arg_pseudo_type_info, const Word *data_value, 
-	const Word *functor_descriptor)
+	int rtti_version, const MR_DuFunctorDesc *functor_desc)
 {
 	Word *arg_type_info;
 	Unsigned arg_num;
@@ -177,20 +181,24 @@
 		/*
 		** This is a universally quantified type variable
 		*/
-		arg_type_info = (Word *) term_type_info[arg_num];
-	} else {
+		return (Word *) term_type_info[arg_num];
+	}
+
 		/*
 		** This is an existentially quantified type variable
 		*/
 
+	if (rtti_version <= MR_RTTI_VERSION__USEREQ) {
+		const Word	*functor_descriptor;
 		Word *type_info_locns;
 		Word type_info_locn;
 
+		functor_descriptor = (Word *) functor_desc;
 		type_info_locns = (Word *) 
 			MR_TYPE_CTOR_LAYOUT_FUNCTOR_DESCRIPTOR_TYPE_INFO_LOCNS(
 				functor_descriptor);
-		type_info_locn =
-			type_info_locns[arg_num - MR_EXISTENTIAL_VAR_BASE - 1];
+		type_info_locn = type_info_locns[arg_num
+				- MR_PSEUDOTYPEINFO_EXIST_VAR_BASE - 1];
 
 		if (MR_TYPE_INFO_LOCN_IS_INDIRECT(type_info_locn)) {
 			/*
@@ -220,6 +228,28 @@
 					type_info_locn);
 			arg_type_info = (Word *) data_value[typeinfo_number];
 		}
+	} else {
+		const MR_DuExistInfo	*exist_info;
+		MR_DuExistLocn		exist_locn;
+		int			exist_varnum;
+		int			slot;
+		int			offset;
+
+		exist_info = functor_desc->MR_du_functor_exist_info;
+		if (exist_info == NULL) {
+			fatal_error("MR_get_arg_type_info: no exist_info");
+		}
+
+		exist_varnum = arg_num - MR_PSEUDOTYPEINFO_EXIST_VAR_BASE - 1;
+		exist_locn = exist_info->MR_exist_typeinfo_locns[exist_varnum];
+		slot = exist_locn.MR_exist_arg_num;
+		offset = exist_locn.MR_exist_offset_in_tci;
+		if (offset < 0) {
+			arg_type_info = (Word *) data_value[slot];
+		} else {
+			arg_type_info = (Word *) MR_typeclass_info_type_info(
+					data_value[slot], offset);
+		}
 	}
 
 	return arg_type_info;
@@ -357,7 +387,6 @@
 MR_collapse_equivalences(Word maybe_equiv_type_info) 
 {
 	MR_TypeCtorInfo	type_ctor_info;
-	Word		*functors;
 	Word		equiv_type_info;
 	
 	type_ctor_info = MR_TYPEINFO_GET_TYPE_CTOR_INFO((Word *) 
@@ -367,16 +396,24 @@
 	while (type_ctor_info->type_ctor_rep == MR_TYPECTOR_REP_EQUIV
 		|| type_ctor_info->type_ctor_rep == MR_TYPECTOR_REP_EQUIV_VAR)
 	{
-		functors = type_ctor_info->type_ctor_functors;
+		if (type_ctor_info->type_ctor_version <=
+			MR_RTTI_VERSION__USEREQ)
+		{
 		equiv_type_info = (Word)
-				MR_TYPE_CTOR_FUNCTORS_EQUIV_TYPE(functors);
+				MR_TYPE_CTOR_FUNCTORS_EQUIV_TYPE(
+				type_ctor_info->type_ctor_functors);
+		} else {
+			equiv_type_info = (Word) type_ctor_info->type_layout.
+				layout_equiv;
+		}
+
 		equiv_type_info = (Word) MR_create_type_info(
 				(Word *) maybe_equiv_type_info, 
 				(Word *) equiv_type_info);
 
 		maybe_equiv_type_info = equiv_type_info;
-		type_ctor_info = MR_TYPEINFO_GET_TYPE_CTOR_INFO((Word *) 
-						maybe_equiv_type_info);
+		type_ctor_info = MR_TYPEINFO_GET_TYPE_CTOR_INFO(
+				(Word *) maybe_equiv_type_info);
 	}
 
 	return maybe_equiv_type_info;
@@ -438,7 +475,8 @@
 	MR_MemoryList *allocated) 
 {
 	return MR_make_type_info_maybe_existq(term_type_info, 
-		arg_pseudo_type_info, NULL, NULL, allocated);
+		arg_pseudo_type_info, NULL,
+		MR_RTTI_VERSION__CLEAN_LAYOUT, NULL, allocated);
 }
 
 	/*
@@ -452,12 +490,15 @@
 Word *
 MR_make_type_info_maybe_existq(const Word *term_type_info, 
 	const Word *arg_pseudo_type_info, const Word *data_value, 
-	const Word *functor_descriptor, MR_MemoryList *allocated) 
+	int rtti_version, const MR_DuFunctorDesc *functor_desc,
+	MR_MemoryList *allocated) 
 {
-	int i, arity, extra_args;
 	MR_TypeCtorInfo type_ctor_info;
 	Word *arg_type_info;
 	Word *type_info;
+	int		extra_args;
+	int		arity;
+	int		i;
 
 	/* 
 	** The arg_pseudo_type_info might be a polymorphic variable.
@@ -466,7 +507,8 @@
 	if (TYPEINFO_IS_VARIABLE(arg_pseudo_type_info)) {
 
 		arg_type_info = MR_get_arg_type_info(term_type_info, 
-			arg_pseudo_type_info, data_value, functor_descriptor);
+			arg_pseudo_type_info, data_value, rtti_version,
+			functor_desc);
 
 		if (TYPEINFO_IS_VARIABLE(arg_type_info)) {
 			fatal_error("make_type_info: "
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/hard_coded
Index: tests/hard_coded/construct.exp
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/construct.exp,v
retrieving revision 1.3
diff -u -b -r1.3 construct.exp
--- tests/hard_coded/construct.exp	1998/12/04 01:11:11	1.3
+++ tests/hard_coded/construct.exp	2000/02/24 03:30:35
@@ -1,19 +1,19 @@
 TESTING DISCRIMINATED UNIONS
 3 functors in this type
-2 - three/0
-1 - two/0
+2 - two/0
+1 - three/0
 0 - one/0
 
 
 3 functors in this type
-2 - three/0
-1 - two/0
+2 - two/0
+1 - three/0
 0 - one/0
 
 
 3 functors in this type
-2 - three/0
-1 - two/0
+2 - two/0
+1 - three/0
 0 - one/0
 
 
Index: tests/hard_coded/existential_rtti.exp
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/existential_rtti.exp,v
retrieving revision 1.1
diff -u -b -r1.1 existential_rtti.exp
--- tests/hard_coded/existential_rtti.exp	2000/01/20 07:39:31	1.1
+++ tests/hard_coded/existential_rtti.exp	2000/02/24 02:28:25
@@ -1,3 +1,17 @@
+Writing copies of terms:
+myf(1)
+f(1, "hello", 42)
+f(2, 'w', 42)
+f(3, goo, 42)
+f(4, g("hello"), 42)
+f(5, g2(12), 42)
+f(6, foo("hello", "world"), 42)
+g(7.00000000000000, g("hello"), 42.0000000000000)
+f(8, u("hello"), 42)
+f2(9, "hello", u("hello"), 432.100000000000, u("world"), 42)
+multi(10, "multiparameter")
+multi2(11, "multiparameter", 42.0000000000000)
+
 Writing some terms: 
 myf(1)
 f(1, "hello", 42)
@@ -11,7 +25,8 @@
 f2(9, "hello", u("hello"), 432.100000000000, u("world"), 42)
 multi(10, "multiparameter")
 multi2(11, "multiparameter", 42.0000000000000)
-Writing copies of terms: 
+
+Writing copies of terms again:
 myf(1)
 f(1, "hello", 42)
 f(2, 'w', 42)
@@ -26,4 +41,3 @@
 multi2(11, "multiparameter", 42.0000000000000)
 Writing a deconstructed term: 
 univ(8 : int), univ(u("hello") : existential_rtti:u(string)), univ(42 : int)
-
Index: tests/hard_coded/existential_rtti.m
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/existential_rtti.m,v
retrieving revision 1.1
diff -u -b -r1.1 existential_rtti.m
--- tests/hard_coded/existential_rtti.m	2000/01/20 07:39:31	1.1
+++ tests/hard_coded/existential_rtti.m	2000/02/24 02:28:15
@@ -51,95 +51,83 @@
 :- import_module list, std_util.
 
 main -->
+	io__write_string("Writing copies of terms:\n"),
 	{ A = 'new myf'(1) },
 	{ copy(A, ACopy) },
+	io__write(ACopy), io__nl,
 		% different types inside
 	{ B = 'new f'(1, "hello", 42) },
 	{ copy(B, BCopy) },
+	io__write(BCopy), io__nl,
 	{ C = 'new f'(2, 'w', 42) },
 	{ copy(C, CCopy) },
+	io__write(CCopy), io__nl,
 		% an enum
 	{ D = 'new f'(3, goo, 42) },
 	{ copy(D, DCopy) },
+	io__write(DCopy), io__nl,
 		% existential inside an existential
 	{ E = 'new f'(4, 'new g'("hello"), 42) },
 	{ copy(E, ECopy) },
+	io__write(ECopy), io__nl,
 		% A no-tag inside
 	{ F = 'new f'(5, g2(12), 42) },
 	{ copy(F, FCopy) },
+	io__write(FCopy), io__nl,
 	{ G = 'new f'(6, foo("hello", "world"), 42) },
 	{ copy(G, GCopy) },
+	io__write(GCopy), io__nl,
 	{ H = 'new g'(7.0, 'new g'("hello"), 42.0) },
 	{ copy(H, HCopy) },
+	io__write(HCopy), io__nl,
 		% universally quantified argument.
 	{ I = 'new f'(8, u("hello"), 42) },
 	{ copy(I, ICopy) },
+	io__write(ICopy), io__nl,
 		% multiple existentially and universally quantified arguments
 	{ J = 'new f2'(9, "hello", u("hello"), 432.1, u("world"), 42) },
 	{ copy(J, JCopy) },
+	io__write(JCopy), io__nl,
 		% multi parameter type class
 	{ K = 'new multi'(10, "multiparameter") },
 	{ copy(K, KCopy) },
+	io__write(KCopy), io__nl,
 		% multi parameter type class, multiple constraints
 	{ L = 'new multi2'(11, "multiparameter", 42.0) },
 	{ copy(L, LCopy) },
+	io__write(LCopy), io__nl,
 
-	io__write_string("Writing some terms: \n"),
-	io__write(A),
 	io__nl,
-	io__write(B),
-	io__nl,
-	io__write(C),
-	io__nl,
-	io__write(D),
-	io__nl,
-	io__write(E),
-	io__nl,
-	io__write(F),
-	io__nl,
-	io__write(G),
-	io__nl,
-	io__write(H),
-	io__nl,
-	io__write(I),
-	io__nl,
-	io__write(J),
-	io__nl,
-	io__write(K),
-	io__nl,
-	io__write(L),
-	io__nl,
+	io__write_string("Writing some terms:\n"),
+	io__write(A), io__nl,
+	io__write(B), io__nl,
+	io__write(C), io__nl,
+	io__write(D), io__nl,
+	io__write(E), io__nl,
+	io__write(F), io__nl,
+	io__write(G), io__nl,
+	io__write(H), io__nl,
+	io__write(I), io__nl,
+	io__write(J), io__nl,
+	io__write(K), io__nl,
+	io__write(L), io__nl,
 
-	io__write_string("Writing copies of terms: \n"),
-	io__write(ACopy),
-	io__nl,
-	io__write(BCopy),
-	io__nl,
-	io__write(CCopy),
 	io__nl,
-	io__write(DCopy),
-	io__nl,
-	io__write(ECopy),
-	io__nl,
-	io__write(FCopy),
-	io__nl,
-	io__write(GCopy),
-	io__nl,
-	io__write(HCopy),
-	io__nl,
-	io__write(ICopy),
-	io__nl,
-	io__write(JCopy),
-	io__nl,
-	io__write(KCopy),
-	io__nl,
-	io__write(LCopy),
-	io__nl,
+	io__write_string("Writing copies of terms again:\n"),
+	io__write(ACopy), io__nl,
+	io__write(BCopy), io__nl,
+	io__write(CCopy), io__nl,
+	io__write(DCopy), io__nl,
+	io__write(ECopy), io__nl,
+	io__write(FCopy), io__nl,
+	io__write(GCopy), io__nl,
+	io__write(HCopy), io__nl,
+	io__write(ICopy), io__nl,
+	io__write(JCopy), io__nl,
+	io__write(KCopy), io__nl,
+	io__write(LCopy), io__nl,
 
-	io__write_string("Writing a deconstructed term: \n"),
+	io__write_string("Writing a deconstructed term:\n"),
 	{ deconstruct(I, _Functor, _Arity, IArgs) },
 	io__write_list(IArgs, ", ", io__write),
-	io__nl,
-
 	io__nl.
-
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing trial
cvs diff: Diffing util
--------------------------------------------------------------------------
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