Project

General

Profile

Actions

Bug #18919

open

Ractor: can't share #Method objects

Added by chucke (Tiago Cardoso) 23 days ago. Updated 12 days ago.

Status:
Open
Priority:
Normal
Assignee:
-
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) 19 days 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) 18 days 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) 12 days 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.

Actions

Also available in: Atom PDF