[m-rev.] Handle polymorphic inequality goals

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Oct 24 17:28:00 AEST 2002


On 24-Oct-2002, Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> Estimated hours taken: 32
> Branches: main
> 
> Simplification now applies the following transformations on the
> builtin inequalities:
> 
> 	X  < Y	--->	some [R] (compare(R, X, Y), R  = (<))
> 	X =< Y	--->	some [R] (compare(R, X, Y), R \= (>))
> 	X >  Y	--->	some [R] (compare(R, X, Y), R  = (>))
> 	X >= Y	--->	some [R] (compare(R, X, Y), R \= (<))
> 
> compiler/add_heap_ops.m:
> compiler/add_trail_ops.m:
> compiler/table_gen.m:
> 	Added `only_mode' argument to calls to
> 	goal_util__generate_simple_call which now has an extra parameter.
> 
> compiler/builtin_ops.m:
> 	Removed builtin translations for int and float inequalities, since
> 	these should now be handled by specialisation of calls to compare/3.

Hmm.  Is the compiler really still capable of generating efficient code
for `X < 42'?

It would need to do a quite complicated set of transformations:

	X =< Y

==> (via your change to simplification)

 	some [R] (compare(R, X, Y), R \= (>))

==> (via specialization)

 	some [R] (
		builtin_compare_int(R, X, Y),
		R \= (>))
	)

==> (via inlining)

 	some [R] (
		( X < Y ->
			R = (<)
		; X = Y ->
			R = (=)
		;
			R = (>)
		),
		\+ (R = (>))
	)

==> (how???)

	\+ builtin_int_gt(X, Y)


Also, isn't there a problem with int:(X < Y) calling builtin__compare
calling private_builtin__builtin_compare_int calling int:(X < Y)??

> library/integer.m:
> library/rational.m:
> 	Fully qualified calls to the integer and rational inequalities.

Isn't this change going to break any user code which uses `<' or similar
on `integer' and `rational' types?

If so, then it sounds to me like the cure may be worse than the disease.

> Index: library/integer.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/library/integer.m,v
> retrieving revision 1.9
> diff -u -r1.9 integer.m
> --- library/integer.m	29 Aug 2002 10:09:07 -0000	1.9
> +++ library/integer.m	3 Oct 2002 08:58:20 -0000
> @@ -1054,7 +1054,9 @@
>   
>  %:- func integer__int(integer) = int.
>  integer__int(Integer) = Int :-
> -    ( Integer >= integer(int__min_int), Integer =< integer(int__max_int) ->
> +    (   integer:'>='(Integer, integer(int__min_int)),
> +        integer:'=<'(Integer, integer(int__max_int))
> +    ->

":" should not be used for module qualification.
Use "__" instead, and preferably infix rather than prefix,
 e.g.  "Integer `'integer__>='` integer(int__min_int)".

This syntax is horrible.  It makes the `integer' and `rational' types
very painful to use.  I'd rather we make changes which make it easier
to use `integer' and `rational' and harder to use `int' and `float'
than vice versa.

Also, the layout here does not match our coding guidelines.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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