[m-dev.] for review: specializing comparisons

Zoltan Somogyi zs at cs.mu.OZ.AU
Wed Nov 1 15:41:11 AEDT 2000


For review by anyone.

compiler/unify_proc.m:
	Generate specialized comparison predicates for types with less than
	four functors. This should speed up comparisons on such types, and
	since we can generate a dummy index predicate for such types, should
	not increase code size much, or at all. (Avoiding the generation of
	index predicates altogether for such types would be much harder
	to arrange.)

tests/hard_coded/comparison.{m,exp}:
	A test case for specialized comparisons.

tests/hard_coded/Mmakefile:
	Enable the test case, and sort the list of test cases.

Zoltan.

cvs diff: Diffing .
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/unify_proc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unify_proc.m,v
retrieving revision 1.90
diff -u -b -r1.90 unify_proc.m
--- compiler/unify_proc.m	2000/10/13 13:56:01	1.90
+++ compiler/unify_proc.m	2000/10/25 05:05:42
@@ -781,8 +781,40 @@
 			%
 			{ error("trying to create index proc for enum type") }
 		;
-			unify_proc__generate_du_index_clauses(Ctors, X, Index,
-				Context, 0, Clauses)
+			% For types with three or fewer functors, the
+			% comparison predicate doesn't call the index
+			% predicate, so we return a dummy clause.
+			% (Avoiding the generation of the whole index predicate
+			% would be preferable, but would also be more complex.)
+			(
+				{ Ctors = [] },
+				{ error("index for type with no functors") }
+			;
+				{ Ctors = [_] },
+				{ create_atomic_unification(Index,
+					functor(int_const(-1), []),
+					Context, explicit, [], Goal) },
+				unify_proc__quantify_clauses_body([Index],
+					Goal, Context, Clauses)
+			;
+				{ Ctors = [_, _] },
+				{ create_atomic_unification(Index,
+					functor(int_const(-1), []),
+					Context, explicit, [], Goal) },
+				unify_proc__quantify_clauses_body([Index],
+					Goal, Context, Clauses)
+			;
+				{ Ctors = [_, _, _] },
+				{ create_atomic_unification(Index,
+					functor(int_const(-1), []),
+					Context, explicit, [], Goal) },
+				unify_proc__quantify_clauses_body([Index],
+					Goal, Context, Clauses)
+			;
+				{ Ctors = [_, _, _, _ | _] },
+				unify_proc__generate_du_index_clauses(Ctors,
+					X, Index, Context, 0, Clauses)
+			)
 		)
 	;
 		{ TypeBody = eqv_type(_Type) },
@@ -843,9 +875,29 @@
 			unify_proc__quantify_clauses_body(ArgVars, Goal,
 				Context, Clauses)
 		;
-			unify_proc__generate_du_compare_clauses(Type, Ctors,
-				Res, H1, H2, Context, Clauses)
+			(
+				{ Ctors = [] },
+				{ error("compare for type with no functors") }
+			;
+				{ Ctors = [Ctor] },
+				unify_proc__generate_du_one_compare_clause(
+					Ctor, Res, H1, H2, Context, Clauses)
+			;
+				{ Ctors = [Ctor1, Ctor2] },
+				unify_proc__generate_du_two_compare_clauses(
+					Ctor1, Ctor2, Res, H1, H2,
+					Context, Clauses)
+			;
+				{ Ctors = [Ctor1, Ctor2, Ctor3] },
+				unify_proc__generate_du_three_compare_clauses(
+					Ctor1, Ctor2, Ctor3, Res, H1, H2,
+					Context, Clauses)
+			;
+				{ Ctors = [_, _, _, _ | _] },
+				unify_proc__generate_du_compare_clauses(Type,
+					Ctors, Res, H1, H2, Context, Clauses)
 		)
+		)
 	;
 		{ TypeBody = eqv_type(_) },
 		% We should check whether _Type is a type variable,
@@ -892,35 +944,33 @@
 	{ Clause = clause([], Body, Context) }.
 
 %-----------------------------------------------------------------------------%
-
-/*
-	For a type such as
 
-		type t(X) ---> a ; b(int) ; c(X); d(int, X, t)
+%	For a type such as
+%
+%		type t(X) ---> a ; b(int) ; c(X); d(int, X, t)
+%
+%	we want to generate code
+%
+%		eq(H1, H2) :-
+%			(
+%				H1 = a,
+%				H2 = a
+%			;
+%				H1 = b(X1),
+%				H2 = b(X2),
+%				X1 = X2,
+%			;
+%				H1 = c(Y1),
+%				H2 = c(Y2),
+%				Y1 = Y2,
+%			;
+%				H1 = d(A1, B1, C1),
+%				H2 = c(A2, B2, C2),
+%				A1 = A2,
+%				B1 = B2,
+%				C1 = C2
+%			).
 
-	we want to generate code
-
-		eq(H1, H2) :-
-			(
-				H1 = a,
-				H2 = a
-			;
-				H1 = b(X1),
-				H2 = b(X2),
-				X1 = X2,
-			;
-				H1 = c(Y1),
-				H2 = c(Y2),
-				Y1 = Y2,
-			;
-				H1 = d(A1, B1, C1),
-				H2 = c(A2, B2, C2),
-				A1 = A2,
-				B1 = B2,
-				C1 = C2
-			).
-*/
-
 :- pred unify_proc__generate_du_unify_clauses(list(constructor), prog_var,
 		prog_var, prog_context, list(clause),
 		unify_proc_info, unify_proc_info).
@@ -953,25 +1003,23 @@
 
 %-----------------------------------------------------------------------------%
 
-/*
-	For a type such as 
-
-		:- type foo ---> f ; g(a, b, c) ; h(foo).
-
-	we want to generate code
-
-		index(X, Index) :-
-			(
-				X = f,
-				Index = 0
-			;
-				X = g(_, _, _),
-				Index = 1
-			;
-				X = h(_),
-				Index = 2
-			).
-*/
+%	For a type such as 
+%
+%		:- type foo ---> f ; g(a, b, c) ; h(foo).
+%
+%	we want to generate code
+%
+%		index(X, Index) :-
+%			(
+%				X = f,
+%				Index = 0
+%			;
+%				X = g(_, _, _),
+%				Index = 1
+%			;
+%				X = h(_),
+%				Index = 2
+%			).
 
 :- pred unify_proc__generate_du_index_clauses(list(constructor), prog_var,
 		prog_var, prog_context, int, list(clause),
@@ -994,8 +1042,7 @@
 		UnifyIndex_Goal) },
 	{ GoalList = [UnifyX_Goal, UnifyIndex_Goal] },
 	{ goal_info_init(GoalInfo0) },
-	{ goal_info_set_context(GoalInfo0, Context,
-		GoalInfo) },
+	{ goal_info_set_context(GoalInfo0, Context, GoalInfo) },
 	{ conj_list_to_goal(GoalList, GoalInfo, Goal) },
 	unify_proc__quantify_clause_body([X, Index], Goal, Context, Clause),
 	{ N1 is N + 1 },
@@ -1004,43 +1051,155 @@
 
 %-----------------------------------------------------------------------------%
 
-/*	For a type such as 
+%	For a du type with one function symbol, such as 
+%
+%		:- type foo ---> f(a, b, c)
+%
+%   	we want to generate code
+%
+%		compare(Res, X, Y) :-
+%			X = f(X1, X2, X3), Y = f(Y1, Y2, Y3),
+%			( compare(R1, X1, Y1), R1 \= (=) ->
+%				R = R1
+%			; compare(R2, X2, Y2), R2 \= (=) ->
+%				R = R2
+%			; 
+%				compare(R, X3, Y3)
+%			)
 
-		:- type foo ---> f ; g(a) ; h(b, foo).
+:- pred unify_proc__generate_du_one_compare_clause(constructor::in,
+	prog_var::in, prog_var::in, prog_var::in,
+	prog_context::in, list(clause)::out,
+	unify_proc_info::in, unify_proc_info::out) is det.
 
-   	we want to generate code
+unify_proc__generate_du_one_compare_clause(Ctor, R, X, Y, Context, Clauses) -->
+	unify_proc__generate_compare_case(Ctor, R, X, Y, Context, Goal),
+	{ HeadVars = [R, X, Y] },
+	unify_proc__quantify_clauses_body(HeadVars, Goal, Context, Clauses).
 
-		compare(Res, X, Y) :-
-			__Index__(X, X_Index),	% Call_X_Index
-			__Index__(Y, Y_Index),	% Call_Y_Index
-			( X_Index < Y_Index ->	% Call_Less_Than
-				Res = (<)	% Return_Less_Than
-			; X_Index > Y_Index ->	% Call_Greater_Than
-				Res = (>)	% Return_Greater_Than
-			;
-				% This disjunction is generated by
-				% unify_proc__generate_compare_cases, below.
-				(
-					X = f, Y = f,
-					R = (=)
-				;
-					X = g(X1), Y = g(Y1),
-					compare(R, X1, Y1)
-				;
-					X = h(X1, X2), Y = h(Y1, Y2),
-					( compare(R1, X1, Y1), R1 \= (=) ->
-						R = R1
-					; 
-						compare(R, X2, Y2)
-					)
-				)
-			->
-				Res = R		% Return_R
-			;
-				compare_error 	% Abort
-			).
-*/
+%-----------------------------------------------------------------------------%
+
+%	For a du type with two or three function symbols, such as 
+%
+%		:- type foo ---> f(a) ; g(a, b, c)
+%
+%   	we want to generate code such as
+%
+%		compare(Res, X, Y) :-
+%			(
+%				X = f(X1),
+%				Y = f(Y1),
+%				compare(R, X1, Y1)
+%			;
+%				X = f(_),
+%				Y = g(_, _, _),
+%				R = (<)
+%			;
+%				X = g(_, _, _),
+%				Y = f(_),
+%				R = (>)
+%			;
+%				X = g(X1, X2, X3),
+%				Y = g(Y1, Y2, Y3),
+%				( compare(R1, X1, Y1), R1 \= (=) ->
+%					R = R1
+%				; compare(R2, X2, Y2), R2 \= (=) ->
+%					R = R2
+%				; 
+%					compare(R, X3, Y3)
+%				)
+%			)
+
+:- pred unify_proc__generate_du_two_compare_clauses(
+	constructor::in, constructor::in, prog_var::in, prog_var::in,
+	prog_var::in, prog_context::in, list(clause)::out,
+	unify_proc_info::in, unify_proc_info::out) is det.
+
+unify_proc__generate_du_two_compare_clauses(Ctor1, Ctor2, R, X, Y,
+		Context, Clauses) -->
+	unify_proc__generate_compare_case(Ctor1, R, X, Y, Context, Case11),
+	unify_proc__generate_compare_case(Ctor2, R, X, Y, Context, Case22),
+	unify_proc__generate_asymmetric_compare_case(Ctor1, Ctor2, "<",
+		R, X, Y, Context, Case12),
+	unify_proc__generate_asymmetric_compare_case(Ctor2, Ctor1, ">",
+		R, X, Y, Context, Case21),
+
+	{ goal_info_init(GoalInfo0) },
+	{ goal_info_set_context(GoalInfo0, Context, GoalInfo) },
+	{ map__init(Empty) },
+	{ Goal = disj([Case11, Case12, Case21, Case22], Empty) - GoalInfo },
+	{ HeadVars = [R, X, Y] },
+	unify_proc__quantify_clauses_body(HeadVars, Goal, Context, Clauses).
+
+:- pred unify_proc__generate_du_three_compare_clauses(
+	constructor::in, constructor::in, constructor::in,
+	prog_var::in, prog_var::in, prog_var::in, prog_context::in,
+	list(clause)::out, unify_proc_info::in, unify_proc_info::out) is det.
+
+unify_proc__generate_du_three_compare_clauses(Ctor1, Ctor2, Ctor3, R, X, Y,
+		Context, Clauses) -->
+	unify_proc__generate_compare_case(Ctor1, R, X, Y, Context, Case11),
+	unify_proc__generate_compare_case(Ctor2, R, X, Y, Context, Case22),
+	unify_proc__generate_compare_case(Ctor3, R, X, Y, Context, Case33),
+	unify_proc__generate_asymmetric_compare_case(Ctor1, Ctor2, "<",
+		R, X, Y, Context, Case12),
+	unify_proc__generate_asymmetric_compare_case(Ctor1, Ctor3, "<",
+		R, X, Y, Context, Case13),
+	unify_proc__generate_asymmetric_compare_case(Ctor2, Ctor3, "<",
+		R, X, Y, Context, Case23),
+	unify_proc__generate_asymmetric_compare_case(Ctor2, Ctor1, ">",
+		R, X, Y, Context, Case21),
+	unify_proc__generate_asymmetric_compare_case(Ctor3, Ctor1, ">",
+		R, X, Y, Context, Case31),
+	unify_proc__generate_asymmetric_compare_case(Ctor3, Ctor2, ">",
+		R, X, Y, Context, Case32),
+
+	{ goal_info_init(GoalInfo0) },
+	{ goal_info_set_context(GoalInfo0, Context, GoalInfo) },
+	{ map__init(Empty) },
+	{ Goal = disj([Case11, Case12, Case13, Case21, Case22, Case23,
+		Case31, Case32, Case33], Empty) - GoalInfo },
+	{ HeadVars = [R, X, Y] },
+	unify_proc__quantify_clauses_body(HeadVars, Goal, Context, Clauses).
 
+%-----------------------------------------------------------------------------%
+
+%	For a du type with four or more function symbols, such as 
+%
+%		:- type foo ---> f ; g(a) ; h(b, foo).
+%
+%   	we want to generate code
+%
+%		compare(Res, X, Y) :-
+%			__Index__(X, X_Index),	% Call_X_Index
+%			__Index__(Y, Y_Index),	% Call_Y_Index
+%			( X_Index < Y_Index ->	% Call_Less_Than
+%				Res = (<)	% Return_Less_Than
+%			; X_Index > Y_Index ->	% Call_Greater_Than
+%				Res = (>)	% Return_Greater_Than
+%			;
+%				% This disjunction is generated by
+%				% unify_proc__generate_compare_cases, below.
+%				(
+%					X = f, Y = f,
+%					R = (=)
+%				;
+%					X = g(X1), Y = g(Y1),
+%					compare(R, X1, Y1)
+%				;
+%					X = h(X1, X2), Y = h(Y1, Y2),
+%					( compare(R1, X1, Y1), R1 \= (=) ->
+%						R = R1
+%					; 
+%						compare(R, X2, Y2)
+%					)
+%				)
+%			->
+%				Res = R		% Return_R
+%			;
+%				compare_error 	% Abort
+%			).
+
 :- pred unify_proc__generate_du_compare_clauses((type)::in,
 	list(constructor)::in, prog_var::in, prog_var::in, prog_var::in,
 	prog_context::in, list(clause)::out,
@@ -1048,13 +1207,8 @@
 
 unify_proc__generate_du_compare_clauses(Type, Ctors, Res, X, Y, Context,
 		[Clause]) -->
-	( { Ctors = [SingleCtor] } ->
-		unify_proc__generate_compare_case(SingleCtor, Res, X, Y,
-			Context, Goal)
-	;
 		unify_proc__generate_du_compare_clauses_2(Type, Ctors, Res,
-			X, Y, Context, Goal)
-	),
+		X, Y, Context, Goal),
 	{ HeadVars = [Res, X, Y] },
 	unify_proc__quantify_clause_body(HeadVars, Goal, Context, Clause).
 
@@ -1119,31 +1273,29 @@
 		    ) - GoalInfo, Empty
 		) - GoalInfo
 	]) - GoalInfo }.
-
-/*	
-	unify_proc__generate_compare_cases: for a type such as 
 
-		:- type foo ---> f ; g(a) ; h(b, foo).
-
-   	we want to generate code
-		(
-			X = f,		% UnifyX_Goal
-			Y = f,		% UnifyY_Goal
-			R = (=)		% CompareArgs_Goal
-		;
-			X = g(X1),	
-			Y = g(Y1),
-			compare(R, X1, Y1)
-		;
-			X = h(X1, X2),
-			Y = h(Y1, Y2),
-			( compare(R1, X1, Y1), R1 \= (=) ->
-				R = R1
-			; 
-				compare(R, X2, Y2)
-			)
-		)
-*/
+%	unify_proc__generate_compare_cases: for a type such as 
+%
+%		:- type foo ---> f ; g(a) ; h(b, foo).
+%
+%   	we want to generate code
+%		(
+%			X = f,		% UnifyX_Goal
+%			Y = f,		% UnifyY_Goal
+%			R = (=)		% CompareArgs_Goal
+%		;
+%			X = g(X1),	
+%			Y = g(Y1),
+%			compare(R, X1, Y1)
+%		;
+%			X = h(X1, X2),
+%			Y = h(Y1, Y2),
+%			( compare(R1, X1, Y1), R1 \= (=) ->
+%				R = R1
+%			; 
+%				compare(R, X2, Y2)
+%			)
+%		)
 
 :- pred unify_proc__generate_compare_cases(list(constructor), prog_var,
 		prog_var, prog_var, prog_context, list(hlds_goal),
@@ -1179,35 +1331,62 @@
 		R, Context, CompareArgs_Goal),
 	{ GoalList = [UnifyX_Goal, UnifyY_Goal, CompareArgs_Goal] },
 	{ goal_info_init(GoalInfo0) },
-	{ goal_info_set_context(GoalInfo0, Context,
-		GoalInfo) },
+	{ goal_info_set_context(GoalInfo0, Context, GoalInfo) },
 	{ conj_list_to_goal(GoalList, GoalInfo, Case) }.
-
-/*	unify_proc__compare_args: for a constructor such as
-
-		h(list(int), foo, string)
-
-	we want to generate code
 
-		(
-			compare(R1, X1, Y1),	% Do_Comparison
-			R1 \= (=)		% Check_Not_Equal
-		->
-			R = R1			% Return_R1
-		;
-			compare(R2, X2, Y2),
-			R2 \= (=)
-		->
-			R = R2
-		; 
-			compare(R, X3, Y3)	% Return_Comparison
-		)
-
-	For a constructor with no arguments, we want to generate code
+:- pred unify_proc__generate_asymmetric_compare_case(constructor::in,
+	constructor::in, string::in, prog_var::in, prog_var::in, prog_var::in,
+	prog_context::in, hlds_goal::out,
+	unify_proc_info::in, unify_proc_info::out) is det.
 
-		R = (=)		% Return_Equal
+unify_proc__generate_asymmetric_compare_case(Ctor1, Ctor2, CompareOp, R, X, Y,
+		Context, Case) -->
+	{ Ctor1 = ctor(ExistQTVars1, _Constraints1, FunctorName1, ArgTypes1) },
+	{ Ctor2 = ctor(ExistQTVars2, _Constraints2, FunctorName2, ArgTypes2) },
+	{ list__length(ArgTypes1, FunctorArity1) },
+	{ list__length(ArgTypes2, FunctorArity2) },
+	{ FunctorConsId1 = cons(FunctorName1, FunctorArity1) },
+	{ FunctorConsId2 = cons(FunctorName2, FunctorArity2) },
+	unify_proc__make_fresh_vars(ArgTypes1, ExistQTVars1, Vars1),
+	unify_proc__make_fresh_vars(ArgTypes2, ExistQTVars2, Vars2),
+	{ create_atomic_unification(
+		X, functor(FunctorConsId1, Vars1), Context, explicit, [], 
+		UnifyX_Goal) },
+	{ create_atomic_unification(
+		Y, functor(FunctorConsId2, Vars2), Context, explicit, [], 
+		UnifyY_Goal) },
+	{ create_atomic_unification(
+		R, functor(cons(unqualified(CompareOp), 0), []),
+			Context, explicit, [], 
+		ReturnResult) },
+	{ GoalList = [UnifyX_Goal, UnifyY_Goal, ReturnResult] },
+	{ goal_info_init(GoalInfo0) },
+	{ goal_info_set_context(GoalInfo0, Context, GoalInfo) },
+	{ conj_list_to_goal(GoalList, GoalInfo, Case) }.
 
-*/
+%	unify_proc__compare_args: for a constructor such as
+%
+%		h(list(int), foo, string)
+%
+%	we want to generate code
+%
+%		(
+%			compare(R1, X1, Y1),	% Do_Comparison
+%			R1 \= (=)		% Check_Not_Equal
+%		->
+%			R = R1			% Return_R1
+%		;
+%			compare(R2, X2, Y2),
+%			R2 \= (=)
+%		->
+%			R = R2
+%		; 
+%			compare(R, X3, Y3)	% Return_Comparison
+%		)
+%
+%	For a constructor with no arguments, we want to generate code
+%
+%		R = (=)		% Return_Equal
 
 :- pred unify_proc__compare_args(list(constructor_arg), existq_tvars,
 		list(prog_var), list(prog_var), prog_var, prog_context,
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/xml
cvs diff: Diffing library
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/hard_coded
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.97
diff -u -b -r1.97 Mmakefile
--- tests/hard_coded/Mmakefile	2000/10/31 02:01:19	1.97
+++ tests/hard_coded/Mmakefile	2000/11/01 04:31:17
@@ -15,12 +15,13 @@
 	boyer \
 	c_write_string \
 	cc_and_non_cc_test \
-	cc_nondet_disj \
 	cc_multi_bug \
+	cc_nondet_disj \
 	checked_nondet_tailcall \
 	closure_extension \
 	common_type_cast \
 	compare_spec \
+	comparison \
 	construct \
 	copy_pred \
 	curry \
@@ -34,14 +35,14 @@
 	division_test \
 	dupcall_types_bug \
 	elim_special_pred \
+	eqv_type_bug \
+	erroneous_liveness \
+	error_func \
 	existential_bound_tvar \
 	existential_float \
 	existential_reordering \
 	existential_type_switch_opt \
 	existential_types_test \
-	eqv_type_bug \
-	error_func \
-	erroneous_liveness \
 	expand \
 	export_test \
 	factt \
@@ -67,8 +68,8 @@
 	ho_univ_to_type \
 	impossible_unify \
 	impure_prune \
-	integer_test \
 	inline_nondet_pragma_c \
+	integer_test \
 	merge_and_remove_dups \
 	minint_bug \
 	mode_choice \
@@ -80,9 +81,9 @@
 	nondet_ctrl_vn \
 	nullary_ho_func \
 	pragma_c_code \
-	pragma_inline \
-	pragma_import \
 	pragma_export \
+	pragma_import \
+	pragma_inline \
 	qual_adv_test \
 	qual_basic_test \
 	qual_is_test \
@@ -107,10 +108,11 @@
 	term_io_test \
 	test_imported_no_tag \
 	tim_qual1 \
-	type_qual \
-	type_to_term_bug \
 	tuple_test \
+	tuple_test \
+	type_qual \
 	type_spec_modes \
+	type_to_term_bug \
 	user_defined_equality \
 	user_defined_equality2 \
 	write \
Index: tests/hard_coded/comparison.exp
===================================================================
RCS file: comparison.exp
diff -N comparison.exp
--- /dev/null	Wed Jul 26 16:10:00 2000
+++ comparison.exp	Sun Oct 22 18:32:47 2000
@@ -0,0 +1,24 @@
+a1(10, 20) < a1(10, 21)
+a1(10, 20) = a1(10, 20)
+a1(10, 20) > a1(9, 20)
+a2(10, 20) > a2(10, 19)
+a2(10, 20) = a2(10, 20)
+a2(10, 20) < a2(11, 20)
+a2(10, 20) < b2(10)
+b2(30) > a2(50, 40)
+b2(30) > b2(29)
+b2(30) = b2(30)
+b2(30) < b2(31)
+a3(10, 20) > a3(10, 19)
+a3(10, 20) = a3(10, 20)
+a3(10, 20) < a3(11, 20)
+a3(10, 20) < b3(10)
+a3(10, 20) < c3
+b3(30) > a3(50, 40)
+b3(30) > b3(29)
+b3(30) = b3(30)
+b3(30) < b3(31)
+b3(30) < c3
+c3 > a3(50, 40)
+c3 > b3(50)
+c3 = c3
Index: tests/hard_coded/comparison.m
===================================================================
RCS file: comparison.m
diff -N comparison.m
--- /dev/null	Wed Jul 26 16:10:00 2000
+++ comparison.m	Sun Oct 22 15:04:53 2000
@@ -0,0 +1,68 @@
+% This is a test to check the correctness of the way we handle specialized
+% comparison predicates for types with three or fewer function symbols.
+
+:- module comparison.
+
+:- interface.
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+:- import_module list, std_util, exception.
+
+:- type t1 ---> a1(int, int).
+
+:- type t2 ---> a2(int, int) ; b2(int).
+
+:- type t3 ---> a3(int, int) ; b3(int) ; c3.
+
+main -->
+	perform_comparison_test(a1(10, 20), a1(10, 21)),
+	perform_comparison_test(a1(10, 20), a1(10, 20)),
+	perform_comparison_test(a1(10, 20), a1( 9, 20)),
+
+	perform_comparison_test(a2(10, 20), a2(10, 19)),
+	perform_comparison_test(a2(10, 20), a2(10, 20)),
+	perform_comparison_test(a2(10, 20), a2(11, 20)),
+	perform_comparison_test(a2(10, 20), b2(10)),
+
+	perform_comparison_test(b2(30), a2(50, 40)),
+	perform_comparison_test(b2(30), b2(29)),
+	perform_comparison_test(b2(30), b2(30)),
+	perform_comparison_test(b2(30), b2(31)),
+
+	perform_comparison_test(a3(10, 20), a3(10, 19)),
+	perform_comparison_test(a3(10, 20), a3(10, 20)),
+	perform_comparison_test(a3(10, 20), a3(11, 20)),
+	perform_comparison_test(a3(10, 20), b3(10)),
+	perform_comparison_test(a3(10, 20), c3),
+
+	perform_comparison_test(b3(30), a3(50, 40)),
+	perform_comparison_test(b3(30), b3(29)),
+	perform_comparison_test(b3(30), b3(30)),
+	perform_comparison_test(b3(30), b3(31)),
+	perform_comparison_test(b3(30), c3),
+
+	perform_comparison_test(c3, a3(50, 40)),
+	perform_comparison_test(c3, b3(50)),
+	perform_comparison_test(c3, c3).
+
+:- pred perform_comparison_test(T::in, T::in, io__state::di, io__state::uo)
+	is det.
+
+perform_comparison_test(X, Y) -->
+	{ compare(R, X, Y) },
+	io__write(X),
+	(
+		{ R = (<) },
+		io__write_string(" < ")
+	;
+		{ R = (=) },
+		io__write_string(" = ")
+	;
+		{ R = (>) },
+		io__write_string(" > ")
+	),
+	io__write(Y),
+	io__write_string("\n").
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing trax
cvs diff: Diffing trial
cvs diff: Diffing util
--------------------------------------------------------------------------
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