Project

General

Profile

Actions

Bug #18023

open

Ractor#make_shareable changes the values of closured shareable objects

Added by slowpilot (Ivan Razuvaev) 3 months ago. Updated 3 months ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
3.0.0, 3.0.1
[ruby-core:104519]

Description

Hi. I encountered strange behaviour or shareable procs when every even closured shareable variable becomes the FalseClass instance.

[usr@srvr ~]$ irb
3.0.1 :001 > v1, v2, v3, v4 = :a, :b, :c, :d
 => [:a, :b, :c, :d] 
3.0.1 :002 > p = Proc.new { p v1, v2, v3, v4 }
 => #<Proc:0x000000000248ed18 (irb):2> 
3.0.1 :003 > p.()
:a
:b
:c
:d
 => [:a, :b, :c, :d] 
3.0.1 :004 > Ractor.make_shareable(p).()
:a
false
:c
false
 => [:a, false, :c, false] 

Updated by slowpilot (Ivan Razuvaev) 3 months ago

slowpilot (Ivan Razuvaev) wrote:

Hi. I encountered strange behaviour or shareable procs when every even closured shareable variable becomes the FalseClass instance.

[usr@srvr ~]$ irb
3.0.1 :001 > v1, v2, v3, v4 = :a, :b, :c, :d
 => [:a, :b, :c, :d] 
3.0.1 :002 > p = Proc.new { p v1, v2, v3, v4 }
 => #<Proc:0x000000000248ed18 (irb):2> 
3.0.1 :003 > p.()
:a
:b
:c
:d
 => [:a, :b, :c, :d] 
3.0.1 :004 > Ractor.make_shareable(p).()
:a
false
:c
false
 => [:a, false, :c, false] 

This is stopping from using dynamically defined methods from ractors. E.g. in Ruby libtorch. So after calling rb_ext_ractor_safe in extension, I am trying to do something like:

cls.define_singleton_method('new', Ractor.make_shareable(Proc.new { ... })

That leads to every second closure assignment to false.

Actions

Also available in: Atom PDF