[m-rev.] For review: Use compare-representation for closure args

Ian MacLarty maclarty at cs.mu.OZ.AU
Sun Jul 25 15:31:20 AEST 2004


For review by Zoltan.

Estimated hours taken: 6
Branches: main

Fixed bug where the arguments of a closure were being compared normally, 
instead of having their representations compared. 

Also fixed some copy-paste errors in the comments for list.foldl3 and foldl4.

library/list.m
	Fixed comments for foldl3 and foldl4.

runtime/mercury_ho_call.c
	When comparing the arguments of a closure use
	MR_generic_compare_representation, instead of MR_generic_compare, since
	one of the arguments may itself be a closure.  Renamed
	MR_compare_closures to MR_compare_closures_representation to make it
	clear that the representation is being compared.

runtime/mercury_unify_compare_body.h
	Changed call to MR_compare_closure to 
	MR_compare_closure_representation.

tests/hard_coded/closure_arg_comparison.m
	Test the bug fix.  Before the fix this program would terminate with
	"Mercury runtime: attempt to compare higher-order terms".

tests/hard_coded/closure_arg_comparison.exp
	Expected output.

Index: library/list.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/list.m,v
retrieving revision 1.120
diff -u -u -r1.120 list.m
--- library/list.m	19 Jul 2004 04:36:12 -0000	1.120
+++ library/list.m	25 Jul 2004 05:03:44 -0000
@@ -520,7 +520,7 @@
 	in, di, uo, di, uo) is cc_multi.
 
 	% list__foldl3(Pred, List, !Acc1, !Acc2, !Acc3)
-	% Does the same job as list__foldl, but with two accumulators.
+	% Does the same job as list__foldl, but with three accumulators.
 	% (Although no more expressive than list__foldl, this is often
 	% a more convenient format, and a little more efficient).
 :- pred list__foldl3(pred(L, A1, A1, A2, A2, A3, A3), list(L),
@@ -539,7 +539,7 @@
 	in, in, out, in, out, di, uo) is cc_multi.
 
 	% list__foldl4(Pred, List, !Acc1, !Acc2, !Acc3, !Acc4)
-	% Does the same job as list__foldl, but with two accumulators.
+	% Does the same job as list__foldl, but with four accumulators.
 	% (Although no more expressive than list__foldl, this is often
 	% a more convenient format, and a little more efficient).
 :- pred list__foldl4(pred(L, A1, A1, A2, A2, A3, A3, A4, A4), list(L),
Index: runtime/mercury_ho_call.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_ho_call.c,v
retrieving revision 1.73
diff -u -u -r1.73 mercury_ho_call.c
--- runtime/mercury_ho_call.c	7 Jul 2004 07:11:12 -0000	1.73
+++ runtime/mercury_ho_call.c	23 Jul 2004 05:41:19 -0000
@@ -322,7 +322,8 @@
 static	MR_Word	MR_generic_unify(MR_TypeInfo type_info, MR_Word x, MR_Word y);
 static	MR_Word	MR_generic_compare_representation(MR_TypeInfo type_info,
 			MR_Word x, MR_Word y);
-static	MR_Word	MR_compare_closures(MR_Closure *x, MR_Closure *y);
+static	MR_Word	MR_compare_closures_representation(MR_Closure *x, 
+			MR_Closure *y);
 
 /*
 ** The called closure may contain only input arguments. The extra arguments
@@ -820,7 +821,7 @@
 }
 
 static	MR_Word
-MR_compare_closures(MR_Closure *x, MR_Closure *y)
+MR_compare_closures_representation(MR_Closure *x, MR_Closure *y)
 {
 	MR_Closure_Layout   *x_layout;
 	MR_Closure_Layout   *y_layout;
@@ -912,7 +913,7 @@
 		}
 
 		arg_type_info = x_arg_type_info;
-		result = MR_generic_compare(arg_type_info,
+		result = MR_generic_compare_representation(arg_type_info,
 				x->MR_closure_hidden_args_0[i],
 				y->MR_closure_hidden_args_0[i]);
 		if (result != MR_COMPARE_EQUAL) {
Index: runtime/mercury_unify_compare_body.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_unify_compare_body.h,v
retrieving revision 1.37
diff -u -u -r1.37 mercury_unify_compare_body.h
--- runtime/mercury_unify_compare_body.h	7 Jul 2004 07:11:19 -0000	1.37
+++ runtime/mercury_unify_compare_body.h	23 Jul 2004 05:40:45 -0000
@@ -697,7 +697,7 @@
                 int     result;
 
                 MR_save_transient_registers();
-                result = MR_compare_closures((MR_Closure *) x,
+                result = MR_compare_closures_representation((MR_Closure *) x,
                             (MR_Closure *) y);
                 MR_restore_transient_registers();
 
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.233
diff -u -u -r1.233 Mmakefile
--- tests/hard_coded/Mmakefile	28 Jun 2004 04:50:09 -0000	1.233
+++ tests/hard_coded/Mmakefile	23 Jul 2004 07:21:52 -0000
@@ -19,6 +19,7 @@
 	cc_multi_bug \
 	cc_nondet_disj \
 	checked_nondet_tailcall \
+	closure_arg_comparison \
 	closure_extension \
 	common_type_cast \
 	compare_spec \
Index: tests/hard_coded/closure_arg_comparison.exp
===================================================================
RCS file: tests/hard_coded/closure_arg_comparison.exp
diff -N tests/hard_coded/closure_arg_comparison.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/closure_arg_comparison.exp	23 Jul 2004 08:13:10 -0000
@@ -0,0 +1 @@
+'<'
Index: tests/hard_coded/closure_arg_comparison.m
===================================================================
RCS file: tests/hard_coded/closure_arg_comparison.m
diff -N tests/hard_coded/closure_arg_comparison.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/closure_arg_comparison.m	25 Jul 2004 05:07:40 -0000
@@ -0,0 +1,29 @@
+:- module closure_arg_comparison.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is cc_multi.
+
+:- implementation.
+
+:- import_module int.
+
+main(!IO) :-
+	compare_representation(R, p(q(1)), p(r(1))),
+	write(R, !IO),
+	nl(!IO).
+
+:- pred p(pred(int), int).
+:- mode p(pred(out) is det, out) is det.
+
+p(P, X) :- P(Y), X = Y+1.
+
+:- pred q(int::in, int::out) is det.
+
+q(X, X+4).
+
+:- pred r(int::in, int::out) is det.
+
+r(X, X+5).
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list