[Tarantool-patches] [PATCH luajit 2/2] Fix use-def analysis for vararg functions.
Igor Munkin
imun at tarantool.org
Tue Jul 4 14:41:38 MSK 2023
Sergey,
Thanks for the patch! LGTM, considering the fixes made to resolve the
comments left by Max. I also applied the changes we discussed offline.
On 09.06.23, Sergey Kaplun via Tarantool-patches wrote:
> From: Mike Pall <mike>
>
> Reported by Shmuel Zeigerman.
>
> (cherry-picked from commit 0e53a314d7910898e1ea5ba90385d43e8a6c5e57)
>
> Use-def analysis for BC_FUNCV may consider slots greater than amount of
> non-vararg parameters as dead slots due to early return for BC_RET
Side note: mentioned BC_JMP here too.
> emitted before usage of BC_VARG. This patch restricts the maxslot to be
> analyzed in such case with amount of parameters for the prototype of the
> current function being recorded.
>
> Sergey Kaplun:
> * added the description and the test for the problem
>
> Part of tarantool/tarantool#8516
> Relates to tarantool/tarantool#8718
> ---
> src/lj_snap.c | 6 +++--
> .../lj-704-bc-varg-use-def.test.lua | 27 ++++++++++++++++++-
> 2 files changed, 30 insertions(+), 3 deletions(-)
>
<snipped>
> diff --git a/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua b/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua
> index c3ba65dd..38606686 100644
> --- a/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua
> +++ b/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua
> @@ -6,7 +6,7 @@ local test = tap.test('lj-704-bc-varg-use-def'):skipcond({
> ['Test requires JIT enabled'] = not jit.status(),
> })
>
> -test:plan(1)
> +test:plan(2)
>
> -- XXX: we don't really need to store this builtins, but this is
> -- reduces `jitdump()` output for reader significantly.
> @@ -62,4 +62,29 @@ wrap(ON_TRACE_VALUE)
>
> test:ok(result ~= 0, 'use-def analysis for BC_VARG')
>
> +-- Now check the same case, but with BC_RET before the BC_VARG,
> +-- so use-def analysis will take early return case.
> +-- See `snap_usedef()` in <src/lj_snap.c> for details.
> +-- The test checks that slots greater than `numparams` are not
> +-- purged.
> +local function varg_ret_bc(...)
> + -- XXX: This branch contains BC_RET. See the comment above.
> + -- luacheck: ignore
> + if false then else end
> + local slot = ({...})[1]
> + return fmod(ARG_ON_RECORDING, slot)
> +end
> +
> +local function wrap_ret_bc(arg)
> + _, result = pcall(varg_ret_bc, arg)
> +end
> +
> +-- Record trace with the 0 result.
> +wrap_ret_bc(ARG_ON_RECORDING)
> +wrap_ret_bc(ARG_ON_RECORDING)
> +-- Record trace with the non-zero result.
> +wrap_ret_bc(ON_TRACE_VALUE)
> +
> +test:ok(result ~= 0, 'use-def analysis for FUNCV with return before BC_VARG')
Side note: Applied the changes we've discussed. The diff is below:
================================================================================
diff --git a/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua b/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua
index 36fa450a..e6a0973b 100644
--- a/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua
+++ b/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua
@@ -62,17 +62,17 @@ wrap(ON_TRACE_VALUE)
test:ok(result ~= 0, 'use-def analysis for BC_VARG')
--- Now check the same case, but with BC_RET before the BC_VARG,
+-- Now check the same case, but with BC_JMP before the BC_VARG,
-- so use-def analysis will take early return case for BCMlit.
-- See `snap_usedef()` in <src/lj_snap.c> for details.
-- The test checks that slots greater than `numparams` are not
-- purged.
local function varg_ret_bc(...)
- -- XXX: This branch contains BC_RET. See the comment above.
+ -- XXX: This branch contains BC_JMP. See the comment above.
-- luacheck: ignore
if false then else end
local slot = ({...})[1]
- -- Forcify stitch and usage of vararg slot. Any NIY is OK here.
+ -- Forcify stitch and usage of vararg slot. Any NYI is OK here.
return fmod(ARG_ON_RECORDING, slot)
end
@@ -88,6 +88,6 @@ wrap_ret_bc(ARG_ON_RECORDING)
-- Record trace with the non-zero result.
wrap_ret_bc(ON_TRACE_VALUE)
-test:ok(result ~= 0, 'use-def analysis for FUNCV with return before BC_VARG')
+test:ok(result ~= 0, 'use-def analysis for FUNCV with jump before BC_VARG')
os.exit(test:check() and 0 or 1)
================================================================================
> +
> os.exit(test:check() and 0 or 1)
> --
> 2.34.1
>
--
Best regards,
IM
More information about the Tarantool-patches
mailing list