✨
[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