Repository navigation
enumerator: Enumerator::Product class + Chain/ArithmeticSequence constructors + break-early take_while (core/enumerator +49) - #597
Merged
Conversation
…ructors, break-early take_while (core/enumerator +49)
Reference: ruby/ruby v3_4_0 enumerator.c (enum_product_initialize,
enum_product_init_copy, enum_product_each/product_each_i,
enum_product_total_size, enum_product_rewind, inspect_enum_product;
arith_seq_eq/arith_seq_hash; the missing ArithmeticSequence allocator/new).
- Enumerator::Product is now a real class backed by productSources on the
enumerator: .new/#initialize store the enumerables, .allocate yields an
uninitialized product, #initialize/#initialize_copy are private,
#each walks the Cartesian product via #each_entry (driven through
enumRunEach so #to_a/#take/#next work, infinite sources included),
#size follows enum_product_total_size (0/nil/INFINITY/Integer rules),
#rewind rewinds each source in order, #inspect renders the enumerables
with a self-reference guard ("..."). Enumerator.product now builds the
same object (top-level product_spec stays 12/12).
- Enumerator::Chain gains .allocate + private #initialize and an
"uninitialized" #inspect.
- Enumerator::ArithmeticSequence.new raises NoMethodError and .allocate
raises TypeError (MRI defines neither); #== / #hash key on the
begin/end/step/exclude_end? tuple.
- Enumerator#take_while breaks at the first falsy element (MRI's
rb_iter_break), so it terminates on unbounded sources — the generic
Enumerable#take_while loops to the end and hung produce_spec.
core/enumerator: fail 22->16, error 40->11, produce_spec FILEFAIL cleared
(pass 348->397). Remaining gaps are harness/object-model limits (shared
before-hook merge, native-method arity, subclass identity, the OpEq
fast-path gate) noted in the PR.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…quence/take_while surface (100% coverage) Covers every new branch via eval() snippets checked byte-for-byte against ruby 4.0.6: Enumerator::Product .new/.allocate/#initialize/#initialize_copy (replace, self-copy, frozen, uninitialized-source, different-class and arity guards)/#rewind/#size (Integer/empty-0/no-size-nil/finite-Float-nil/Symbol-nil/ Bignum/INFINITY)/#inspect (normal, uninitialized, self-referential); Enumerator::Chain .allocate + private #initialize + "uninitialized" #inspect; Enumerator::ArithmeticSequence .new (NoMethodError) / .allocate (TypeError) / #== / #hash; Enumerator#take_while breaking early on unbounded sources. Also simplifies #uninitialized (Inspect handles Product/Chain before it is reached) and drops an unreachable Bignum-zero branch in #size (0 always normalises to an Integer). go tool cover -func shows enumerator.go at 100%. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tannevaled
added a commit
that referenced
this pull request
Sep 8, 2026
…598) Wave-20 merged three bibliography-first conformance PRs: - #596 core/io: File.open/new trailing-Hash options, IO#read/readchar/gets external->internal transcoding, IO#set_encoding_by_bom, BOM stripping — +62 (and core/file +8 incidental). - #597 core/enumerator: Enumerator::Product class, Chain/ArithmeticSequence constructors, Enumerator#take_while break-early (clearing the produce_spec hang) — +49. - #595 core/module: extend_object, const_source_location, const_set const_added + redefinition warning, class_variable ancestry search, Module.constants singleton, remove/undef_method hooks — +19. Measured total on merged main: 19915 passing (2172 files load, +1 that was a hang). 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.
Summary
Advances MRI-Ruby-4.0.x conformance of
core/enumerator. Adds the fullEnumerator::Productclass, the missingEnumerator::ChainandEnumerator::ArithmeticSequenceconstructors, and fixes an infinite-loop hangin
Enumerator#take_while.All work is in
internal/vm/enumerator.go(+ a new whitebox test file). Themarshal files were investigated but left unchanged — see "Marshal: why no change".
core/enumerator: fail 22 → 16, error 40 → 11,
produce_specFILEFAIL cleared (pass 348 → 397, +49)Reference: ruby/ruby
v3_4_0enumerator.c—enum_product_initialize,enum_product_init_copy,enum_product_each/product_each_i,enum_product_total_size,enum_product_rewind,inspect_enum_product;arith_seq_eq/arith_seq_hash; and the fact that ArithmeticSequence definesneither an allocator nor
.new.take_whilefollowsrb_iter_break.Enumerator::Productis now a real class backed by aproductSourcesslice on the enumerator:
.new/#initialize(private) store the enumerables;.allocateyields anuninitialized product;
#initialize_copy(private) replaces the enumerableswith MRI's
OBJ_INIT_COPYguards (self-copy no-op even when frozen, thenFrozenError, thenTypeError "initialize_copy should take same class object", thenArgumentError "uninitialized product").#eachwalks the Cartesian product through#each_entry, driven viaenumRunEachso#to_a/#take/#nextall work (infinite sourcesincluded).
Enumerator.productbuilds the same object (top-levelproduct_specstays 12/12).#sizefollowsenum_product_total_size:0on an empty source,nilfor amissing/
nil/finite-non-Integer size,Float::INFINITYfor an infinite one,otherwise the Integer product.
#rewindrewinds each source in order;#inspectrenders the enumerableswith a self-reference guard (
...) via the shared repr guard.Enumerator::Chaingains.allocate+ a private#initializeand an"uninitialized"#inspect.Enumerator::ArithmeticSequence:.newraisesNoMethodErrorand.allocateraisesTypeError "allocator undefined for Enumerator::ArithmeticSequence"(MRI defines neither);#==/#hashkey onthe
begin/end/step/exclude_end?tuple.Enumerator#take_whilenow breaks at the first falsy element, so itterminates on unbounded sources (
Enumerator.produce,Array#cycle). Thegeneric
Enumerable#take_whileloops to the end, which hungproduce_spec.Coverage / gates
go build ./...andGOWORK=off go test ./...— all packages green.internal/vm/enumerator.goat 100% (go tool cover -func); new whiteboxtests in
enumerator_wave20_internal_test.go, every case byte-checked againstruby 4.0.6.gofmt -l internal/vm/empty;GOOS=wasip1 GOARCH=wasmbuild OK.Marshal: why no change
core/marshalwas measured at fail=49, error=9 and stays there. Every remainingfailure is blocked outside the four in-scope files:
I/e/Cdump/load cases) — out of scopeper the task; rbgo's object model can't attach ivars to built-in
String/Array/Hash/Regexp/Time/Struct (this is the large majority of the
failures).
object.Symbolcarries no encoding, so a binary-encodedsymbol can't be distinguished from a UTF-8 one on dump, and
Symbol#encoding(needed by the load specs) lives in the symbol/object model, not marshal.
Time.localignoresTZ(always UTC in rbgo), so thezone/offset dump+load specs can't be satisfied from marshal alone; the marshal
encoder was already correct for the offset-only case.
_dumpresult encoding,'o'/'C'validation, wrapped C pointer (dTYPE_DATA),
Random#marshal_load, UTF-16/32encode, StringIO binmode — allneed work in
object,builtins.go,io*,random, or the encodingsubsystem, which are outside this branch's editable files.
core/enumerator: remaining failures, all blocked outside scope
with_index(fail 3, error 7): the shim'sit_behaves_likedoes not merge ashared
before(:each)into the parent context the way real mspec'sit_should_behave_likedoes, so@enumisnilin the parent examples. Fixbelongs in
spec_helper.rb(off-limits).each(fail 2),chain/inspect"calls inspect on elements" (fail 1): theshim's mock
and_yield/and_returnchaining (spec_helper.rb).each_with_objectarity,product/eacharity,lazy/grep+grep_varity: anative method reports arity
-1; setting a fixed arity needs aMethodfieldin
object_model.go.arithmetic_sequence/==: the==operator uses thevalueEqualfast path,which only dispatches a user
#==for types listed inhasCustomEq(
digest_bind.go);#==itself is correct (covered via#send).arithmetic_sequence/inspect: MRI omits the step only when it was defaulted,which needs a "step given" flag recorded by
Numeric#step/Range#stepinbuiltins.go.product/initialize_copydifferent-classTypeError: a Ruby subclass of abuilt-in Enumerator can't carry its own class identity (object model).
producekwargs-as-initial-value: the shim declares version 3.4.1 and selectsthe pre-4.0 example, but rbgo (correctly for MRI 4.0.5) rejects the keywords.
lazy/take(loopenumerator),lazy/force+lazy/zipinfinite:Kernel#loopwithout a block and
Range#eachover0..Float::INFINITY(builtins.go).🤖 Generated with Claude Code