Feature #22215
openIntroduce narrow internal interfaces for bundled extensions
Description
Abstract¶
Introduce narrow internal interfaces for bundled extensions so that they do not need to depend on VM implementation headers such as vm_core.h or thread implementation files such as thread_pthread.h.
These interfaces are declared in internal/ headers and are not intended to be stable APIs for third-party extensions.
Background¶
Some bundled extensions currently include private implementation headers to access a small part of CRuby internals.
For example, ext/coverage needs to enumerate method coverage data. Doing that directly requires knowledge of method entries, IMEMOs, the object space, and VM-private structures. Consequently, the extension depends on internal/gc.h and vm_core.h.
Likewise, ext/objspace accesses fields of call-info and call-cache IMEMOs directly.
These dependencies expose the extensions to much more of the VM implementation than they actually need. They also cause extensions to depend transitively on thread implementation files through vm_core.h.
Proposal¶
Add narrow internal interfaces for the bundled extensions:
- Collect coverage constants and declarations in
internal/coverage.h. - Perform method-entry traversal in the core and pass normalized method coverage data to
ext/coveragethroughrb_coverage_each_method. - Add
rb_imemo_callinfo_midandrb_imemo_callcache_get_datafor the information required byext/objspace. - Keep these declarations in
internal/headers rather than publicruby/headers. - Remove the transitive inclusion of
vm_core.hfrominternal/gc.h.
The new interfaces must be exported because the bundled extensions can be built as shared libraries. They are internal implementation interfaces, not supported extension APIs.
With these interfaces, extensions under ext no longer depend on vm_core.h or thread_pthread.[ch].
Compatibility¶
There is no intended Ruby-level behavior change.
The new interfaces are internal to CRuby and are not intended to provide API or ABI compatibility guarantees for third-party extensions.
No data to display