https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112020-09-19T21:33:16ZRuby Issue Tracking SystemRuby master - Misc #17180: Ractor and constant referencinghttps://bugs.ruby-lang.org/issues/17180?journal_id=875972020-09-19T21:33:16Zkirs (Kir Shatrov)shatrov@me.com
<ul></ul><p>Another example:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="no">Person</span> <span class="o">=</span> <span class="no">Struct</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="ss">:name</span><span class="p">)</span>
<span class="no">CREATOR</span> <span class="o">=</span> <span class="no">Person</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="s2">"Matz"</span><span class="p">).</span><span class="nf">freeze</span>
<span class="n">parser</span> <span class="o">=</span> <span class="no">Ractor</span><span class="p">.</span><span class="nf">new</span> <span class="p">{</span> <span class="no">CREATOR</span> <span class="p">}</span>
<span class="no">Ractor</span><span class="p">.</span><span class="nf">select</span><span class="p">(</span><span class="n">parser</span><span class="p">)</span>
</code></pre>
<pre><code>./test.rb:12:in `block in <main>': can not access non-sharable objects in constant Object::CREATOR by non-main Ractor. (NameError)
make: *** [runruby] Error 1
</code></pre>
<p>Should something as plain as a frozen struct be shareable?</p>
<p>I am aware that you can make it copy the constant (<code>Ractor.new(CREATOR) { |creator| creator }</code> but it will become really lengthy to copy every constant that will ever be referenced from a Ractor. I don't think that will make developers happy.</p> Ruby master - Misc #17180: Ractor and constant referencinghttps://bugs.ruby-lang.org/issues/17180?journal_id=876052020-09-20T17:43:02ZEregon (Benoit Daloze)
<ul></ul><p>For the Struct example above, probably it needs the "Matz" String to be frozen too, or <code>#deep_freeze</code> (<a class="issue tracker-2 status-6 priority-4 priority-default closed" title="Feature: Ractor-aware `Object#deep_freeze` (Rejected)" href="https://bugs.ruby-lang.org/issues/17145">#17145</a>) to mark it as a shareable value.</p> Ruby master - Misc #17180: Ractor and constant referencinghttps://bugs.ruby-lang.org/issues/17180?journal_id=1042862023-08-24T17:46:42Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>Tracker</strong> changed from <i>Bug</i> to <i>Misc</i></li><li><strong>ruby -v</strong> deleted (<del><i>ruby 3.0.0dev (2020-09-19T08:47:40Z master 73a626c078) [x86_64-darwin19]</i></del>)</li><li><strong>Backport</strong> deleted (<del><i>2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN</i></del>)</li></ul>