Repository navigation
Hash: advance MRI 4.0.6 conformance (aliases, block arity, compare_by_identity/default retention, sized enumerators, inspect dispatch, dig/fetch/delete/default_proc=/initialize/to_hash) - #545
Merged
Conversation
… sized enumerators, inspect dispatch Advance MRI 4.0.6 conformance for core/hash residual methods: - Make has_key?/include?/member?/length/store/update/filter/filter!/to_s genuine built-in aliases (shared method records) so UnboundMethod == holds. - select/reject/delete_if/keep_if/select!/reject! yield key and value as two separate arguments (not a single pair), matching MRI. - merge/slice/except/select/reject/compact/transform_values propagate the compare_by_identity flag; merge also carries the receiver's default and default_proc. - Give Hash iteration methods sized Enumerators so #size does not destructively materialise the in-place forms. - Hash#inspect dispatches #inspect to each key/value through the VM and to_s is a true alias of it. - merge/merge!/update coerce a non-Hash argument via #to_hash. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…cion, to_hash, tests Further MRI 4.0.6 conformance for core/hash residual methods: - dig reads a first-level miss through the hash default (value or proc), so it respects Hash.new defaults and can keep digging into them. - fetch raises ArgumentError for other than 1..2 arguments. - delete calls a supplied block with the key when the key is absent. - to_h with a block coerces a non-Array pair via #to_ary. - Add Hash#to_hash returning self. - Hash[] coerces a single argument via #to_hash then #to_ary, and names a nil element as 'nil' (not 'NilClass') in its element-type error. - Hash#initialize resets both the default value and default proc and is marked private. - default_proc= coerces via #to_proc and rejects a fixed-arity lambda whose arity is not 2. - Hash.ruby2_keywords_hash retains the default, default_proc and compare_by_identity flag. - Add internal/vm/hash_method_residuals_test.go covering the new branches. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ll coverage Exercise every symbol-label branch of symIsPlainLabel (bare label, trailing ?/!, quoted operator/ivar/setter, empty) by calling #inspect explicitly rather than via p (which uses the low-level repr). 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.
Advances MRI 4.0.6 conformance for
core/hashresidual (non-equality) methods. Measured against/opt/homebrew/bin/ruby4.0.x and the rubyspec corpus:core/hash/*_spec.rbgoes from ~479 to 532 passing examples (fail 21, error 4), with no regressions in the hash suite or incore/enumerableHash usage.What changed (Hash methods only)
Genuine built-in aliases — installed as shared method records so
Hash.instance_method(:x) == Hash.instance_method(:y)holds, fixing whole spec files that were failing on identity:has_key?/include?/member?↔key?,has_value?↔value?,length↔size,store↔[]=,update↔merge!,filter↔select,filter!↔select!,to_s↔inspect.Block arity —
select/reject/delete_if/keep_if/select!/reject!now yield the key and value as two separate arguments (a|*a|block sees[k, v], a single-parameter block sees the key), matching MRI;each/mapstill yield the single pair.compare_by_identity / default propagation —
merge/slice/except/select/reject/compact/transform_valuescarry the receiver'scompare_by_identityflag into their result (set before insertion, so identity-distinct keys survive);mergeadditionally retains the receiver's default value and default proc;Hash.ruby2_keywords_hashretains all three.Sized enumerators — the block-less iteration methods return sized
Enumerators, so#sizereports the hash length without materialising — which for the in-place forms (transform_values!,select!, …) had destructively mutated the hash.Per-method fixes
Hash#inspectdispatches#inspectto each key/value through the VM (honouring a Ruby-level override) andto_sis a true alias of it; symbol labels follow MRI's 4.0 rule (a:bare,"<=>":quoted).digreads a first-level miss through the hash default, so it respectsHash.newdefaults and keeps digging.merge/merge!/updatecoerce a non-Hash argument via#to_hash.fetchraisesArgumentErrorfor other than 1..2 arguments.deletecalls a supplied block with the key when the key is absent.to_hwith a block coerces a non-Array pair via#to_ary.Hash#to_hashreturning self.Hash[]coerces a single argument via#to_hashthen#to_ary, and names anilelement asnil(notNilClass) in its error.Hash#initializeresets both the default value and default proc and is marked private.default_proc=coerces via#to_procand rejects a fixed-arity lambda whose arity is not 2.Out of scope / not fixed
The remaining residual failures need machinery outside the Hash methods:
hash_spec(#hashvalue function — deliberately untouched),inspect_spec(stale corpus expecting the pre-3.4=>format, which MRI 4.0 itself no longer produces),new_speccapacity:/unknown-keyword handling andallocate/subclass wrapping and Hash instance variables (VM call-convention/allocation features), and thetransform_keys!/delete/shiftmutate-while-iterating cases.Verification
go test ./internal/vm/andgo test ./...green.GOOS=wasip1 GOARCH=wasm go build ./...OK.gofmt -lclean on changed files.internal/vm/hash_method_residuals_test.gocovers the added branches; every function changed/added is at 100% coverage; repo total unchanged at 99.9%.🤖 Generated with Claude Code