Problem with MLton
Lars Magnusson <[email protected]> Thu, 16 Feb 2012 13:41:12 +0100
| Newsgroups | gmane.comp.lang.ml.mlton.devel |
|---|---|
| Message-ID | <CAMjzkTtROBqGf7mu0pcQtUFnhkAviy+JLWcGeG4-oC0ibzV7=Q@mail.gmail.com> |
Hello
We use MLton to build our system for automatic programming called
ADATE, which has its own internal compiler capable of compiling a
subset of SML. In the last year I have been working on upgrading this
internal compiler to generate x86-64 code and to include a simple
garbage collector in the runtime environment. For the last month I've
been using MLton as a reference compiler for testing our internal
compiler on a great number of different programs developed by the
ADATE system i.e. I compile the generated programs with both compilers
and compare the results.
I've found an instance that gives a mismatch, and I've spent the last
week investigating why my compiler fails to properly compile the
program. I wasn't able to find the problem by investigating the
generated code, so I thought I'd try executing the program on paper by
hand to figure out where my code goes wrong. To my surprise my manual
execution produced the exact same output as my compiler, so I did it
again, and again, and all three times with the same result. I then
decided to test the program on other existing ML compilers. I've tried
the program on both SML/NJ and Poly/ML, and they both produce the same
output as mine.
I'm currently running MLton 20100608, but we have also tested the
program on an older release (2006) with the same problems.
Here is the code I've been using:
datatype ilist = nill | cons of int * ilist
fun f Xs =
case Xs of
nill => nill
| cons( VFE8, VFE9 ) =>
let
fun gA1F7A0( V2F59797, V1DE219B, VA7D8E2, VA1F7A1 ) =
case VA1F7A1 of
nill => cons( VA7D8E2, nill )
| cons( VA1F7A2, VA1F7A3 ) =>
case ( VA1F7A2 < V1DE219B ) of
false => cons( VA7D8E2, VA1F7A1 )
| true =>
cons(
VA1F7A2,
case ( VFE8 < V2F59797 ) of
false =>
gA1F7A0( V1DE219B, VA7D8E2, VA7D8E2, VA1F7A3 )
| true => cons( VA7D8E2, nill )
)
in
case VFE9 of
nill => Xs
| cons( VA1F78E, VA1F78F ) =>
gA1F7A0(
VFE8,
VFE8,
VFE8,
f( gA1F7A0( VFE8, VFE8, VA1F78E, VA1F78F ) )
)
end
fun print_ilist( nill ) = print "\n"
| print_ilist( cons( X, Xs ) ) = ( print( Int.toString X ^ " " );
print_ilist Xs )
val Input = cons( 6, cons( 5, cons( 7, cons( 3, cons( 1, cons( 2,
cons( 4, nill ) ) ) ) ) ) )
val _ = print_ilist( f Input )
(* end of code *)
The input is the shortest instance I've found which produce the
problem. On my compiler, sml/nj and poly/ml this program produces; 1,
2, 3, 5, 6, 7, but with MLton it produces; 1, 2, 3, 4, 5, 6, 7.
I'm hesitant about drawing this conclusion, but based on the
observations I am forced to think that there's a bug in MLton.
Kind regards
Lars Magnusson
PS. I can clean up the generated code if that is desired.
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/