[m-dev.] diff: fix bug in type specialization

Simon Taylor stayl at cs.mu.OZ.AU
Fri Oct 27 16:01:43 AEDT 2000



Estimated hours taken: 1

Fix a bug in type specialization which caused no-tag types
with user-defined equality to be specialized incorrectly.

compiler/higher_order.m:
	Check for user-defined equality before unwrapping
	a no-tag type.

tests/hard_coded/Mmakefile:
tests/hard_coded/user_defined_equality.{m,exp}:
	Test case.



Index: compiler/higher_order.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/higher_order.m,v
retrieving revision 1.78
diff -u -u -r1.78 higher_order.m
--- compiler/higher_order.m	2000/10/18 03:11:03	1.78
+++ compiler/higher_order.m	2000/10/25 15:08:09
@@ -1838,6 +1838,8 @@
 		type_is_no_tag_type(ModuleInfo, SpecialPredType, 
 			Constructor, WrappedType),
 		\+ type_has_user_defined_equality_pred(ModuleInfo,
+			SpecialPredType, _),
+		\+ type_has_user_defined_equality_pred(ModuleInfo,
 			WrappedType, _),
 
 		% This could be done for non-atomic types, but it would
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.94
diff -u -u -r1.94 Mmakefile
--- tests/hard_coded/Mmakefile	2000/10/26 03:31:56	1.94
+++ tests/hard_coded/Mmakefile	2000/10/27 04:58:36
@@ -110,6 +110,7 @@
 	type_to_term_bug \
 	tuple_test \
 	user_defined_equality \
+	user_defined_equality2 \
 	write \
 	write_reg1
 
Index: tests/hard_coded/user_defined_equality2.exp
===================================================================
RCS file: user_defined_equality2.exp
diff -N user_defined_equality2.exp
--- /dev/null	Fri Oct 27 15:49:45 2000
+++ user_defined_equality2.exp	Fri Oct 27 15:54:36 2000
@@ -0,0 +1 @@
+yes
Index: tests/hard_coded/user_defined_equality2.m
===================================================================
RCS file: user_defined_equality2.m
diff -N user_defined_equality2.m
--- /dev/null	Fri Oct 27 15:49:45 2000
+++ user_defined_equality2.m	Fri Oct 27 15:53:30 2000
@@ -0,0 +1,35 @@
+% This is a regression test.
+%
+% The Mercury compiler of 27/10/2000 failed this test
+% due to overeager specialization of unifications
+% involving no-tag types with user-defined equality.
+
+:- module user_defined_equality2.
+:- interface.
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is cc_multi.
+
+:- implementation.
+
+:- import_module std_util.
+
+:- type foo ---> foo(int)
+	where equality is foo_equal.
+
+:- pred foo_equal(foo::in, foo::in) is semidet.
+
+foo_equal(_, _) :-
+	semidet_succeed.
+
+main -->
+	( { unify_no_tag(foo(1), foo(2)) } ->
+		io__write_string("yes\n")
+	;
+		io__write_string("no\n")
+	).
+
+:- pred unify_no_tag(T::in, T::in) is semidet.
+:- pragma type_spec(unify_no_tag/2, T = foo).
+
+unify_no_tag(T, T).
--------------------------------------------------------------------------
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