[m-dev.] for review: change existential tvar encoding in RTTI

David Glen JEFFERY dgj at cs.mu.OZ.AU
Wed Jan 12 18:08:37 AEDT 2000


This one's for Zoltan.

===================================================================

Estimated hours taken: 2

Change the encoding of existentially quantified type variables in
the RTTI; rather than representing the nth existentially quantified
variable by the number (n + number of universally quantified tvars),
represent it as (n + 512). This really just simplifies things, since
we no longer need to look inside the type-constructor-info to find
the number of universally quantified variables when instantiating
a tvar at runtime.

compiler/base_type_layout.m:
	Use the new encoding.
runtime/mercury_type_info.c:
	Detect existentially quantified type variables using the new
	method.
runtime/mercury_type_info.h:
	Add some macros.
runtime/mercury_layout_util.c:
	Delete the code that fjh recently added which constructed a
	fake type constructor info.

===================================================================

Index: compiler/base_type_layout.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/base_type_layout.m,v
retrieving revision 1.50
diff -u -t -r1.50 base_type_layout.m
--- base_type_layout.m	1999/12/13 05:22:57	1.50
+++ base_type_layout.m	2000/01/12 05:48:54
@@ -118,7 +118,9 @@
 %          If under 1024, the rest of the word is a type variable number,
 %          that is, the polymophic argument number (starting at 1) of
 %          the type. Substitute that variable, and you have the type
-%          this type is equivalent to.
+%          this type is equivalent to. (Variable numbers greater than
+%          `existential_var_base' correspond to existentially quantified
+%          variables).
 %
 %          If over 1024, it's just a pointer to a vector, containing
 %               - an indicator whether this is a no_tag or not
@@ -1361,7 +1363,7 @@
                                 list__nth_member_search(ExistQTvars, 
                                         Var, ExistNum0)
                         ->
-                                VarInt = ExistNum0 + NumUnivQTvars
+                                VarInt = ExistNum0 + existential_var_base
                         ;
                                 error("base_type_layout: var not in list")
                         )
@@ -1376,6 +1378,11 @@
                 error("type_ctor_layout: type neither var nor non-var")
         ).
 
+        % The base number from which we count existentially quantified 
+        % variables. Note that this number must be kept in synch with
+        % MR_EXISTENTIAL_VAR_BASE in runtime/mercury_type_info.h
+:- func existential_var_base = int.
+existential_var_base = 512.
 
         % Remove a create() from an rval, if present.
         
Index: runtime/mercury_layout_util.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_layout_util.c,v
retrieving revision 1.15
diff -u -t -r1.15 mercury_layout_util.c
--- mercury_layout_util.c	1999/12/12 14:29:06	1.15
+++ mercury_layout_util.c	2000/01/12 05:50:54
@@ -63,30 +63,6 @@
         save_transient_registers();
 }
 
-        /* 
-        ** Dummy type_ctor_info for stack layouts.
-        ** This is used by MR_materialize_type_infos_base().
-        ** The only important thing about the contents
-        ** of this dummy type_ctor_info is that the
-        ** arity should be the maximum arity,
-        ** so that any type variables are treated as
-        ** universally quantified when the type_info is
-        ** passed to MR_get_arg_type_info().
-        */
-MR_STATIC_CODE_CONST struct MR_TypeCtorInfo_struct
-mercury_data___type_ctor_info_stack_layout_0 = {
-        TYPE_CTOR_LAYOUT_MAX_VARINT, /* arity = maximum */
-        0,
-        0,
-        0,
-        MR_TYPECTOR_REP_UNKNOWN,
-        0,
-        0,
-        string_const("private_builtin", 7),
-        string_const("stack_layout", 4),
-        MR_RTTI_VERSION
-};
-
 Word *
 MR_materialize_typeinfos(const MR_Stack_Layout_Vars *vars,
         Word *saved_regs)
@@ -109,11 +85,9 @@
                 type_params = MR_NEW_ARRAY(Word, count + 1);
 
                 /*
-                ** type_params should look like a typeinfo, so
-                ** we need to fill in type_params[0] with a dummy type_ctor_info.
+                ** type_params should look like a typeinfo;
+                ** type_params[0] is empty and will not be referred to
                 */
-                type_params[0] = (Word)
-                        &mercury_data___type_ctor_info_stack_layout_0;
                 for (i = 0; i < count; i++) {
                         if (vars->MR_slvs_tvars->MR_tp_param_locns[i] != 0) {
                                 type_params[i + 1] = MR_lookup_long_lval_base(
@@ -122,11 +96,11 @@
                                         saved_regs, base_sp, base_curfr,
                                         &succeeded);
                                 if (! succeeded) {
-                                        fatal_error("missing type param in "
-                                            "MR_materialize_typeinfos_base");
+                                        fatal_error("missing type param in MR_materialize_typeinfos_base");
                                 }
                         }
                 }
+
                 return type_params;
         } else {
                 return NULL;
Index: runtime/mercury_type_info.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_type_info.c,v
retrieving revision 1.30
diff -u -t -r1.30 mercury_type_info.c
--- mercury_type_info.c	1999/12/12 14:29:07	1.30
+++ mercury_type_info.c	2000/01/12 05:47:21
@@ -269,16 +269,11 @@
         const Word *functor_descriptor)
 {
         Word *arg_type_info;
-        MR_TypeCtorInfo type_ctor_info;
-        int num_univ_type_infos;
         Unsigned arg_num;
 
         arg_num = (Unsigned) arg_pseudo_type_info;
 
-        type_ctor_info = MR_TYPEINFO_GET_TYPE_CTOR_INFO(term_type_info);
-
-        num_univ_type_infos = type_ctor_info->arity;
-        if (arg_num <= num_univ_type_infos) {
+        if (MR_TYPE_VARIABLE_IS_UNIV_QUANT(arg_num)) {
                 /*
                 ** This is a universally quantified type variable
                 */
@@ -295,7 +290,7 @@
                         MR_TYPE_CTOR_LAYOUT_FUNCTOR_DESCRIPTOR_TYPE_INFO_LOCNS(
                                 functor_descriptor);
                 type_info_locn =
-                        type_info_locns[arg_num - num_univ_type_infos - 1];
+                        type_info_locns[arg_num - MR_EXISTENTIAL_VAR_BASE - 1];
 
                 if (MR_TYPE_INFO_LOCN_IS_INDIRECT(type_info_locn)) {
                         /*
Index: runtime/mercury_type_info.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_type_info.h,v
retrieving revision 1.35
diff -u -t -r1.35 mercury_type_info.h
--- mercury_type_info.h	2000/01/11 00:10:16	1.35
+++ mercury_type_info.h	2000/01/12 05:46:34
@@ -296,6 +296,19 @@
 #define TYPEINFO_IS_VARIABLE(T)         ( (Word) T <= TYPE_CTOR_LAYOUT_MAX_VARINT )
 
 /*
+** The number above or equal to which a type variable is considered to be
+** existentially quantified.
+**
+** Should be kept in sync with existential_var_base in
+** compiler/base_type_layout.m
+*/
+
+#define MR_EXISTENTIAL_VAR_BASE                 512
+
+#define MR_TYPE_VARIABLE_IS_EXIST_QUANT(T)      ( (Word) T > MR_EXISTENTIAL_VAR_BASE )
+#define MR_TYPE_VARIABLE_IS_UNIV_QUANT(T)       ( (Word) T <= MR_EXISTENTIAL_VAR_BASE )
+
+/*
 ** This constant is also used for other information - for
 ** ctor infos a small integer is used for higher order types.
 ** Even integers represent preds, odd represent functions.

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