Repository navigation
kernel: implement caller_locations, add caller start/length/range args, fix raise #exception protocol - #575
Merged
Merged
Conversation
…s, fix raise
Kernel#caller_locations was entirely unimplemented (NoMethodError), which also
poisoned raise_spec: its shared group evaluates caller_locations(1, 2) at
collection time, so the whole group failed to load. Kernel#caller ignored all
arguments.
Bibliography read: ruby/spec core/kernel/{caller,caller_locations,raise}_spec.rb
and shared/kernel/raise.rb; MRI eval.c make_exception; existing rbgo
backtraceFrames / backtraceLocation (Thread::Backtrace::Location already present).
- caller / caller_locations now share callerSlice(args): a Range slices caller(0)
via Array#[] (endless/beginless/negative bounds); an Integer start (default 1)
omits that many innermost levels with an optional non-negative length cap;
negative start/length -> ArgumentError "negative level/size (N)"; a start past
the top returns nil (== end returns []); start/length coerced through #to_int.
caller_locations maps each frame string through backtraceLocation. Registered
as a Kernel module function (private instance + public module method).
- raise: bare raise with nothing handled now yields RuntimeError with an empty
message (was "unhandled exception"); raiseExceptionObject implements MRI's
#exception protocol (single String -> RuntimeError; else require
respond_to?(:exception) else TypeError "exception class/object expected"; call
obj.exception(msg?); result must be an Exception else TypeError "exception
object expected"); Kernel#raise now rejects a circular cause: chain with
ArgumentError "circular causes".
core/kernel: pass 1767->1796 (+29), fail 230->215, error 154->140, no regressions.
caller 7->16, caller_locations 0->16, raise 32->36.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…nged funcs) Cover every new branch of callerSlice (default/start/length/nil-length/Range/ Float coercion/negative-arg ArgumentError/overshoot-nil vs empty-at-end), caller_locations (Location shape, Range, overshoot, Kernel module-function visibility) and the raise changes (make_exception #exception protocol incl. both TypeError messages, bare-raise empty message, circular-cause ArgumentError, cause==self non-circular, bad-cause TypeError). callerSlice, raiseExceptionObject and nativeRaise are at 100% statement coverage. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The bare-raise fix (message "unhandled exception" -> "") is correct per MRI 4.0 (ruby -e 'begin;raise;rescue=>e;p e.message;end' => ""). The pre-existing TestRaise/bare pinned the old buggy string; the arch lanes run the full go test ./... and caught it (the internal/vm-only run in the wave missed it). "unhandled exception" survives only as RuntimeError#detailed_message's display default (exception_residuals_test.go still asserts that, unchanged). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tannevaled
added a commit
that referenced
this pull request
Sep 6, 2026
…578) Wave-15 merged three disjoint-file, bibliography-first conformance PRs: - #576 core/io: fd-based IO constructors (IO.open/new/for_fd + mode/encoding/ binmode/autoclose resolution per io.c) — core/io +107. - #575 core/kernel: Kernel#caller_locations (unblocks the raise_spec collection cascade), caller start/length/range args, raise #exception protocol + empty bare-raise message per MRI — core/kernel +29. - #577 core/regexp+enumerator: Regexp.linear_time?, quote/escape result encoding, \u-escape fixed_encoding, named_captures dup names, Lazy value packing — core/regexp +17, enumerator +2. Measured total on merged main: 19179 passing (files loaded 2171, +7 that previously failed to load). 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
Wave-15 Kernel conformance against MRI 4.0.6. Raises
core/kernelpass 1767 → 1796 (+29), fail 230 → 215, error 154 → 140, with no regressions in any other spec.Per-spec:
caller_locations_spec: 0 → 16 pass (was 4 fail + 13 error → 1 fail, 0 error)caller_spec: 7 → 16 pass (was 11 fail → 2 fail)raise_spec: 32 → 36 pass (was 11 fail + 2 error → 8 fail, 1 error)What changed
Kernel#caller_locations— implemented (was NoMethodError)It was entirely missing, which additionally poisoned
raise_spec: the shared:kernel_raisegroup evaluatescaller_locations(1, 2)at collection time, so the whole group failed to load. Implementing it recovers that cascade. Backed by the existingThread::Backtrace::Locationclass andbacktraceLocationhelper.Kernel#caller— argument handling (start / length / range)callerignored all arguments.callerandcaller_locationsnow sharecallerSlice(args), applying MRI's semantics overcaller(0):Rangeslicescaller(0)viaArray#[](endless / beginless / negative bounds);start(default 1) omits that many innermost levels, with an optional non-negativelengthcap;ArgumentError "negative level/size (N)";nil(an exactly-at-the-end start returns[]);#to_int(Float truncates).Kernel#raise— MRImake_exceptionfixesraisewith nothing being handled now yieldsRuntimeErrorwith an empty message (was"unhandled exception").raiseExceptionObjectnow implements MRI's#exceptionprotocol: a lone String → RuntimeError; otherwise the object mustrespond_to?(:exception)(elseTypeError "exception class/object expected"),obj.exception(msg?)is called, and its result must be anException(elseTypeError "exception object expected"). This fixes duck-typed exception objects and both TypeError messages.cause:chain that loops back to the raised exception is rejected withArgumentError "circular causes"; acause:equal to the exception itself is not treated as circular.Bibliography
ruby/spec
core/kernel/{caller,caller_locations,raise}_spec.rbandshared/kernel/raise.rb; MRIeval.cmake_exception; existing rbgobacktraceFrames/backtraceLocation.Tests / gates
internal/vm/kernel_caller_raise_internal_test.gocovers every new branch;callerSlice,raiseExceptionObject,nativeRaiseare at 100% statement coverage (registerKernelIntrospection/registerKernelModuleFunctionsalso 100%).go build ./...,gofmt -l internal/vm/clean, wasip1 (GOOS=wasip1 GOARCH=wasm) build all green. The vm suite's only failures are pre-existing network-dependent tests (redis/etcd/excon dialing the unreachable 127.0.0.1:1), unrelated to this change.Remaining
caller/caller_locationsresiduals require real source line numbers (systemically0in this VM) and are out of scope; remainingraiseresiduals are$!-restoration in nested rescue (VM rescue handling) and shim artifacts.🤖 Generated with Claude Code