✨
[Feature #21033] Proc を Ractor.make_shareable する際の条件を緩和する提案
[Feature #21033] Allow lambdas that don't access self to be Ractor shareable
-
ProcオブジェクトをRactor.make_shareableで共有可能オブジェクトにする場合にselfがfrozenである必要がある
class Foo
def make_lambda
x = 123
lambda { x }
end
end
foo = Foo.new
# self = foo は frozen でないのでエラーになる
# error: Proc's self is not shareable: #<Proc:0x00007decf7597998 /tmp/vh9EJDh/25:4 (lambda)> (Ractor::IsolationError)
Ractor.make_shareable(foo.make_lambda)
foo.freeze
# self = foo は frozen なのでエラーにならない
# no error
Ractor.make_shareable(foo.make_lambda)
- この時に
Procがselfにアクセスしない場合は『selfの状態に関わらず共有可能オブジェクトにすることができるように緩和する』提案 -
proc内の命令をみてselfを利用しているかどうかの判断をするみたいですね- なので
proc内でevalを使用した場合は暗黙的にselfへの参照がされるのでこの場合はエラーになるみたい -
bindingを参照した場合も同様
- なので
- これなんですが議論の内容をみていると
selfを参照していない、っていう部分がなかなか難しそうですねえ
Discussion