lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


For a long time I've used the following example to benchmark tail calls in Lua 5.1, 5.2, 5.3 and LuaJIT.

```
local function ack(m, n)
  if m == 0 then
    return n + 1
  end
  if n == 0 then
    return ack(m - 1, 1)
  end
  return ack(m - 1, ack(m, n - 1))
end

local res = ack(3,10)
print(res)
assert(res == 8189)
```

However I've just noticed that Lua 5.4 fails to execute this, with the following error:

```
lua5.4: benchmarks/lua/ackermann.lua:16: C stack overflow
stack traceback:
benchmarks/lua/ackermann.lua:16: in upvalue 'ack'
benchmarks/lua/ackermann.lua:16: in upvalue 'ack'
benchmarks/lua/ackermann.lua:16: in upvalue 'ack'
benchmarks/lua/ackermann.lua:16: in upvalue 'ack'
benchmarks/lua/ackermann.lua:16: in upvalue 'ack'
benchmarks/lua/ackermann.lua:16: in upvalue 'ack'
benchmarks/lua/ackermann.lua:16: in upvalue 'ack'
benchmarks/lua/ackermann.lua:16: in upvalue 'ack'
benchmarks/lua/ackermann.lua:16: in upvalue 'ack'
benchmarks/lua/ackermann.lua:16: in upvalue 'ack'
... (skipping 1958 levels)
benchmarks/lua/ackermann.lua:16: in upvalue 'ack'
benchmarks/lua/ackermann.lua:16: in upvalue 'ack'
benchmarks/lua/ackermann.lua:16: in upvalue 'ack'
benchmarks/lua/ackermann.lua:16: in upvalue 'ack'
benchmarks/lua/ackermann.lua:16: in upvalue 'ack'
benchmarks/lua/ackermann.lua:16: in upvalue 'ack'
benchmarks/lua/ackermann.lua:16: in function <benchmarks/lua/ackermann.lua:2>
(...tail calls...)
benchmarks/lua/ackermann.lua:16: in upvalue 'ack'
benchmarks/lua/ackermann.lua:16: in local 'ack'
benchmarks/lua/ackermann.lua:19: in main chunk
```

While benchmark runs fine in Lua 5.1, 5.2, 5.3, LuaJIT and Ravi in Lua 5.4 it does not.

I've tried to use the patches for Lua 5.4 bugs, but it didn't improve the situation.
Then I saw that the default LUAI_MAXCSTACK is much lower now than it was in Lua 5.3. Why did the default value change? Is there any performance degradation when it is set too high now?