[mercury-users] User-defined Extension of builtin__copy?

Zoltan Somogyi zs at cs.mu.OZ.AU
Mon Sep 19 14:51:54 AEST 2005


On 14-Sep-2005, Kral Stefan <skral at mips.complang.tuwien.ac.at> wrote:
> To allow the creation of unique copies, the GMP binding(s) will
> offer dedicated functions/predicates, like the following.
> 	:- pred gmpint_copy(gmpint, gmpint).
> 	:- mode gmpint_copy(in,     uo) is det.
> 	:- mode gmpint_copy(di,     uo) is det.

What is the purpose behind allowing users to create unique copies? What can
they do with them that they cannot do with nonunique copies?

> I noticed that using that assertion caused the compiler to omit some
> boxing/unboxing statements (which -- I believe -- are optimized away
> anyway by the C compiler, as it knows about the sizes of MR_Word and
> GMPInt *).

The last time I checked, which wasn't recently, the C compiler didn't optimize
away the boxing and unboxing code, which calls memcpy.

> Our current implementation does not alter memory of values that are alive.
> However, we reuse memory wherever possible.
> 
> I am not sure if this suffices to quality the type as stable.

The design intent behind the "stable" annotation was to allow tabling
(memoization etc), which requires that the memory pointed to stay unchanged
until execution ends, so no, it doesn't qualify. However, it is sufficient
to make it safe for copy operations to ignore the value, *provided* that
you don't reuse the memory until all copies referring to it are dead.
It looks like another annotation that promises just that may be useful.
In the meantime, you may use the stable annotation as a workaround
if you can ensure that you won't table values of the type.

Zoltan Somogyi <zs at cs.mu.OZ.AU> http://www.cs.mu.oz.au/~zs/
Department of Computer Science and Software Engineering, Univ. of Melbourne
--------------------------------------------------------------------------
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