Add LuaJIT-specific code generation optimizations#12754
Add LuaJIT-specific code generation optimizations#12754jdonaldson wants to merge 3 commits intoHaxeFoundation:developmentfrom
Conversation
|
I found some old half-baked LuaJit optimization branch and had Claude finish it off. The optimizations are accessible with the -D luajit flag, making it actually useful for something now. |
|
|
||
| class IssueLuaJit extends Test { | ||
| function testGotoContinue() { | ||
| #if lua_jit |
There was a problem hiding this comment.
My bad. I gave Claude an instruction not to do this anymore, but it ignored me, and I pushed this late last night and didn't check things over properly.
So, this was helpful for me. When someone asks me to change behavior permanently with my AI tooling, I'm going to try and figure out how to do it with "rules" rather than "suggestions".
For this particular case, I added a pre-commit hook that specifically looks for this scenario and blocks pushes if it detects test gating : https://github.com/jdonaldson/dotfiles/blob/jdonaldson/.config/git/hooks/pre-commit
Thanks for helping me figure out the "new normal", sorry for being annoying, but honestly I missed you getting annoyed at my work :)
There was a problem hiding this comment.
I'm not annoyed, it's ultimately a very minor thing and watching you trying to get Claude under control is quite entertaining! Also, that's a creative solution for that particular problem.
There was a problem hiding this comment.
I really should've saved the conversation, it looked at genlua and noted how I was getting around Lua's limited conditional control of flow options, gave me a nice pat on the head for it, and then one upped me here.
|
I'd imagine that some of the cases in Also, it looks like luajit 2.0 does not have table.new. I was also wondering if we could also optimise bitwise operations for luajit using bit.tobit, but maybe best to merge the other bit related PRs first. |
d63dcc3 to
8f5b69e
Compare
When -D lua_jit is set, use goto-based continue emulation instead of the repeat-until + flag variable pattern. Inside try-catch blocks, use distinct pcall sentinels (_hx_pcall_continue vs _hx_pcall_break) so the error handler can emit goto for continue and break for break. Nested try-catch correctly re-throws sentinels. Also adds _hx_tab_array_jit.lua which uses LuaJIT's table.new for pre-allocated array construction, and updates the -D lua_jit doc string.
Tests are pure Haxe with no target-specific imports, so they should run on all targets.
- Use pcall to optionally load table.new for LuaJIT 2.0 compatibility - Remove redundant tests (continue, break, arrays, nested loops) that overlap with existing test suite coverage - Keep unique try-catch + continue/break tests that validate pcall sentinel codegen
8f5b69e to
53efd6f
Compare
Summary
-D lua_jitis set, usegoto-based continue emulation (do...end+::_hx_continue_N::labels) instead ofrepeat-until+ flag variable pattern_hx_pcall_continuevs_hx_pcall_break) so the error handler can emitgotofor continue andbreakfor break; nested try-catch correctly re-throws sentinels_hx_tab_array_jit.luawhich uses LuaJIT'stable.newfor pre-allocated array construction-D lua_jitdoc string (was incorrectly referencing "version 5.2 only")Test plan
luajit bin/unit.lua— 11741 assertions)lua bin/unit.lua— 11715 assertions)IssueLuaJit.hxcover: basic continue, break+continue, nested loop continue, continue in try-catch, break in try-catch, nested try-catch with continue, combined break+continue in try-catchrepeat-untilpatterns remain in LuaJIT output (verified via grep)_hx_pcall_continuesentinel appears in generated output for try-catch+continue loops