[MLton-user] MLton misbehaving?

Johan Grönqvist johan.gronqvist at matfys.lth.se
Wed Apr 30 05:30:18 PDT 2008


Hi,

I have a program that, in many situations, seems to produce reasonable
results.
I have had sporadic problems, however, and now have a case that is
repeatable.

This version of teh program raises an unhandled exception. In order to
debug,
I compile with -const 'Exn.keepHistory true', but then no unhandled
exception is raised,
and the program keeps runing happily.

Also, commenting out a few unused lines of code (for details, see below),
seems to make the unhandled exception go away, which seems very strange
to me.

As I do not expect this to be normal behaviour for mlton, I wanted to
also ask
if this is known, if there are situations where I should expect it to
happen and/or if
someone has advice on how to debug such problems and avoid them in the
future.

More details are available below

Thanks in advance for any help.

/ johan






More details follow here:

I use mlton verion
MLton 20070826 (built Wed Aug 29 09:44:07 2007 on
silver-star.cs.uchicago.edu)
that I installed from precompiled archive downloaded from mlton.org on a
computer running suse (10.0, I believe)
I also have a computer running debian testing, but have not yet tested
on that one.
I will do so tomorrow.

The program is a few thousand lines of code. Most of those are not used
at all in this example run.
The program essentially minimizes a polynomial in many variables, and
then writes data to files
before exiting. Most of the code is for bookkeeping on the variables,
and for extracting data.
The unhandled exception Bug that is raised by the rogram should only
be raised when I have made a mistake in the code or an incorrect
assumption about the code.
I never hadle such exceptions. I do not use any additional libraries,
and do not use any C-like facilities.
I do not use infinite precision integers.



To test the problem I run the following script:

------------------------------------------
johan at aeki:~/projects/elasticity/bug> cat expose.sh

echo "Running normally."

mlton vff.mlb
./vff


echo "Running with 'Exn.keepHistory true'"
mlton -const 'Exn.keepHistory true' vff.mlb
./vff

echo "Done."
-------------------------------------------------------



Below is the output in the terminal window.
I deleted compiler warnings of the form "* is not exhaustive".
At the end I exit the program by force with ctrl-c, as it would
otherwise run for very long.

-------------------------------
johan at aeki:~/projects/elasticity/bug> ./expose.sh
Running normally.
Starting nanowire calculation for side 3 and height 2.
Minimising pure case.
unhandled exception: Bug

Running with 'Exn.keepHistory true'
Starting nanowire calculation for side 3 and height 2.
Minimising pure case.
Minimization done. Energy: 3.57008568294E~20.
Minimising mixed case.
--------------------------------------------------------------

In the first run, an unhandled exception is raised before any result
has been computed. In the second case, the program goes on without problem,
and I exit by force.

Instead of exiting by force, I thought I could comment-out the rest of
the program (5 lines),
but that seems to change the behaviour.
 

The program used here ends in
------------------------
   
val _ = csnw_minimized (3, 2)

val _ = csnw_minimized (4, 2)
   
val _ = csnw_minimized (12, 3)
val _ = csnw_minimized (12, 10)
   
val _ = csnw_minimized (20, 3)
val _ = csnw_minimized (20, 10)
------------------------


Commenting out the last five of those lines prevents the unhandled
exception from being raised.

I comment out the 5 lines, and run the same script again
The output is then (warnings deleted again)

---------------------------------------
johan at aeki:~/projects/elasticity/bug> ./expose.sh
Running normally.
Starting nanowire calculation for side 3 and height 2.
Minimising pure case.
Minimization done. Energy: 3.01984609884E~20.
Minimising mixed case.
Minimization done. Energy: 5919.45929566.
Done.
Running with 'Exn.keepHistory true'
Starting nanowire calculation for side 3 and height 2.
Minimising pure case.
Minimization done. Energy: 9.3088938774E~21.
Minimising mixed case.
Minimization done. Energy: 5937.34353531.
Done.
Done.
johan at aeki:~/projects/elasticity/bug>

------------------------------------------

Thus, I conclude that commenting out unused code
alters the program behaviour.


Side note: As I do not use any kind of random numbers,
I am also puzzled by the fact that I get different numerical answers
depending on compiler options.




More information about the MLton-user mailing list