Skip to content

Enumerator + Lazy + Yielder: advance MRI 4.0.6 conformance - #550

Merged
tannevaled merged 4 commits into
mainfrom
feat/agent-enumr
Sep 2, 2026
Merged

tannevaled merged 4 commits into
mainfrom
feat/agent-enumr

Conversation

@tannevaled

@tannevaled tannevaled commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Advances core/enumerator and core/enumerator/lazy residuals toward MRI Ruby 4.0.6, entirely within internal/vm/enumerator.go and internal/vm/lazy.go plus a new enumerator_residuals_test.go. Suite total for those specs: pass 233 → 298 (fail 45 → 20, error 34 → 25); no regressions.

Highlights:

  • Enumerator#feed (queued value returned by the source's next yield; TypeError on double-feed; cleared by #rewind); Yielder#yield returns that value, Yielder#<< enforces arity 1, Yielder#to_proc lets &yielder be a block.
  • *Enumerator#each(args) appends to the receiver's #each; #each_with_index rejects extra args; uninitialized (allocate) enumerators inspect as #<Class: uninitialized>.
  • Enumerator::Lazy.new(obj, size) { |y, *vals| ... }; lazy #size propagation (map/with_index/zip keep, take/drop bound, filtering ops -> nil); lazy external iteration #next/#peek/#next_values/#peek_values/#rewind (no over-evaluation); #to_enum/#enum_for; the MRI method aliases and full instance_methods(false) whitelist.
  • Multi-value block semantics (rb_yield_values2): map/flat_map/filter_map/take_while/drop_while pass raw args by arity; select/reject/uniq and grouping ops see the gathered value; args survive a filter into a later mapping op.
  • flat_map flattens an Array or a forceable Lazy (not a plain Enumerator); zip validates list-like args (TypeError); with_index nil offset -> 0; take stops driving the source the moment its quota is met (take(0) drives it zero times).

Builds, go test ./internal/vm/ and go test ./... green, GOOS=wasip1 GOARCH=wasm go build ./... OK, gofmt -l clean; every changed function is 100% in the merged -coverpkg profile. FLOOR untouched.

🤖 Generated with Claude Code

tannevaled and others added 4 commits September 1, 2026 16:47
Enumerator::Lazy now answers #size by threading the source's size through
the op chain (map/with_index/zip keep it, take/drop bound it, filtering ops
make it unknown). Adds Enumerator::Lazy.new(obj, size) { |y, *vals| … },
Lazy#next/#peek/#next_values/#peek_values/#rewind driven one element at a
time through a fiber (no over-evaluation), and shares Method objects so
collect/filter/find_all/collect_concat/enum_for match their MRI aliases and
the Lazy method whitelist is complete. Adds Lazy#to_enum/#enum_for.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…index

Enumerator#feed queues a value the source's next yield returns during external
iteration (TypeError on double-feed, cleared by #rewind); Yielder#yield now
returns that value, Yielder#<< enforces arity 1, and Yielder#to_proc lets a
yielder be passed as &block. Enumerator#each_with_index rejects extra args;
uninitialized (allocate) enumerators inspect as "#<Class: uninitialized>".
Lazy#take stops driving the source once its quota is met (never running a
source that raises on its n+1-th step, and take(0) drives it zero times);
Lazy#zip validates list-like arguments (TypeError) and Lazy#with_index treats
a nil offset as 0; Lazy#flat_map flattens an Array or a forceable Lazy.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…tests

The lazy pipeline now threads a source's raw yield arguments alongside the
gathered value, so a multi-value yield reaches each op the way MRI does
(rb_yield_values2): map/flat_map/filter_map/take_while/drop_while pass the
arguments by block arity (a single-parameter block sees only the first),
while select/reject/uniq and the grouping ops operate on the gathered value;
the arguments survive a filter into a later mapping op. Enumerator#each(*args)
appends its arguments to the receiver's #each. Adds enumerator_residuals_test.go
covering feed, Yielder, aliases, lazy size/next/peek, to_enum, flat_map
flattening, zip validation, with_index offset and take quota behaviour.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ches

lazySize now only propagates an Integer or +Infinity size (any other base is
reported unknown), so lazyOpSize's take/drop arithmetic has no dead
non-numeric fallbacks. Removes the take op's now-redundant rem<=0 guard (the
pre-loop takeSaturated check plus stopping the pull the moment the quota is
met already keep take(0) from driving the source). Extends the residual tests
to cover the live-Lazy #inspect path, to_enum(meth) forcing, take followed by
an early-stopping terminal, and a lazy over a Chain source.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit b49a598 into main Sep 2, 2026
7 checks passed
@tannevaled
tannevaled deleted the feat/agent-enumr branch September 2, 2026 18:47
tannevaled added a commit that referenced this pull request Sep 3, 2026
Locks in #548 (Proc/Method/UnboundMethod), #549 (Integer/Float/Numeric) and
#550 (Enumerator/Lazy/Yielder). Measured 18245 passing on the pinned corpus,
up from 18102.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
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