Repository navigation
Conversation
Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
A deflua or Elixir callback can now return {:suspend, values} (or
{:suspend, values, lua} to thread state) to park the running machine.
Lua.eval!/2 and Lua.call_function/3 return {:suspended, values, lua}
with a continuation on the %Lua{}; the new Lua.resume/2 and
Lua.resume!/2 re-enter the parked machine, the resume values becoming
the suspended call's results inside Lua. Heap effects made before a
suspend are kept, and a :max_instructions budget spans the whole
suspend/resume cycle.
The suspend travels as a Lua.VM.Suspend exception raised by the
callback wrappers; the executor and dispatcher catch it at their
native-call and engine-boundary sites and attach resumable machine
layers (a stack, innermost first) to the exception, which crosses the
tail-recursive BEAM frame to Lua.VM.execute/3 — the same channel VM
errors already use to ferry raise-time state out. Continuation.run/3
re-enters the layers innermost-first; the heap flows through the
completion states, not the layers.
A suspend that cannot be resumed — across pcall/xpcall, a metamethod,
a table.sort comparator, a string.gsub replacement function, a
generic-for iterator, a load reader, a required module, or a
re-entrant native call — is reported as the catchable Lua error
"attempt to suspend across a native call boundary".
Plan: A51
Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
PR: tv-labs#434 Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
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
Host-driven suspension/resumption of a Lua evaluation (plan A51).
A
defluaor Elixir callback can return{:suspend, values}(or{:suspend, values, lua}to thread state) to park the running machine.Lua.eval!/2andLua.call_function/3then return{:suspended, values, lua}with a continuation on the%Lua{}; the newLua.resume/2/Lua.resume!/2re-enter the parked machine — the resume values become the suspended call's results inside Lua.Design
Lua.VM.Suspendexception raised by the callback wrappers (execute_function/4,wrap_callback/3); the executor and dispatcher catch it at their native-call and engine-boundary sites and attach resumable machine layers (a stack, innermost first) to the exception, which crosses the tail-recursive BEAM frame toLua.VM.execute/3— the same channel VM errors already use to ferry raise-time state out. Zero happy-path cost: layers are built only inrescueblocks.Lua.VM.Continuation.run/3re-enters the layers innermost-first; the heap flows through the completion states, not the layers. A:max_instructionsbudget spans the whole suspend/resume cycle.pcallsemantics).pcall/xpcall, a metamethod, atable.sortcomparator, astring.gsubreplacement function, a generic-for iterator, aloadreader, a required module, or a re-entrant native call — is reported as the catchable Lua error"attempt to suspend across a native call boundary"(the Lua 5.2-style "yield across a C-call boundary" divergence). Fullcoroutinesupport remains a separate non-goal (coroutine.luastays a documented suite skip).Verification
mix test: 2917 passed (baseline 2870 + 44 new tests + 3 new doctests), 0 failuresmix test test/lua53_suite_test.exs --only lua53: 20/29 unchangedmix compile --warnings-as-errorsandmix format: cleantest/lua/suspend_resume_test.exs(44 tests: result placements, chained suspends, loops, dispatcher path, heap effects, error-after-resume, pcall/xpcall boundary, re-entrant deflua,call_functiondirect + pending_call, ArgumentError, encoded-value validation,:max_instructionsacross resume,decode: false, eval-between-suspend-and-resume, chunk clause, metamethod/comparator/gsub/iterator/load boundaries)Plan: A51