Project

General

Profile

Actions

Feature #18919

open

Ractor: can't share #Method objects

Added by chucke (Tiago Cardoso) over 2 years ago. Updated over 1 year ago.

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

Description

The following is not shareable:

> meth = ::Kernel.method(:BigDecimal)
=> #<Method: Kernel.BigDecimal(*)>
<internal:ractor>:816:in `make_shareable': can not make shareable object for #<Method: Kernel.BigDecimal(*)> (Ractor::Error)

I understand that procs have the issue of accessing outer-scope variables, but does the same apply to methods converted to procs?

Updated by shan (Shannon Skipper) over 2 years ago

This is just an aside, but for what it's worth you can pass the class and method name and reconstitute a Method instance inside a Ractor.

require 'bigdecimal'

meth = Kernel.method(:BigDecimal)

ractor = Ractor.new(meth.owner, meth.name) do |meth_owner, meth_name|
  meth_owner.method(meth_name)
end

ractor.take.call(42)
#=> 0.42e2

Updated by Eregon (Benoit Daloze) over 2 years ago

I don't see a .to_proc call in the description.
Either way, both Method and Proc objects can't be shared, they have mutable state.

For Method/UnboundMethod they could potentially be made immutable and therefore shareable (sounds good to me), but it would be a potentially-breaking change.

Updated by chucke (Tiago Cardoso) over 2 years ago

  • Subject changed from Ractor: can't share method-to-proc objects to Ractor: can't share #Method objects

Indeed, I didn't mean "to-proc", Method objects, as per the usage example, is the one I meant.

Updated by ko1 (Koichi Sasada) about 2 years ago

  • Assignee set to ko1 (Koichi Sasada)

Now Method object is not shareable, but if the receiver is shareable, we can make it shareable.
Matz asked me to make it shareable, so we can consider the spec.

Actions #5

Updated by hsbt (Hiroshi SHIBATA) almost 2 years ago

  • Status changed from Open to Assigned
Actions #6

Updated by jeremyevans0 (Jeremy Evans) over 1 year ago

  • Tracker changed from Bug to Feature
  • Backport deleted (2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN)
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0