for review: multiple constraints on instance

David Glen JEFFERY dgj at cs.mu.OZ.AU
Sun Feb 28 17:31:03 AEDT 1999


Hi,

Could you please review this, Fergus?

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

Estimated hours taken: 25

Fix a bug whereby the @#$!% typeclass-infos nested inside another 
typeclass-info (ie. from the constraints on an instance decl) were being
inserted in the reverse order. This caused the code to jump to the wrong
type class method.

compiler/polymorphism.m:
	Reverse the list of argument variables that we get back from
	polymorphism__make_typeclass_info_vars_2 because they are built
	up in reverse.

	Also fix a buggy comment about the order that the extra arguments
	are added in by this pass.

tests/hard_coded/typeclasses/implied_instance_multi_constraint.{m, exp}:
	A test case for this bug fix.
tests/hard_coded/typeclasses/Mmakefile:
	Add this test case.

cvs diff: Diffing .
Index: polymorphism.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/polymorphism.m,v
retrieving revision 1.158
diff -u -t -r1.158 polymorphism.m
--- polymorphism.m	1998/12/06 23:44:24	1.158
+++ polymorphism.m	1999/02/28 06:16:48
@@ -294,10 +294,10 @@
 % The argument passing convention is that the new parameters
 % introduced by this pass are placed in the following order:
 %
-%       First the UnivTypeClassInfos (for universally quantified constraints)
-%       then the ExistTypeClassInfos (for existentially quantified constraints)
-%       then the UnivTypeInfos (for universally quantified type variables)
+%       First the UnivTypeInfos (for universally quantified type variables)
 %       then the ExistTypeInfos (for existentially quantified type variables)
+%       then the UnivTypeClassInfos (for universally quantified constraints)
+%       then the ExistTypeClassInfos (for existentially quantified constraints)
 %       and finally the original arguments of the predicate.
 %
 %-----------------------------------------------------------------------------%
@@ -1826,9 +1826,14 @@
                         polymorphism__make_typeclass_info_vars_2(
                                 InstanceConstraints,
                                 ExistQVars, Context,
-                                [], InstanceExtraTypeClassInfoVars, 
+                                [], InstanceExtraTypeClassInfoVars0, 
                                 ExtraGoals0, ExtraGoals1, 
                                 Info1, Info2),
+                        
+                                % The variables are built up in 
+                                % reverse order.
+                        list__reverse(InstanceExtraTypeClassInfoVars0,
+                                InstanceExtraTypeClassInfoVars),
 
                         polymorphism__construct_typeclass_info(
                                 InstanceExtraTypeInfoVars, 
cvs diff: Diffing notes


cvs diff: Diffing .
cvs diff: Diffing sub-modules
cvs diff: Diffing typeclasses
Index: typeclasses/Mmakefile
===================================================================
RCS file: /home/staff/zs/imp/tests/hard_coded/typeclasses/Mmakefile,v
retrieving revision 1.14
diff -u -t -r1.14 Mmakefile
--- Mmakefile	1999/02/12 04:19:22	1.14
+++ Mmakefile	1999/02/28 06:26:45
@@ -13,6 +13,7 @@
         extra_typeinfo \
         ho_map \
         implied_instance \
+        implied_instance_multi_constraint \
         implied_instance_poly \
         inference_test \
         inference_test_2 \
cvs diff: typeclasses/implied_instance_multi_constraint.exp is a new entry, no comparison available
cvs diff: typeclasses/implied_instance_multi_constraint.m is a new entry, no comparison available



New file: implied_instance_multi_constraint.m:
===================================================================
:- module implied_instance_multi_constraint.

:- interface.

:- import_module io.

:- pred main(io__state::di, io__state::uo) is det.

:- implementation.

:- typeclass a(T) where [
	pred a(T::in, io__state::di, io__state::uo) is det
].
:- typeclass b(T) where [
	pred b(T::in, io__state::di, io__state::uo) is det
].
:- typeclass c(T) where [
	pred c(T::in, io__state::di, io__state::uo) is det
].
:- typeclass d(T) where [
	pred d(T::in, io__state::di, io__state::uo) is det
].

:- type foo(A, B, C) ---> foo(A, B, C).

:- instance a(int) where [
	pred(a/3) is int_a
].

:- instance b(int) where [
	pred(b/3) is int_b
].

:- instance c(int) where [
	pred(c/3) is int_c
].

:- instance d(foo(A, B, C)) <= (a(A), b(B), c(C)) where [
	pred(d/3) is my_d
].

:- pred my_d(foo(A, B, C), io__state, io__state) <= (a(A), b(B), c(C)).
:- mode my_d(in, di, uo) is det.

my_d(foo(A, B, C)) -->
	a(A),
	b(B),
	c(C).

:- pred int_a(int::in, io__state::di, io__state::uo) is det.
int_a(_) --> io__write_string("A\n").
:- pred int_b(int::in, io__state::di, io__state::uo) is det.
int_b(_) --> io__write_string("B\n").
:- pred int_c(int::in, io__state::di, io__state::uo) is det.
int_c(_) --> io__write_string("C\n").

main -->
	d(foo(7, 42, 69)).

New file: implied_instance_multi_constraint.exp:
===================================================================
A
B
C
----------------------------------------------------------------------------


dgj
-- 
David Jeffery (dgj at cs.mu.oz.au) |  Marge: Homer, is this how you pictured
PhD student,                    |         married life?
Dept. of Comp. Sci. & Soft. Eng.|  Homer: Yup, pretty much... except we
The University of Melbourne     |         drove around in a van solving
Australia                       |         mysteries.



More information about the developers mailing list