Skip to content

kernel: place public Kernel methods on the Kernel module; then/yield_self blockless Enumerator (+8 core/kernel) - #592

Merged
tannevaled merged 3 commits into
mainfrom
wave19/kernel
Sep 7, 2026
Merged

tannevaled merged 3 commits into
mainfrom
wave19/kernel

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

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 Kernel module — and by giving #then/#yield_self their 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)

registerKernelPublicMethods mirrors respond_to?, respond_to_missing?, eql?, remove_instance_variable, then and yield_self onto the Kernel module, exactly as the existing registerKernelModuleFunctions does for the module_function set:

  • The body 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), so re-owning e.g. is_a? to Kernel would make KindaClass.new.is_a?(KindaClass) run on the unwrapped String and answer false. Each Object record is instead copied onto cKernel with a Kernel owner.
  • So Kernel.public_instance_methods(false) lists them, Kernel.private_instance_methods(false) lists respond_to_missing? (private via its record's visibility), and Kernel.instance_method(:m) resolves them.
  • A class-method copy for respond_to?/respond_to_missing? lets Kernel.method(:m).owner report Kernel (resolveMethod consults singleton/class methods before the ancestor walk that would find the Object record first).

#then/#yield_self without a block now return a size-1 Enumerator over self (MRI: obj.then.size == 1; #inspect always names the primary #then, even through #yield_self). yield_self is made a genuine alias of then (primary in MRI 3.4+: yield_self.original_name == :then, #to_s annotates yield_self(then)), sharing one record so Kernel.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 one Kernel#kind_of? example green at the cost of four core/method + core/unboundmethod reflection examples — a net loss. The one kind_of? alias example stays failing.

Specs fixed (each now fully green)

spec before after
respond_to_spec fail=2 0
respond_to_missing_spec fail=2 0
eql_spec fail=1 0
remove_instance_variable_spec fail=1 0
then_spec fail=1 0
yield_self_spec error=1 0

Not addressed (out of this wave's file scope)

methods/public_methods still miss a public singleton method defined after a private/protected in a reopened class << self block: the singleton-class body's default visibility leaks across reopenings. Root cause is defaultVis not being reset on singleton-class body entry in internal/vm/vm.go, outside this change's builtins.go/kernel_introspect.go scope.

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. Every behavior verified byte-for-byte against ruby 4.0.5.

Tests / gates

  • New whitebox tests TestKernelPublicMethodsMirror, TestThenYieldSelfNoBlock; updated TestReflectionErrors (dropped the stale then LocalJumpError 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, registerKernelPublicMethods at 100% coverage.

🤖 Generated with Claude Code

tannevaled and others added 3 commits September 7, 2026 23:38
… 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
tannevaled merged commit 4cddb04 into main Sep 7, 2026
7 checks passed
@tannevaled
tannevaled deleted the wave19/kernel branch September 7, 2026 23:18
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>
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