Repository navigation
kernel: place public Kernel methods on the Kernel module; then/yield_self blockless Enumerator (+8 core/kernel) - #592
Merged
Merged
Conversation
… core/kernel)
MRI keeps respond_to?, respond_to_missing?, eql?, remove_instance_variable,
then/yield_self and is_a?/kind_of? on the Kernel module (Object merely includes
it), so Kernel.public/private_instance_methods(false) lists them,
Kernel.instance_method(:m) resolves them, and Kernel.method(:respond_to?).owner
reports Kernel. rbgo defined the bodies on Object, so these reflection queries
failed and the then/kind_of alias equalities (Kernel.instance_method-based, per
ruby/spec on RUBY_VERSION 3.4) were false.
registerKernelPublicMethods mirrors each Object record onto cKernel with a Kernel
owner, exactly as registerKernelModuleFunctions does for the module_function set.
The record stays owned by Object for dispatch: callNative unwraps a built-in
value subclass's receiver for any method whose owner is not Object/BasicObject
(isBuiltinValueMethod, object.c-style), so re-owning is_a? to Kernel would make
`KindaClass.new.is_a?(KindaClass)` run on the unwrapped String and answer false.
An alias pair shares one Object record, so it shares one Kernel copy too, keeping
the mirrored UnboundMethods ==. A class-method copy for the two methods whose
spec reads Kernel.method(:m).owner lets resolveMethod find the Kernel-owned copy
first.
then/yield_self without a block now return a size-1 Enumerator over self
(MRI: obj.then.size == 1; #inspect names the primary #then even via #yield_self),
and both alias pairs share one record so Kernel.instance_method(:then) ==
Kernel.instance_method(:yield_self) and :kind_of? == :is_a?.
References: ruby/spec core/kernel {then,yield_self,kind_of,is_a,respond_to,
respond_to_missing,eql,remove_instance_variable}_spec.rb and shared/then.rb;
MRI object.c (rb_obj_is_kind_of, rb_f_kernel), vm_eval.c. Verified byte-for-byte
against ruby 4.0.5. core/kernel pass 1811 -> 1820, fail 200 -> 192, error 140 -> 139.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
… Enumerator 5.then with no block returns a size-1 Enumerator in MRI (and now rbgo), not a LocalJumpError; #tap still requires a block. The positive Enumerator behavior is covered by TestThenYieldSelfNoBlock. Verified against ruby 4.0.5. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…imary Reverts sharing is_a?'s record for kind_of?: MRI keeps them as two entries that merely compare == equal, so #original_name and #to_s report each under its own name with no "(is_a?)" alias annotation. rbgo keys native-method identity on the record pointer and cannot equate two distinct records without labelling one an alias, so sharing turned Kernel#kind_of?'s one == example green at the cost of four core/method + core/unboundmethod original_name/to_s examples. Keep them independent; leave the kind_of? == example failing. Also flips the then/yield_self alias direction to match MRI 3.4+, where then is primary: yield_self's #original_name is :then and its #to_s annotates "yield_self(then)". Drops is_a?/kind_of? from the Kernel-module mirror (they need no reflection placement any spec checks). Verified against ruby 4.0.5. core/kernel pass 1811 -> 1819; core/method and core/unboundmethod unchanged from baseline (159 / 70). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tannevaled
added a commit
that referenced
this pull request
Sep 8, 2026
…594) Wave-19 merged three bibliography-first conformance PRs: - #593 core/io: pread/pwrite, sysopen, dup, initialize/reopen, to_io/path/ inspect, set_encoding, ungetbyte, lineno, sysread, std-stream halves — +56. - #591 core/file+dir: File::Stat surface, ftype, chmod/umask/truncate/rename errno + coercion, realpath ELOOP, Dir Enumerable + entries/children/foreach/ each_child (fixing a nil-pointer crash) — core/file +22, core/dir +29. - #592 core/kernel: respond_to?/eql?/remove_instance_variable mirrored on Kernel, then/yield_self blockless Enumerator — +8. Measured total on merged main: 19773 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 conformance of core/kernel by putting the plain (non-module-function) public Kernel instance methods where CRuby keeps them — on the
Kernelmodule — and by giving#then/#yield_selftheir blockless Enumerator form.core/kernel: pass 1811 → 1819 (+8), fail 200 → 193, error 140 → 139. No regressions in core/method, core/unboundmethod, core/module, core/object, core/comparable, core/enumerable, core/enumerator, or core/basicobject (each byte-identical to the pre-change binary).
What changed (all in
internal/vm/builtins.go, Kernel only)registerKernelPublicMethodsmirrorsrespond_to?,respond_to_missing?,eql?,remove_instance_variable,thenandyield_selfonto the Kernel module, exactly as the existingregisterKernelModuleFunctionsdoes for themodule_functionset:callNativeunwraps a built-in value subclass's receiver for any method whose owner is not Object/BasicObject (isBuiltinValueMethod), so re-owning e.g.is_a?to Kernel would makeKindaClass.new.is_a?(KindaClass)run on the unwrapped String and answerfalse. Each Object record is instead copied ontocKernelwith a Kernel owner.Kernel.public_instance_methods(false)lists them,Kernel.private_instance_methods(false)listsrespond_to_missing?(private via its record's visibility), andKernel.instance_method(:m)resolves them.respond_to?/respond_to_missing?letsKernel.method(:m).ownerreportKernel(resolveMethod consults singleton/class methods before the ancestor walk that would find the Object record first).#then/#yield_selfwithout a block now return a size-1 Enumerator over self (MRI:obj.then.size == 1;#inspectalways names the primary#then, even through#yield_self).yield_selfis made a genuine alias ofthen(primary in MRI 3.4+:yield_self.original_name == :then,#to_sannotatesyield_self(then)), sharing one record soKernel.instance_method(:then) == Kernel.instance_method(:yield_self).is_a?/kind_of?are deliberately left as two independent records. MRI treats them as separate entries that merely compare==equal, reporting each under its own name in#original_name/#to_s. rbgo keys native-method identity on the record pointer and cannot equate two distinct records without labelling one an alias, so sharing them turned oneKernel#kind_of?example green at the cost of four core/method + core/unboundmethod reflection examples — a net loss. The onekind_of?alias example stays failing.Specs fixed (each now fully green)
Not addressed (out of this wave's file scope)
methods/public_methodsstill miss a public singleton method defined after aprivate/protectedin a reopenedclass << selfblock: the singleton-class body's default visibility leaks across reopenings. Root cause isdefaultVisnot being reset on singleton-class body entry ininternal/vm/vm.go, outside this change'sbuiltins.go/kernel_introspect.goscope.References
ruby/spec core/kernel
{then,yield_self,kind_of,is_a,respond_to,respond_to_missing,eql,remove_instance_variable}_spec.rbandshared/then.rb; MRIobject.c(rb_obj_is_kind_of,rb_f_kernel),vm_eval.c. Every behavior verified byte-for-byte againstruby4.0.5.Tests / gates
TestKernelPublicMethodsMirror,TestThenYieldSelfNoBlock; updatedTestReflectionErrors(dropped the stalethenLocalJumpError case).go build ./...,GOWORK=off go test ./...(full suite green; only the pre-existing 127.0.0.1:1 network binds log),gofmt -l internal/vm/empty, wasip1 build,registerKernelPublicMethodsat 100% coverage.🤖 Generated with Claude Code