[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Tail-call regression from Lua 5.3 to 5.4
- From: Jan Behrens <jbe-mlist@...>
- Date: Sat, 26 Aug 2023 16:46:54 +0200
Hello,
I think there is a regression in regard to tail-calls from Lua 5.3 to
Lua 5.4. Consider the following program:
---
local tbl = { 1 }
local function func(n)
if n >= 100 then
print(debug.traceback())
return
end
for k, v in pairs(tbl) do
return func(n + 1)
end
end
func(0)
---
On Lua 5.3.6, we get:
stack traceback:
tailtest.lua:5: in function <tailtest.lua:3>
(...tail calls...)
tailtest.lua:13: in main chunk
[C]: in ?
But on Lua 5.4.6, we get:
stack traceback:
tailtest.lua:5: in upvalue 'func'
tailtest.lua:9: in upvalue 'func'
tailtest.lua:9: in upvalue 'func'
tailtest.lua:9: in upvalue 'func'
tailtest.lua:9: in upvalue 'func'
tailtest.lua:9: in upvalue 'func'
tailtest.lua:9: in upvalue 'func'
tailtest.lua:9: in upvalue 'func'
tailtest.lua:9: in upvalue 'func'
tailtest.lua:9: in upvalue 'func'
... (skipping 81 levels)
tailtest.lua:9: in upvalue 'func'
tailtest.lua:9: in upvalue 'func'
tailtest.lua:9: in upvalue 'func'
tailtest.lua:9: in upvalue 'func'
tailtest.lua:9: in upvalue 'func'
tailtest.lua:9: in upvalue 'func'
tailtest.lua:9: in upvalue 'func'
tailtest.lua:9: in upvalue 'func'
tailtest.lua:9: in local 'func'
tailtest.lua:13: in main chunk
[C]: in ?
I think this is because of the introduction of to-be-closed variables
in Lua 5.4 and the fourth argument to generic for-loops. Note, however,
that the example program does not use to-be-closed variables. Yet, the
generic for-loop prohibits the recursive call to be executed as a tail
call.
Is there any plan to fix this behavior?
Regards,
Jan Behrens
Attachment:
tailtest.lua
Description: Binary data