Feature #18919
open
Ractor: can't share #Method objects
Added by chucke (Tiago Cardoso) over 2 years ago.
Updated over 1 year ago.
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?
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
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.
- 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.
- 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.
- Status changed from Open to Assigned
- Tracker changed from Bug to Feature
- Backport deleted (
2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN)
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0