diff: fix for check_typeclass.m

David Glen JEFFERY dgj at cs.mu.OZ.AU
Thu May 21 16:55:13 AEST 1998


Hi,

Could someone please review this? (Fergus?)

--------------------------------------------------------------------------

Estimated hours taken: 4

Fix a variable renaming bug in the recently introduced changes to
check_typeclass.m.

compiler/check_typeclass.m:
	When adding constraints from the instance declaration to the
	generated predicate, rename them apart from the vars of the
	class declaration.

	This is only a concern where a class method uses type variables
	that are not parameters of the class, so was missed by the test
	cases.

Test case coming soon (as soon as I can cut it down a bit).

--------------------------------------------------------------------------

cvs diff: Diffing compiler
Index: compiler/check_typeclass.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/check_typeclass.m,v
retrieving revision 1.7
diff -u -t -r1.7 check_typeclass.m
--- check_typeclass.m	1998/05/20 17:57:48	1.7
+++ check_typeclass.m	1998/05/21 06:40:17
@@ -262,7 +262,7 @@
                 Info0, Info) :-
         InstanceDefn0 = hlds_instance_defn(A, InstanceConstraints,
                                 InstanceTypes, InstanceInterface,
-                                MaybeInstancePredProcs, E, F),
+                                MaybeInstancePredProcs, InstanceVarSet, F),
         Info0 = instance_method_info(ModuleInfo, PredName, PredArity, 
                 ArgTypes, ClassContext, ArgModes, Errors0, ArgTypeVars,
                 Status, PredOrFunc, Context),
@@ -278,7 +278,8 @@
                 ->
                         handle_instance_method_overloading(ClassVars, 
                                 InstanceTypes, InstanceConstraints, 
-                                InstancePredName, InstancePredIds,
+                                InstanceVarSet, 
+                                InstancePredName, InstancePredIds, 
                                 InstancePredId, InstanceProcIds, Info0, Info),
 
                         MakeClassProc = 
@@ -302,7 +303,8 @@
                         InstanceDefn = hlds_instance_defn(A,
                                         InstanceConstraints, InstanceTypes,
                                         InstanceInterface,
-                                        yes(InstancePredProcs), E, F)
+                                        yes(InstancePredProcs), InstanceVarSet,
+                                        F)
                 ;
                         InstanceDefn = InstanceDefn0,
                                 % XXX make a better error message
@@ -382,23 +384,27 @@
 :- type triple(T1, T2, T3) ---> triple(T1, T2, T3).
 
 :- pred handle_instance_method_overloading(list(var), 
-        list(type), list(class_constraint), sym_name, list(pred_id), 
+        list(type), list(class_constraint), varset, sym_name, list(pred_id), 
         pred_id, list(proc_id), instance_method_info, instance_method_info).
-:- mode handle_instance_method_overloading(in, in, in, in, in, out, out, 
+:- mode handle_instance_method_overloading(in, in, in, in, in, in, out, out, 
         in, out) is det.
 
 handle_instance_method_overloading(ClassVars, 
-                InstanceTypes, InstanceConstraints, InstancePredName,
-                InstancePredIds, InstancePredId, InstanceProcIds, 
-                Info0, Info) :-
+                InstanceTypes0, InstanceConstraints, InstanceVarSet,
+                InstancePredName, InstancePredIds, InstancePredId, 
+                InstanceProcIds, Info0, Info) :-
 
         Info0 = instance_method_info(ModuleInfo, PredName, PredArity, 
-                ArgTypes0, ClassContext0, ArgModes, Errors0, ArgTypeVars,
+                ArgTypes0, ClassContext0, ArgModes, Errors0, ArgTypeVars0,
                 Status, PredOrFunc, Context),
 
         module_info_get_predicate_table(ModuleInfo, PredicateTable),
         predicate_table_get_preds(PredicateTable, PredTable),
 
+        varset__merge_subst(ArgTypeVars0, InstanceVarSet, ArgTypeVars,
+                RenameSubst),
+        term__apply_substitution_to_list(InstanceTypes0,
+                RenameSubst, InstanceTypes),
         map__from_corresponding_lists(ClassVars,
                 InstanceTypes, TypeSubst),
         term__apply_substitution_to_list(ArgTypes0,
@@ -408,7 +414,7 @@
                 % constraints from the class method. This allows an instance
                 % method to have constraints on it which are part of the
                 % instance declaration as a whole.
-        apply_subst_to_constraints(TypeSubst, ClassContext0, ClassContext1),
+        apply_subst_to_constraints(RenameSubst, ClassContext0, ClassContext1),
         list__append(InstanceConstraints, ClassContext1, ClassContext),
 
         Info1 = instance_method_info(ModuleInfo, PredName, PredArity, 
cvs diff: Diffing compiler/notes





love and cuddles,
dgj
--
David Jeffery (dgj at cs.mu.oz.au) |  Marge: Did you just call everyone "chicken"?
MEngSc student,                 |  Homer: Noooo.  I swear on this Bible!
Department of Computer Science  |  Marge: That's not a Bible; that's a book of
University of Melbourne         |         carpet samples!
Australia                       |  Homer: Ooooh... Fuzzy.



More information about the developers mailing list