102 Commits
Author SHA1 Message Date
Kevin Newton 5c9c69bbe6 [PRISM] Use Prism checksum for hash comparison 2026-10-19 17:30:05 -04:00
Kevin Newton 98fd04f76c [ruby/prism] attach_comments
Revisit how we attach comments, allowing consumers to do it in C.

https://github.com/ruby/prism/commit/eb3528e580
2026-10-12 13:01:34 -04:00
Nobuyoshi Nakada d06e3f2a5d Isolate coroutine test
Create coroutine test files under the dedicated directory.
2026-10-04 01:48:16 +09:00
Samuel Williams e7551c0883 coroutine: allow pthread resumption across threads. (#18820) 2026-09-14 22:15:24 +12:00
Samuel Williams e96cea4e03 coroutine: add native behavior tests. (#18817) 2026-09-14 19:27:52 +12:00
ydah e947cbd199 Regenerate build dependencies after revision changes 2026-08-29 12:15:34 +09:00
Nobuyoshi Nakada 8b81626c34 [Misc #22206] Cache generated dependency freshness
Record scanned paths beside generated dependency files so repeated
configuration can avoid rescanning unchanged source trees.
2026-08-16 19:01:44 +09:00
Nobuyoshi Nakada 8268969efb [Misc #22206] Regenerate build dependencies through make
Keep the core dependency generation rule in `depend` so configure and
Windows setup share the same entry point.  Preserve NMake output when
the generated dependency file is rebuilt.
2026-08-16 18:09:21 +09:00
Kevin Newton d0d1560d31 [PRISM] Integrate new prism error formatting API 2026-07-24 17:08:34 -04:00
Nobuyoshi Nakada d0dc160347 [Misc #22206] Generate extension dependencies after configuring Ruby
Generate only core and encoding dependencies during configure.
Generate extension dependency files from `configure-ext.mk` after
`miniruby` is available, so `THREAD_MODEL` can be resolved before
rules enter an extension Makefile.

Select the extension scope when `-extensions` is passed.  Keep quoted
project-internal headers ahead of similarly named public headers while
scanning extension sources.  Limit snapshot expansion to files needed
before `miniruby`.
2026-07-23 00:54:12 +09:00
Nobuyoshi Nakada bfb05e41be [Misc #22206] Unify dependency output mappings
Use depends declarations for emitted dependency names instead of
overloading generated declarations or rewriting thread headers in
code.  This keeps scanning, generation, and dependency expansion
separate and makes platform-selected thread dependencies explicit.
2026-07-23 00:54:12 +09:00
Nobuyoshi Nakada b92606aebf [Misc #22206] Declare conditional dependency scan rules
Move fixed preprocessor macro handling into dependency declarations so
the scan inputs and emitted dependencies are visible in depend files.
Add source-specific define and undef declarations for `parse.y` and
`ripper.y`.
2026-07-23 00:54:12 +09:00
Nobuyoshi Nakada 7d4461e162 [Misc #22206] Generate dependencies without compiler builds
Replace `tool/update-deps` with a Ruby source scanner so dependency
updates no longer require GNU make, a configured build, or compiler
preprocessor output.

Keep compact source mappings and scanner declarations in dependency
files, and expand complete rules into the build directory.  Avoid the
temporary fixture headers required by the compiler-driven prototype.

Use the generated rules from GNU make, BSD make, and NMake builds.
Support out-of-tree and read-only source trees, and retain expanded
dependencies shipped in release archives when baseruby is unavailable.
2026-07-23 00:04:47 +09:00
Hiroshi SHIBATA 22258b1d5f Load the error decoration gems from non-main Ractors too
rb_require_string delegates requires from non-main Ractors to the
main Ractor via rb_ractor_require, so the main-Ractor guard here was
unnecessary. Drop it and claim the load with an atomic exchange,
because Ractors run in parallel and the plain bool flag was only safe
under that guard. did_you_mean already keeps its state Ractor-safe,
so suggestions now appear in non-main Ractors as well.

Suggested by John Hawthorn.
2026-07-21 11:49:03 +09:00
Hiroshi SHIBATAandClaude Fable 5 cadf8e7933 Lazy load error_highlight, did_you_mean, and syntax_suggest
[Feature #21951]

Defer loading these gems from boot to the first error display. They
only decorate Exception#detailed_message, so requiring them at boot is
unnecessary overhead. `ruby -e1` with user-installed gems drops from
114.3ms to 30.2ms on Apple M1 Pro, matching the --disable-* flags for
the three gems.

exc_detailed_message forces the autoload entries once on the first
call, only in the main Ractor, and then re-dispatches to pick up the
detailed_message decorators the gems prepend. When the first call
arrives through an already-prepended decorator, re-dispatching is
skipped to avoid decorating twice. The gems are loaded with the
C-level require so that displaying an error neither invokes nor
depends on Kernel#require monkeypatches.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-21 11:49:03 +09:00
Hiroshi SHIBATAandClaude Fable 5 3b53517b5a Register error decoration gem autoloads in rb_define_gem_modules
The empty modules existed only as feature flags for gem_prelude to
require the gems at boot. Autoload entries serve the same flag role
and also load the gems on direct constant access. gem_prelude now
requires 'syntax_suggest' itself, which only loads core_ext, so that
the eager require does not trigger the autoload circularly.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-21 11:49:03 +09:00
Luke Gruber 1aebcb61d0 ZJIT: duparray allocation fastpath for arrays we embed
We can reuse some of this work for gen_new_array fastpath for
embedded arrays.
2026-07-16 22:32:15 -04:00
Matt Valentine-House f11bae5280 ZJIT: Inline GC fastpath for string resurrection 2026-07-16 09:56:10 +01:00
Jean Boussier 24337e3cbe Refactor rb_obj_copy_ivar
Share more code with `rb_copy_generic_ivar`.
2026-07-14 23:50:17 +02:00
Jean Boussier 71ee81f7d9 imemo.c: embed the st_table inside rb_fields
Followup: https://github.com/ruby/ruby/pull/17631

Now that complex `RObject` always have an IMEMO/fields, we no
longer need to have an external `st_table` to replicate the
memory layout of `RObject`.
2026-07-14 23:50:17 +02:00
Matt Valentine-House 1fcccaec8c ZJIT: Inline GC fastpath in ZJIT for object allocation
Speeds up object allocation by 70%

```
master: ruby 4.1.0dev (2026-07-09T11:46:27Z master 835ad5c09e) +ZJIT +PRISM [x86_64-linux]
experiment: ruby 4.1.0dev (2026-07-09T17:43:21Z mvh-zjit-inline-fa.. 60534f3b33) +ZJIT +PRISM [x86_64-linux]

---------------------  -----------  ---------------  ------------------  -----------------
bench                  master (ms)  experiment (ms)  experiment 1st itr  master/experiment
object-new             17.9 ± 1.6%      10.3 ± 2.7%               1.002              1.729
object-new-initialize  51.4 ± 1.4%      44.9 ± 1.7%               1.095              1.144
object-new-no-escape   91.0 ± 0.4%      77.0 ± 0.5%               1.150              1.182
---------------------  -----------  ---------------  ------------------  -----------------

Legend:
- experiment 1st itr: ratio of master/experiment time for the first benchmarking iteration.
- master/experiment: ratio of master/experiment time. Higher is better for experiment. Above 1 represents a speedup.
```
2026-07-09 20:15:53 +01:00
Koichi SasadaandClaude Opus 4.8 7896d376fb Prohibit at_exit and END{} in non-main Ractors
Registering an exit handler with Kernel#at_exit or END{} in a non-main
Ractor behaved confusingly: the block ran in the main Ractor at process
exit even though it was registered from another Ractor. Raise
Ractor::IsolationError instead.

[Feature #22139]

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-09 22:05:24 +09:00
Matt Valentine-House ff8e913048 Inline RHash ifnone offset into jit_bindgen_constants 2026-07-08 23:20:00 +01:00
Matt Valentine-House 251a19f69e Fix depends 2026-07-08 23:20:00 +01:00
Kunshan Wang 89e7b08a9f eBPF-based timeline visualization tool (#17190) 2026-07-07 19:07:22 +09:00
Peter Zhu d9b4ab5b40 Inline GC fastpath in ZJIT for newarray instruction
This commit implements support in ZJIT for inlining GC fast path. The GC
fast path is defined in gc_fastpath.rs for both the default GC and MMTk.

For the default GC, the fast path uses the bump pointer allocator that
was implemented in https://github.com/ruby/ruby/pull/17201. If the bump
pointer region is full, it will bail out and fall back to the slow path.

This GC fast path is used by the newarray instruction in ZJIT in the empty
array case. We can see significant improvements in the following microbenchmark,
which allocates 100 million empty arrays:

    def run(max)
      i = 0
      while i < max
        a = []
        i += 1
      end
    end

    30.times { run(2) }
    run(100_000_000)

This microbenchmark runs 1.5x faster on my machine:

    Benchmark 1: master
      Time (mean ± σ):     583.3 ms ±  10.1 ms    [User: 569.3 ms, System: 12.0 ms]
      Range (min … max):   571.9 ms … 600.0 ms    10 runs

    Benchmark 2: branch
      Time (mean ± σ):     389.5 ms ±   8.2 ms    [User: 375.0 ms, System: 12.1 ms]
      Range (min … max):   380.2 ms … 405.3 ms    10 runs

    Summary
      branch ran
        1.50 ± 0.04 times faster than master
2026-07-07 03:59:42 -04:00
Jean 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 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
Kevin Newton 6e53ba7309 [PRISM] Fix depend 2026-07-05 19:24:48 -04:00
Koichi SasadaandClaude Opus 4.8 c4bda536f6 depend: add ruby/ractor.h for concurrent_set.o
concurrent_set.c now includes ruby/ractor.h for RB_OBJ_SET_SHAREABLE.
(id_table.c is #included into symbol.c, which already depends on ruby/ractor.h,
so no separate entry is needed.)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-03 23:50:37 +09:00
Matt Valentine-House f6ab0a1bae Fix depends 2026-06-26 10:46:30 +01:00
Samuel Williams 1619cf7cea io_buffer: add safe callback wrappers for String views. (#17473) 2026-06-25 14:28:09 +12:00
Sampo Kuokkanen 93e977936f Define String#ascii_only? and #valid_encoding? in Ruby
Get rid of the CFUNC overhead in String#ascii_only? and #valid_encoding?. Define them as leaf Primitive.cexpr! builtins in a new string.rb, following the pattern of numeric.rb.

This makes them 1.2x-1.4x faster across the interpreter, YJIT, and
ZJIT.

Move ZJIT's cfunc annotation for String#ascii_only? to annotate_builtin!, and add one for String#valid_encoding?.

Fix CI for builtin String#ascii_only?
2026-06-24 17:17:33 -04:00
Yaroslav Markin 35b7652058 Speed up Array#join with a memcpy fast path
When every element is a String sharing one ASCII-compatible fast-path
encoding (UTF-8/US-ASCII/ASCII-8BIT) and the separator is compatible, build
the result with a single memcpy pass instead of appending element by element
through rb_str_buf_append. Other cases fall back to the existing path.
2026-06-11 20:59:01 +02:00
Aaron Patterson c4d09f416c Reapply "Reserve 2 bits for expressing object layout (#17139)" (#17158)
This reverts commit ddb5055d96.
2026-06-01 19:30:58 +00:00
Aaron Patterson ddb5055d96 Revert "Reserve 2 bits for expressing object layout (#17139)"
This reverts commit 63d9f090b5.
2026-05-29 16:41:31 -07:00
63d9f090b5 Reserve 2 bits for expressing object layout (#17139)
* Reserve 2 bits for expressing object layout

We would like to make instance variable reads in the JIT compiler faster
(as well as simplify the JIT implementation).  Currently, in order to
read an instance variable, we have to:

1. Test for heap object
2. Load object to a 64 bit register
3. Mask the object header
4. Bit test against the masked header
5. JNE
6. Load field

We would like to:

1. Test for heap object
2. Load object shape to a 32 bit register
3. Bit test against the shape
4. JNE
5. Load field

The way we fetch instance variables is not consistent across objects.
In order to realize our goal, we need to encode object layout inside the
shape.  If we encode object layout inside the shape, then the shape
itself will guarantee that the access pattern generated by the JIT
compiler is correct.

We should encode the following load patterns into the shape tag bits.
This way we can share shapes on transitions, but be able to
differentiate the access patterns for the JIT compiler.  In other words,
two objects can have an `@a -> @b -> @c` transition and share the same
shape, but the tag bits can differentiate the access pattern so that the
JIT compiler can be confident that the machine code is correct.

Here are the patterns:

1. Embedded/Extended T_OBJECT Instance Variables

Objects with direct references to instance variables or via malloc
buffer

2. Objects with fields_objects fields

These are Data and TypedData objects.  They have an associated axillary
imemo/fields object that stores the instance variables.  The access
pattern is `object[2] + 2`.  The fields object is the 3rd field, and the
instance variables start at +2 inside the fields object.  The fields
object itself is a Ruby object, so it contains the usual header bits +
class headers.

3. Non Boxable Classes / Modules

This is similar to Objects with fields_objects, but the fields object is
stored at a different offset.  We’re differentiating this from boxable
classes and modules because those are harder to support.

4. Other

"Other" pattern is for objects that are rare, or have
difficult-to-implement access patterns.  This includes:

* Boxable classes and modules
* Structs (for now)
* Objects that use the geniv table

Proposed shape bit layout:

```
  Current shape_id_t is 32 bits:
  31        28 27 26 25 24 23 22        19 18                         0
  +-----------+--+--+--+--+--+------------+----------------------------+
  | unused    |L1|L0|OI|FR|CX| heap index | shape tree offset          |
  +-----------+--+--+--+--+--+------------+----------------------------+
               |  |  |  |  |  |            |
               |  |  |  |  |  |            +-- bits 0-18: SHAPE_ID_OFFSET_MASK
               |  |  |  |  |  +--------------- bits 19-22: SHAPE_ID_HEAP_INDEX_MASK
               |  |  |  |  +------------------ bit 23: SHAPE_ID_FL_COMPLEX
               |  |  |  +--------------------- bit 24: SHAPE_ID_FL_FROZEN
               |  |  +------------------------ bit 25: SHAPE_ID_FL_HAS_OBJECT_ID
               +--+--------------------------- bits 26-27: SHAPE_ID_LAYOUT_MASK
```

The important part about these layout patterns is that they do not
reflect the _type_ of object, only how the object is laid out in memory.
For example, we currently treat structs as "other", but we can refactor
them to have the same layout as "Objects with fields_objects", and when
we do that they should get a different bit in the shape header.

This commit only reserves the two bits, it doesn't use them in the JIT
compiler yet.

Co-Authored-By: John Hawthorn <john@hawthorn.email>
Co-Authored-By: Max Bernstein <tekknolagi@gmail.com>

* Update gc.c

Co-authored-by: Nobuyoshi Nakada <nobu.nakada@gmail.com>

* Update shape.h

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>

* fix function name

* Update shape.c

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>

* fix function name

* Revert "Update shape.c"

This reverts commit 900711defc6c541a93f3393a350819ae88cf87f1.

* add comment

---------

Co-authored-by: John Hawthorn <john@hawthorn.email>
Co-authored-by: Max Bernstein <tekknolagi@gmail.com>
Co-authored-by: Nobuyoshi Nakada <nobu.nakada@gmail.com>
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2026-05-29 15:09:34 -07:00
Takashi KokubunandAlan Wu d485eb663c ZJIT: Store JITFrame in the native stack (#16955)
Co-authored-by: Alan Wu <alanwu@ruby-lang.org>
2026-05-22 10:12:29 -07:00
John HawthornandJean Boussier fe3f45187b Allocate RMatch storage embedded
Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
2026-05-14 07:07:45 -07:00
Nobuyoshi Nakada 7c5c967fca pathname: Define has_separator? instead of SEPARATOR_PAT 2026-05-13 17:37:48 +09:00
Nobuyoshi Nakada 9021799650 pathname: Move absolute? to pathname.c 2026-05-13 17:37:48 +09:00
Satoshi Tagomori 276f0d9b3e [Bug #21881] Separate the master and root box
This change separates the master box from the root box, as the single
master copy of boxes.
Before this change, the root box is the source of copies, and also
it runs builtin classes' code. Builtin code makes changes by
requiring files, thus the source of copies is mutable, be different
from the past one. This causes different internal states of boxes,
depending on when it is created.
After this change, all boxes are created from the master box, and
the master box never runs code, so it realizes the immutable source
of copies.

This also makes is possible to separate RubyGems (and other default
gems) from each boxes. All boxes will have their own copies of RubyGems.
RubyGems has its internal state, but it'll be separated between boxes
after this change.
2026-05-10 09:38:45 +09:00
John Hawthorn 3d861274e6 Introduce RMATCH_{BEG,END,NREGS} helpers
These are internal-only helpers which can be used instead of the
RMATCH_REGS struct directly. RMATCH_REGS is just a pointer offset from
the RMatch VALUE itself, so this should not significantly affect
codegen.

The motivation for this is that it's both simpler, and should move us
towards being able to replace the storage for RMATCH, and to be able to
store the positions embedded instead of in separate malloc memory.
2026-05-08 13:41:12 -07:00
Nobuyoshi Nakada 5fa9c730d8 Update dependencies
Fix-up for d3ef85a100.
2026-04-29 19:12:58 +09:00
Jean Boussier 9a2ffd8e54 Fix sending backtraces across ractors
[Bug #21818]

Currently exceptions can be sent across ractors,
but because of a limitation in the TypedData API,
the exception backtrace is duped as an empty backtrace.

The problem is that backtraces are embedded objects,
hence the classic `rb_class_alloc(klass)` API is insufficient
because we need to know the size of the Backtrace object we're
duping to instantiate the copy.

This is worked around by changing Ractors to call `#clone` on objects
rather than use `rb_obj_clone`, and to implement `Thread::Backtrace#clone`
to properly clone the variable size object.
2026-04-01 11:43:55 +01:00
Takashi Kokubun 59fe446e8f ZJIT: Use bare opcode variant in iseq_may_write_block_code
Add rb_iseq_bare_opcode_at_pc which uses rb_vm_insn_addr2insn to
return the base instruction, stripping trace/zjit variants. Use it
in iseq_may_write_block_code to simplify the match arms.
2026-03-27 16:26:12 -07:00
Takashi KokubunandAlan Wu c8f97943ef ZJIT: Lightweight Frames
Co-authored-by: Alan Wu <alanwu@ruby-lang.org>
2026-03-27 16:26:12 -07:00
Benoit Daloze cb03bf43eb Freeze all instances of Regexp, except subclass instances
* Instances of a subclass of Regexp are not frozen for compatibility.
* [Feature #8948]
* Use a less confusing example in test_regexp2,
  the ivar was named @encoding but had no effect on Regexp#encoding.
2026-03-25 10:00:03 +01:00
Nobuyoshi Nakada 72eb59d0b2 [Feature #21932] Add MatchData#get_int 2026-03-24 13:19:15 +09:00
Takashi Kokubun 26bedb534a Update outdated dependencies 2026-03-20 10:22:43 -07:00