[mercury-users] Structure reuse

Simon Taylor stayl at cs.mu.OZ.AU
Wed Jul 16 15:01:01 AEST 2003

On 15-Jul-2003, Nancy Mazur <Nancy.Mazur at cs.kuleuven.ac.be> wrote:
> >>Even if you let the programmer annotate unique modes by hand, I thought 
> >>the philosophy of the Mercury compiler was always not to trust the 
> >>programmer, and therefore an automatic verification of these annotations 
> >>should still be done.
> >
> >That's right, so if the data structure isn't used in a single-threaded
> >way, the compiler will report an error showing where. If you leave it all
> >up to the compiler, you're on your own if the reuse doesn't happen.
> If the user is interested, the compiler can produce interesting feedback 
> as to why reuse at some place wasn't possible (example: some alias with 
> some live structure that the programmer overlooked)...

It will be extremely difficult to produce useful messages for the
programmer, especially if the unexpected aliasing is not near the
expected reuse.  I'd be very surprised if you can do this without
drowning the programmer in analyser-produced gibberish.

Also, in some cases the programmer will expect that only some calls
to a predicate will be able to perform reuse (for the other calls
an aliased value is passed which can't be reused).  How will the
analyser work out which calls to produce warnings for, without
producing lots of spurious warnings?
> >>But some cooperation human-compiler is interesting: let the compiler 
> >>deduce automatically the reuse, let the programmer indicate some hints 
> >>where reuse should be possible according to him, and then provide the 
> >>adequate feedback if the two views do not match.
> >
> >That's what unique modes are for.
> Yes and no. The unique modes are too strict as such. If you want to use 
> unique modes, you need to have the discipline to write these modes for 
> each predicate or function that manipulates the data structure you're 
> interested in reusing...
> It would be more user-friendly to use the unique modes only for those 
> predicates where the programmer thinks reuse may be possible, and let 
> the compiler figure out the rest of the predicates...

This assumes that the only use for unique modes is to allow reuse.
In most cases where you want reuse, you also want to ensure that
the structure is used in a single-threaded manner.  Using unique
modes allows the compiler to report errors if it is not.

mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe

More information about the users mailing list