最近在研究LuaJIT,遇到down-recursion的语义(trace link和trace abort里都有),不知道怎么理解,还望各位老师指导:
require("jit.dump").on("six", "t1.dlog")--require("jit.v").on("t1.log")--
---
local function f1(v)
if v == 0 then return 0 end
f1(v - 1)
end
for i = 1, 40 do
f1(i)
end
对应的jit.v的log:
[TRACE 1 t1.lua:3 up-recursion]
[TRACE --- (1/3) t1.lua:4 -- down-recursion, restarting at t1.lua:6]
[TRACE 2 t1.lua:6 down-recursion]
对应的jit.dump的log:
---- TRACE 1 start t1.lua:3
---- TRACE 1 IR
.... SNAP #0 [ ---- ---- ]
0001 > num SLOAD #1 T
.... SNAP #1 [ ---- ---- ]
0002 > num NE 0001 +0
.... SNAP #2 [ ---- ---- ]
0003 fun SLOAD #0 R
0004 > fun EQ 0003 t1.lua:3
0005 num SUB 0001 +1
.... SNAP #3 [ t1.lua:3|---- t1.lua:3|---- ]
0006 > num NE 0005 +0
0007 num SUB 0005 +1
.... SNAP #4 [ t1.lua:3|---- t1.lua:3|0005 t1.lua:3|---- ]
0008 > num NE 0007 +0
0009 num SUB 0007 +1
.... SNAP #5 [ t1.lua:3|---- t1.lua:3|0005 t1.lua:3|0007 t1.lua:3|0009 ]
---- TRACE 1 stop -> up-recursion
---- TRACE 1 exit 3
---- TRACE 1 exit 1
---- TRACE 1 exit 3
---- TRACE 1 exit 4
---- TRACE 1 exit 1
---- TRACE 1 exit 3
---- TRACE 1 exit 4
---- TRACE 1 exit 1
---- TRACE 1 exit 3
---- TRACE 1 exit 4
---- TRACE 1 exit 1
---- TRACE 1 exit 3
---- TRACE 1 exit 4
---- TRACE 1 exit 1
---- TRACE 1 exit 3
---- TRACE 1 exit 4
---- TRACE 1 exit 1
---- TRACE 1 exit 3
---- TRACE 1 exit 4
---- TRACE 1 exit 1
---- TRACE 1 exit 3
---- TRACE 1 exit 4
---- TRACE 1 exit 1
---- TRACE 1 exit 3
---- TRACE 1 exit 4
---- TRACE 1 exit 1
---- TRACE 1 exit 3
---- TRACE 2 start 1/3 t1.lua:4
---- TRACE 2 abort t1.lua:6 -- down-recursion, restarting
---- TRACE 2 start t1.lua:6
---- TRACE 2 IR
.... SNAP #0 [ ---- ]
.... SNAP #1 [ ---- ]
0002 > p32 RETF proto: 0x203382c8 [0x20338328]
.... SNAP #2 [ ---- ---- ]
0003 > p32 RETF proto: 0x203382c8 [0x20338328]
.... SNAP #3 [ ---- ---- ]
0004 > p32 RETF proto: 0x203382c8 [0x20338328]
.... SNAP #4 [ ---- ]
---- TRACE 2 stop -> down-recursion
---- TRACE 2 exit 3
额外地,jit.dump的log中的
"if v == 0"上面为什么会有3个守卫?