https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112021-06-14T01:24:31ZRuby Issue Tracking SystemRuby master - Bug #17951: Collisions in Proc#hash values for blocks defined at the same linehttps://bugs.ruby-lang.org/issues/17951?journal_id=924362021-06-14T01:24:31Zxtkoba (Tee KOBAYASHI)
<ul></ul><p>A possible fix:</p>
<pre><code class="diff syntaxhl" data-language="diff"><span class="gd">--- a/proc.c
</span><span class="gi">+++ b/proc.c
</span><span class="p">@@ -1451,7 +1451,7 @@</span> rb_hash_proc(st_index_t hash, VALUE prc)
GetProcPtr(prc, proc);
hash = rb_hash_uint(hash, (st_index_t)proc->block.as.captured.code.val);
hash = rb_hash_uint(hash, (st_index_t)proc->block.as.captured.self);
<span class="gd">- return rb_hash_uint(hash, (st_index_t)proc->block.as.captured.ep >> 16);
</span><span class="gi">+ return rb_hash_uint(hash, (st_index_t)proc->block.as.captured.ep);
</span> }
MJIT_FUNC_EXPORTED VALUE
</code></pre>
<p>I do not understand the meaning of the 16-bit right shift in the original code.</p> Ruby master - Bug #17951: Collisions in Proc#hash values for blocks defined at the same linehttps://bugs.ruby-lang.org/issues/17951?journal_id=924382021-06-14T08:35:50Zdecuplet (Nikita Shilnikov)fg@flashgordon.ru
<ul></ul><p>It was there since 1.9 as far as I can see <a href="https://github.com/ruby/ruby/commit/a3e1b1ce7ed7e7ffac23015fc2fde56511b30681#diff-2672918174f926386106967d117f11da8aa1905772dcf48fce53694386e4a666R658-R668" class="external">https://github.com/ruby/ruby/commit/a3e1b1ce7ed7e7ffac23015fc2fde56511b30681#diff-2672918174f926386106967d117f11da8aa1905772dcf48fce53694386e4a666R658-R668</a></p> Ruby master - Bug #17951: Collisions in Proc#hash values for blocks defined at the same linehttps://bugs.ruby-lang.org/issues/17951?journal_id=925012021-06-15T18:00:32Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul></ul><p>I have submitted a pull request with @xtkoba's fix: <a href="https://github.com/ruby/ruby/pull/4574" class="external">https://github.com/ruby/ruby/pull/4574</a></p> Ruby master - Bug #17951: Collisions in Proc#hash values for blocks defined at the same linehttps://bugs.ruby-lang.org/issues/17951?journal_id=925022021-06-15T18:09:06Zdecuplet (Nikita Shilnikov)fg@flashgordon.ru
<ul><li><strong>Subject</strong> changed from <i>Collistions in Proc#hash values for blocks defined at the same line</i> to <i>Collisions in Proc#hash values for blocks defined at the same line</i></li></ul> Ruby master - Bug #17951: Collisions in Proc#hash values for blocks defined at the same linehttps://bugs.ruby-lang.org/issues/17951?journal_id=926432021-06-25T04:50:52Zjeremyevans (Jeremy Evans)code@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset <a class="changeset" title="Remove shift of ep when computing Proc#hash The shift was causing far fewer unique values of has..." href="https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/be230615d016e27d5b45b465d1481f6ecf7f1d28">git|be230615d016e27d5b45b465d1481f6ecf7f1d28</a>.</p>
<hr>
<p>Remove shift of ep when computing Proc#hash</p>
<p>The shift was causing far fewer unique values of hash than expected.</p>
<p>Fix pointed out by xtkoba (Tee KOBAYASHI)</p>
<p>Fixes [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Collisions in Proc#hash values for blocks defined at the same line (Closed)" href="https://bugs.ruby-lang.org/issues/17951">#17951</a>]</p>