diff: unbound type variables.

Tyson Richard DOWD trd at hydra.cs.mu.oz.au
Tue Apr 29 16:59:26 AEST 1997


Hi,

	Fergus, can you please review this?

	Thanks,
		Tyson.

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

Estimated hours taken: 1.5

Fix the (long-time) temporary hack to generate NULL pointers as
type_infos for unbound type variables.

compiler/polymorphism.m:
	- Generate references to void directly, rather than generating 
	  NULL pointers. 

library/std_util.m:
	- Remove special case code in mercury_compare_type_info, and
	  create_type_info to handle unbound type variables represented
	  as NULLs. Since they are now represented as a normal
	  type_info, there doesn't need to be any special code.


Index: compiler/polymorphism.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/polymorphism.m,v
retrieving revision 1.101
diff -u -r1.101 polymorphism.m
--- polymorphism.m	1997/04/07 05:39:41	1.101
+++ polymorphism.m	1997/04/29 06:41:13
@@ -821,17 +821,17 @@
 		%
 		% In this case T is unbound, so there cannot be any objects
 		% of type T, and so q/1 cannot possibly use the unification
-		% predicate for type T.  We just pass a dummy value (0).
+		% predicate for type T.  We pass the type-info for the
+		% type `void'/0.
 		%
 		%	:- pred p.
 		%	:- pred q(type_info(T), list(T)).
-		%	p :- q(0, []).
+		%	p :- q(<void/0>, []).
 		%
-		% (This isn't really type-correct, but we're already past
-		% the type-checker.  Passing 0 should ensure that we get
-		% a core dump if we ever attempt to call the unify pred,
-		% whether we are using one_cell, one_or_two_cell, or
-		% shared_one_or_two_cell typeinfos.)
+		% Passing `void'/0 should ensure that we get a runtime
+		% error if the special predicates for this type are
+		% every used (void has its special predicates set to
+		% `unused'/0).
 		%
 		% XXX what about io__read_anything/3?
 		% e.g.
@@ -841,10 +841,10 @@
 		% introduce a new variable, and
 		% create a construction unification which initializes the
 		% variable to zero
-		polymorphism__new_type_info_var(Type, "type_info",
-			VarSet0, VarTypes0, Var, VarSet, VarTypes),
-		polymorphism__init_with_int_constant(Var, 0, Goal),
-		ExtraGoals = [Goal]
+		TypeId = unqualified("void") - 0,
+		polymorphism__construct_type_info(Type, TypeId, [],
+			no, ModuleInfo, TypeInfoMap, VarSet0, VarTypes0,
+			Var, ExtraGoals, VarSet, VarTypes)
 	).
 
 :- pred polymorphism__construct_type_info(type, type_id, list(type),
Index: library/std_util.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/std_util.m,v
retrieving revision 1.81
diff -u -r1.81 std_util.m
--- std_util.m	1997/04/28 12:12:12	1.81
+++ std_util.m	1997/04/29 06:31:30
@@ -730,21 +730,12 @@
 	Word	base_type_info_1, base_type_info_2;
 #endif
 
-	/* Test to see if either of the type_infos are null
-	 * pointers, which represent a free type variable
-	 * (see compiler/polymorphism.m for
-	 * an explanation of when that can happen).
-	 * We define the ordering so that free type variables precede
-	 * ground types (this choice is arbitrary).
-	 * Free type variables are considered to have been instantiated
-	 * to a single type, so two free type variables compare equal.
-	 */
+	/* 
+	** If type_infos are equal, they must represent the
+	** same type.
+	*/
 	 if (type_info_1 == type_info_2)
 		return COMPARE_EQUAL;
-	 if (type_info_1 == (Word) NULL)
-		return COMPARE_LESS;
-	 if (type_info_2 == (Word) NULL)
-		return COMPARE_GREATER;
 
 	/* Next find the addresses of the unify preds in the type_infos */
 
@@ -2343,8 +2334,6 @@
 	** instead of on the heap.
 	*/
 
-MR_DECLARE_STRUCT(mercury_data___base_type_info_void_0);
-
 Word * 
 create_type_info(Word *term_type_info, Word *arg_pseudo_type_info)
 {
@@ -2362,13 +2351,7 @@
 			term_type_info[(Word) arg_pseudo_type_info];
 	}
 
-		/* 
-		** If it's still a variable, make it a reference to 'void'.
-		*/
-	if (arg_pseudo_type_info == NULL) {
-		return (Word *) (Word) &mercury_data___base_type_info_void_0;
-	}
-	else if ((Word) arg_pseudo_type_info < TYPELAYOUT_MAX_VARINT) {
+	if ((Word) arg_pseudo_type_info < TYPELAYOUT_MAX_VARINT) {
 		fatal_error(""unbound type variable"");
 	}
 
@@ -2386,16 +2369,7 @@
 	for (i = 0; i <= arity; i++) {
 		if (arg_pseudo_type_info[i] < TYPELAYOUT_MAX_VARINT) {
 			type_info[i] = term_type_info[arg_pseudo_type_info[i]];
-
-			/* 
-			** If it's still a variable, make it a reference 
-			** to `void'.
-			*/
-			if ((Word *) type_info[i] == NULL) {
-				type_info[i] = (Word) 
-					&mercury_data___base_type_info_void_0;
-			}
-			else if (type_info[i] < TYPELAYOUT_MAX_VARINT) {
+			if (type_info[i] < TYPELAYOUT_MAX_VARINT) {
 				fatal_error(""unbound type variable"");
 			}
 
-- 
       Tyson Dowd           #
                            #             Sign on refrigerator:
     trd at cs.mu.oz.au        #           Refrigerate after opening. 
http://www.cs.mu.oz.au/~trd #                  - C. J. Owen.



More information about the developers mailing list