Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[||] == [||] is false when using the native compiler but true when using the bytecode compiler #5235

Closed
vicuna opened this issue Mar 7, 2011 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Mar 7, 2011

Original bug ID: 5235
Reporter: ecull78
Status: closed (set by @xavierleroy on 2011-06-04T14:40:52Z)
Resolution: not a bug
Priority: normal
Severity: minor
Version: 3.12.0
Category: ~DO NOT USE (was: OCaml general)
Monitored by: "Pascal Cuoq" "Julien Signoles"

Bug description

Empty 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 information

tested under MacOSX 10.6.6 using a 32 bit version of ocaml compiled from sources according to the instructions

@vicuna
Copy link
Author

vicuna commented May 17, 2011

Comment author: @damiendoligez

Is this a problem in practice ? This behaviour is within the specification of ==.

@vicuna
Copy link
Author

vicuna commented Jun 4, 2011

Comment author: @xavierleroy

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.

@vicuna vicuna closed this as completed Jun 4, 2011
@vicuna vicuna added the bug label Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant