Also found while running in the addressable specs.
$ ruby -e 'puts /(?<foo>.)(?<bar>.)/.freeze.named_captures'
$ jt p '/(?<foo>.)(?<bar>.)/.freeze.named_captures'
$ /Users/brandonfish/Documents/jruby/bin/jruby -X+T -Xtruffle.core.load_path=/Users/brandonfish/Documents/jruby/truffle/src/main/ruby -Xtruffle.graal.warn_unless=false -e 'p begin /(?<foo>.)(?<bar>.)/.freeze.named_captures end'
/Users/brandonfish/Documents/jruby/truffle/src/main/ruby/core/regexp.rb:312:in `named_captures': can't modify frozen Regexp (RuntimeError)
from -e:1:in `<main>'
cc'ing: @eregon because it appears he has working on this recently: d88a101
MRI appears to avoid this frozen issue by always re-calculating. However maybe we have a way to cache this while avoiding this frozen error?
This is unfortunate. Maybe we can modify the code to avoid writing if frozen?. Or specialize that write to bypass the frozen check.
Or even simpler, remove the caching since I doubt this is called enough to matter.
I'm not sure which cache you're talking about, but the various regexp caches were added because they made a pretty big difference when testing gems.
This caching the mapping of captures names and captured Strings.
[Truffle] Workaround to avoid errors when trying to cache on a frozen…
* Fixes #4436.
[Truffle] Do not cache Regexp#named_captures.
* It is not a fast-path operation, neither Regexp#names nor MatchData#names.
* Caching still involves Hash#dup.
* See #4436.