[mercury-users] unification and polymorphism

Peter Schachte pets at students.cs.mu.OZ.AU
Thu Aug 6 10:15:11 AEST 1998


On Wed, 5 Aug 1998, Fergus Henderson wrote:

> I think it would be nice if there was a compiler option that
> if enabled caused the compiler to specialize unifications of
> polymorphic data types if the type was known.  The compiler has
> all the necessary information to do this specialization, the
> only reason that it is not done is that no one has implemented
> it yet.

Maybe it would be good to bring back the old `fastcode' and `compactcode'
directives from DEC-10 Prolog.  It does seem useful to be able to coach the
compiler about which bits of code are used most.  In the context of Mercury,
you could interpret

	:- pragma fast_code.

as requesting that any polymorphic goals for which the types are known, up
to the next

	:- pragma compact_code.

declaration, should be specialized.  If this is being done, I suppose you
might as well specialize any other calls to the same predicates with the
same polymorphic types and in the same mode:  as long as you've generated
the code, you might as well make use of it!  Anyway, this would give
finer-grain control over the optimization than a switch which would have to
be turned on for a whole module or not at all.

This is going to be hard to implement for intermodule calls, though.

One way to cut down on code bloat:  share identical code.  E.g., the types

	:- type t1 ---> t1(int,int).
	:- type t2 == int.
	:- type t3 --> t3(t2,t2).

could share their unification and comparison code.  Maybe you already do
this?  Anyway, they could also share all specialized versions of polymorphic
predicates.


-Peter Schachte               | There's no left or right, just up and down.
mailto:pets at cs.mu.OZ.AU       | All the fat cats up there having a good
http://www.cs.mu.oz.au/~pets/ | time, while the rest of us are down here
PGP: finger pets at 128.250.37.3 | struggling to survive. -- Carolyn Chute 




More information about the users mailing list