Project

General

Profile

Actions

Feature #17513

open

Methods of shareable objects and UnboundMethods should be shareable

Feature #17513: Methods of shareable objects and UnboundMethods should be shareable

Added by marcandre (Marc-Andre Lafortune) about 5 years ago. Updated 10 days ago.

Status:
Assigned
Target version:
-
[ruby-core:101945]

Description

class Foo
  def foo
  end
end

f = Foo.new.freeze
Ractor.shareable?(f) # => true
Ractor.make_shareable(f.method(:foo).to_proc) # => Proc, ok
Ractor.make_shareable(f.method(:foo)) # => Ractor::Error, expected Method
Ractor.make_shareable(Foo.instance_method(:foo)) # => Ractor::Error, expected UnboundMethod

Updated by Eregon (Benoit Daloze) about 5 years ago Actions #1 [ruby-core:101966]

Methods can be defined via define_method { capture_state } and so rely on mutable state, so I guess this is only OK for def methods.

Updated by marcandre (Marc-Andre Lafortune) about 5 years ago Actions #2 [ruby-core:101967]

Agreed, some methods can not be made shareable 👍.

Updated by jeremyevans0 (Jeremy Evans) over 2 years ago Actions #3

  • Tracker changed from Bug to Feature
  • ruby -v deleted (3.0.0p0)
  • Backport deleted (2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN)

Updated by hsbt (Hiroshi SHIBATA) almost 2 years ago Actions #4

  • Status changed from Open to Assigned

Updated by trinistr (Alexander Bulancov) 10 days ago Actions #5 [ruby-core:124821]

A def-ed method of a shareable object may depend on unshareable state. Even worse, shareability of state may dynamically change:

module Checker
  CHECK = []

  def check?
    CHECK.include?(self)
  end
end

class A; include Checker; end

obj = A.new.freeze
Ractor.shareable?(obj) # => true
Ractor.new(obj) { |o| p o.check? } # Ractor::IsolationError

Checker::CHECK.freeze
Ractor.new(A.new.freeze) { |o| p o.check? } # false

Checker::CHECK = []
# And here we go again
Actions

Also available in: PDF Atom