[m-dev.] for review: polymorphism.m: fix c_code typeclass_info types

Fergus Henderson fjh at cs.mu.OZ.AU
Sun May 21 16:57:48 AEST 2000


DJ, could you please review this change?

If it passes bootcheck, I think I'll go ahead and commit it, but you
might as well review it since you're currently modifying polymorphism.m.

----------

Estimated hours taken: 1

Fix a bug that broke tests/hard_coded/existential_type_classes in MLDS
grades.  The bug was that the typeclass_info type generated for pragma
c_code instructions was wrong: it was missing the `constraint' parameter.
This caused the MLDS code generator (specifically ml_gen_box_or_unbox_rval)
to insert an unnecessary cast, which in turn mean that the generated
rval was one that ml_gen_c_code_for_rval didn't know how to handle.

compiler/polymorphism.m:
	Change the code that generates types for typeclass_info
	variables in `pragma c_code' instructions so that it does so
	using `polymorphism__generate_typeclass_info_type', rather
	than hand-coding it, since the hand-coded version was wrong.
	Similarly, change a few places to use
	`polymorphism__build_type_info_type' to construct types for
	type_infos, rather than hand-coding it (in this case the
	hand-coding was OK, but the new code is more maintainable).

Workspace: /home/pgrad/fjh/ws/hg
Index: compiler/polymorphism.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/polymorphism.m,v
retrieving revision 1.185
diff -u -d -r1.185 polymorphism.m
--- compiler/polymorphism.m	2000/04/14 08:38:15	1.185
+++ compiler/polymorphism.m	2000/05/21 06:41:19
@@ -1459,16 +1459,11 @@
 	% insert type_info/typeclass_info types for all the inserted 
 	% type_info/typeclass_info vars into the arg-types list
 	%
-	mercury_private_builtin_module(PrivateBuiltin),
-	MakeType = lambda([TypeVar::in, TypeInfoType::out] is det,
-		construct_type(qualified(PrivateBuiltin, "type_info") - 1,
-			[term__variable(TypeVar)], TypeInfoType)),
-	list__map(MakeType, PredTypeVars, TypeInfoTypes),
-	MakeTypeClass = lambda([_::in, TypeClassInfoType::out] is det,
-		construct_type(qualified(PrivateBuiltin, "typeclass_info") - 0,
-			[], TypeClassInfoType)),
-	list__map(MakeTypeClass, UnivCs, UnivTypes),
-	list__map(MakeTypeClass, ExistCs, ExistTypes),
+	term__var_list_to_term_list(PredTypeVars, PredTypeVarTypes),
+	list__map(polymorphism__build_type_info_type, PredTypeVarTypes,
+		TypeInfoTypes),
+	list__map(polymorphism__build_typeclass_info_type, UnivCs, UnivTypes),
+	list__map(polymorphism__build_typeclass_info_type, ExistCs, ExistTypes),
 	list__append(TypeInfoTypes, OrigArgTypes0, OrigArgTypes1),
 	list__append(ExistTypes, OrigArgTypes1, OrigArgTypes2),
 	list__append(UnivTypes, OrigArgTypes2, OrigArgTypes).
@@ -2465,9 +2460,7 @@
 		% a type_info, we need to adjust its type.
 		% Since type_ctor_info_const cons_ids are handled
 		% specially, this should not cause problems.
-		mercury_private_builtin_module(MercuryBuiltin),
-		construct_type(qualified(MercuryBuiltin, "type_info") - 1,
-			[Type], NewBaseVarType),
+		polymorphism__build_type_info_type(Type, NewBaseVarType),
 		map__det_update(VarTypes0, BaseVar, NewBaseVarType, VarTypes),
 
 		VarSet = VarSet0,
@@ -2824,8 +2817,8 @@
 	construct_type(unqualified("int") - 0, [], IntType),
 
 	varset__new_var(DummyTVarSet1, DummyTVar, DummyTVarSet),
-	construct_type(qualified(PrivateBuiltin, "type_info") - 1,
-		[term__variable(DummyTVar)], TypeInfoType),
+	polymorphism__build_type_info_type(term__variable(DummyTVar),
+		TypeInfoType),
 	get_pred_id_and_proc_id(ExtractTypeInfo, predicate, DummyTVarSet, 
 		[TypeClassInfoType, IntType, TypeInfoType],
 		ModuleInfo, PredId, ProcId),

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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