Issue #16377 has been updated by byroot (Jean Boussier).


>  just for the sake of Communicating the Holy Gospel of Immutability?

Please put ideological thoughts on me, that's not a good basis for debate.

> Regexp literals are not deduplicated in the same sense as frozen string literals; one /abc/ is independant from another /abc/

And if they were frozen, they could be.

> so we're not actually leaking "global" state

On a particular callsite it does.

> Or, more realistically, what about something like this?

```ruby
class Regexp
  @@analyses = {}.compare_by_identity

  def analyze
    @@analyses[self] ||= RegexpAnalyzer.analyze_performance_issues(self)
  end
end
```

----------------------------------------
Feature #16377: Regexp literals should be frozen
https://bugs.ruby-lang.org/issues/16377#change-83103

* Author: byroot (Jean Boussier)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
The following script:

```ruby
def mutate
  re = /foo/
  state = re.instance_variable_get(:@state)
  re.instance_variable_set(:@state, state.to_i + 1)
  state
end

3.times do
  p mutate
end
```

Output this:

```
nil
1
2
```

IMHO, you shouldn't be able to mutate an unduplicated literal.

GitHub pull request: https://github.com/ruby/ruby/pull/2705



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>