[m-dev.] diff: fix another typeclass bug

Simon Taylor stayl at cs.mu.OZ.AU
Thu Aug 24 16:09:16 AEST 2000



Estimated hours taken: 1

Fix a bug in the handling of instances with unconstrained type
variables where a type variable occurs multiple times in the
instance declaration. The compiler was adding multiple copies
of the type_info for such variables to the typeclass_info.

compiler/type_util.m:
	Remove duplicates in the list of variables returned by
	`get_unconstrained_tvars/3'.

tests/hard_coded/Mmakefile:
tests/hard_coded/instance_unconstrained_tvar_dup.m:
tests/hard_coded/instance_unconstrained_tvar_dup.exp:
	Test case.


Index: compiler/type_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/type_util.m,v
retrieving revision 1.86
diff -u -u -r1.86 type_util.m
--- compiler/type_util.m	2000/08/10 05:11:05	1.86
+++ compiler/type_util.m	2000/08/23 10:06:29
@@ -1423,6 +1423,7 @@
 
 get_unconstrained_tvars(Tvars, Constraints, Unconstrained) :-
 	constraint_list_get_tvars(Constraints, ConstrainedTvars),
-	list__delete_elems(Tvars, ConstrainedTvars, Unconstrained).
+	list__delete_elems(Tvars, ConstrainedTvars, Unconstrained0),
+	list__remove_dups(Unconstrained0, Unconstrained).
 
 %-----------------------------------------------------------------------------%
Index: tests/hard_coded/typeclasses/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/typeclasses/Mmakefile,v
retrieving revision 1.31
diff -u -u -r1.31 Mmakefile
--- tests/hard_coded/typeclasses/Mmakefile	2000/08/24 05:59:34	1.31
+++ tests/hard_coded/typeclasses/Mmakefile	2000/08/24 06:03:43
@@ -24,6 +24,7 @@
 	implied_instance_poly \
 	impure_methods \
 	instance_unconstrained_tvar \
+	instance_unconstrained_tvar_dup \
 	inference_test \
 	inference_test_2 \
 	intermod_typeclass_bug \
@@ -67,6 +68,7 @@
 NO_TYPE_SPEC_FLAGS = --no-user-guided-type-specialisation \
 				--no-type-specialisation
 MCFLAGS-instance_unconstrained_tvar = $(NO_TYPE_SPEC_FLAGS)
+MCFLAGS-instance_unconstrained_tvar_dup = $(NO_TYPE_SPEC_FLAGS)
 MCFLAGS-typeclass_exist_method_2 = $(NO_TYPE_SPEC_FLAGS)
 
 #-----------------------------------------------------------------------------#
Index: tests/hard_coded/typeclasses/instance_unconstrained_tvar_dup.exp
===================================================================
RCS file: instance_unconstrained_tvar_dup.exp
diff -N instance_unconstrained_tvar_dup.exp
--- /dev/null	Thu Aug 24 16:05:01 2000
+++ instance_unconstrained_tvar_dup.exp	Thu Aug 24 09:00:52 2000
@@ -0,0 +1,3 @@
+[1, 2, 3]
+[4, 5, 6]
+
Index: tests/hard_coded/typeclasses/instance_unconstrained_tvar_dup.m
===================================================================
RCS file: instance_unconstrained_tvar_dup.m
diff -N instance_unconstrained_tvar_dup.m
--- /dev/null	Thu Aug 24 16:05:01 2000
+++ instance_unconstrained_tvar_dup.m	Thu Aug 24 16:03:13 2000
@@ -0,0 +1,40 @@
+% The code generated by the compiler of 11/6/2000 for this
+% test case gets a segmentation fault at runtime because
+% the compiler doesn't remove duplicates in the list of
+% unconstrained type variables for which it adds type-infos
+% to a typeclass-info. The predicate generated to call
+% write_list_pair for the instance `p(list(T), list(T))'
+% expects one type-info for `T' but was given two.
+%
+:- module instance_unconstrained_tvar_dup.
+
+:- interface.
+
+:- import_module io, list.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- typeclass p(T, U) where [
+	pred m(T, U, io__state, io__state),
+	mode m(in, in, di, uo) is det
+].
+
+:- instance p(list(T), list(T)) where [
+	pred(m/4) is write_list_pair
+].
+
+:- implementation.
+
+main -->
+	m([1,2,3], [4,5,6]),
+	io__nl.
+
+:- pred write_list_pair(list(T), list(U), io__state, io__state).
+:- mode write_list_pair(in, in, di, uo) is det.
+
+write_list_pair(T, U) -->
+	io__write(T),
+	io__nl,
+	io__write(U),
+	io__nl.
+
--------------------------------------------------------------------------
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