[MLton-user] Potential bug in MLton.eq?

Nicholas Kidd nakidd at gmail.com
Wed Apr 28 11:24:01 PDT 2010


"The semantics is a bit murky"[1] ... indeed :-)

Thanks for quick and informative response.

Best,
-Nick

[1] http://mlton.org/MLtonStructure

On Wed, Apr 28, 2010 at 2:14 PM, Matthew Fluet <matthew.fluet at gmail.com> wrote:
> No bug; you are seeing the expected behavior.
>
> MLton.eq tries very hard to not inhibit other optimizations.  So,
> MLton.eq does not imply a use of the components of a data object.
> Various other optimizations will eliminate unused components of data
> objects.  In your program, the string component of the A variant is
> never used, so it can be eliminated.  (Furthermore, the B variant is
> never used at all, so can be eliminated from the datatype
> declaration.)   What remains is a program equivalent to:
>
>  datatype d = A
>  val v1 = A
>  val v2 = A
>
> At this point, you can see that common subexpression elimination would
> allow us to share the same object for both v1 and v2, and
> MLton.eq(v1,v2) would return true.  Actually, MLton will further
> optimize the above, accomplish the constant folding of MLton.eq at
> compile-time, and your entire program is simply equivalent to:
>
>  val _ = print ("v1 <eq> v2 : " ^ (Bool.toString true) ^ "\n")
>
> You've probably noticed that if you uncomment the line that includes a
> call to MLton.equal, then MLton.eq returns false.  This again is the
> expected behavior, because MLton.equal is a deep structural equality
> test, and it does imply a use of all of the components of a data
> object.
>
> On Wed, Apr 28, 2010 at 12:32 PM, Nicholas Kidd <nakidd at gmail.com> wrote:
>> Hi,
>>
>> For the attached program ab.sml the following occurs:
>>
>> ----------------------------
>> $ cat ab.sml
>> datatype d = A of string | B of string
>>
>> val v1 = A("y")
>> val v2 = A("x")
>>
>> val _ = print ("v1 <eq> v2 : " ^ (Bool.toString (MLton.eq(v1,v2))) ^ "\n")
>> (*val _ = print ("v1 <equal> v2 : " ^ (Bool.toString
>> (MLton.equal(v1,v2))) ^ "\n")*)
>> $ mlton
>> MLton 20070826 (built Mon Sep 03 18:05:04 2007 on eponym)
>> $ mlton ab.sml
>> $ ./ab
>> v1 <eq> v2 : true
>> $ uname -a
>> Linux jack 2.6.26-2-686 #1 SMP Wed Feb 10 08:59:21 UTC 2010 i686 GNU/Linux
>>
>> ----------------------------
>>
>> I believe the last line should be "v1 <eq> v2 : false" as v1 and v2
>> should not hold the same
>> address. The output was produced on Debian lenny, and has been
>> reproduced on OS 10.{5,6} and with MLton v7387
>> and v7452 from svn. Finally, uncommenting the last line outputs:
>>
>> v1 <eq> v2 : false
>> v1 <equal> v2 : false
>>
>> Any idea what could be going on?
>>
>> Thanks,
>> -Nick
>>
>> _______________________________________________
>> MLton-user mailing list
>> MLton-user at mlton.org
>> http://mlton.org/mailman/listinfo/mlton-user
>>
>



More information about the MLton-user mailing list