Skip to content

kernel: Kernel#loop rescues StopIteration + blockless Enumerator; add Kernel#fail - #599

Merged
tannevaled merged 2 commits into
mainfrom
wave21/kernel
Sep 8, 2026
Merged

tannevaled merged 2 commits into
mainfrom
wave21/kernel

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Summary

Advances MRI-Ruby-4.0.x conformance of rbgo's core/kernel suite by fixing Kernel#loop and adding Kernel#fail, both entirely within internal/vm/builtins.go (the owned monolith this wave). Every change was verified byte-for-byte against MRI ruby 4.0.5.

Kernel#loop (ref: ruby/ruby v3_4_0 eval.c rb_f_loop / loop_size)

  • Rescues StopIteration (and subclasses): a StopIteration raised in the block now ends the loop cleanly and loop returns that exception's #result (a finished iterator's value). Every other exception still propagates, and break still unwinds to the call site — the recover re-raises anything that is not a StopIteration, so the break signal reaches the enclosing sendCatchBreak untouched.
  • Blockless form returns an infinite Enumerator over Kernel#loop whose #size is Float::INFINITY (was: raise LocalJumpError). loop.each { … } re-drives loop with the given block.

Verified vs MRI 4.0.5: rescue StopIteration, rescue a StopIteration subclass, StopIteration#result, does-not-rescue-StandardError, break value, blockless enumerator, loop.size == Float::INFINITY.

Kernel#fail (ref: ruby/ruby v3_4_0 eval.c, rb_f_raise registered under both names)

A genuine alias of Kernel#raise: the two names share one method record (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.

Conformance (core/kernel, ruby/spec @ 87b1631992, judged against MRI 4.0.5)

pass fail error skip
before 1822 194 135 56
after 1829 194 128 56

+7 passing, error 135 → 128 (loop ×5, fail ×2); fail count unchanged; no regressions. (require_relative/kernel_require symlink examples flake ±1 across runs independently of this change; exit_spec.rb is a pre-existing FILEFAIL.)

Tests / gates

  • New whitebox suite internal/vm/kernel_loop_fail_wave21_internal_test.go covers every new branch (StopIteration rescue, subclass, #result, break re-raise, non-StopIteration propagation, blockless Enumerator + Float::INFINITY, fail/raise record sharing).
  • Updated the now-stale TestLoopNoBlock (phase5w_test.go) to the MRI-verified blockless-Enumerator behaviour.
  • go build ./... and GOWORK=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

tannevaled and others added 2 commits September 8, 2026 20:22
… 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
tannevaled merged commit e66e0cd into main Sep 8, 2026
7 checks passed
@tannevaled
tannevaled deleted the wave21/kernel branch September 8, 2026 20:33
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant