Commit graph

115 commits

Author SHA1 Message Date
Nobuyoshi Nakada
4a67ef09cc
[Feature #21116] Extract RJIT as a third-party gem 2025-02-13 18:01:03 +09:00
Peter Zhu
cfee3d9f4b Revert "[MMTk/CI] Skip Ractor btests with MMTk"
This reverts commit 58b4e249ed.

The bug that it encountered was fixed in f76d40789d.
2025-01-10 10:17:16 -05:00
Peter Zhu
f1049aa55d Don't check for presence of ENV['GITHUB_WORKFLOW']
We already check whether `ENV['GITHUB_WORKFLOW']` is equal to `Compilations`,
so we don't need to check that it's not nil.
2025-01-10 10:17:16 -05:00
Hiroshi SHIBATA
3a1414a70b Rewrite Benchmark to Tempfile on bootstraptest/test_ractor.rb 2025-01-10 10:19:39 +09:00
Luke Gruber
38af38edcb Fix ractor move of unshareable frozen objects
These objects didn't retain their frozen status after the move

Bug [#19408]
2024-12-24 11:38:44 +09:00
Koichi Sasada
0bdb38ba6b Ractor.set_if_absent(key)
to initialize ractor local storage in thread-safety.
[Feature #20875]
2024-12-13 06:22:13 +09:00
Matt Valentine-House
58b4e249ed [MMTk/CI] Skip Ractor btests with MMTk
currently these are flaky, so until we can make them more robust, we'll
skip them for MMTk CI
2024-12-06 09:48:30 +00:00
Koichi Sasada
78064d0770 skip SystemStackError
with -O0 build, prism parser consumes a lot of machine stack and
it doesn't work with minimum machine stack for threads, which
specified with `RUBY_THREAD_MACHINE_STACK_SIZE=1`.

So simply ignore `SystemStackError` for btest.
2024-11-08 18:02:46 +09:00
Koichi Sasada
aa63699d10 support require in non-main Ractors
Many libraries should be loaded on the main ractor because of
setting constants with unshareable objects and so on.

This patch allows to call `requore` on non-main Ractors by
asking the main ractor to call `require` on it. The calling ractor
waits for the result of `require` from the main ractor.

If the `require` call failed with some reasons, an exception
objects will be deliverred from the main ractor to the calling ractor
if it is copy-able.

Same on `require_relative` and `require` by `autoload`.

Now `Ractor.new{pp obj}` works well (the first call of `pp` requires
`pp` library implicitly).

[Feature #20627]
2024-11-08 18:02:46 +09:00
tompng
f4e548924e Update bootstraptest test for colon-style hash inspect 2024-10-03 18:47:09 +09:00
Koichi Sasada
43aee3393d fix defined?(@ivar) with Ractors
`defined?(@ivar)` on the non main Ractor has two issues:

1. raising an exception

```ruby
class C
  @iv1 = []
  def self.defined_iv1 = defined?(@iv1)
end

Ractor.new{
  p C.defined_iv1
  #=> can not get unshareable values from instance variables of classes/modules from non-main Ractors (Ractor::IsolationError)
}.take
```

-> Do not raise an exception but return `"instance-variable"` because
it is defined.

2. returning `"instance-variable"` if there is not defined.

```
class C
  # @iv2 is not defined
  def self.defined_iv2 = defined?(@iv2)
end

Ractor.new{
  p C.defined_iv2 #=> "instance-variable"
}.take
```

-> returns `nil`
2024-07-12 04:43:14 +09:00
Luke Gruber
6747fbe77d
Fix interrupts during Ractor.select
Fixes [Bug #20168]
2024-05-05 15:14:53 +00:00
Takashi Kokubun
a1db69f0c9 Skip a flaky Ractor test for YJIT
2431063188
2430763832

This seems like an existing, separate issue from what we're currently
investigating. The `iseq->body->jit_entry` setup is not Ractor-safe?
Let me suppress this for now and revisit this after resolving the
ongoing issue.
2024-04-26 11:11:30 -07:00
Étienne Barrié
12be40ae6b Implement chilled strings
[Feature #20205]

As a path toward enabling frozen string literals by default in the future,
this commit introduce "chilled strings". From a user perspective chilled
strings pretend to be frozen, but on the first attempt to mutate them,
they lose their frozen status and emit a warning rather than to raise a
`FrozenError`.

Implementation wise, `rb_compile_option_struct.frozen_string_literal` is
no longer a boolean but a tri-state of `enabled/disabled/unset`.

When code is compiled with frozen string literals neither explictly enabled
or disabled, string literals are compiled with a new `putchilledstring`
instruction. This instruction is identical to `putstring` except it marks
the String with the `STR_CHILLED (FL_USER3)` and `FL_FREEZE` flags.

Chilled strings have the `FL_FREEZE` flag as to minimize the need to check
for chilled strings across the codebase, and to improve compatibility with
C extensions.

Notes:
  - `String#freeze`: clears the chilled flag.
  - `String#-@`: acts as if the string was mutable.
  - `String#+@`: acts as if the string was mutable.
  - `String#clone`: copies the chilled flag.

Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
2024-03-19 09:26:49 +01:00
Jean Boussier
91bf7eb274 Refactor frozen_string_literal check during compilation
In preparation for https://bugs.ruby-lang.org/issues/20205.

The `frozen_string_literal` compilation option will no longer
be a boolean but a tri-state: `on/off/default`.
2024-03-15 15:52:33 +01:00
Jean Boussier
09d8c99cdc Ensure test suite is compatible with --frozen-string-literal
As preparation for https://bugs.ruby-lang.org/issues/20205
making sure the test suite is compatible with frozen string
literals is making things easier.
2024-03-14 17:56:15 +01:00
Takashi Kokubun
2918e43dee Skip a flaky Ractor test for YJIT
`[BUG] pthread_mutex_lock: Invalid argument (EINVAL)` doesn't seem like
a fault of YJIT?

2073675497
2073957248
2024-01-22 10:31:21 -08:00
Luke Gruber
32c4b0125f Set Ractor moved object's shape to original object's shape
Fixes [Bug #19409]
2024-01-02 08:10:59 +09:00
Koichi Sasada
054f56fd3e moved object should not have a shape ID
fix [Bug #19917]
2023-12-20 07:04:32 +09:00
Koichi Sasada
c9a9b8036c remove Ractor::Selector from Ruby level
`Ractor::Selector` is not approved by Matz so remove it from
Ruby-level.

The implementation is used by `Ractor.select` so most of implementation
was remaind and calling `rb_init_ractor_selector()`, `Ractor::Selector`
will be defined. I will provide `ractor-selector` gem to try it.
2023-12-16 01:00:01 +09:00
Nobuyoshi Nakada
d3bcff0158
Fix a typo [ci skip] 2023-07-17 00:15:05 +09:00
Nobuyoshi Nakada
ce47ee00ae Fix indirect counter increment
`*pcnt++` just dereferences `pcnt` then increments the local variable,
but has no side effect.
2023-03-15 13:59:11 +09:00
Takashi Kokubun
973cb64b1c RJIT: Skip a flaky test_thread test for now
and unskip a ractor test that was actually running
2023-03-10 23:24:18 -08:00
Takashi Kokubun
23ec248e48 s/mjit/rjit/ 2023-03-06 23:44:01 -08:00
Takashi Kokubun
3034553e8d Add more GC guards 2023-03-05 23:28:59 -08:00
Koichi Sasada
883871d722 add a test for Ractor
Ractor should take care method cache invalidation.
Added test will miss method cache on each method call.
2023-03-06 13:30:54 +09:00
Takashi Kokubun
4782bb352e Another attempt to skip test_ractor on ci.rvm.jp
This reverts commit 8d31a60f47.
2023-03-03 20:39:38 -08:00
Takashi Kokubun
8d31a60f47 Fix a YJIT enablement check
This should be enough for `make test` and `make btest-ruby` while it
doesn't work for `make btest`.
2023-03-03 17:03:26 -08:00
Takashi Kokubun
533c8c0c44 Re-skip an unstable Ractor test
7532190115
http://ci.rvm.jp/results/trunk-yjit@ruby-sp2-docker/4466770
2023-03-02 09:47:07 -08:00
Takashi Kokubun
fac92cd050 Revert "Revert "Re-enable test_ractor for YJIT""
This reverts commit 9792d9e40f.

Ractor implementation has been rewritten. Let's see if it works now.
2023-03-02 09:11:24 -08:00
Koichi Sasada
5875fce6ce Ractor::Selector#empty?
It returns the waiting set is empty or not.

Also add Ractor::Selector's tests.
2023-03-03 00:08:02 +09:00
Koichi Sasada
6207a3f588 Enable flaky ractor test
I hope a4421bd73c will solve the issue...
2023-03-02 16:14:49 +09:00
Koichi Sasada
a4421bd73c Rewrite Ractor synchronization mechanism
This patch rewrites Ractor synchronization mechanism, send/receive
and take/yield.

* API
  * Ractor::Selector is introduced for lightweight waiting
    for many ractors.
* Data structure
  * remove `struct rb_ractor_waiting_list` and use
    `struct rb_ractor_queue takers_queue` to manage takers.
  * remove `rb_ractor_t::yield_atexit` and use
    `rb_ractor_t::sync::will_basket::type` to check the will.
  * add `rb_ractor_basket::p.take` to represent a taking ractor.
* Synchronization protocol
  * For the Ractor local GC, `take` can not make a copy object
    directly so ask to generate the copy from the yielding ractor.
  * The following steps shows what `r1.take` does on `r0`.
    * step1: (r0) register `r0` into `r1`'s takers.
    * step2: (r0) check `r1`'s status and wakeup r0 if `r1` is waiting
             for yielding a value.
    * step3: (r0) sleep until `r1` wakes up `r0`.
  * The following steps shows what `Ractor.yield(v)` on `r1`.
    * step1: (r1) check first takers of `r1` and if there is (`r0`),
             make a copy object of `v` and pass it to `r0` and
             wakes up `r0`.
    * step2: (r1) if there is no taker ractors, sleep until
             another ractor try to take.
2023-03-02 14:31:54 +09:00
Benoit Daloze
6abe20e87b Remove Encoding#replicate 2023-01-11 13:41:41 +01:00
Takashi Kokubun
9792d9e40f Revert "Re-enable test_ractor for YJIT"
This reverts commit 650a20a3e1.

Now that 3.2.0 is released, let's disable flaky tests. Koichi said he'll
rework Ractor implementation for this, and it has not been done yet.
2023-01-09 17:43:47 -08:00
Takashi Kokubun
67ef3cd3cc
Skip a flaky Ractor test for mswin 2022-12-21 16:56:41 -08:00
Takashi Kokubun
650a20a3e1
Re-enable test_ractor for YJIT
This would be still flaky, but we want to make sure there's no
YJIT-specific issue when Ruby 3.2 is released. We might skip it again
after the release.
2022-12-19 13:59:36 -08:00
Koichi Sasada
ae19ac5b5b fixed encoding table
This reduces global lock acquiring for reading.
https://bugs.ruby-lang.org/issues/18949
2022-12-16 10:04:37 +09:00
Takashi Kokubun
307d2e0e91
Skip yet another flaky Ractor test 2022-12-13 22:40:13 -08:00
Takashi Kokubun
7b38853bc3
Skip another flaky Ractor test for YJIT 2022-12-02 10:26:54 -08:00
Takashi Kokubun
85f041c0c5
Skip a couple of Ractor tests
Koichi plans to rework Ractor implementation to address these failures.
He agreed to skip flaky Ractor tests for now.
2022-12-02 10:18:50 -08:00
Takashi Kokubun
d15d1c01c2
Rename --mjit-min-calls to --mjit-call-threshold (#6731)
for consistency with YJIT
2022-11-14 23:38:52 -08:00
Nobuyoshi Nakada
131c31a920
[Bug #19081] Show the caller location in warning for Ractor
The internal location in ractor.rb is not usefull at all.
```
$ ruby -e 'Ractor.new {}'
<internal:ractor>:267: warning: Ractor is experimental, ...
```
2022-10-26 19:43:14 +09:00
Jemma Issroff
9a5684bf7f Add test for ractor race condition on ivar sets 2022-10-14 11:59:36 -07:00
Koichi Sasada
6050e3e2a6 @@cv is not accessible from non-main ractors
Class variables (@@cv) is not accessible from non-main ractors.
But without this patch cached @@cv can be read.

fix [Bug #18128]
2021-12-24 13:52:02 +09:00
Koichi Sasada
397a509b6d prohibit load by autoload on non-main Ractor
fix [Bug #18120]
2021-12-15 02:33:17 +09:00
Koichi Sasada
cce331272b Ractor.make_shareable checks proc's sefl
`Ractor.make_shareable(proc_obj)` raises an `IsolationError`
if the self of `proc_obj` is not a shareable object.

[Bug #18243]
2021-12-09 16:20:04 +09:00
Nobuyoshi Nakada
334b69e504 rb_id_serial_to_id: return unregistered ID as an internal ID
```ruby
def foo(*); ->{ super }; end
```

This code makes anonymous parameters which is not registered as an
ID.  The problem is that when Ractors try to scan `getlocal`
instructions, it puts the Symbol corresponding to the parameter
in to a hash.  Since it is not registered, we end up with a
strange exception.  This commit wraps the unregistered ID in an
internal ID so that we get the same exception for `...` as `*`.

Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
Co-Authored-By: John Hawthorn <john@hawthorn.email>
2021-11-07 12:40:27 +09:00
Satoshi Moris Tagomori
489e5e3a82 the core problem is the Proc is not shareable 2021-10-27 16:13:43 +09:00
Koichi Sasada
acb23454e5 allow to access ivars of classes/modules
if an ivar of a class/module refer to a shareable object, this ivar
can be read from non-main Ractors.
2021-10-23 01:32:55 +09:00