Repository navigation
kernel: Kernel#loop rescues StopIteration + blockless Enumerator; add Kernel#fail - #599
Merged
Merged
Conversation
… Kernel#fail Kernel#loop (internal/vm/builtins.go): - With no block, return an infinite Enumerator over Kernel#loop whose #size is Float::INFINITY (was: raise LocalJumpError). loop.each re-drives loop with the given block. Ref: ruby/ruby v3_4_0 eval.c rb_f_loop / loop_size. - A StopIteration (or subclass) raised in the block now ends the loop cleanly and loop returns that exception's #result; every other exception (and break) still propagates. Ref: eval.c rb_f_loop (rb_rescue2 over StopIteration). Verified byte-for-byte vs MRI 4.0.5 for: rescue StopIteration, rescue a StopIteration subclass, StopIteration#result, does-not-rescue-StandardError, break value, blockless enumerator, loop.size == Float::INFINITY. Kernel#fail: a genuine alias of Kernel#raise (shared method record via aliasBuiltin), mirrored onto the Kernel module beside "raise" so Kernel.instance_method(:fail) == …(:raise) and Kernel.method(:fail) == …(:raise), with fail private on instances and Kernel.fail public. Ref: eval.c rb_f_raise registered under both names. Verified vs MRI 4.0.5. core/kernel: pass 1822 -> 1829, error 135 -> 128 (loop x5, fail x2); fail count unchanged. ruby/spec corpus @ 87b1631992. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…Kernel#fail New whitebox suite (internal/vm/kernel_loop_fail_wave21_internal_test.go, package vm) covers every new branch: loop rescuing StopIteration and a subclass, the StopIteration#result return, a break unwinding through the recover, propagation of a non-StopIteration error (the panic re-raise), the blockless Enumerator + Float::INFINITY size, and Kernel#fail sharing raise's instance/singleton records. Updated TestLoopNoBlock (phase5w_test.go): blockless Kernel#loop now returns an infinite Enumerator (MRI eval.c rb_f_loop), not a LocalJumpError; the assertion is pinned to the MRI 4.0.5 behaviour and the now-unused strings import dropped. vm package: all tests pass, 99.9% coverage; the new branches are covered and bootstrap holds at its pre-existing 99.7%. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tannevaled
added a commit
that referenced
this pull request
Sep 8, 2026
…602) Wave-21 merged three bibliography-first conformance PRs: - #600 core/io: IO::Buffer transfer/locked/and!/or!/xor!/not!/for/resize/valid?, IO#advise validated no-op — +59. - #601 core/file+dir: File.lutime, File.utime nil (UTIME_NOW), Dir.chroot — +10. - #599 core/kernel: Kernel#loop StopIteration rescue + infinite Enumerator, Kernel#fail alias of raise — +7. Measured total on merged main: 19993 passing. 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 rbgo's core/kernel suite by fixing
Kernel#loopand addingKernel#fail, both entirely withininternal/vm/builtins.go(the owned monolith this wave). Every change was verified byte-for-byte against MRIruby 4.0.5.Kernel#loop(ref: ruby/ruby v3_4_0eval.crb_f_loop/loop_size)StopIteration(and subclasses): aStopIterationraised in the block now ends the loop cleanly andloopreturns that exception's#result(a finished iterator's value). Every other exception still propagates, andbreakstill unwinds to the call site — the recover re-raises anything that is not aStopIteration, so the break signal reaches the enclosingsendCatchBreakuntouched.EnumeratoroverKernel#loopwhose#sizeisFloat::INFINITY(was:raise LocalJumpError).loop.each { … }re-drives loop with the given block.Verified vs MRI 4.0.5: rescue
StopIteration, rescue aStopIterationsubclass,StopIteration#result, does-not-rescue-StandardError,breakvalue, blockless enumerator,loop.size == Float::INFINITY.Kernel#fail(ref: ruby/ruby v3_4_0eval.c,rb_f_raiseregistered under both names)A genuine alias of
Kernel#raise: the two names share one method record (aliasBuiltin), mirrored onto theKernelmodule besideraise, soKernel.instance_method(:fail) == …(:raise)andKernel.method(:fail) == …(:raise), withfailprivate on instances andKernel.failpublic.Conformance (core/kernel, ruby/spec @ 87b1631992, judged against MRI 4.0.5)
+7 passing, error 135 → 128 (loop ×5, fail ×2);
failcount unchanged; no regressions. (require_relative/kernel_requiresymlink examples flake ±1 across runs independently of this change;exit_spec.rbis a pre-existing FILEFAIL.)Tests / gates
internal/vm/kernel_loop_fail_wave21_internal_test.gocovers every new branch (StopIteration rescue, subclass,#result, break re-raise, non-StopIteration propagation, blockless Enumerator +Float::INFINITY,fail/raiserecord sharing).TestLoopNoBlock(phase5w_test.go) to the MRI-verified blockless-Enumerator behaviour.go build ./...andGOWORK=off go test ./...green; vm package 99.9% coverage with the new branches covered (bootstrap holds at its pre-existing 99.7%);gofmt -l internal/vm/empty;GOOS=wasip1 GOARCH=wasm go build ./...OK.🤖 Generated with Claude Code