Metatable __eq sometimes not called when JIT is on

  • From: Nils Nordman <nino@xxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 18 Oct 2012 12:11:40 +0200

Hi,

I've run into a weird case with metatables and __eq, where it seems __eq is
_sometimes_ not called when JIT is on. This manifests itself as erratically
failing tests in my test suite. The setup is this:

I have two objects with the same metatable, containing an __eq function.
The tests in question verifies that the objects are equal, by using the
test framework's assert.equal(). The actual comparison in the framework
ends up being this:

  if arguments[1] ~= arguments[i] then
    -- fails incorrectly sometimes

Then when troubleshooting I added printouts to the __eq function to see
whether it's called and what the return value is, and I added the following
sanity check printout right below the above if statement:

  print('res ~= ' .. tostring(arguments[1] ~= arguments[i]))

What seems to happen when this fails is that

1) The __eq function is not invoked for the if conditional
2) The print statement below the if still causes the __eq function to be
invoked correctly, and thus prints "res ~= false"

The argument table is not altered between these two calls in any way.

This happens like I said only some times, with the majority of runs passing
as they should. For successful runs I see the printout from __eq function
caused by the if conditional just like expected. When disabling the JIT
with jit.off(), I'm no longer able to reproduce the problem. Unfortunately
I've not been able to limit this to any small and useful test case. It
happens when I run all of the tests in all test files (32) at the same
time, but never if I try running only one test file for instance.

Relevant details:

$ uname -a
Linux zen 3.0.0-22-generic #36-Ubuntu SMP Tue Jun 12 17:13:04 UTC 2012 i686
i686 i386 GNU/Linux

LuaJIT:

LuaJIT-2.0.0-beta11, embedded. Compiled with 'gcc version 4.6.1
(Ubuntu/Linaro 4.6.1-9ubuntu3)', using 'make
XCFLAGS=-DLUAJIT_ENABLE_LUA52COMPAT'.

(FWIW, I've seen this with at least beta10 as well, but haven't been able
to debug it until now).

Sorry for the lack of a test case, let me know if there's any additional
information I could provide that would help.

Regards,

-- 
Nils Nordman <nino@xxxxxxxxxxx>

Other related posts: