From: marcandre-ruby-core@... Date: 2020-10-25T19:33:34+00:00 Subject: [ruby-core:100535] [Ruby master Feature#17145] Ractor-aware `Object#deep_freeze` Issue #17145 has been updated by marcandre (Marc-Andre Lafortune). Not only should the default be `skip_shareable: true`, I don't really see the use-case for `skip_shareable: false`. Unless someone comes up with one, the option should probably be removed altogether, or maybe we could start without the option and see. If `Object#make_shareable` is preferred, that's ok too, but I still think `deep_freeze` is clearer. ---------------------------------------- Feature #17145: Ractor-aware `Object#deep_freeze` https://bugs.ruby-lang.org/issues/17145#change-88163 * 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: #" ``` -- https://bugs.ruby-lang.org/ Unsubscribe: