Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005235OCamlOCaml generalpublic2011-03-07 17:442011-06-04 16:40
Reporterecull78 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionno change required 
PlatformOSOS Version
Product Version3.12.0 
Target VersionFixed in Version 
Summary0005235: [||] == [||] is false when using the native compiler but true when using the bytecode compiler
DescriptionEmpty arrays, unlike empty lists, seem to be not physically equal if compiled in the native code:

$ cat test.ml
print_endline (if [||] == [||] then "Equal!" else "Not equal!")
$ ocamlopt -o test.native test.ml
$ ./test.native
Not equal!

But when I check this in top level I have:

# [||] == [||];;
- : bool = true

and even this:

# (Array.create 0 0) == [||];;
- : bool = true

And using the bytecode compiler I have a similar result:

$ ocamlc -o test.byte test.ml
$ ./test.byte
Equal!

In comparison, empty lists are physically equal when using the native compiler:
$ cat test1.ml
print_endline (if [] == [] then "Equal!" else "Not equal!")
$ ocamlopt -o test1.native test1.ml
$ ./test1.native
Equal!

Additional Informationtested under MacOSX 10.6.6 using a 32 bit version of ocaml compiled from sources according to the instructions
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0005897)
doligez (administrator)
2011-05-17 14:19

Is this a problem in practice ? This behaviour is within the specification of ==.
(0005973)
xleroy (administrator)
2011-06-04 16:40

Yes, ocamlc and ocamlopt treat zero-sized heap blocks differently. (Note that the empty list is not a block, hence the different behavior.) As Damien notes, the empty array is actually immutable, so == is not specified in this case.

Unifying the treatment of empty blocks between ocamlc and ocamlopt would be quite a bit of work without any clear benefits, so I'd rather stay with the status quo.

- Issue History
Date Modified Username Field Change
2011-03-07 17:44 ecull78 New Issue
2011-05-17 14:19 doligez Note Added: 0005897
2011-05-17 14:19 doligez Status new => feedback
2011-06-04 16:40 xleroy Note Added: 0005973
2011-06-04 16:40 xleroy Status feedback => closed
2011-06-04 16:40 xleroy Resolution open => no change required


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker