Repository navigation
Array/Hash value equality: dispatch member #==/#eql?/#hash (MRI rb_equal) - #533
Merged
Merged
Conversation
Array#==, Hash#==, and the membership/search methods (include?, index, rindex, count, assoc, rassoc, key, value?, Hash#<=/</>=/>) compared elements by Go identity or the internal structural path, so an element with a redefined #== was ignored: [C.new] == [C.new] was false where MRI gives true. Thread a live VM through the recursive value-equality routine (valueEqualRec) so every leaf whose own #== matters — a user object, or a built-in with a custom #== such as Digest/Set — has that Ruby #== dispatched, matching MRI's rb_equal per element (including the reflexive Integer#== rule and the identity short-circuit that terminates self-referential members). VM-less callers keep the structural fallback. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…+ to_ary Extend the value-equality work to eql? and the set operations, and finish Array#== / Array#<=> conformance: - Array#eql? / Hash#eql? dispatch each member's own #eql? (VM-aware valueEql), so a value with a redefined #eql? participates. - uniq / & / | / - / difference / union / intersection group members by Ruby #hash and compare with #eql? (eqlHashCode + eqlKeys), matching MRI: a custom #hash/#eql? participates and #eql? is never asked across differing hash codes. - Array#== accepts an Array-like #to_ary object (reflexive dispatch), treats an Array subclass as a plain array, and makes [NaN] == [NaN] true via the per-element #equal? short-circuit (while bare NaN == NaN stays false). - Array#<=> returns an element's raw non-zero <=> result, converts the argument via #to_ary, and unwraps an Array subclass without calling to_ary. - Hash key lookup no longer sends #eql? when the stored key IS the lookup object (identity), so Hash#== does not spuriously compare a key to itself. Specs: equal_value 7->13, hash equal_value 13->17, hash eql 16/16, comparison 7->10, uniq 17->25 (2 remaining are the pre-existing iteration-mutation edge). Full internal/vm suite green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
… branches - eqlHashCode raises TypeError on a non-Integer #hash (MRI parity) and folds a Bignum #hash, via the shared hashAsInt helper. - Array#- (difference) is handled entirely in binaryOp, which has the VM to dispatch each member's #eql?/#hash; the dead VM-less arrayOp #- branch and the now-unused free arrayIncludes are removed. - rb_eql has no reflexive rule, so Array#eql?/Hash#eql? consult only the receiver member's #eql? (drop the unreachable right-operand dispatch). - reflexiveContainerEq is guarded at its callers (no dead nil-VM branch). - Extend array_equality_test with the #to_ary/#to_hash reflexive cases, Array/Hash subclass equality, [NaN] == [NaN], reflexive right operand, Bignum/non-Integer #hash, recursive-hash #eql?, and a VM-less Struct-of-Set path, bringing every changed function to 100% statement coverage. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Rerouting Set-member comparison through the top-level custom-#== dispatch left Set.eq reachable only via the VM-less path (Struct#== over a Set field), so add the unequal and size-mismatched Struct-of-Set cases to keep Set.eq at 100% statement coverage alongside the rest of the changed equality code. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tannevaled
added a commit
that referenced
this pull request
Aug 31, 2026
Locks in the gains from #530 (Encoding compatibility: Converter.new, concat negotiation, multibyte codepoints, ascii_only?), #531 (language def/method/super/keyword-argument), #532 (Enumerable residuals) and #533 (Array/Hash value equality dispatching #==/#eql?/#hash). Measured 17654 passing on the pinned corpus, up from 17470. 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.
Array / Hash value equality (MRI rb_equal / rb_eql)
Array#==,Array#eql?,Hash#==,Hash#eql?, and the membership / setoperations compared elements by Go identity or the internal structural path, so
an element with a redefined
#==/#eql?/#hashwas ignored:[C.new] == [C.new]wasfalsewhere MRI givestrue.What changed
#==dispatch —Array#==/Hash#==andinclude?,index,rindex,count,assoc,rassoc,key,value?,Hash#<=/</>=/>now dispatch each member's own Ruby
#==(MRI'srb_equalper element),including the reflexive
Integer#==rule and the#equal?identityshort-circuit (so
a=[]; a<<a; a==aand[NaN] == [NaN]are bothtrue).#eql?/#hashdispatch —Array#eql?/Hash#eql?compare memberswith
#eql?;uniq,&,|,-,difference,union,intersectiongroup members by Ruby
#hashand compare with#eql?(a custom#hash/#eql?participates;
#eql?is never asked across differing hash codes; a non-Integer#hashraisesTypeError).Array#==operand handling — accepts an Array-like#to_aryobject(reflexive dispatch), treats an
Array/Hashsubclass structurally;Hash#==accepts a
#to_hashobject.Array#<=>— returns an element's raw non-zero<=>result, converts anon-Array argument via
#to_ary, and unwraps an Array subclass without callingto_ary.#eql?when the stored key IS the lookupobject (identity), so
Hash#==does not spuriously compare a key to itself.rubyspec deltas (core)
The 2 remaining
uniqfailures are the pre-existing "tolerates increasing anarray size during iteration" edge (an iteration-helper concern, out of scope).
Verification
go test ./internal/vm/andgo test ./...green.GOOS=wasip1 GOARCH=wasm go build ./...OK;gofmt -lempty on changed files.-coverpkgover allinternal/...); every changedfunction at 100% statement coverage.
🤖 Generated with Claude Code