Repository navigation
feat(interp): run VM calls from host functions nested - #310
Merged
Merged
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
siyul-park
force-pushed
the
feat/reentrant-invoke
branch
from
November 9, 2026 23:40
8a3394d to
be589af
Compare
A Go func bound to a VM function returned ErrInterpreterBusy whenever Run was active, so a host function could not call back into the VM (a comparator for a host sort, for example). Host calls now count themselves in Interpreter.hosts. While one runs, invoke pushes the callee and arguments above the host's stack, writes a CALL-only frame, raises the floor to it, and dispatches nested on the same interpreter, restoring every saved register afterwards. A trap or cancellation unwinds the nested frames and returns as the Go func's error. ErrInterpreterBusy remains for calls during Run from outside a host function. Fixes #250 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
siyul-park
force-pushed
the
feat/reentrant-invoke
branch
from
November 10, 2026 00:02
22c4cae to
bba9d39
Compare
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
Fixes #250. A Go func bound to a VM function, for example through
Unmarshal, returnedErrInterpreterBusywheneverRunwas active. So a host function could not call back into the VM, e.g. a comparator for a host sort.Interpreter.hostscounts running host calls. The generated host call increments it beforeFnand decrements it after a normal return.Runclears it on return, since aFnthat panicked skips the decrement.invokenow has three cases:Runactive: the path is unchanged.Runactive and a host function running:nest.Run:ErrInterpreterBusy.nestfollowsengine.reenter's pattern:floorto it, so handler search and the dispatch recover stop at the boundary.fr/fp/floor/hosts/ctx/done/the frame slot.On a trap or cancellation it unwinds the nested frames and stack, and returns the error to the Go func.
ExitCallto a host target deopts and replays, so a host function always runs from threaded code. Inside a served call (reenter),engine.depthis already raised, so a nested dispatch that enters native code nests below the suspended activations. That last part relies on fix(jit): abandon only the native stack the latest entry started #308.Tests (
TestRegistry_Unmarshalsubcases, red on main withinterpreter busy)WithThreshold(1). Results are correct and live refs return to baseline.Runerrors withErrDivideByZeroand refs balance afterReset.tryaround the host call. The caught code is the trap's own (TrapCodeDivideByZero), because the host returns the nested*RuntimeError.context.Canceled.Run, outside any host function, still getsErrInterpreterBusy.go test -raceon the interp tests,make check(pre-commit) andgit diff --check: pass.Docs
docs/host-integration.md,README.md,README.ko.md, and the Go docs ofHostFunctionandErrInterpreterBusy.Not covered
No JIT case for a trap inside a nested native call. Threshold 1 runs the success path only.
🤖 Generated with Claude Code