Repository navigation
Return block escape values from String substitution - #407
Conversation
284km
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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 araisefrom any block, now leave the substitution beforew_to_sconversion, the frozen/modified check, receiver writeback and$~republication.break 9therefore answers9instead of being spliced in as"a9c". A lambda'sbreak/returnstill 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--bothis 1040/1040 on both engines, and the instruction cost is within +0.1%.
No findings from me.
A
break 9from a String substitution block now returns9, 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-localbreakandreturnstill 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, selectorstest_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. Loadingruby/test_string.rbwas also attempted, but the reference lacks its real-test-/stringextension; 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 leaveMERE_RUBY_VMunset.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.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_hygieneand staged/unstaged whitespace checks pass.ruby/test_m17n.rbselection 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=1andlarge 20 --seed=1were remeasured on current main and the integrated candidate. The latter repeatedly substitutes a 40,000-character string. Each engine usesMERE_RUBY_GC_TIGHT=1, fixed seed 1, three alternating main/candidate pairs. Instructions are medians; RSS is the maximum of three runs in MiB.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.