Repository navigation
fix: implement Lua 5.4 patterns (P1-5b) and while pure cond re-evaluation (P1-9) - #24
Merged
Merged
Conversation
…tion (P1-9) - P1-9: While condition purity check (IsPureNativeNumericExp): Prevent hoisting non-pure numeric expressions (e.g. #t table length which requires emitting FlLenInt statements) into single-evaluation outer while statements. Pure numeric expressions (literals, local variables, pure binary ops) continue to use native fast-path while loops. Add regression test test_jitbug_while_cond_reval.lua. - P1-5b: Standard Lua 5.4 pattern matching for string.find/match/gmatch/gsub: Replace boost::regex ECMAScript engine with a self-contained byte-pattern matcher ported from Lua 5.4 lstrlib.c. Supports % escapes, character classes (%a, %d, %w, etc.), custom sets/ranges, quantifiers (*, +, -, ?), captures (), backreferences %1-%9, %b(), %f[set], and gsub Lua replacement templates (%0-%9, %%, function/table dispatch). Update tests and docs accordingly.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #24 +/- ##
==========================================
+ Coverage 87.93% 88.04% +0.11%
==========================================
Files 122 123 +1
Lines 24885 25216 +331
==========================================
+ Hits 21882 22201 +319
- Misses 3003 3015 +12 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR resolves the two remaining critical open bugs identified during FakeFish integration:
Bug 1 (P1-9): Re-evaluate while conditions for impure numeric expressions
whilecondition contained#t(table length), the expression was inferred asT_INTand passed the numeric gate inTryCompileNativeBoolExpr. As a result,FlLenIntwas emitted outside the generated native loop, evaluating#tonly once before loop entry. Mutating operations liketable.removeinside the loop did not update the bound, leading to infinite loops or out-of-boundsnilaccess.IsPureNativeNumericExpcheck inc_gen. Only pure expressions (numeric literals, local variables, and pure binary expressions) can be emitted directly as a single nativewhile (cond)loop without external statement dependencies. Impure expressions (e.g.#t) fall back to per-iteration re-evaluation.test_jitbug_while_cond_reval.lua.Bug 2 (P1-5b): Implement standard Lua 5.4 pattern matching for string library
string.find,match,gmatch, andgsubwere backed byboost::regexECMAScript mode. Standard Lua patterns like%.%.,%d+, lazy quantifier-, frontier pattern%f[], balanced pattern%b(), and%1-%9backreferences failed or had incorrect semantics.src/native/string/lua_pattern.cpp/lua_pattern.h) ported from Lua 5.4lstrlib.c. Completely rewiredstring.find,string.match,string.gmatch, andstring.gsubto use the Lua pattern engine.test_string_lua_pattern.luacovering classes, quantifiers, captures, nested captures, frontier patterns, balanced matching, and gsub replacement forms. All 54 string unit tests pass across all backends.Testing
test_string*,infer.test_jitbug_while_cond_reval).