From: daniel@dan42.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:100462] [Ruby master Feature#17256] Freeze all Regexp objects
Date: Wed, 21 Oct 2020 02:57:27 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-88081.20201021025727.17@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-17256.20201009074233.17@ruby-lang.org
Issue #17256 has been updated by Dan0042 (Daniel DeLorme).
Given that string literals with interpolation were recently unfrozen, it would appear slightly inconsistent to freeze regexp literals with interpolation.
`/#{str}/` is equivalent to `Regexp.new(str)` so I would find it a bit weird if they had a different behavior w/r freezing. It would make more sense to say that _all_ new regexps (including `Regexp.new` and `Regexp.compile`) are frozen. That way all constants such as `UNSAFE = Regexp.new("[^#{SAFE_STRING}]", false)` would be automatically ractor-safe.
And if someone really needs to modify a regexp maybe they can use `dup`?
`rx = Regexp.new(str).dup.extend(PrintWhenMatch)`
----------------------------------------
Feature #17256: Freeze all Regexp objects
https://bugs.ruby-lang.org/issues/17256#change-88081
* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
----------------------------------------
To be shared between ractors, Regexp objects should be frozen.
Now, Matz has proposed to make all Regexp objects frozen.
Ten months ago, there was a note https://bugs.ruby-lang.org/issues/16377#note-7 :
> For the record: Regexp.new should continue to return unfrozen Regexp instance.
So I'm not sure whether it is a good way or not.
Could you give me your comment on it?
If no comments are given, I'll try to freeze them before Ruby 3.0 preview 2.
BTW, I believe `/#{expr}/o` should be frozen because this expression only returns one Regexp object.
--
https://bugs.ruby-lang.org/
next prev parent reply other threads:[~2020-10-21 2:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-09 7:42 [ruby-core:100345] [Ruby master Feature#17256] Freeze all Regexp objects ko1
2020-10-20 6:25 ` [ruby-core:100443] " ko1
2020-10-20 20:47 ` [ruby-core:100455] " eregontp
2020-10-21 2:57 ` daniel [this message]
2020-10-21 4:08 ` [ruby-core:100463] " marcandre-ruby-core
2020-10-26 16:40 ` [ruby-core:100586] " ko1
2020-10-29 16:05 ` [ruby-core:100645] " ko1
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-88081.20201021025727.17@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).