[mercury-users] Automatic Recognition of Uniqueness

Fergus Henderson fjh at cs.mu.OZ.AU
Sat Sep 12 15:19:56 AEST 1998


On 10-Sep-1998, Ralph Becket <rwab1 at cam.sri.com> wrote:
> Maurice Bruynooghe wrote on 10 Sep:
> > > 
> > > 	:- pred append(list(T), list(T), list(T)).
> > > 	:- mode append(di, di, uo) is det.
> > 
> > In Leuven, work is going on about the feasibility of an analysis which
> > would infer the di/uo declarations, taking away from the programmer the
> > burden of worrying about these low level details of memory management.
> 
> This is more along the lines I was considering.  It seems to me that
> while the compiler will tell you if the determinism declaration for a
> predicate is weaker than necessary,

The current implementation reports warnings for some such cases, but
not for all.  In particular, it generally won't warn about the determinism
declaration being weaker than necessary if the predicate in question
is recursive.

Change the compiler to report warnings in those cases too would be pretty
trivial, but would slow down compilation a little bit.

> can it deduce that a predicate's
> modes are as tight as possible?  My thought was that it should be
> possible to spot when arguments with modes
> 
> 	:- pred p(..., T::in, T::out, ...) is det.
> 
> could be replaced with
> 
> 	:- pred p(..., T:di, T::uo, ...) is det.
> 
> I would have thought this was managable on an intra-module basis.

The current implementation is capable of inferring unique modes
such as `di' and `uo' and mostly unique (backtrackable destructive
update) modes such as `mdi' and `muo', if you don't provide a mode
declaration.  However, if you do provide a mode declaration, it
doesn't do any inference.  Probably it would be feasible to infer
just the uniqueness attributes, but the current implementation
doesn't do that.  I'm hoping the people at Leuven will help us with
this one ;-)

> Just as a matter of interest, has anybody done any analysis to see
> what proportion of code generated could benefit from destructive
> update like this?

Not that I'm aware of.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.



More information about the users mailing list