Project

General

Profile

Actions

Feature #17401

closed

The class `Ractor::MovedObject` should not be frozen

Added by marcandre (Marc-Andre Lafortune) over 3 years ago. Updated over 3 years ago.

Status:
Closed
Target version:
-
[ruby-core:101483]

Description

If Ractor::MovedObject can be not frozen that would be more helpful than currently. For example, to implement a helpful inspect in pure Ruby 3.0 like in #17393

It is currently possible to go around the fact that it is frozen with refinements:

using Module.new {
  refine Ractor::MovedObject do
    def inspect
      "I was moved! Don't use me!"
    end
  end
}
o = Object.new
Ractor.new{ receive }.send(o, move:true)
puts o.inspect # => "I was moved! Don't use me!"

Another (ugly) way to bypass the fact that it is frozen without refinements is to modify its ancestor:

module Ext
  def inspect
    return super unless Ractor::MovedObject === self

    "I was moved! Don't use me!"
  end
end

BasicObject.prepend Ext

o = Object.new
Ractor.new{ receive }.send(o, move:true)
p o # => "I was moved! Don't use me!"

My point remain that this "security" can be bypassed unless it is stricly necessary it, it would be nice to unfreeze the class. It could be documented that this is experimental / not recommended to modify the class in production, for example.

Updated by ko1 (Koichi Sasada) over 3 years ago

Matz prefers to provide a free to shoot the foot.

Actions #2

Updated by ko1 (Koichi Sasada) over 3 years ago

  • Status changed from Open to Closed

Applied in changeset git|76e88480371469400346fca609efe67096813915.


unfreeze Ractor::MovedObject

Matz prefers to unfreeze the class.
[Feature #17401]

Actions

Also available in: Atom PDF

Like0
Like0Like0