Repository navigation
Array & Array#pack: advance MRI 4.0.6 conformance (element_reference ArithmeticSequence, sum Kahan, pack U/P/p/buffer, residuals) - #567
Merged
Conversation
…uence, aliases, arity, enumerator size) core/array residuals wave 12: - Array#[] can be sliced with an Enumerator::ArithmeticSequence (a[(m..n).step(k)]): positive/negative steps, endless/beginless ranges, exclusive endpoints, negative indices, the begin-past-end nil result, and MRI's RangeError guard when |step| > 1 and the declared span reaches past the array. Verified byte-for-byte against MRI 4.0.6 (element_reference 56 -> 69 pass, 0 fail/error). - Array#[] accepts a user subclass of Range; a Range passed with a length is a TypeError; an index/length beyond the Fixnum range raises RangeError (arrayArefLong) instead of silently overflowing. - Array#length is a true alias of Array#size (shared method record). - Array#clear / Array#map reject stray positional arguments (ArgumentError). - Array.allocate returns a fully-formed empty Array and takes no arguments. - Block-less Array#bsearch / #bsearch_index / #rindex Enumerators report an unknown (nil) size, matching MRI. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
More core/array residuals (wave 12): - Array#sum uses MRI's exact-then-Kahan folding: integer/bignum/rational elements accumulate exactly, the first Float switches to Kahan–Babuška– Neumaier compensated summation ([floats].sum is exact where reduce(:+) drifts), a non-numeric element falls back to #+, and NaN/Infinity follow MRI's rules. (sum 12 -> 13 pass.) - Array#index is a full #find_index (value / block / no-arg Enumerator forms) and a true alias of #find_index (shared method record, so Array.instance_method(:index) == Array.instance_method(:find_index)). - Array#permutation without a block returns a lazy Enumerator that re-reads self when iterated (so a later mutation is seen) and reports the descending-factorial #size. (permutation 15 -> 16 pass.) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Clears the entire core/array/pack conformance backlog (35 fail+error -> 0):
- 'U' (Unicode) packs the full MRI extended-UTF-8 range (1..6 bytes, past
U+10FFFF where Go's own encoder clamps), coerces the argument via #to_int
(TypeError if it does not return an Integer), and raises RangeError for a
negative codepoint or one above 0x7FFFFFFF. (pack/u 35 -> 43, +8.)
- 'P'/'p' (pointer): a native-width word standing in for a pointer to the
argument string, backed by a process registry so pack/unpack round-trips
("hello" -> P -> P5 -> "hello"); nil is a null pointer. (pack/p 2 -> 14, +12.)
- 'a'/'A'/'Z' pack a nil argument as an empty string (space/NUL padded) rather
than raising. (pack/a +6, pack/z +3.)
- Array#pack :buffer option: directs the bytes into an existing String
(mutated and returned), packing from its current end with @ repositioning
absolutely; TypeError for a non-String buffer, FrozenError for a frozen one,
and the buffer's encoding is preserved. (pack/buffer 2 -> 8, +6.)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…r for |step|>1) Match MRI: a[(-9..).step(1)] resolves the begin to a still-negative index and returns nil (like a[-9..]), rather than clamping to 0; with |step| > 1 the same out-of-range begin raises RangeError (a[(-9..).step(2)]). Adds the covering tests and the Array.allocate subclass / permutation(k>n) enumerator cases. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
String#unpack("P"/"p") with fewer bytes than a pointer produces no element
("".unpack("P") == []), matching MRI, instead of a nil. Adds the covering tests
(short data, and a 'P' count clamped to the string length).
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 the
core/arrayresidual cluster, clearing the entirecore/array/packbacklog and a range ofcore/arraymethod residuals. All changes are pure-Go (CGO=0) and confined tointernal/vm/builtins.go,internal/vm/array_edges.go, andinternal/vm/pack.go.Array (
internal/vm/builtins.go,array_edges.go)Array#[]with anEnumerator::ArithmeticSequence(a[(m..n).step(k)]): positive/negative steps, endless/beginless ranges, exclusive endpoints, negative indices, the begin-past-endnilresult, and MRI'sRangeErrorwhen|step| > 1and the declared span reaches past the array — verified byte-for-byte against MRI. (element_reference56 → 69 pass.)Array#[]also accepts a user subclass ofRange; aRangepassed with a length is aTypeError; an index/length beyond the Fixnum range raisesRangeErrorinstead of silently overflowing.Array#sumuses MRI's exact-then-Kahan folding: integer/bignum/rational elements accumulate exactly, the firstFloatswitches to Kahan–Babuška–Neumaier compensated summation ([floats].sumis exact wherereduce(:+)drifts), a non-numeric element falls back to#+, and NaN/Infinity follow MRI's rules.Array#indexis a full#find_index(value / block / no-argEnumeratorforms) and a true alias of#find_index(shared method record).Array#lengthis a true alias of#size;#clear/#mapreject stray positional arguments;Array.allocatereturns a fully-formed empty Array and takes no arguments.Array#permutationwithout a block returns a lazyEnumeratorthat re-readsselfwhen iterated (so a later mutation is seen) and reports the descending-factorial#size.#bsearch/#bsearch_index/#rindexEnumerators report an unknown (nil) size.Array#pack / String#unpack (
internal/vm/pack.go) — pack backlog cleared (35 → 0)Upacks the full MRI extended-UTF-8 range (1..6 bytes, pastU+10FFFF), coerces via#to_int, and raisesRangeError/TypeErrorper MRI.P/p(pointer): a native-width word backed by a process registry so pack/unpack round-trips ("hello" → P → P5 → "hello");nilis a null pointer; too few bytes on unpack yields no element.a/A/Zpack anilargument as an empty (padded) string rather than raising.Array#pack:bufferoption: directs bytes into an existing String (mutated and returned), packing from its end with@repositioning absolutely;TypeError/FrozenErrorguards; encoding preserved.Verification
core/array/*+core/array/pack/*: 2615 pass, 37 fail, 6 error (down from ~102 fail+error). Every remaining failure is a spec-harness fidelity artifact (e.g.before-block ivars such as@never_passed/@value_to_returnnot propagating across sibling/nesteddescribes —fill, the "size increasing during iteration" shared examples) or requires touching out-of-scope shared code (Array#hash, the#eql?/#hash-mock set operations,arith.gooperators, the Enumerable prelude, the sharedcheckArrayTypecoercion); rbgo's own behaviour there matches MRI in direct tests.go test ./internal/vm/green;go test ./...green;GOOS=wasip1 GOARCH=wasm go build ./...OK;gofmt -lempty.internal/vm/array_residuals_wave12_test.go(every expectation checked against MRI 4.0.6); the changed named helpers report 100% coverage with no shadowed dead code.🤖 Generated with Claude Code