Project

General

Profile

Actions

Bug #18919

open

Ractor: can't share #Method objects

Added by chucke (Tiago Cardoso) 7 months ago. Updated 15 days ago.

Status:
Assigned
Priority:
Normal
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) 7 months 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) 7 months 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) 7 months 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) 4 months 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) 15 days ago

  • Status changed from Open to Assigned
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0