Commit Graph
2515 Commits
Author SHA1 Message Date
Jean BoussierandJean Boussier cd070c053f st.c: swap types of entries_start and rebuilds_num
A char is more than large enough for counting rebuilds, and it's
fine if it rolls over.
The table being rebuilt exactly 255 times between two check seems
impossible.

On the other hand, if `Hash#shift` is abused, `entries_start` is
more likely to reach MAX_UCHAR.

So swapping the two members is preferable.
2026-08-07 17:21:02 +02:00
9658933451 [Feature #9779] Add Module#descendants
Module#descendants returns an array of classes and modules that have
the receiver in their ancestors; it is the inverse of Module#ancestors.
The receiver itself, singleton classes, and refinements are not included.

Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
2026-08-06 23:05:57 +09:00
Jean BoussierandJean Boussier 1ba809e748 C API: Expose rb_iseq_load_from_binary
[Feature #22222]

This allows to efficiently load iseq from mmaped files and other
buffers without having to copy the bytes into a Ruby string an
then invoke `RubyVM::InstructionSequence.load_from_binary`.
2026-08-06 10:35:28 +02:00
Jean BoussierandJean Boussier 8cb76c13e4 Shrink st_table from 48B down to 40B
This allows `st_table + RHash` to fit in a `64B` slot.

It is achieved by turning `entries_start` from pointer size
down to a single byte.

This means it can now overflow, if you delete the first element
255 times, but in such case we can rebuild the table entirely,
which is an acceptable tradeoff.

The same change is applied to `set_table`, but mostly for consistency,
as another 8B would need to be reclaimed for `Set` to fit in 64B slots.
2026-08-05 06:26:39 +02:00
Claude Fable 5andHiroshi SHIBATA 5dec40dc5f [DOC] Fix typos in C comments
- vm_eval.c: contant -> constant (RDoc for Module#module_eval;
  the sentence two lines above spells it correctly)
- include/ruby/internal/intern/thread.h: funciton -> function
- include/ruby/st.h, parser_st.h: Optionnally -> Optionally
2026-07-23 12:08:25 +09:00
Jean BoussierandJean Boussier 86951165b8 Get rid of ROBJECT_HEAP flag
This flag is now entirely redundant with the shape_id layout bits.
2026-07-15 15:43:28 +02:00
Nobuyoshi NakadaandNobuyoshi Nakada 4b638eecd1 Provide a fallback implementation of memrchr
Move the local fallback out of string.c so other source files can use
memrchr on platforms that do not provide it.
2026-07-15 13:28:39 +09:00
e0083cffa3 Refactor RObject to use T_IMEMO/fields_obj on overflow
Instead of spilling into a raw buffer, `RObject` now spills
into an `IMEMO/fields` object like other types.

From an instance variable layout standpoint, an extended `RObject`
is now identical to a `RTypedData`, as in they both store the
reference to their `IMEMO/fields` at the same offset (`VALUE * 2`).

One positive consequence of this is that the only case where a `T_OBJECT`
needs sweeping is if a finalizer was registered.

YJIT now side exit when it need to write a new ivar into a `RObject`
that is out of space. This is unlikely to cause a performance regression
as this codepath isn't supposed to happen after warmup given `max_iv_count`
is recorded on classes, so future objects should be large enough.
Hence it's best not to waste executable memory for such codepath.

ZJIT lost support for writting into extended `RObject`.
Most of the code to support it is there it's just missing an
implementation of `RBASIC_SET_SHAPE_ID`, which recently changed
to strip some bits out of the shape (see comments).
I will leave it to the ZJIT team to implement it (sorry).

There are a few future cleanups planned that I keep for followups:

  - We can now get rid of the `ROBJECT_HEAP` flag, it's redundant with
    the shape layout bits.
  - `imemo_fields` can now embed the `st_table` when complex.

Co-Authored-By: John Hawthorn <[email protected]>
Co-authored-by: Randy Stauner <[email protected]>
2026-07-14 10:44:39 +02:00
Nobuyoshi Nakada db7fba3217 Make __VA_ARGS__ check mandatory
Since we already require C99 compilers, and autoconf 2.67 or later.
`__VA_ARGS__` is always available.
2026-07-13 20:03:55 +09:00
Sharon RosnerandGitHub b072acf0c1 Add rb_process_status_for to intern/process.h. (#15213)
[Feature #21704]
2026-07-12 12:41:23 +12:00
5aa5c1aad1 Remove stale rb_class_descendants() declaration
The implementation was removed together with Class#descendants in
3bd5f27f73 ([Feature #14394]), but the
declaration was left behind.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-07-11 09:54:43 +09:00
Samuel WilliamsandGitHub aa7b013a0f Add rb_nogvl flag for pending interrupts. (#17553)
[Feature #22138]
2026-07-10 09:18:04 +00:00
Jean BoussierandJean Boussier 2c574ca7e2 Symbol#to_s now returns a frozen string.
[Feature #22137]

It has returned a chilled string, hence emitting deprecation
warnings for two versions.
2026-07-10 10:02:00 +02:00
Peter Zhu 61b5f059cb Remove dead RARRAY_EMBED_LEN_MAX 2026-07-09 02:53:20 -04:00
Jean BoussierandJean Boussier 0fd945f3de Stop including onigmo.h in rregexp.h
Followup: https://github.com/ruby/ruby/pull/17671

[Bug #22184]

`onigmo.h` contains a lot of declarations that can easily
conflict with third party code, hence it's better to keep
it opaque. That however requires a few hacks.
2026-07-07 09:21:13 +02:00
Jean BoussierandJean Boussier b58a6024a0 Make T_REGEXP embedded
When embeddeding `struct re_pattern_buffer`, `RRegexp` end up
488B large, which result in a rather minimal 24B waste in 512B slots.

This however requires a few changes:
  - Stop relying on `RREGEXP_PTR == NULL` to check for initialization.
  - `reg_copy` requires a new `onig_reg_copy_body` API.
2026-07-06 11:56:40 +02:00
Peter Zhu ee74bca0e5 Make ROBJECT_FIELDS private
Commit 0ea210d renamed ROBJECT_IVPTR to ROBJECT_FIELDS, so it would have
caused compatibility issues anyways. Since there has been no issues, it
means that nobody is using it. We can make this dangerous API private since
no C extension should be using it anyways.
2026-06-26 19:32:09 -04:00
John Hawthorn d44862fe2a [Feature #22067] Add RUBY_TYPED_THREAD_SAFE_FREE flag
Lets a TypedData type declare its dfree as thread-safe, so the GC may
run it on any thread, in parallel, and concurrently with Ruby code.
Implies RUBY_TYPED_FREE_IMMEDIATELY.
2026-06-22 15:57:36 -07:00
Jean BoussierandJean Boussier cd7e59d45b Improve inlinability of rb_define_class and rb_define_module
By moving the `rb_intern` to the caller, we allow compilers to
precompute the `strlen` part of `rb_intern` which isn't a huge win,
but happens quite a lot as part of Ruby's boot process and when
requiring native gems.
2026-06-19 17:49:17 +02:00
Jean BoussierandJean Boussier bc1e5772c5 rb_define_method: allow compilers to precompute strlen
By inlining the `rb_intern()` call, we allow it to be replaced
by `rb_intern_const()` which with most compiler will allow to
save the `strlen` call when invoked with a string literal.

This is a small optimization, but during program boot, `rb_define_method`
is called thousands of times.

Other `rb_define_*` function could benefit from the same treatment,
but that require exposing an `_id` versionm, which most of them lack.
2026-06-19 17:48:52 +02:00
Nobuyoshi Nakada 63c3d76dd3 Bump the ABI version due to the change to rb_alloc_tmp_buffer 2026-06-17 10:05:41 +09:00
Jean Boussier 78495ca415 imemo_tmp_buffer: skip marking when useless
In many place ALLOC_V / ALLOCV_N is used as a safer `alloca`,
and to behave like stack memory, `ALLOCV` does scan its buffer
for references using `rb_gc_mark_locations`.

The problem is that it's quite slow, and in many cases, the
temporary buffer is known not to contain any references.

e.g. `ALLOCV_N(uint32_t, buf0, len)` can't possibly contain references,
as the element size is too small.
2026-06-16 16:52:32 +02:00
Nobuyoshi Nakada 7a07a54298 Bump RUBY_ABI_VERSION
Prior to a26f528b3b, `rbimpl_rtypeddata_p`
checked whether a flag that is no longer used since that commit was set.
As a result, typed data objects created in newer versions of Ruby are
considered as untyped in extension libraries compiled with older headers.
2026-05-29 23:34:40 +09:00
Jean Boussier 4af6e12493 Rename RUBY_FL_USERPRIV0 into RUBY_FL_UNUSED6
Last usage was removed in a26f528b3b
https://github.com/ruby/ruby/pull/15447
2026-05-29 07:25:03 +02:00
Nobuyoshi Nakada 5497859f40 Remove use of RTYPEDDATA_P and rbimpl_rtypeddata_p 2026-05-28 19:29:32 +09:00
Nobuyoshi Nakada a26f528b3b Deprecate struct RData in favor of struct RTypedData
For the backward compatibility for some wrapper generator gems, keep
only `RData` definition.
2026-05-28 19:29:31 +09:00
John Hawthorn 8c854d2cfb Bump RUBY_ABI_VERSION 2026-05-27 16:18:43 -07:00
John Hawthorn 594ae9f073 Give legacy T_DATA the same layout as TypedData
This allows us to treat the two types of T_DATA the same way when
reading instance variables.

Non-TypedData T_DATA are deprecated, so making them faster isn't
particularly important, but it is helpful to avoid needing to test for
TypedData and adding another special case.
2026-05-27 16:18:43 -07:00
Jean Boussier 837f684377 st.c: Store st_table->bins at the end of st_table->entries
Same optimization that was applied to `set_table` in
85c52079aa

This saves one pointer per `st_table`.
Now that GC support 64B slots, if we can save another 8B
either in `st_table` or in `struct RHash`, hashes would now
fit in 64B slots.
2026-05-17 23:54:19 +03:00
Jean Boussier 5eb4284144 Stop using rb_class_path_cached, and deprecate it.
That API made sense before b00f280d4b
as finding a module name was costly, but it now is a very cheap
operation, and that function is now just an outdated alias.
2026-05-17 20:15:21 +03:00
John Hawthorn 39d428e356 Build match struct when requested 2026-05-14 07:07:45 -07:00
John HawthornandJean Boussier fe3f45187b Allocate RMatch storage embedded
Co-authored-by: Jean Boussier <[email protected]>
2026-05-14 07:07:45 -07:00
Nobuyoshi Nakada 78562d38fb mingw: Include stdio.h for __MINGW_PRINTF_FORMAT
This macro is not pre-defined but defined in stdio.h.
2026-05-10 19:54:36 +09:00
Peter Zhu 39257a3e11 Add field in RObject for too complex hash case
Avoids the need to cast fields into a st_table.
2026-05-03 10:04:57 -04:00
Hiroya FujinamiandGitHub 493d26dcde Reject overflowed repeat/null-check IDs in huge regexps (#16801)
Add explicit errors for excessive range-repeat and null-check IDs;
map new errors in regerror; add regression tests for oversized generated
patterns.
2026-04-29 11:09:24 +09:00
Jean Boussier 8d929853d8 Get rid of rb_matchext_struct
It can simply be merged inside `RMatch`.
2026-04-28 15:21:11 +09:00
Jean Boussier 379b95a2df Get rid of RGENGC_WB_PROTECTED_NODE_CREF
It's unused.
2026-04-28 09:39:07 +09:00
Jean Boussier c95a190d9c Get rid of RGENGC_WB_PROTECTED_BIGNUM
It has been the default for a very long time and there is no good reason to
disable it.
2026-04-28 09:39:07 +09:00
Jean Boussier 70451a4018 Get rid of RGENGC_WB_PROTECTED_RATIONAL
It has been the default for a very long time and there is no good reason to
disable it.
2026-04-28 09:39:07 +09:00
Jean Boussier 5e99295f1e Get rid of RGENGC_WB_PROTECTED_COMPLEX
It has been the default for a very long time and there is no good reason to
disable it.
2026-04-28 09:39:07 +09:00
Jean Boussier 92cba2ef72 Get rid of RGENGC_WB_PROTECTED_FLOAT
It has been the default for a very long time and there is no good reason to
disable it.
2026-04-28 09:39:07 +09:00
Jean Boussier ac0a319dd5 Get rid of RGENGC_WB_PROTECTED_CLASS
It has been the default for a very long time and there is no good reason to
disable it.
2026-04-28 09:39:07 +09:00
Jean Boussier 9e47f988fb Get rid of RGENGC_WB_PROTECTED_MATCH
It has been the default for a very long time and there is no good reason to
disable it.
2026-04-28 09:39:07 +09:00
Jean Boussier e9f372a231 Get rid of RGENGC_WB_PROTECTED_REGEXP
It has been the default for a very long time and there is no good reason to
disable it.
2026-04-28 09:39:07 +09:00
Jean Boussier 83d4117b07 Get rid of RGENGC_WB_PROTECTED_OBJECT
It has been the default for a very long time and there is no good reason to
disable it.
2026-04-28 09:39:07 +09:00
Jean Boussier 267ce6f842 Get rid of RGENGC_WB_PROTECTED_STRING
It has been the default for a very long time and there is no good reason to
disable it.
2026-04-28 09:39:07 +09:00
Jean Boussier 9307d1b5b6 Get rid of RGENGC_WB_PROTECTED_STRUCT
It has been the default for a very long time and there is no good reason to
disable it.
2026-04-28 09:39:07 +09:00
Jean Boussier 7040286dfc Get rid of RGENGC_WB_PROTECTED_HASH
It has been the default for a very long time and there is no good reason to
disable it.
2026-04-28 09:39:07 +09:00
Jean Boussier e603aa0d2f Get rid of RGENGC_WB_PROTECTED_ARRAY
It has been the default for a very long time and there is no good reason to
disable it.
2026-04-28 09:39:07 +09:00
jinroqandNobuyoshi Nakada 0cb9c43318 Expose rb_int_parse_cstr() as public API
Move rb_int_parse_cstr() declaration and RB_INT_PARSE_* flags from
internal/bignum.h to the public header include/ruby/internal/intern/bignum.h
so that C extensions can use this function without writing their own
prototype declarations.

The flags are changed from an enum to #define macros to follow the
convention used in the public header for similar constants.
2026-04-24 18:09:20 +09:00