122 Commits
Author SHA1 Message Date
Hiroshi SHIBATAandClaude Opus 5.5 3d73c09fa3 Keep the branch target count of the coverage cache as rb_len_t
LONG2FIX and FIX2LONG would narrow it to long once rb_len_t widens on mswin, where Fixnum is also only 31 bits.

https://bugs.ruby-lang.org/issues/22400

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 16:31:01 +09:00
Hiroshi SHIBATAandClaude Opus 5.5 6b3b0b8083 Use rb_len_t for String and Array lengths in ext/coverage and ext/objspace
ObjectSpace.dump writes the lengths with dump_append_sizet, because dump_append_ld takes a long and is also used for Fixnum values. The lengths are never negative, so the output does not change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 16:45:25 +09:00
mugitti9 22e4a75d67 [Bug #22269] Make coverage_enabled: false effective for compile/compile_file
Use it in Coverage.line_stub so compiling the stub does not overwrite already-collected coverage data.
2026-08-29 15:48:53 +09:00
Yusuke EndohandClaude Fable 5 c9e9101403 Cache a template of the method coverage result [Bug #22250]
Likewise for method coverage: walking me_set and cme2counter and hashing
the array keys on every peek dominated the cost.  Maintain
{ path => { key => me or [me, ...] } } incrementally (both hashes are
append-only) and fill in the counts from cme2counter on each peek.
Extract rb_coverage_method_data_of() from thread.c for that.

10k methods: 24 ms -> 0.7 ms per peek.  rack's test suite with SimpleCov
per-test tracking (lines+branches+methods): 30 s -> 8.4 s.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-21 16:50:27 +09:00
Yusuke EndohandClaude Fable 5 d43737d2a8 Cache a template of the branch coverage result [Bug #22250]
Coverage.peek_result rebuilt the nested branch coverage hash on every
call, and hashing its array keys (Array#hash via the recursion guard)
dominated the cost.  Build { base_key => { target_key => counter_index } }
once per file and cache it; each peek dups it and fills in the counters.

40k branch sites: 40 ms -> 3.5 ms per peek.  The key arrays are now frozen
and shared between results.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-21 16:50:27 +09:00
Nobuyoshi Nakada 8f4a3c9401 [Feature #22215] Extract internal coverage API
Provide a narrow coverage interface so `ext/coverage` does not depend
on GC or VM implementation headers.
2026-08-07 09:59:15 +09:00
Yusuke EndohandClaude Opus 4.8 b26b0227f8 Fix method coverage dropping redefined/removed methods after GC [Bug #22179]
Method coverage rebuilt its result by walking the heap for method
entries, so a shadowed or removed method that was never called could be
reclaimed by GC and vanish from the result depending on GC timing.

Record each defined method entry in me_set as it is defined, and compute
the result from me_set and cme2counter instead of walking the heap.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-03 20:25:35 +09:00
Yusuke EndohandClaude Opus 4.8 20cb1759e9 coverage.c: Extract method_coverage_add helper
Behavior-preserving refactoring extracted from method_coverage_i.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-03 20:25:35 +09:00
Yusuke EndohandClaude Opus 4.8 7039708dbc Rename me2counter to cme2counter
The counter is keyed by the callable method entry (cme) at the call site.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-03 20:25:35 +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
Peter Zhu 99d90125c0 [DOC] Improve docs for Coverage.start 2026-02-02 17:09:07 -05:00
Peter Zhu 554ca2eb62 [DOC] Fix broken link in Coverage.setup 2026-01-28 17:13:39 -05:00
Peter Zhu b75938e2c3 [DOC] Improve class doc for Coverage 2026-01-25 10:09:17 -05:00
Peter Zhu 319f142a3a [DOC] Improve docs for Coverage.setup 2026-01-22 17:11:44 -05:00
Peter Zhu 965b16d766 [DOC] Add doc about eval coverage 2026-01-21 17:43:44 -05:00
Peter Zhu c939330b7a [DOC] Escape Coverage 2026-01-19 17:09:29 -05:00
Peter Zhu 342d25785c [DOC] Fix backticks in Coverage.peek_result 2025-12-23 22:30:54 -05:00
Peter Zhu ade2b51a3b Don't GC unprotect hash in Coverage.peek_result
The call to unprotect the coverages hash was introduced in commit 99093e1
where we used the raw ST table and st_foreach. We now use rb_hash_foreach
which no longer requires GC unprotecting the coverages hash.
2025-11-11 10:17:48 -08:00
Nobuyoshi Nakada 953fee11b3 [DOC] Document of Coverage.line_stub from NEWS-2.6.0 2025-11-09 22:11:39 +09:00
Satoshi Tagomori aaa1234702 update referenced filenames from namespace to box 2025-11-07 13:14:54 +09:00
Jeremy Evans 0b23a8db60 Update dependencies for addition of set.h to public headers 2025-07-11 15:24:23 +09:00
Satoshi Tagomori 382645d440 namespace on read 2025-05-11 23:32:50 +09:00
Jean Boussier 3ec7bfff2e Use a set_table for rb_vm_struct.unused_block_warning_table
Now that we have a hash-set implementation we can use that
instead of a hash-table with a static value.
2025-04-27 11:59:28 +02:00
Peter Zhu a58675386c Prefix asan_poison_object with rb 2024-12-19 09:14:34 -05:00
卜部昌平 c844968b72 ruby tool/update-deps --fix 2024-04-27 21:55:28 +09:00
Peter Zhu 6bd3e8fbb2 Use rb_hash_foreach in coverage
Using RHASH_TBL_RAW is a private API, so we should use rb_hash_foreach
rather than RHASH_TBL_RAW with st_foreach.
2024-02-23 10:24:21 -05:00
yui-knk b481b673d7 [Feature #19719] Universal Parser
Introduce Universal Parser mode for the parser.
This commit includes these changes:

* Introduce `UNIVERSAL_PARSER` macro. All of CRuby related functions
  are passed via `struct rb_parser_config_struct` when this macro is enabled.
* Add CI task with 'cppflags=-DUNIVERSAL_PARSER' for ubuntu.
2023-06-12 18:23:48 +09:00
Matt Valentine-House 5e4b80177e Update the depend files 2023-02-28 09:09:00 -08:00
Matt Valentine-House f38c6552f9 Remove intern/gc.h from Make deps 2023-02-27 10:11:56 -08:00
Matt Valentine-House 72aba64fff Merge gc.h and internal/gc.h
[Feature #19425]
2023-02-09 10:32:29 -05:00
Nobuyoshi Nakada 899ea35035 Extract include/ruby/internal/attr/packed_struct.h
Split `PACKED_STRUCT` and `PACKED_STRUCT_UNALIGNED` macros into the
macros bellow:
* `RBIMPL_ATTR_PACKED_STRUCT_BEGIN`
* `RBIMPL_ATTR_PACKED_STRUCT_END`
* `RBIMPL_ATTR_PACKED_STRUCT_UNALIGNED_BEGIN`
* `RBIMPL_ATTR_PACKED_STRUCT_UNALIGNED_END`
2023-02-08 12:34:13 +09:00
Kevin Murphy b3d330c39e Coverage.supported? recognizes oneshot_lines mode (#7040)
This adds oneshot_lines as a mode of coverage that is supported.
2022-12-29 21:23:25 +13:00
Daniel Colson 64cdf8bae7 Update dependencies 2022-12-06 12:37:23 -08:00
Yudai Takada 29e6d97517 Fix typos (#6775)
* s/Innteger/Integer/

* s/diretory/directory/

* s/Bufer/Buffer/

* s/defalt/default/

* s/covearge/coverage/
2022-11-20 21:07:18 -08:00
Jemma Issroff ad63b668e2 Revert "Revert "This commit implements the Object Shapes technique in CRuby.""
This reverts commit 9a6803c90b.
2022-10-11 08:40:56 -07:00
Aaron Patterson 9a6803c90b Revert "This commit implements the Object Shapes technique in CRuby."
This reverts commit 68bc9e2e97d12f80df0d113e284864e225f771c2.
2022-09-30 16:01:50 -07:00
Samuel Williams bd2fbd3588 Add Coverage.supported? to detect what modes are supported. 2022-09-29 09:44:14 +13:00
Samuel Williams 9dd902b831 Add eval: true/false flag to Coverage.setup. 2022-09-29 09:44:14 +13:00
d594a5a8bd This commit implements the Object Shapes technique in CRuby.
Object Shapes is used for accessing instance variables and representing the
"frozenness" of objects.  Object instances have a "shape" and the shape
represents some attributes of the object (currently which instance variables are
set and the "frozenness").  Shapes form a tree data structure, and when a new
instance variable is set on an object, that object "transitions" to a new shape
in the shape tree.  Each shape has an ID that is used for caching. The shape
structure is independent of class, so objects of different types can have the
same shape.

For example:

```ruby
class Foo
  def initialize
    # Starts with shape id 0
    @a = 1 # transitions to shape id 1
    @b = 1 # transitions to shape id 2
  end
end

class Bar
  def initialize
    # Starts with shape id 0
    @a = 1 # transitions to shape id 1
    @b = 1 # transitions to shape id 2
  end
end

foo = Foo.new # `foo` has shape id 2
bar = Bar.new # `bar` has shape id 2
```

Both `foo` and `bar` instances have the same shape because they both set
instance variables of the same name in the same order.

This technique can help to improve inline cache hits as well as generate more
efficient machine code in JIT compilers.

This commit also adds some methods for debugging shapes on objects.  See
`RubyVM::Shape` for more details.

For more context on Object Shapes, see [Feature: #18776]

Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
Co-Authored-By: Eileen M. Uchitelle <eileencodes@gmail.com>
Co-Authored-By: John Hawthorn <john@hawthorn.email>
2022-09-28 08:26:21 -07:00
Aaron Patterson 06abfa5be6 Revert this until we can figure out WB issues or remove shapes from GC
Revert "* expand tabs. [ci skip]"

This reverts commit 830b5b5c35.

Revert "This commit implements the Object Shapes technique in CRuby."

This reverts commit 9ddfd2ca00.
2022-09-26 16:10:11 -07:00
9ddfd2ca00 This commit implements the Object Shapes technique in CRuby.
Object Shapes is used for accessing instance variables and representing the
"frozenness" of objects.  Object instances have a "shape" and the shape
represents some attributes of the object (currently which instance variables are
set and the "frozenness").  Shapes form a tree data structure, and when a new
instance variable is set on an object, that object "transitions" to a new shape
in the shape tree.  Each shape has an ID that is used for caching. The shape
structure is independent of class, so objects of different types can have the
same shape.

For example:

```ruby
class Foo
  def initialize
    # Starts with shape id 0
    @a = 1 # transitions to shape id 1
    @b = 1 # transitions to shape id 2
  end
end

class Bar
  def initialize
    # Starts with shape id 0
    @a = 1 # transitions to shape id 1
    @b = 1 # transitions to shape id 2
  end
end

foo = Foo.new # `foo` has shape id 2
bar = Bar.new # `bar` has shape id 2
```

Both `foo` and `bar` instances have the same shape because they both set
instance variables of the same name in the same order.

This technique can help to improve inline cache hits as well as generate more
efficient machine code in JIT compilers.

This commit also adds some methods for debugging shapes on objects.  See
`RubyVM::Shape` for more details.

For more context on Object Shapes, see [Feature: #18776]

Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
Co-Authored-By: Eileen M. Uchitelle <eileencodes@gmail.com>
Co-Authored-By: John Hawthorn <john@hawthorn.email>
2022-09-26 09:21:30 -07:00
Takashi Kokubun 5b21e94beb Expand tabs [ci skip]
[Misc #18891]
2022-07-21 09:42:04 -07:00
f90549cd38 Rust YJIT
In December 2021, we opened an [issue] to solicit feedback regarding the
porting of the YJIT codebase from C99 to Rust. There were some
reservations, but this project was given the go ahead by Ruby core
developers and Matz. Since then, we have successfully completed the port
of YJIT to Rust.

The new Rust version of YJIT has reached parity with the C version, in
that it passes all the CRuby tests, is able to run all of the YJIT
benchmarks, and performs similarly to the C version (because it works
the same way and largely generates the same machine code). We've even
incorporated some design improvements, such as a more fine-grained
constant invalidation mechanism which we expect will make a big
difference in Ruby on Rails applications.

Because we want to be careful, YJIT is guarded behind a configure
option:

```shell
./configure --enable-yjit # Build YJIT in release mode
./configure --enable-yjit=dev # Build YJIT in dev/debug mode
```

By default, YJIT does not get compiled and cargo/rustc is not required.
If YJIT is built in dev mode, then `cargo` is used to fetch development
dependencies, but when building in release, `cargo` is not required,
only `rustc`. At the moment YJIT requires Rust 1.60.0 or newer.

The YJIT command-line options remain mostly unchanged, and more details
about the build process are documented in `doc/yjit/yjit.md`.

The CI tests have been updated and do not take any more resources than
before.

The development history of the Rust port is available at the following
commit for interested parties:
https://github.com/Shopify/ruby/commit/1fd9573d8b4b65219f1c2407f30a0a60e537f8be

Our hope is that Rust YJIT will be compiled and included as a part of
system packages and compiled binaries of the Ruby 3.2 release. We do not
anticipate any major problems as Rust is well supported on every
platform which YJIT supports, but to make sure that this process works
smoothly, we would like to reach out to those who take care of building
systems packages before the 3.2 release is shipped and resolve any
issues that may come up.

[issue]: https://bugs.ruby-lang.org/issues/18481

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
Co-authored-by: Noah Gibbs <the.codefolio.guy@gmail.com>
Co-authored-by: Kevin Newton <kddnewton@gmail.com>
2022-04-27 11:00:22 -04:00
Peter Zhu 2d5ecd60a5 [Feature #18249] Update dependencies 2022-02-22 09:55:21 -05:00
Nobuyoshi Nakada a202408180 Fix typos 2021-11-02 19:17:37 +09:00
Yusuke Endoh 86e3d77abb Make Coverage suspendable (#4856)
* Make Coverage suspendable

Add `Coverage.suspend`, `Coverage.resume` and some methods.

[Feature #18176] [ruby-core:105321]
2021-10-25 20:00:51 +09:00
Alan Wu c02517bacb Tie lifetime of uJIT blocks to iseqs
* Tie lifetime of uJIT blocks to iseqs

   Blocks weren't being freed when iseqs are collected.

* Add rb_dary. Use it for method dependency table

* Keep track of blocks per iseq

  Remove global version_tbl

* Block version bookkeeping fix

* dary -> darray

* free ujit_blocks

* comment about size of ujit_blocks
2021-10-20 18:19:29 -04:00
卜部昌平 6413dc27dc dependency updates 2021-04-13 14:30:21 +09:00
Nobuyoshi Nakada 6ed6b85ece Expose atomic operation macros with RUBY prefix
Now we need atomic operations, which are lighter than mutex, more
widely for extension libraries because of Ractor.
2020-12-24 11:43:21 +09:00
Kevin Murphy 0026f644d7 Document Different Coverage Modes
This commits adds in documentation to illustrate the different modes you
can start coverage with. Examples are provided to show how to start each
of these modes, along with an explanation of the mode and a description
of the output.
2020-11-20 09:24:46 +09:00