https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112019-11-28T06:37:07ZRuby Issue Tracking SystemRuby master - Feature #16377: Regexp literals should be frozenhttps://redmine.ruby-lang.org/issues/16377?journal_id=828502019-11-28T06:37:07Zbyroot (Jean Boussier)byroot@ruby-lang.org
<ul></ul><p>Apparently it's a duplicate of <a href="https://bugs.ruby-lang.org/issues/8948" class="external">https://bugs.ruby-lang.org/issues/8948</a></p> Ruby master - Feature #16377: Regexp literals should be frozenhttps://redmine.ruby-lang.org/issues/16377?journal_id=828512019-11-28T06:38:36Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul><li><strong>Is duplicate of</strong> <i><a class="issue tracker-2 status-2 priority-4 priority-default" href="/issues/8948">Feature #8948</a>: Frozen regex</i> added</li></ul> Ruby master - Feature #16377: Regexp literals should be frozenhttps://redmine.ruby-lang.org/issues/16377?journal_id=830932019-12-11T14:54:10ZDan0042 (Daniel DeLorme)
<ul></ul><p>I really hope this does not go through.</p>
<p>Regexp literals have been "unduplicated" like this since at least 1.8 and we've never had problems. And now we should freeze them and introduce an incompatibility just for the sake of Communicating the Holy Gospel of Immutability? I don't find that a valid reason.</p>
<p>Additionaly, Regexp literals are not deduplicated in the same sense as frozen string literals; one <code>/abc/</code> is independant from another <code>/abc/</code> so we're not actually leaking "global" state. In the example above the state is local to the method but shared between invocations. Not sure how that should be called, but certainly not "global".</p>
<p>And what if the <code>mutate</code> behavior shown above is actually wanted? Sure it's a hack, but it's a bit like function-static variables in php.</p>
<p>Or, more realistically, what about something like this?</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">class</span> <span class="nc">Regexp</span>
<span class="k">def</span> <span class="nf">analyze</span>
<span class="vi">@analyze</span> <span class="o">||=</span> <span class="no">RegexpAnalyzer</span><span class="p">.</span><span class="nf">analyze_performance_issues</span><span class="p">(</span><span class="nb">self</span><span class="p">)</span>
<span class="k">end</span>
<span class="k">end</span>
</code></pre>
<p>Freezing objects closes off possibilities when it's done by default, and should only be done when absolutely necessary.</p> Ruby master - Feature #16377: Regexp literals should be frozenhttps://redmine.ruby-lang.org/issues/16377?journal_id=831032019-12-12T10:09:22Zbyroot (Jean Boussier)byroot@ruby-lang.org
<ul></ul><blockquote>
<p>just for the sake of Communicating the Holy Gospel of Immutability?</p>
</blockquote>
<p>Please don't put ideological thoughts on me, that's not a good basis for debate.</p>
<blockquote>
<p>Regexp literals are not deduplicated in the same sense as frozen string literals; one /abc/ is independant from another /abc/</p>
</blockquote>
<p>And if they were frozen, they could be.</p>
<blockquote>
<p>so we're not actually leaking "global" state</p>
</blockquote>
<p>On a particular callsite it does.</p>
<blockquote>
<p>Or, more realistically, what about something like this?</p>
</blockquote>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">class</span> <span class="nc">Regexp</span>
<span class="vc">@@analyses</span> <span class="o">=</span> <span class="p">{}.</span><span class="nf">compare_by_identity</span>
<span class="k">def</span> <span class="nf">analyze</span>
<span class="vc">@@analyses</span><span class="p">[</span><span class="nb">self</span><span class="p">]</span> <span class="o">||=</span> <span class="no">RegexpAnalyzer</span><span class="p">.</span><span class="nf">analyze_performance_issues</span><span class="p">(</span><span class="nb">self</span><span class="p">)</span>
<span class="k">end</span>
<span class="k">end</span>
</code></pre> Ruby master - Feature #16377: Regexp literals should be frozenhttps://redmine.ruby-lang.org/issues/16377?journal_id=831082019-12-13T02:43:40ZDan0042 (Daniel DeLorme)
<ul></ul><blockquote>
<p>Please don't put ideological thoughts on me, that's not a good basis for debate.</p>
</blockquote>
<p>Oh no, I'm not. Sorry for the misunderstanding. I was mostly replying to comments in <a class="issue tracker-2 status-2 priority-4 priority-default" title="Feature: Frozen regex (Assigned)" href="https://redmine.ruby-lang.org/issues/8948">#8948</a>, but I ended up posting here because this is the ticket that is linked in <a class="issue tracker-5 status-5 priority-4 priority-default closed" title="Misc: DevelopersMeeting20191220Japan (Closed)" href="https://redmine.ruby-lang.org/issues/16393">#16393</a> DevelopersMeeting20191220Japan.</p>
<p>Yes, of course when one way is blocked there's always an alternate way of doing things. But the point is that if someone is <em>currently</em> relying on Regexp literals not being frozen, this change will break their code. Given that the benefit is close to zero, I don't think it's responsible to force anyone to bear that cost. I'm very conservative about backward compatibility.</p> Ruby master - Feature #16377: Regexp literals should be frozenhttps://redmine.ruby-lang.org/issues/16377?journal_id=833972019-12-25T12:15:10Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Target version</strong> set to <i>36</i></li></ul> Ruby master - Feature #16377: Regexp literals should be frozenhttps://redmine.ruby-lang.org/issues/16377?journal_id=834112019-12-26T02:43:03Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Assignee</strong> set to <i>mame (Yusuke Endoh)</i></li></ul><p>At the previous dev meeting, matz said that let's give it a try :-)</p>
<p>For the record: <code>Regexp.new</code> should continue to return unfrozen Regexp instance.</p>
<p>I'll review the pull request.</p> Ruby master - Feature #16377: Regexp literals should be frozenhttps://redmine.ruby-lang.org/issues/16377?journal_id=838712020-01-15T01:38:33Zko1 (Koichi Sasada)
<ul></ul><p>Could you add a NEWS entry?</p> Ruby master - Feature #16377: Regexp literals should be frozenhttps://redmine.ruby-lang.org/issues/16377?journal_id=838722020-01-15T01:39:07Zbyroot (Jean Boussier)byroot@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset <a class="changeset" title="Freeze Regexp literals [Feature #8948] [Feature #16377] Since Regexp literals always reference ..." href="https://redmine.ruby-lang.org/projects/ruby-master/repository/git/revisions/98ef38ada43338c073f50a0093196f0356284625">git|98ef38ada43338c073f50a0093196f0356284625</a>.</p>
<hr>
<p>Freeze Regexp literals</p>
<p>[Feature <a class="issue tracker-2 status-2 priority-4 priority-default" title="Feature: Frozen regex (Assigned)" href="https://redmine.ruby-lang.org/issues/8948">#8948</a>] [Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Regexp literals should be frozen (Closed)" href="https://redmine.ruby-lang.org/issues/16377">#16377</a>]</p>
<p>Since Regexp literals always reference the same instance,<br>
allowing to mutate them can lead to state leak.</p> Ruby master - Feature #16377: Regexp literals should be frozenhttps://redmine.ruby-lang.org/issues/16377?journal_id=877872020-09-29T03:37:27Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>Target version</strong> changed from <i>36</i> to <i>3.0</i></li></ul>