for review: expand equivalence types in typeclass contexts

David Glen JEFFERY dgj at cs.mu.oz.au
Wed Jan 14 15:32:50 AEDT 1998


Hi,

Tom, can you please review this?


Estimated hours taken: 2

Bug fix: equivalence types were not being expanded inside typeclasses or
instance declarations, nor in class contexts for preds or funcs.

compiler/equiv_type.m
	Expand equivalence types in class contexts and typeclass and instance
	decls.

Index: compiler/equiv_type.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/equiv_type.m,v
retrieving revision 1.12
diff -u -r1.12 equiv_type.m
--- equiv_type.m	1998/01/13 09:58:50	1.12
+++ equiv_type.m	1998/01/14 03:44:39
@@ -114,28 +114,55 @@
 
 equiv_type__replace_in_item(
 		pred(VarSet0, PredName, TypesAndModes0, 
-			Det, Cond, Purity, ClassContext),
+			Det, Cond, Purity, ClassContext0),
 		EqvMap,
 		pred(VarSet, PredName, TypesAndModes, 
 			Det, Cond, Purity, ClassContext),
 		no) :-
-	equiv_type__replace_in_tms(TypesAndModes0, VarSet0, EqvMap, 
+	equiv_type__replace_in_class_constraints(ClassContext0, VarSet0, 
+				EqvMap, ClassContext, VarSet1),
+	equiv_type__replace_in_tms(TypesAndModes0, VarSet1, EqvMap, 
 					TypesAndModes, VarSet).
 
 equiv_type__replace_in_item(
 			func(VarSet0, PredName, TypesAndModes0, 
 				RetTypeAndMode0, Det, Cond, Purity,
-				ClassContext),
+				ClassContext0),
 			EqvMap,
 			func(VarSet, PredName, TypesAndModes, 
 				RetTypeAndMode, Det, Cond, Purity,
 				ClassContext),
 			no) :-
-	equiv_type__replace_in_tms(TypesAndModes0, VarSet0, EqvMap,
-				TypesAndModes, VarSet1),
-	equiv_type__replace_in_tm(RetTypeAndMode0, VarSet1, EqvMap,
+	equiv_type__replace_in_class_constraints(ClassContext0, VarSet0, 
+				EqvMap, ClassContext, VarSet1),
+	equiv_type__replace_in_tms(TypesAndModes0, VarSet1, EqvMap,
+				TypesAndModes, VarSet2),
+	equiv_type__replace_in_tm(RetTypeAndMode0, VarSet2, EqvMap,
 				RetTypeAndMode, VarSet).
 
+equiv_type__replace_in_item(
+			typeclass(Constraints0, ClassName, Vars, 
+				ClassInterface0, VarSet0),
+			EqvMap,
+			typeclass(Constraints, ClassName, Vars, 
+				ClassInterface, VarSet),
+			no) :-
+	equiv_type__replace_in_class_constraints(Constraints0, VarSet0, 
+				EqvMap, Constraints, VarSet),
+	equiv_type__replace_in_class_interface(ClassInterface0,
+				EqvMap, ClassInterface).
+
+equiv_type__replace_in_item(
+			instance(Constraints0, ClassName, Ts0, 
+				InstanceInterface, VarSet0),
+			EqvMap,
+			instance(Constraints, ClassName, Ts, 
+				InstanceInterface, VarSet),
+			no) :-
+	equiv_type__replace_in_class_constraints(Constraints0, VarSet0, 
+				EqvMap, Constraints, VarSet1),
+	equiv_type__replace_in_type_list(Ts0, VarSet1, EqvMap, Ts, VarSet, _).
+
 :- pred equiv_type__replace_in_type_defn(type_defn, tvarset, eqv_map,
 					type_defn, tvarset, bool).
 :- mode equiv_type__replace_in_type_defn(in, in, in, out, out, out) is semidet.
@@ -154,6 +181,79 @@
 			EqvMap, du_type(TName, TArgs, TBody, EqPred), VarSet,
 			no) :-
 	equiv_type__replace_in_du(TBody0, VarSet0, EqvMap, TBody, VarSet).
+
+%-----------------------------------------------------------------------------%
+
+:- pred equiv_type__replace_in_class_constraints(list(class_constraint), 
+			varset, eqv_map, list(class_constraint), varset).
+:- mode equiv_type__replace_in_class_constraints(in, in, in, out, out) is det.
+
+equiv_type__replace_in_class_constraints([], VarSet, _, [], VarSet).
+equiv_type__replace_in_class_constraints([C0|C0s], VarSet0, EqvMap, 
+				[C|Cs], VarSet) :-
+	equiv_type__replace_in_class_constraint(C0, VarSet0, EqvMap, C,
+		VarSet1),
+	equiv_type__replace_in_class_constraints(C0s, VarSet1, EqvMap, Cs, 
+		VarSet).
+
+:- pred equiv_type__replace_in_class_constraint(class_constraint, varset, 
+					eqv_map, class_constraint, varset).
+:- mode equiv_type__replace_in_class_constraint(in, in, in, out, out) is det.
+
+equiv_type__replace_in_class_constraint(Constraint0, VarSet0, EqvMap,
+				Constraint, VarSet) :-
+	Constraint0 = constraint(ClassName, Ts0),
+	equiv_type__replace_in_type_list(Ts0, VarSet0, EqvMap, Ts, VarSet, _),
+	Constraint = constraint(ClassName, Ts).
+
+%-----------------------------------------------------------------------------%
+
+:- pred equiv_type__replace_in_class_interface(class_interface,
+					eqv_map, class_interface).
+:- mode equiv_type__replace_in_class_interface(in, in, out) is det.
+
+equiv_type__replace_in_class_interface(ClassInterface0, EqvMap,
+				ClassInterface) :-
+	list__map(equiv_type__replace_in_class_method(EqvMap),
+		ClassInterface0, ClassInterface).
+
+:- pred equiv_type__replace_in_class_method(eqv_map, class_method, 
+					class_method).
+:- mode equiv_type__replace_in_class_method(in, in, out) is det.
+
+equiv_type__replace_in_class_method(EqvMap,
+			pred(VarSet0, PredName, TypesAndModes0, 
+				Det, Cond, ClassContext0, Context),
+			pred(VarSet, PredName, TypesAndModes, 
+				Det, Cond, ClassContext, Context)
+			) :-
+	equiv_type__replace_in_class_constraints(ClassContext0, VarSet0, 
+				EqvMap, ClassContext, VarSet1),
+	equiv_type__replace_in_tms(TypesAndModes0, VarSet1, EqvMap, 
+					TypesAndModes, VarSet).
+
+equiv_type__replace_in_class_method(EqvMap,
+			func(VarSet0, PredName, TypesAndModes0, 
+				RetTypeAndMode0, Det, Cond,
+				ClassContext0, Context),
+			func(VarSet, PredName, TypesAndModes, 
+				RetTypeAndMode, Det, Cond,
+				ClassContext, Context)
+			) :-
+	equiv_type__replace_in_class_constraints(ClassContext0, VarSet0, 
+				EqvMap, ClassContext, VarSet1),
+	equiv_type__replace_in_tms(TypesAndModes0, VarSet1, EqvMap,
+				TypesAndModes, VarSet2),
+	equiv_type__replace_in_tm(RetTypeAndMode0, VarSet2, EqvMap,
+				RetTypeAndMode, VarSet).
+
+equiv_type__replace_in_class_method(_,
+			pred_mode(A,B,C,D,E,F),
+			pred_mode(A,B,C,D,E,F)).
+
+equiv_type__replace_in_class_method(_, 
+			func_mode(A,B,C,D,E,F,G),
+			func_mode(A,B,C,D,E,F,G)).
 
 %-----------------------------------------------------------------------------%
 


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