Repository navigation
fix: deoptimize math-specialized functions on non-numeric arguments - #30
Merged
Merged
Conversation
File-level math-specialized functions hard-failed in the TCC/GCC entry dispatcher when a math-position argument was non-numeric (string/bool/ nil/table, or nil from a missing argument). The exception escaped the dylib with no handler and aborted the process; pcall could not catch it, while the INTERP backend ran the function body normally (e.g. a type() guard returning early). - emit a <fn>__dyn full-dynamic variant for each specialized function (CompileFuncBody with spec_bitmask=-1, the mature non-specialized path); the entry dispatcher routes non-numeric math arguments to it instead of throwing, so body-level errors stay pcall-able Lua errors - add FakeluaSpecMissException: tentative native numeric compilation (CompileNumericExp etc., 7 sites) now falls back silently as normal control flow; escaping Build() still becomes the same hard compile error text as before - forward-declare __dyn in the decls section - tests: add test_spec_deopt (type guard/multi-arg/heterogeneous return/pcall/recursion across all backends and debug modes); update math_param_non_numeric_error to the unified body-level message and run on AllJitTypes(); InferGetCCode strips __dyn bodies by default so existing shape assertions target the specialized variants
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #30 +/- ##
==========================================
+ Coverage 87.99% 88.00% +0.01%
==========================================
Files 124 124
Lines 25388 25414 +26
==========================================
+ Hits 22339 22366 +27
+ Misses 3049 3048 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
esrrhs
added a commit
that referenced
this pull request
Oct 11, 2026
…xit code (#31) * fix: reject redis pub/sub commands, auto-seed math.random, CLI exit code Fixes three issues from the FakeLua Phase 16 integration report (docs/fakelua-bugs-phase16.md, based on dafdac7). redis (high-value safety fix): SUBSCRIBE/PSUBSCRIBE/UNSUBSCRIBE/ PUNSUBSCRIBE issued via the one-shot conn:command() channel left hiredis holding a dangling CmdOp* as privdata after the first ack popped and destroyed it; every subsequent published message wrote through the freed pointer (use-after-free/heap corruption). Full pub/sub needs a dedicated long-lived subscription context, so for now the command verbs are rejected case-insensitively before the readiness check with a clear error (pcall-catchable, works without a live server), and both native READMEs document the limitation plus the polling workaround. math.random: std::rand() defaulted to seed 1, so without an explicit math.randomseed every process start produced the identical sequence. The math library now auto-seeds once per process on first state init (time + std::random_device + stack-address entropy), matching Lua 5.4; explicit math.randomseed(x) still overrides. flua CLI: an uncaught FakeluaException propagated to libc++abi and killed the process with SIGABRT (exit 134). main() now catches std::exception around compile/run, prints "flua: <msg>" to stderr and exits 1, per standard Lua interpreter convention. The report's Bug 1 (math-specialization entry guard aborting on non-numeric args) is addressed by the independent PR #30. Tests: new test_redis.subscribe_rejected (all backends, no server required); full suite passes except the 8 test_mysql integration tests that need a live MySQL server. * fix: reject sharded pub/sub commands (ssubscribe/sunsubscribe)
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.
Problem
A file-level math-specialized function whose math-position argument was non-numeric (
string/bool/nil/table, includingnilfilled in for a missing argument) hard-failed directly in the TCC/GCC entry dispatcher. The exception escaped the generated dylib with no handler →terminate due to uncaught exception, aborting the whole process. It could not be caught bypcall, while the INTERP backend executed the function body normally:Fix
<fn>__dynfull-dynamic variant compiled withCompileFuncBody(..., spec_bitmask=-1)— the mature non-specialized CVar path. The entry dispatcher routes to it when any math argument is neitherVAR_INTnorVAR_FLOAT, instead of throwing. Genuine arithmetic errors inside the body still take the pcall-able Lua error path, and all three backends now report the same body-level message (attempt to perform arithmetic on non-numeric value).FakeluaSpecMissException(util/exception.h): the 7 tentative native-numeric compile sites (CompileNumericExp, raw native binop/unop) throw this instead of a logged hard error.TryCompileNativeExprcatches it as routine fallback; if it escapesBuild(),Generate()converts it to the sameCode generate failed, ...text as before.__dynis forward-declared in the decls section.__dynre-enters through the VM entry dispatcher;RTLD_LOCALkeeps same-named symbols isolated across files.Tests
test/lua/infer/test_spec_deopt.lua+infer.test_spec_deopt: type guard, multiple math params, heterogeneous return (string),pcall, recursion, C++ boundary catch — across TCC/GCC/INTERP × debug on/off.exception.math_param_non_numeric_errorupdated to the unified message and now runs onAllJitTypes().InferGetCCodestrips__dynbodies by default so the 100+ existing shape assertions keep targeting the specialized variants; the deopt test opts in withkeep_dyn_variants=true.test_mysql.integration_*tests that require a live MySQL server (pre-existing environment baseline).