Skip to content

Fix backward jump optimization in generic for loops - #541

Open
sjh9714 wants to merge 1 commit into
yuin:masterfrom
sjh9714:codex/20261001-540-generic-for-jump
Open

sjh9714 wants to merge 1 commit into
yuin:masterfrom
sjh9714:codex/20261001-540-generic-for-jump

Conversation

@sjh9714

@sjh9714 sjh9714 commented Oct 1, 2026

Copy link
Copy Markdown

Fixes #540.

Changes proposed in this pull request:

  • Stop following jump chains when they reach the current or an earlier instruction. Earlier jumps have already been patched from label IDs to relative offsets; interpreting those offsets as labels can make a generic for with a constant-false branch lose return values, panic, or loop forever. Leaving the backward jump intact preserves its target without changing the VM.
  • Add regression cases for the reported return, sum, and preceding-loop failures, dead branches containing break or a nested loop, and runtime-false/numeric-loop controls. Five cases fail before the fix; all seven pass afterward.

Testing passed:

  • go test -count=1 ./...
  • go test -race -run '^TestGenericForConstantFalseBranch$' -count=1 -v .
  • make build
  • go build ./...

Additional checks found existing baseline failures: go vet ./... reports self-assignment and unreachable code, and go test -race -count=1 ./... reports a finalizer race in TestLocalVarFree. The vet diagnostics are identical on pristine upstream; go test -race -run '^TestLocalVarFree$' -count=1 . also reproduces the race there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

if false then local x end inside a generic for loses the chunk's return value, panics with index out of range, or never finishes

1 participant