I really hope this does not go through.
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.
Additionaly, Regexp literals are not deduplicated in the same sense as frozen string literals; one /abc/
is independant from another /abc/
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".
And what if the mutate
behavior shown above is actually wanted? Sure it's a hack, but it's a bit like function-static variables in php.
Or, more realistically, what about something like this?
class Regexp
def analyze
@analyze ||= RegexpAnalyzer.analyze_performance_issues(self)
end
end
Freezing objects closes off possibilities when it's done by default, and should only be done when absolutely necessary.