[MLton] Elaborator bug

Stephen Weeks MLton@mlton.org
Sat, 4 Feb 2006 17:56:40 -0800


> The attached source exhibits the following bug:
>    ElaborateEnv.functorClosure: firstTycons
> 
> I note that the bug is sensitive to the _number_ of structure/functor 
> bindings made. 

That was the key observation.  I made a simple example, to be
evaluated in the _prim environment, that shows the problem.

------------------------------------------------------------
structure S = struct end
functor F () = S
... (* 84 F's in total *)
functor F () = S
------------------------------------------------------------

As soon as I saw how dependent it was on the number, I began to think
"what is so special about 84?".  Somehow, my brain managed to guess
that that was about the number of primitive type constructors that
MLton supports.  And in fact, mlton -show-basis reveals that there are
exactly 84 primitive tycons.  From there, it was easy to see that the
functorClosure code was mistakenly removing one element from the
allTycons list for each functor definition.  I've committed a fix.