[mercury-users] Many data elements using Mercury on cygwin?

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Feb 6 17:45:39 AEDT 2003

On 06-Feb-2003, Douglas Auclair <dauclair at msn.com> wrote:
> I'm scanning a file line-by-line, converting it into a typed-relation, and 
> then adding that relation into a list.  These files are 1 megabyte.
> Mercury 0.10.1 on Cygwin using --asm-fast segfaults after scanning ~5000 or 
> ~~10000 records (depending on which machine I'm using) out of a total of 
> ~~45000 records.

Most likely you have overflowed the stack.

There is no `--asm-fast' option.
Are you using `--grade asm_fast'?  Or `--grade asm_fast.gc'?
If you are using `--grade asm_fast', then you have turned off
garbage collection.  Turning off garbage collection may cause
Mercury to run out of heap space prematurely, which could
cause the symptom that you have observed.

On Cygwin, I think Mercury's detection of heap and stack overflow
is disabled due to a bug in Cygwin's mprotect() function.
So "segmentation fault" is the normal message that you get
when the Mercury heap or stack overflows.

The sizes of the Mercury stacks and heap can be set using the
MERCURY_OPTIONS environment variable (see the "Environment variables"
chapter of the Mercury User's Guide) or the --runtime-flags linker option. 
In grade "asm_fast.gc", the relevant options are `--detstack-size' and
`--nondetstack-size'; the default sizes for these are 4096k (i.e. 4M)
and 128k respectively.  In grade "asm_fast", the `--heap-size' option is
also relevant; but I recommend you use "asm_fast.gc" instead, in which
case the heap will be automatically resized as needed.

If adjusting the stack size does make the problem go away,
then you might be able to eliminate the problem completely
by rewriting your main loop(s) to be tail recursive, so
that they do not consume stack space proportional to
the size of the input.

The bug in Cygwin's mprotect() was in a very old version of Cygwin
(back when it was called gnu-win32), and may well have been fixed in more
recent versions.  So if you want better error messages when Mercury runs
out of memory on Cygwin, you could try building Mercury from the source
distribution, after commenting out the following lines in `configure.in'

   # Don't try to use mprotect() on gnu-win32, since it is broken
   # (at least for version b18, anyway) and trying it can crash Win95.
   case "$host" in
                   ac_cv_func_mprotect=no ;;

and after running `autoconf' to regenerate `configure' from `configure.in'.

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