[mercury-users] Exceptions and unique modes
Fergus Henderson
fjh at cs.mu.OZ.AU
Fri Mar 2 01:33:36 AEDT 2001
On 01-Mar-2001, Peter Ross <peter.ross at miscrit.be> wrote:
> On Fri, Feb 23, 2001 at 11:38:46AM +1100, Fergus Henderson wrote:
> > On 22-Feb-2001, Peter Ross <peter.ross at miscrit.be> wrote:
> > > On Thu, Feb 22, 2001 at 05:01:28PM +1100, Fergus Henderson wrote:
> > > > In particular, what would you do about code which tries to reuse the
> > > > storage for something with a `di' mode, e.g. by explicitly deallocating
> > > > it so that the allocator can reuse it to hold something that has a
> > > > different type?
> > >
> > > You would think that the best canditate for reuse of that memory is the
> > > next state. Unfortunately it is not quite that easy as the following
> > > type indicates.
> > >
> > > :- type t
> > > ---> f(int)
> > > ; g(int, int).
> > >
> > > No matter what you initialise this type to you need to make sure that
> > > you allocate 2 words so that you can possibly hold the g constructor at
> > > some later date.
> >
> > That would be a bad idea in general, e.g. consider
> >
> > :- type t2
> > ---> f2(int)
> > ; g2(int, int, int, int, int, int, int, int, int, int,
> > int, int, int, int, int, int, int, int, int, int).
> >
> > and suppose that 99% of all values of type `t' use f2/1 rather than g2/22.
> > Even for your type t, the cost of the extra space needed to allocate
> > two words rather than one for f/1 may outweigh any gains you get from
> > additional reuse.
>
> A simple source to source transformation along the lines of
>
> :- type t2
> ---> f2(int)
> ; wrapper(t2_g2).
>
> :- type t2_g2
> ---> g2(int, int, int, int, int, int, int, int, int, int,
> int, int, int, int, int, int, int, int, int, int).
>
> Would avoid this problem.
In this particular case. But knowing when to apply such a source to source
transformation is difficult. What if it's the other way around,
99% of all values of type `t' use g2/22 rather than f2/1? Your transformation
adds an extra level of indirection to every access of a g2/22 field.
Also, doing it as a source to source transformation would cause problems
for RTTI, because the transformation would be visible in the RTTI.
This would cause problems with routines such as io__print.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
| of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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