local pass over engine internals: caller globals survive engine calls (#5)#6
Merged
Conversation
Verification first refuted the issue as filed: its example declares the global AFTER load_file, an order where cross-module writes are insulated. Declared BEFORE the load — the realistic order — the clobber is real and worse than filed: caller globals like `pos is 42` corrupt the ENGINE's own parse/VM state (9 of 11 regression checks failed, including the engine producing wrong results). The order dependence itself is now upstream as EigenScript#373 (GAPS.md entry added). The fix is the mechanical `local` pass the issue prescribed, over regex_parse/regex_compile/regex_vm/regex.eigs (~150 first assignments), plus two hand-fixes the mechanical rule misses — sibling if-branches where the first textual assignment doesn't dominate the others (`c` in the char/any/class opcode branches, `result` in regex_vm_run's anchored/search split): a `local` in one branch never executes when a sibling runs, so the sibling's bare assignment still clobbered. tests/test_s9_scope.eigs (11 checks, auto-picked-up by tests/run.sh) declares ten engine-working names as module globals BEFORE loading the engine and asserts they all survive re_compile/re_search/re_find_all — fails 9/11 on the unfixed tree. Suite: 358/358 (347 original + 11 new). Closes #5 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
The verification story (worth reading — the issue as filed was a non-repro)
Reproduce-before-believing turned up a surprise: the issue's own example (
load_file, thenpos is 42) does not reproduce — cross-module writes are insulated in that order. Declared before the load, the clobber is real and worse than filed: the caller's globals corrupt the engine's state (pos is 42breaks the parse — 9 of 11 regression checks failed, including wrong match results). The order dependence is itself an upstream semantics wart, now filed as EigenScript#373 and logged in GAPS.md.The fix
The mechanical
localpass the issue prescribed (~150 first assignments across the four engine files), plus two hand-fixes for a pattern the mechanical rule misses: siblingifbranches. Alocalon the first textual assignment doesn't dominate siblings —local cin the"char"opcode branch never executes when"any"/"class"run, so their barec isstill clobbered. Same shape forresultinregex_vm_run(the anchored branch always returns). A dominance audit script flagged these; both fixed with per-branchlocal.Regression test
tests/test_s9_scope.eigs— ten common engine working names (pos,c,n,out,parts,branches,ranges,results,i,j) declared as module globals before the engine loads, thenre_compile/re_search/re_find_all, asserting the engine ran correctly and every global survived. Fails 9/11 on the unfixed tree; auto-wired viatests/run.sh's glob.Gates
Suite 358/358 (347 original + 11 new).
Closes #5
🤖 Generated with Claude Code