Skip to content

Return block escape values from String substitution - #407

Merged
284km merged 3 commits into
mainfrom
codex-misc-gsub-block-break
Nov 30, 2026
Merged

284km merged 3 commits into
mainfrom
codex-misc-gsub-block-break

Conversation

@284km

@284km 284km commented Nov 30, 2026 •

Copy link
Copy Markdown
Owner

A break 9 from a String substitution block now returns 9, rather than inserting it into a partial result such as "a9c". Preserve the escape flow before conversion, frozen/modified-string checks, writeback, and match publication. Lambda-local break and return still supply replacement values.

Corpus 1161 covers sub, sub!, gsub, gsub!, direct/send calls, nil and object escape values, lambdas, return/throw/raise, string mutation/freezing, and retained values across GC. It matches ruby on both engines, including GC stress. Existing fixtures 291, 745, 954 and 1068 also match on main and the candidate.

Original CRuby file comparison: unchanged ruby/test_m17n.rb, selectors test_gsub, test_sub, test_sub2, test_sub3, test_scan, test_dup_scan: 6 tests, 15 assertions, 0 failures/errors/skips on ruby, main evaluator/VM, and candidate evaluator/VM. Loading ruby/test_string.rb was also attempted, but the reference lacks its real -test-/string extension; that attempt is not counted as a pass, and no stub or test edit was used.

Merged main 9d1c0f3 (#409 included) and rebuilt with pinned Mere 9dec2ff6, mgz 661a01d8, ordinary O2. Reference: clean ruby 4.0.10 via tools/ref_ruby.sh. Native candidate SHA-256: 6d7191fb2f3cf013816f5f885ae40b77eef550663b5106138866adee3f9c86d2. All runtime input hashes are checked before and after validation; evaluator runs leave MERE_RUBY_VM unset.

  • sh run_corpus.sh --both: 1040/1040 PASS, index on/off.
  • MERE_RUBY_VM=1 sh run_corpus.sh --both: 1040/1040 PASS, index on/off.
  • MERE_RUBY_VM=1 sh tools/iseq/vm_corpus.sh -j 2: 1040 on the VM, 0 fallback, 0 FAIL.
  • All source gates pass, including strbuf_region_check.py, GC roots, duplicate/dead definitions, method writes, ivar door, names/namespaces/lengths, regexp captures and bracket depth. Packed GC mark checks pass under O2 and ASan/UBSan. record_hygiene and staged/unstaged whitespace checks pass.
  • The same original ruby/test_m17n.rb selection was rerun against current main and the integrated candidate: 6 tests, 15 assertions, 0 failures/errors/skips, on all five reference/main/candidate sides.

bench/string_substitution_blocks.rb normal 10000 --seed=1 and large 20 --seed=1 were remeasured on current main and the integrated candidate. The latter repeatedly substitutes a 40,000-character string. Each engine uses MERE_RUBY_GC_TIGHT=1, fixed seed 1, three alternating main/candidate pairs. Instructions are medians; RSS is the maximum of three runs in MiB.

Workload Engine Instructions, main → candidate Change Max RSS, main → candidate
normal evaluator 1,623,498,312 → 1,623,759,299 +0.016% 89.797 → 89.750
normal VM 1,498,291,870 → 1,498,324,473 +0.002% 90.672 → 90.734
large evaluator 16,159,970,130 → 16,175,191,517 +0.094% 107.922 → 107.266
large VM 15,459,646,944 → 15,469,089,158 +0.061% 107.797 → 108.547

No collector or arena-policy changes are included. The earlier standard-corpus preflight failure was inherited from the pre-#409 base; the current integrated head passes that gate and all three sweeps above. Local validation is complete; exact-head re-review and hosted CI remain, with no queue exception or merge-hold waiver claimed.

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head 0489368 against current main 5b815b6. No new actionable findings.

Keeping the escape flow separate from replacement text correctly avoids to_s conversion, receiver writeback and match republication after a block escape. The lambda guard preserves lambda-local replacement values, and the legacy regex fallback now carries the same flow contract.

Independent validation in isolated temporary checkouts:

  • Fresh ordinary O2 head build using local Mere v0.1.732; reused the current-main O2 binary built earlier in this review session after confirming its tracked files remain unchanged and mgz remains at 661a01d8. Reference: clean Ruby 4.0.10 via tools/ref_ruby.sh.
  • Corpus1161 matches Ruby on both engines in default, hash-index-disabled and GC-stress=32 configurations (6/6). Main reproduces the escape-value bug in all six.
  • An independent 136-case probe covers all four methods, zero-width/no-match/String patterns, break/next, lambda break/return, Enumerator/retained Method calls, throw, subclasses and mutation/GC in ensure. All 136 cases match in each of the six head configurations; main matches 98/136 in each, with no previously matching case lost.
  • Existing corpus291/745/954/1068 match on both revisions in all six configurations (48/48 comparisons). GC-root, duplicate-definition, dead-definition, method-write, ivar-door and diff whitespace checks pass.
  • The StrBuf gate reports the same inherited read_path_whole/read_path_at failures as current main. No suppression, full corpus/upstream-file pass, or performance remeasurement is claimed here.

Main CI run46170689621 remains the disclosed baseline: build-linux/corpus fail at that StrBuf gate and the VM comparison is skipped. PR CI run46332776874 still has build-linux running and 15 queued jobs; downstream coverage is incomplete, so no queue exception applies. This remains draft and is not merged; the recorded global merge hold is preserved.

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed head 0475e85 against current main 9d1c0f3 after the main integration. No new actionable findings. The PR-specific runtime diff is unchanged from the previous review; the added validation record distinguishes completed local checks from pending hosted CI.

The separate escape flow still prevents replacement conversion, receiver writeback and match republication after an interrupted substitution, while preserving lambda-local replacement values. Both the primary regex engine and legacy fallback follow that contract.

Independent checks on the current trees in isolated temporary checkouts:

  • Fresh ordinary O2 builds of both revisions with local Mere v0.1.732 and pinned mgz 661a01d8; clean Ruby 4.0.10 selected through tools/ref_ruby.sh. Candidate binary SHA-256: 874604244cb4032fb66952a587944c9c2193d3c05555d6fdc4ee921d5ead07cd. Tracked sources remain unchanged.
  • Corpus1161 matches Ruby in all six configurations: evaluator/VM, each with default settings, hash index disabled, or GC stress=32. Current main reproduces the original escape-value differences in all six.
  • Re-ran the independent 136-case substitution probe in those six configurations. Candidate matches 136/136 each; main matches 98/136 each, with no previously matching case lost. Coverage includes all four methods, zero-width/no-match/String patterns, break/next, lambda break/return, Enumerator and retained Method calls, throw, subclasses, and mutation/GC in ensure.
  • Existing corpus291/745/954/1068 match on both revisions in all six configurations (48/48 comparisons). Generated-C/source StrBuf, GC roots, duplicate/dead definitions, method-write, ivar-door and diff whitespace checks pass. The inherited StrBuf gate failure reported in the earlier review is absent on this integrated head.

I did not independently repeat the full corpus sweeps, upstream-file comparisons, performance measurements or platform/resource acceptance reported by the author. Main CI run46342657606 was inspected job by job: 24 successful jobs and one skipped evaluator/VM comparison. PR CI run46356192342 still has build jobs running and downstream matrices incomplete; other PR workflows also remain unfinished. No runner-queue exception or merge-hold clearance is claimed. This PR remains draft and is not merged.

@284km
284km marked this pull request as ready for review November 30, 2026 05:13

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head 0475e85a (main.mere: rx_gsub_blk / rx_gsub_blk2 return a flow next to the text; invoke_with_block0 answers an interrupted flow's value; corpus 1161).

  • A non-lambda block's break/return, and a raise from any block, now leave the substitution before w_to_s conversion, the frozen/modified check, receiver writeback and $~ republication. break 9 therefore answers 9 instead of being spliced in as "a9c". A lambda's break/return still supplies the replacement, as in Ruby. Both the Onigmo-path (rx_gsub_blk2) and the fallback (rx_gsub_blk, RBadPat) carry the flow.
  • Corpus 1161 covers sub/sub!/gsub/gsub!, direct and send, nil/object escape values, lambdas, return/throw/raise, mutation and freezing, and GC retention, on both engines. The branch includes current main (with #409's gate), corpus --both is 1040/1040 on both engines, and the instruction cost is within +0.1%.

No findings from me.

@284km
284km merged commit 98aa453 into main Nov 30, 2026
27 of 36 checks passed
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.

1 participant