ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: ko1@atdot.net
To: ruby-core@ruby-lang.org
Subject: [ruby-core:100514] [Ruby master Feature#17145] Ractor-aware `Object#deep_freeze`
Date: Fri, 23 Oct 2020 20:00:08 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-88137.20201023200006.182@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-17145.20200903184227.182@ruby-lang.org

Issue #17145 has been updated by ko1 (Koichi Sasada).


Sorry I misunderstood this proposal.
`Ractor.make_shareable(obj)` proposal (#17274) satisfies the functionality proposed here.
(I thought `deep_freeze(skip_shareable: false)` was the proposal. sorry I skipped to read).

We discussed about the name "deep_freeze", and Matz said `deep_freeze` should be only for freezing, not related to Ractor. So classes/module should be frozen if `[C].deep_freeze`. This is why I proposed a `Object#deep_freeze(skip_shareable: true)` and `Ractor.make_shareable(obj)`.

Anyway maybe the functionality should be okay (calling `freeze` by `make_shareable` proposal).

So naming issue is reamained?

* `Object#deep_freeze` (matz doesn't like it)
* `Object#deep_freeze(skip_sharable: true)` (I don't know how Matz feel. And it is difficult to define Class/Module/...)
* `Ractor.make_shareable(obj)` (clear for me, but it is a bit long)
* `Ractor.shareable!(obj)` (shorter. is it clear?)
* `Object#shareable!` (is it acceptable?)
* ... other ideas?

----------------------------------------
Feature #17145: Ractor-aware `Object#deep_freeze`
https://bugs.ruby-lang.org/issues/17145#change-88137

* Author: marcandre (Marc-Andre Lafortune)
* Status: Open
* Priority: Normal
----------------------------------------
I'd like to propose `Object#deep_freeze`:

Freezes recursively the contents of the receiver (by calling `deep_freeze`) and
then the receiver itself (by calling `freeze`).
Values that are shareable via `Ractor` (e.g. classes) are never frozen this way.

```ruby
# freezes recursively:
ast = [:hash, [:pair, [:str, 'hello'], [:sym, :world]]].deep_freeze
ast.dig(1, 1) # => [:str, 'hello']
ast.dig(1, 1).compact! # => FrozenError

# does not freeze classes:
[[String]].deep_freeze
String.frozen? # => false

# calls `freeze`:
class Foo
  def freeze
    build_cache!
    puts "Ready for freeze"
    super
  end
  # ...
end
[[[Foo.new]]].deep_freeze # => Outputs "Ready for freeze"
```


I think a variant `deep_freeze!` that raises an exception if the result isn't Ractor-shareable would be useful too:

```ruby
class Fire
  def freeze
    # do not call super
  end
end

x = [Fire.new]
x.deep_freeze! # => "Could not be deeply-frozen: #<Fire:0x00007ff151994748>"
```



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

  parent reply	other threads:[~2020-10-23 20:00 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-03 18:42 [ruby-core:99885] [Ruby master Feature#17145] Ractor-aware `Object#deep_freeze` marcandre-ruby-core
2020-09-03 19:06 ` [ruby-core:99888] " eregontp
2020-09-03 19:20 ` [ruby-core:99889] " ko1
2020-09-03 19:27 ` [ruby-core:99890] " eregontp
2020-09-03 19:34 ` [ruby-core:99892] " marcandre-ruby-core
2020-09-03 19:39 ` [ruby-core:99893] " marcandre-ruby-core
2020-09-03 20:44 ` [ruby-core:99900] " ko1
2020-09-04  2:55 ` [ruby-core:99912] " duerst
2020-09-20 17:57 ` [ruby-core:100055] " eregontp
2020-09-21 13:50 ` [ruby-core:100060] " marcandre-ruby-core
2020-10-02  8:44 ` [ruby-core:100277] " shatrov
2020-10-02 16:10 ` [ruby-core:100282] " marcandre-ruby-core
2020-10-19 20:48 ` [ruby-core:100429] " ko1
2020-10-19 20:53 ` [ruby-core:100430] " ko1
2020-10-19 21:24 ` [ruby-core:100431] " marcandre-ruby-core
2020-10-20  0:43 ` [ruby-core:100438] " ko1
2020-10-20 10:00 ` [ruby-core:100444] " marcandre-ruby-core
2020-10-20 20:23 ` [ruby-core:100452] " eregontp
2020-10-20 20:42 ` [ruby-core:100454] " eregontp
2020-10-20 21:42 ` [ruby-core:100460] " marcandre-ruby-core
2020-10-21  5:23 ` [ruby-core:100464] " marcandre-ruby-core
2020-10-21 13:28 ` [ruby-core:100474] " daniel
2020-10-21 19:03 ` [ruby-core:100478] " eregontp
2020-10-23 20:00 ` ko1 [this message]
2020-10-25 13:45 ` [ruby-core:100533] " eregontp
2020-10-25 19:33 ` [ruby-core:100535] " marcandre-ruby-core
2020-10-25 21:30 ` [ruby-core:100539] " daniel
2020-10-26  5:28 ` [ruby-core:100554] " marcandre-ruby-core
2020-10-26  7:46 ` [ruby-core:100559] " eregontp
2020-10-26  7:58 ` [ruby-core:100563] " matz
2020-10-26  9:02 ` [ruby-core:100565] " matz
2020-10-26 13:36 ` [ruby-core:100570] " daniel

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-88137.20201023200006.182@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).