[mercury-users] Printing reference's values

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Dec 5 15:21:22 AEDT 2002


On 05-Dec-2002, Maria Garcia de la Banda <mbanda at mail.csse.monash.edu.au> wrote:
> 
> I am trying to debug a program which uses references from the
> extras/reference.m library.  ...  The
> messages are either a segmentation violation; a "Mercury runtime:
> MR_expand_functor_only: attempt to deconstruct variable", or a
> "MR_expand_functor_args: invalid sectag_locn", depending on what one
> executes afterwards.
...
> P.S. The program that causes this is part of the HAL compiler (which I am
>      trying to boostrap) and thus involves many different modules.  I have
>      failed to obtain a small version of the program which still shows the
>      bug.

It's a good thing you asked, since I happen to know exactly what the problem is.
Currently there is a conflict between the `--reserve-tag' option, which you
are using for the HAL implementation, and the implementation of references in
extras/reference.  Similar issues arise in a few other places in the Mercury
libraries (e.g. library/store.m).

 |         --reserve-tag                   (grade modifier: `.rt')
 |                 Reserve a tag in the data representation of the generated
 |                 code. This tag is intended to be used to give an explicit
 |                 representation to free variables.
 |                 This is necessary for a seamless Herbrand constraint solver -
 |                 for use with HAL.

The implementation of references in extras/references/ uses a type defined by

	:- type ref ---> ref(c_pointer).

or something equivalent to that, and assumes that this data structure
will use the "no-tag" representation, i.e. that the representation
of this will be just a c_pointer.  However, with the `--reserve-tag'
option, there are two possible states which need to be represented,
unbound and bound to ref(c_pointer), and so a tag (and an extra
level of indirection) is needed.

The pragma c_code used in extras/references is declared to
return a `ref', but actually just returns a c_pointer.
When io__write is called on one of these values, it tries to
look at the (non-existant) tag, and then tries to dereference
something which isn't there or otherwise gets confused.

The simplest solution is probably to change the code in extras/references
so that rather than these routines being implemented directly in
`pragma c_code', there is a small piece of Mercury code which calls a
`pragma c_code' routine that is declared to return `c_pointer',
and then wraps the c_pointer returned in a `ref/1' constructor.
The same solution may need to be applied in every place that the
standard library or the libraries in the extras distribution
use c_pointer (`find . -name \*.m | xargs grep c_pointer').

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  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