Repository navigation
Regexp linear_time?/quote/\u encoding + dup named_captures; Lazy#each value packing - #577
Merged
Merged
Conversation
…t build) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Reachable core/regexp conformance wins (parser-blocked u/s/e/n literal
modifiers left aside — the go-ruby-parser lexer drops them before they
reach this package):
- Regexp.linear_time?(re_or_str[, flags]): new singleton method. Linear
unless the pattern uses a back-reference (\1…\9, \k<>) or a
subexpression call (\g<>), which is exactly the go-ruby-regexp engine's
own memoisation gate (HasBackref/HasCall). A String arg is compiled
(RegexpError on a bad pattern); a Regexp arg ignores flags and warns
"flags ignored" (ref: MRI rb_reg_s_linear_time_p; re.c). +12 (was all
errors: undefined method).
- Regexp#named_captures: accumulate every group index a repeated name
owns instead of overwriting — /(?<is>.)(?<pat>.)(?<is>.)/.named_captures
== {"is"=>[1,3],"pat"=>[2]} (ref: re.c named_captures). +1.
- Regexp#encoding / #fixed_encoding?: a \u escape resolving to a
non-ASCII code point fixes the pattern to UTF-8 even when the source
bytes are all ASCII (/\u{9879}/.encoding == UTF-8, fixed_encoding? ==
true), matching re.c's unescape_unicode → rb_utf8_encoding. +2
(encoding_spec, fixed_encoding_spec).
- Regexp.quote / .escape: tag the result encoding as MRI's rb_reg_quote
does — US-ASCII when the operand is all ASCII, otherwise the operand's
own encoding (BINARY for an ASCII-8BIT input). +2 (quote_spec 7/7).
Whitebox tests cover every new branch, including the malformed-\u and
trailing-backslash paths a compilable Regexp can never reach. Every
expectation checked byte-for-byte against MRI 4.0.5.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Enumerator::Lazy#each mishandled a source that yields several values at
once. The lazy pipeline already threads the raw arguments of a multi-value
yield (`multi`) alongside the gathered value, but the terminal #each sink
dropped them, so it always passed the packed Array as a single block
argument.
MRI's rule (rb_enum_values_pack, confirmed against ruby 4.0.5):
- a bare lazy (no ops) forwards the yielded values to the block by
ordinary arity, so `{ |x| }` sees the first value and `{ |*a| }` the
whole tuple;
- once any op has run, a multi-value yield is packed into one Array
element, which the block then receives as its single value.
lazyRun's sink now carries `multi`, and #each spreads it only for a bare
lazy (len(ops)==0); an op-bearing pipeline keeps the packed value. Fixes
core/enumerator/each_spec (lazy variant) and the enumerable_value_packing
shared examples across the lazy select/reject/drop/take/uniq/compact
suites, with no regressions.
core/enumerator/each_spec: pass 22 -> 24.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tannevaled
added a commit
that referenced
this pull request
Sep 6, 2026
…578) Wave-15 merged three disjoint-file, bibliography-first conformance PRs: - #576 core/io: fd-based IO constructors (IO.open/new/for_fd + mode/encoding/ binmode/autoclose resolution per io.c) — core/io +107. - #575 core/kernel: Kernel#caller_locations (unblocks the raise_spec collection cascade), caller start/length/range args, raise #exception protocol + empty bare-raise message per MRI — core/kernel +29. - #577 core/regexp+enumerator: Regexp.linear_time?, quote/escape result encoding, \u-escape fixed_encoding, named_captures dup names, Lazy value packing — core/regexp +17, enumerator +2. Measured total on merged main: 19179 passing (files loaded 2171, +7 that previously failed to load). Local measure at TIMEOUT=25; CI runs TIMEOUT=60 so its total is >= this floor. Co-authored-by: Claude Opus 4.8 <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.
What
MRI-4.0.6 conformance for
core/regexpandcore/enumerator, edited only ininternal/vm/regexp.goandinternal/vm/lazy.go(plus new_test.go).Regexp
Regexp.linear_time?(re_or_str[, flags])— new singleton method. A patternmatches in linear time unless it uses a back-reference (
\1…\9,\k<name>)or a subexpression call (
\g<name>), which is exactly the go-ruby-regexpengine's own memoisation gate (
HasBackref/HasCall). A String argument iscompiled (
RegexpErroron a bad pattern); a Regexp argument ignores flags andwarns
flags ignored. Ref: MRIre.crb_reg_s_linear_time_p.Regexp#named_captures— a repeated capture name now collects every groupindex it owns instead of keeping only the last, e.g.
/(?<is>.)(?<pat>.)(?<is>.)/.named_captures == {"is"=>[1,3], "pat"=>[2]}.Ref:
re.cnamed-capture map.Regexp#encoding/#fixed_encoding?— a\uescape resolving to anon-ASCII code point now fixes the pattern to UTF-8 even when the source bytes
are all ASCII (
/\u{9879}/.encoding == UTF-8,fixed_encoding? == true).Ref:
re.cunescape_unicode→rb_utf8_encoding.Regexp.quote/.escape— the result now carries MRI's encoding tag:US-ASCII when the operand is all ASCII, otherwise the operand's own encoding
(BINARY for an ASCII-8BIT input). Ref:
re.crb_reg_quote.Enumerator / Lazy
Enumerator::Lazy#eachvalue packing — a bare lazy now forwards amulti-value source yield to the block by ordinary arity (
{ |x| }sees thefirst value,
{ |*a| }the whole tuple), while a lazy that has run any oppacks a multi-value yield into a single Array element, matching MRI's
rb_enum_values_pack. The pipeline already threaded the raw argumentsalongside the gathered value; the terminal
#eachwas dropping them.Measured deltas (ruby/spec corpus)
(linear_time +12, quote +2, named_captures +1, encoding +1, fixed_encoding +1).
each_specpass 22 → 24 (+2) (the lazyeachfix);full
core/enumerator/lazysuite re-measured with no regressions.Out of reach from this file set (noted, not attempted)
The
u/s/e/nregexp literal modifiers are dropped by thego-ruby-parserlexer (lexer.go: onlyi/m/x/oare recorded) beforethey ever reach
regexp.go, so theoptions_specFIXEDENCODING/NOENCODINGcases, the
//nixminspect ordering,==for/x/uvs/x/n, and theu/s/e/nrows ofcompile/new/encoding/fixed_encodingcannot befixed here — they need a change in the parser dependency, which is outside this
agent's file set.
Tests
Whitebox
_test.go(packagevm) cover every new branch — including themalformed-
\uand trailing-backslash paths a compilable Regexp can never reach,and all three arms of the lazy value-packing rule.
go build ./...,go test ./internal/vm/,gofmt, and thewasip1/wasmbuild are all green;100% coverage on the new/changed code in
regexp.goandlazy.go. Everyexpectation was checked byte-for-byte against MRI 4.0.5.
🤖 Generated with Claude Code