Ractor-safe
Rubyのmain Ractorで安全に実行できる性質を指して言う
Ractor-unsafeは「そもそもnon main Ractorでは動かない」のでcompatible/incompatibleのほうが感覚的には正しい?
ruby/ruby や https://bugs.ruby-lang.org/ にはどちらの表現もある
Ruby本体
RubyKaigi Takeout 2021とtest-unit - Ractor対応とdebug.rb対応とCoreAssertionsの置き換え #rubykaigi
minitest
Ractor専用のアサーションを独自で用意していた
test-unitへ移行した
https://www.slideshare.net/hsbt/how-to-develop-the-standard-libraries-of-ruby#16
test-unitではRactor対応しているかどうかのテスト方法が2種類ある
assert_ractor
別プロセスでRubyを立ち上げてその中でRactorを使ったコードを実行してその結果をアサートする
実装 https://github.com/ruby/ruby/blob/v3_4_0_preview1/tool/lib/core_assertions.rb#L370-L389
なぜ?
https://github.com/ruby/ruby/commit/bc23216e5a4204b8e626704c7277e9edc1708189
Ractorを使うとRubyインタプリター内の実行モードが変わってRactorがいなくなってもそのモードは元に戻らず他のテストに影響があるから (3.0.0時点)
例
did_you_mean gemにRactor compatibleかどうかのテストがある
https://github.com/ruby/ruby/blob/v3_4_0_preview1/test/did_you_mean/test_ractor_compatibility.rb
ractor def test_foo; end
Ractor関連のテストを最後に実行する機構
test-unitのこのcommitで実装 https://github.com/test-unit/test-unit/commit/276a8199e8c51a9c4826d94b20906889f7661e06
なのでruby/ruby以外でも使える
Ruby本体にはあまりない
これぐらい? https://github.com/ruby/ruby/commit/44bfe72892a5a07040d806c2aee89ee52955d86d
Ruby の中にある解決できると嬉しい人が多分多いタフな問題
Ractor対応のパッチ一覧(rm155が頑張っていた)
https://github.com/search?q=org%3Aruby+author%3Arm155&type=pullrequests
C extension
https://github.com/ruby/ruby/pull/3824
rb_ext_ractor_safe()で宣言でき、Ractor-safeであると示されたC拡張のみがnon main Ractorで実行できる
https://bugs.ruby-lang.org/issues/17307
対応事例
https://github.com/ruby/csv/pull/218