ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:99885] [Ruby master Feature#17145] Ractor-aware `Object#deep_freeze`
@ 2020-09-03 18:42 marcandre-ruby-core
  2020-09-03 19:06 ` [ruby-core:99888] " eregontp
                   ` (30 more replies)
  0 siblings, 31 replies; 32+ messages in thread
From: marcandre-ruby-core @ 2020-09-03 18:42 UTC (permalink / raw)
  To: ruby-core

Issue #17145 has been reported by marcandre (Marc-Andre Lafortune).

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

* 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/

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2020-10-26 13:36 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [ruby-core:100514] " ko1
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

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