[m-dev.] for review: add type_ctor_reps for user-defined equality

Tyson Dowd trd at cs.mu.OZ.AU
Tue Oct 26 14:56:37 AEST 1999


Estimated hours taken: 4

Add support for distinguishing types with user defined equality from 
system defined equality.  This information is encoded in the
type_ctor_rep.

It is intended to be used for implementing RTTI driven compare and unify
procedures.

This change uses the version number in the type_ctor_info to allow 
Easy Bootstrapping(TM).

compiler/base_type_info.m:
	Add new alternatives for user defined equality types.
	Update RTTI version number.
	Change `type_ctor_info_version' to `type_ctor_info_rtti_version'.

runtime/mercury_type_info.c:
	Define MR_get_new_type_ctor_rep which gets the type_ctor_rep,
	automatically converting older versions.
	(this change is just for bootstrapping).

library/std_util.m:
runtime/mercury_deep_copy_body.h:
runtime/mercury_ho_call.c:
runtime/mercury_tabling.c:
runtime/mercury_type_info.h:
runtime/mercury_wrapper.c:
	Use MR_get_new_type_ctor_rep to get the type_ctor_rep.
	(this change is just for bootstrapping).

	Add new alternatives to code that uses type_ctor_rep (at the
	moment they just fall through).


Index: compiler/base_type_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/base_type_info.m,v
retrieving revision 1.27
diff -u -r1.27 base_type_info.m
--- base_type_info.m	1999/10/20 07:02:55	1.27
+++ base_type_info.m	1999/10/25 17:35:22
@@ -135,8 +135,8 @@
 	% runtime that uses RTTI to conform to whatever changes the new
 	% version introduces.
 
-:- func type_ctor_info_version = int.
-type_ctor_info_version = 2.
+:- func type_ctor_info_rtti_version = int.
+type_ctor_info_rtti_version = 3.
 
 base_type_info__generate_llds(ModuleInfo, CModules) :-
 	module_info_base_gen_infos(ModuleInfo, BaseGenInfos),
@@ -182,7 +182,8 @@
 		prog_out__sym_name_to_string(ModuleName, ModuleNameString),
 		NameArg = yes(const(string_const(TypeName))),
 		ModuleArg = yes(const(string_const(ModuleNameString))),
-		VersionArg = yes(const(int_const(type_ctor_info_version))),
+		VersionArg = yes(const(int_const(
+			type_ctor_info_rtti_version))),
 		list__append(PredAddrArgs, [TypeCtorArg, FunctorsArg, LayoutArg,
 			ModuleArg, NameArg, VersionArg], FinalArgs)
 	;
@@ -258,8 +259,11 @@
 
 :- type type_ctor_representation 
 	--->	enum
+	;	enum_usereq
 	;	du
+	;	du_usereq
 	;	notag
+	;	notag_usereq
 	;	equiv
 	;	equiv_var
 	;	int
@@ -277,23 +281,26 @@
 
 :- pred base_type_info__type_ctor_rep_to_int(type_ctor_representation::in,
 	int::out) is det.
-base_type_info__type_ctor_rep_to_int(enum, 0).
-base_type_info__type_ctor_rep_to_int(du, 1).
-base_type_info__type_ctor_rep_to_int(notag, 2).
-base_type_info__type_ctor_rep_to_int(equiv, 3).
-base_type_info__type_ctor_rep_to_int(equiv_var, 4).
-base_type_info__type_ctor_rep_to_int(int, 5).
-base_type_info__type_ctor_rep_to_int(char, 6).
-base_type_info__type_ctor_rep_to_int(float, 7).
-base_type_info__type_ctor_rep_to_int(string, 8).
-base_type_info__type_ctor_rep_to_int(pred, 9).
-base_type_info__type_ctor_rep_to_int(univ, 10).
-base_type_info__type_ctor_rep_to_int(void, 11).
-base_type_info__type_ctor_rep_to_int(c_pointer, 12).
-base_type_info__type_ctor_rep_to_int(typeinfo, 13).
-base_type_info__type_ctor_rep_to_int(typeclassinfo, 14).
-base_type_info__type_ctor_rep_to_int(array, 15).
-base_type_info__type_ctor_rep_to_int(unknown, 16).
+base_type_info__type_ctor_rep_to_int(enum, 		0).
+base_type_info__type_ctor_rep_to_int(enum_usereq,	1).
+base_type_info__type_ctor_rep_to_int(du,		2).
+base_type_info__type_ctor_rep_to_int(du_usereq,		3).
+base_type_info__type_ctor_rep_to_int(notag,		4).
+base_type_info__type_ctor_rep_to_int(notag_usereq,	5).
+base_type_info__type_ctor_rep_to_int(equiv,		6).
+base_type_info__type_ctor_rep_to_int(equiv_var,		7).
+base_type_info__type_ctor_rep_to_int(int,		8).
+base_type_info__type_ctor_rep_to_int(char,		9).
+base_type_info__type_ctor_rep_to_int(float,	 	10).
+base_type_info__type_ctor_rep_to_int(string,		11).
+base_type_info__type_ctor_rep_to_int(pred,		12).
+base_type_info__type_ctor_rep_to_int(univ,		13).
+base_type_info__type_ctor_rep_to_int(void,		14).
+base_type_info__type_ctor_rep_to_int(c_pointer,		15).
+base_type_info__type_ctor_rep_to_int(typeinfo,		16).
+base_type_info__type_ctor_rep_to_int(typeclassinfo,	17).
+base_type_info__type_ctor_rep_to_int(array,		18).
+base_type_info__type_ctor_rep_to_int(unknown,		19).
 
 
 :- pred base_type_info__construct_type_ctor_representation(hlds_type_defn,
@@ -312,18 +319,36 @@
 		TypeBody = abstract_type,
 		TypeCtorRep = unknown
 	;
-		TypeBody = du_type(Ctors, _ConsTagMap, Enum, _EqualityPred),
+		TypeBody = du_type(Ctors, _ConsTagMap, Enum, EqualityPred),
 		(
 			Enum = yes,
-			TypeCtorRep = enum
+			(
+				EqualityPred = yes(_),
+				TypeCtorRep = enum_usereq
+			;
+				EqualityPred = no,
+				TypeCtorRep = enum
+			)
 		;
 			Enum = no,
 			( 
 				type_is_no_tag_type(Ctors, _Name, _TypeArg)
 			->
-				TypeCtorRep = notag
+				(
+					EqualityPred = yes(_),
+					TypeCtorRep = notag_usereq
+				;
+					EqualityPred = no,
+					TypeCtorRep = notag
+				)
 			;
-				TypeCtorRep = du
+				(
+					EqualityPred = yes(_),
+					TypeCtorRep = du_usereq
+				;
+					EqualityPred = no,
+					TypeCtorRep = du
+				)
 			)
 		)
 	),
Index: library/std_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/std_util.m,v
retrieving revision 1.168
diff -u -r1.168 std_util.m
--- std_util.m	1999/10/20 07:03:13	1.168
+++ std_util.m	1999/10/25 08:35:18
@@ -2177,9 +2177,10 @@
     layout_for_tag = type_ctor_layout[data_tag];
     layout_vector_for_tag = MR_strip_tag(layout_for_tag);
 
-    switch(type_ctor_info->type_ctor_rep) {
+    switch(MR_get_new_type_ctor_rep(type_ctor_info)) {
 
         case MR_TYPECTOR_REP_ENUM:
+        case MR_TYPECTOR_REP_ENUM_USEREQ:
             info->functor = MR_TYPE_CTOR_LAYOUT_ENUM_VECTOR_FUNCTOR_NAME(
                 layout_vector_for_tag, data_word);
             info->arity = 0;
@@ -2188,6 +2189,7 @@
             break;
 
         case MR_TYPECTOR_REP_DU:
+        case MR_TYPECTOR_REP_DU_USEREQ:
             tag_rep = MR_get_tag_representation((Word) layout_for_tag);
             switch (tag_rep) {
             case MR_DISCUNIONTAG_SHARED_LOCAL:
@@ -2252,6 +2254,7 @@
 	break;
 
         case MR_TYPECTOR_REP_NOTAG:
+        case MR_TYPECTOR_REP_NOTAG_USEREQ:
         {
             int i;
 	    Word * functor_descriptor = (Word *) layout_vector_for_tag;
Index: runtime/mercury_deep_copy_body.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_deep_copy_body.h,v
retrieving revision 1.13
diff -u -r1.13 mercury_deep_copy_body.h
--- mercury_deep_copy_body.h	1999/10/19 04:11:40	1.13
+++ mercury_deep_copy_body.h	1999/10/25 03:38:22
@@ -31,7 +31,6 @@
 
     Word functors_indicator;
     Word layout_entry, *entry_value, *data_value;
-    MR_TypeCtorRepresentation type_ctor_rep;
     MR_DiscUnionTagRepresentation tag_rep;
     int data_tag; 
     Word new_data, data;
@@ -45,7 +44,7 @@
     layout_entry = type_ctor_info->type_ctor_layout[data_tag];
     entry_value = (Word *) MR_strip_tag(layout_entry);
 
-    switch (type_ctor_info->type_ctor_rep) {
+    switch (MR_get_new_type_ctor_rep(type_ctor_info)) {
         case MR_TYPECTOR_REP_ENUM:
             new_data = data;    /* just a copy of the actual item */
             break;
Index: runtime/mercury_ho_call.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_ho_call.c,v
retrieving revision 1.24
diff -u -r1.24 mercury_ho_call.c
--- mercury_ho_call.c	1999/10/19 05:26:10	1.24
+++ mercury_ho_call.c	1999/10/22 04:19:10
@@ -274,10 +274,11 @@
 	type_ctor_info = MR_TYPEINFO_GET_TYPE_CTOR_INFO((Word *) type_info);
 
 #ifdef	MR_CTOR_REP_STATS
-	MR_ctor_rep_unify[type_ctor_info->type_ctor_rep]++;
+	MR_ctor_rep_unify[MR_get_new_type_ctor_rep(
+				type_ctor_info->type_ctor_rep)]++;
 #endif
 
-	switch (type_ctor_info->type_ctor_rep) {
+	switch (MR_get_new_type_ctor_rep(type_ctor_info)) {
 
 			/*
 			** For notag and equiv types, we should probably
@@ -288,8 +289,10 @@
 			*/
 
 		case MR_TYPECTOR_REP_DU:
+		case MR_TYPECTOR_REP_DU_USEREQ:
 		case MR_TYPECTOR_REP_ARRAY:
 		case MR_TYPECTOR_REP_NOTAG:
+		case MR_TYPECTOR_REP_NOTAG_USEREQ:
 		case MR_TYPECTOR_REP_EQUIV:
 		case MR_TYPECTOR_REP_EQUIV_VAR:
 
@@ -355,6 +358,7 @@
 				LABEL(mercury__unify_2_0));
 
 		case MR_TYPECTOR_REP_ENUM:
+		case MR_TYPECTOR_REP_ENUM_USEREQ:
 		case MR_TYPECTOR_REP_INT:
 		case MR_TYPECTOR_REP_CHAR:
 			r1 = ((Integer) x == (Integer) y);
@@ -504,10 +508,11 @@
 	type_ctor_info = MR_TYPEINFO_GET_TYPE_CTOR_INFO((Word *) type_info);
 
 #ifdef	MR_CTOR_REP_STATS
-	MR_ctor_rep_index[type_ctor_info->type_ctor_rep]++;
+	MR_ctor_rep_index[MR_get_new_type_ctor_rep(
+				type_ctor_info->type_ctor_rep)]++;
 #endif
 
-	switch (type_ctor_info->type_ctor_rep) {
+	switch (MR_get_new_type_ctor_rep(type_ctor_info)) {
 
 			/*
 			** For notag and equiv types, we should probably
@@ -699,10 +704,11 @@
 	type_ctor_info = MR_TYPEINFO_GET_TYPE_CTOR_INFO((Word *) type_info);
 
 #ifdef	MR_CTOR_REP_STATS
-	MR_ctor_rep_compare[type_ctor_info->type_ctor_rep]++;
+	MR_ctor_rep_compare[MR_get_new_type_ctor_rep(
+				type_ctor_info->type_ctor_rep)]++;
 #endif
 
-	switch (type_ctor_info->type_ctor_rep) {
+	switch (MR_get_new_type_ctor_rep(type_ctor_info)) {
 
 			/*
 			** For notag and equiv types, we should probably
Index: runtime/mercury_tabling.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_tabling.c,v
retrieving revision 1.13
diff -u -r1.13 mercury_tabling.c
--- mercury_tabling.c	1999/10/18 15:47:00	1.13
+++ mercury_tabling.c	1999/10/22 04:20:00
@@ -487,11 +487,11 @@
 #ifdef  MR_TABLE_DEBUG
     if (MR_tabledebug) {
         printf("ENTRY %p %x, data rep: %d\n",
-            table, data, type_ctor_info->type_ctor_rep);
+            table, data, MR_get_new_type_ctor_rep(type_ctor_info));
     }
 #endif  /* MR_TABLE_DEBUG */
 
-    switch (type_ctor_info->type_ctor_rep) {
+    switch (MR_get_new_type_ctor_rep(type_ctor_info)) {
         case MR_TYPECTOR_REP_ENUM: {
             int functors = MR_TYPE_CTOR_LAYOUT_ENUM_VECTOR_NUM_FUNCTORS(
                                 layout_vector_for_tag);
Index: runtime/mercury_type_info.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_type_info.c,v
retrieving revision 1.24
diff -u -r1.24 mercury_type_info.c
--- mercury_type_info.c	1999/10/20 07:03:23	1.24
+++ mercury_type_info.c	1999/10/22 04:17:28
@@ -550,3 +550,30 @@
 		mercury_data___type_ctor_info_pred_0, _pred_);
 }
 
+/*---------------------------------------------------------------------------*/
+
+	/* Functions for handling previous versions of the RTTI code */
+
+	/*
+	** After updating the type_ctor_rep enumeration to add user
+	** defined equality alternatives, we need to convert old
+	** type_ctor_reps into the new type_ctor_rep.
+	*/
+MR_TypeCtorRepresentation
+MR_get_new_type_ctor_rep(MR_TypeCtorInfo type_ctor_info)
+{
+	if (type_ctor_info->type_ctor_version < MR_RTTI_VERSION__USEREQ) {
+		if (type_ctor_info->type_ctor_rep < 3) {
+			return type_ctor_info->type_ctor_rep * 2;
+		} else {
+			return type_ctor_info->type_ctor_rep + 3;
+		}
+	} else {
+		return type_ctor_info->type_ctor_rep;
+	}
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+
Index: runtime/mercury_type_info.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_type_info.h,v
retrieving revision 1.29
diff -u -r1.29 mercury_type_info.h
--- mercury_type_info.h	1999/10/20 07:03:23	1.29
+++ mercury_type_info.h	1999/10/22 04:16:59
@@ -36,8 +36,9 @@
 
 /*---------------------------------------------------------------------------*/
 
-#define MR_RTTI_VERSION 		MR_RTTI_VERSION__INITIAL
+#define MR_RTTI_VERSION 		MR_RTTI_VERSION__USEREQ
 #define MR_RTTI_VERSION__INITIAL 	2
+#define MR_RTTI_VERSION__USEREQ 	3
 
 /* 
 ** The version of the RTTI data structures -- useful for bootstrapping.
@@ -772,16 +773,20 @@
 
 /*
 ** MR_DataRepresentation is the representation for a particular type
-** constructor.  For the cases of MR_TYPE_CTOR_REP_DU the exact
-** representation depends on the tag value -- lookup the tag value in
-** type_ctor_layout to find out this information.
+** constructor.  For the cases of MR_TYPE_CTOR_REP_DU and
+** MR_TYPE_CTOR_REP_DU_USEREQthe exact representation depends on the tag
+** value -- lookup the tag value in type_ctor_layout to find out this
+** information.
 **
 ** 
 */
 typedef enum MR_TypeCtorRepresentation {
 	MR_TYPECTOR_REP_ENUM,
+	MR_TYPECTOR_REP_ENUM_USEREQ,
 	MR_TYPECTOR_REP_DU,
+	MR_TYPECTOR_REP_DU_USEREQ,
 	MR_TYPECTOR_REP_NOTAG,
+	MR_TYPECTOR_REP_NOTAG_USEREQ,
 	MR_TYPECTOR_REP_EQUIV,
 	MR_TYPECTOR_REP_EQUIV_VAR,
 	MR_TYPECTOR_REP_INT,
@@ -810,6 +815,37 @@
 	MR_TYPECTOR_REP_UNKNOWN
 } MR_TypeCtorRepresentation;
 
+typedef enum MR_OldTypeCtorRepresentation {
+	MR_OLD_TYPECTOR_REP_ENUM,
+	MR_OLD_TYPECTOR_REP_DU,
+	MR_OLD_TYPECTOR_REP_NOTAG,
+	MR_OLD_TYPECTOR_REP_EQUIV,
+	MR_OLD_TYPECTOR_REP_EQUIV_VAR,
+	MR_OLD_TYPECTOR_REP_INT,
+	MR_OLD_TYPECTOR_REP_CHAR,
+	MR_OLD_TYPECTOR_REP_FLOAT,
+	MR_OLD_TYPECTOR_REP_STRING,
+	MR_OLD_TYPECTOR_REP_PRED,
+	MR_OLD_TYPECTOR_REP_UNIV,
+	MR_OLD_TYPECTOR_REP_VOID,
+	MR_OLD_TYPECTOR_REP_C_POINTER,
+	MR_OLD_TYPECTOR_REP_TYPEINFO,
+	MR_OLD_TYPECTOR_REP_TYPECLASSINFO,
+	MR_OLD_TYPECTOR_REP_ARRAY,
+	MR_OLD_TYPECTOR_REP_SUCCIP,
+	MR_OLD_TYPECTOR_REP_HP,
+	MR_OLD_TYPECTOR_REP_CURFR,
+	MR_OLD_TYPECTOR_REP_MAXFR,
+	MR_OLD_TYPECTOR_REP_REDOFR,
+	MR_OLD_TYPECTOR_REP_REDOIP,
+	MR_OLD_TYPECTOR_REP_TRAIL_PTR,
+	MR_OLD_TYPECTOR_REP_TICKET,
+	/*
+	** MR_OLD_TYPECTOR_REP_UNKNOWN should remain the last alternative;
+	** MR_CTOR_REP_STATS depends on this.
+	*/
+	MR_OLD_TYPECTOR_REP_UNKNOWN
+} MR_OldTypeCtorRepresentation;
 /*
 ** If the MR_TypeCtorRepresentation is MR_TYPE_CTOR_REP_DU, we have a
 ** discriminated union type (other than a no-tag or enumeration).  Each
@@ -893,6 +929,13 @@
 
 #define MR_TYPE_CTOR_INFO_GET_TYPE_MODULE_NAME(TypeCtorInfo)		\
 	((TypeCtorInfo)->type_ctor_module_name)
+
+/*---------------------------------------------------------------------------*/
+
+	/* Functions for handling previous versions of the RTTI code */
+
+MR_TypeCtorRepresentation
+MR_get_new_type_ctor_rep(MR_TypeCtorInfo type_ctor_info);
 
 /*---------------------------------------------------------------------------*/
 #endif /* not MERCURY_TYPEINFO_H */
Index: runtime/mercury_wrapper.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_wrapper.c,v
retrieving revision 1.47
diff -u -r1.47 mercury_wrapper.c
--- mercury_wrapper.c	1999/10/18 15:47:02	1.47
+++ mercury_wrapper.c	1999/10/22 04:23:22
@@ -923,10 +923,17 @@
 		if (fp != NULL) {
 			fprintf(fp, "UNIFY ENUM %ld\n",
 				MR_ctor_rep_unify[MR_TYPECTOR_REP_ENUM]);
+			fprintf(fp, "UNIFY ENUM_USEREQ %ld\n",
+				MR_ctor_rep_unify[MR_TYPECTOR_REP_ENUM_USEREQ]);
 			fprintf(fp, "UNIFY DU %ld\n",
 				MR_ctor_rep_unify[MR_TYPECTOR_REP_DU]);
+			fprintf(fp, "UNIFY DU_USEREQ %ld\n",
+				MR_ctor_rep_unify[MR_TYPECTOR_REP_DU_USEREQ]);
 			fprintf(fp, "UNIFY NOTAG %ld\n",
 				MR_ctor_rep_unify[MR_TYPECTOR_REP_NOTAG]);
+			fprintf(fp, "UNIFY NOTAG_USEREQ %ld\n",
+				MR_ctor_rep_unify[
+					MR_TYPECTOR_REP_NOTAG_USEREQ]);
 			fprintf(fp, "UNIFY EQUIV %ld\n",
 				MR_ctor_rep_unify[MR_TYPECTOR_REP_EQUIV]);
 			fprintf(fp, "UNIFY EQUIV_VAR %ld\n",
@@ -974,10 +981,16 @@
 
 			fprintf(fp, "INDEX ENUM %ld\n",
 				MR_ctor_rep_index[MR_TYPECTOR_REP_ENUM]);
+			fprintf(fp, "INDEX ENUM_USEREQ %ld\n",
+				MR_ctor_rep_index[MR_TYPECTOR_REP_ENUM_USEREQ]);
 			fprintf(fp, "INDEX DU %ld\n",
 				MR_ctor_rep_index[MR_TYPECTOR_REP_DU]);
+			fprintf(fp, "INDEX DU_USEREQ %ld\n",
+				MR_ctor_rep_index[MR_TYPECTOR_REP_DU_USEREQ]);
 			fprintf(fp, "INDEX NOTAG %ld\n",
 				MR_ctor_rep_index[MR_TYPECTOR_REP_NOTAG]);
+			fprintf(fp, "INDEX NOTAG_USEREQ %ld\n",
+				MR_ctor_rep_index[MR_TYPECTOR_REP_NOTAG_USEREQ]);
 			fprintf(fp, "INDEX EQUIV %ld\n",
 				MR_ctor_rep_index[MR_TYPECTOR_REP_EQUIV]);
 			fprintf(fp, "INDEX EQUIV_VAR %ld\n",
@@ -1025,10 +1038,16 @@
 
 			fprintf(fp, "COMPARE ENUM %ld\n",
 				MR_ctor_rep_compare[MR_TYPECTOR_REP_ENUM]);
+			fprintf(fp, "COMPARE ENUM_USEREQ %ld\n",
+				MR_ctor_rep_compare[MR_TYPECTOR_REP_ENUM_USEREQ]);
 			fprintf(fp, "COMPARE DU %ld\n",
 				MR_ctor_rep_compare[MR_TYPECTOR_REP_DU]);
+			fprintf(fp, "COMPARE DU_USEREQ %ld\n",
+				MR_ctor_rep_compare[MR_TYPECTOR_REP_DU_USEREQ]);
 			fprintf(fp, "COMPARE NOTAG %ld\n",
 				MR_ctor_rep_compare[MR_TYPECTOR_REP_NOTAG]);
+			fprintf(fp, "COMPARE NOTAG_USEREQ %ld\n",
+				MR_ctor_rep_compare[MR_TYPECTOR_REP_NOTAG_USEREQ]);
 			fprintf(fp, "COMPARE EQUIV %ld\n",
 				MR_ctor_rep_compare[MR_TYPECTOR_REP_EQUIV]);
 			fprintf(fp, "COMPARE EQUIV_VAR %ld\n",


-- 
       Tyson Dowd           # 
                            #  Surreal humour isn't eveyone's cup of fur.
     trd at cs.mu.oz.au        # 
http://www.cs.mu.oz.au/~trd #
--------------------------------------------------------------------------
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