[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: C stack overflow in Lua 5.4 in ackermann benchmark
- From: Andrew Gierth <andrew@...>
- Date: Tue, 18 Aug 2020 22:30:22 +0100
>>>>> "Eduardo" == Eduardo Bart <edub4rt@gmail.com> writes:
Eduardo> For a long time I've used the following example to benchmark
Eduardo> tail calls in Lua 5.1, 5.2, 5.3 and LuaJIT.
Eduardo> ```
Eduardo> local function ack(m, n)
Eduardo> if m == 0 then
Eduardo> return n + 1
Eduardo> end
Eduardo> if n == 0 then
Eduardo> return ack(m - 1, 1)
Eduardo> end
Eduardo> return ack(m - 1, ack(m, n - 1))
The inner ack() in this expression is not a tail call. So you need
enough available stack to cope with the number of times it will recurse
through this specific path.
The difference in 5.4 is that Lua-to-Lua function calls now consume
space on the C stack (for a stack frame of luaV_execute), which was not
the case in earlier versions.
--
Andrew.