Ractor: can't share #Method objects
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.