[ruby-core:124924] [Ruby Feature#21942] Allow reading class variables from non-main Ractors
Issue #21942 has been reported by tenderlovemaking (Aaron Patterson). ---------------------------------------- Feature #21942: Allow reading class variables from non-main Ractors https://bugs.ruby-lang.org/issues/21942 * Author: tenderlovemaking (Aaron Patterson) * Status: Open ---------------------------------------- It's very common in Rails applications to use class variables, and today class variables aren't even allowed to be read inside a Ractor: ```ruby class Foo # This is NOT allowed to be read in non-main Ractors @@bar = 123 def self.bar; @@bar; end # This is allowed to be read in non-main Ractors @baz = 123 def self.baz; @baz; end end # This is OK Ractor.new { p Foo.baz }.value # Exception here Ractor.new { p Foo.bar }.value ``` Output is like this: ``` test.rb:4:in 'Foo.bar': can not access class variables from non-main Ractors (@@bar from Foo) (Ractor::IsolationError) from test.rb:10:in 'block in <main>' ``` Can we allow shareable values to cross the Ractor boundary, similar to class instance variables? Just for reference, the Rails code in question is [here](https://github.com/rails/rails/blob/371cbc9711b0b1fdadc186739c507b88ec0f288b...). -- https://bugs.ruby-lang.org/
Issue #21942 has been updated by tenderlovemaking (Aaron Patterson). I sent a patch [here](https://github.com/ruby/ruby/pull/16308) ---------------------------------------- Feature #21942: Allow reading class variables from non-main Ractors https://bugs.ruby-lang.org/issues/21942#change-116583 * Author: tenderlovemaking (Aaron Patterson) * Status: Open ---------------------------------------- It's very common in Rails applications to use class variables, and today class variables aren't even allowed to be read inside a Ractor: ```ruby class Foo # This is NOT allowed to be read in non-main Ractors @@bar = 123 def self.bar; @@bar; end # This is allowed to be read in non-main Ractors @baz = 123 def self.baz; @baz; end end # This is OK Ractor.new { p Foo.baz }.value # Exception here Ractor.new { p Foo.bar }.value ``` Output is like this: ``` test.rb:4:in 'Foo.bar': can not access class variables from non-main Ractors (@@bar from Foo) (Ractor::IsolationError) from test.rb:10:in 'block in <main>' ``` Can we allow shareable values to cross the Ractor boundary, similar to class instance variables? Just for reference, the Rails code in question is [here](https://github.com/rails/rails/blob/371cbc9711b0b1fdadc186739c507b88ec0f288b...). -- https://bugs.ruby-lang.org/
participants (1)
-
tenderlovemaking (Aaron Patterson)