Project

General

Profile

Actions

Feature #17393

open

`Ractor::Moved#inspect`

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

Status:
Assigned
Target version:
-
[ruby-core:101455]

Description

It could be helpful to define Ractor::Moved#inspect and output the source location of when the data was moved. If preferred, it could raise an error with this information:

x = []
Ractor.new{ receive }.send(x, move: true)
p x # => "Data was moved in `example.rb:4`"
# or
p x # => "Data was moved in `example.rb:4`" (Ractor::MovedError)

Also @zverok (Victor Shepelev) and myself were wondering if there was a technical reason to freeze Ractor::Moved? If not, is it only to "force" people to use refinements (which are allowed on frozen classes)? It's already known that it is in general a bad idea to modify builtin classes, so it's not clear to me that freezing that class is best.

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

Maybe refining the message from method_missing is the best and simplest. (giving info that object was moved, and where).
I would also unfreeze the class unless there's a good reason not to.

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

  • Assignee changed from matz (Yukihiro Matsumoto) to ko1 (Koichi Sasada)

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

Discussed with ko1, who said he is afraid that unfreezing the class might create issues, as implementation is quite special. Possible implementation of #inspect for Ruby 3.1

Two things to keep in mind:

  • usecase for unfreezing the class would be to implement #inspect in pure Ruby for 3.0, for example.
  • it is possible to refine frozen classes, including Ractor::Moved, so freezing that class may not have the desired effect?

Updated by ko1 (Koichi Sasada) over 3 years ago

I don't think providing #inspect is good idea because any methods should respond to the moved object.
Otherwise there is possibility to ignore the accessing moved objects.

I prefer to show the moved location in the error message.

x = []
Ractor.new{ receive }.send(x, move: true)
x.size

...:in `method_missing': can not send any methods to a moved object (moved at foo.rb:123) (Ractor::MovedError)

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

Yes, that looks good, that is what I was proposing in note 1 too 👍

Updated by ko1 (Koichi Sasada) over 3 years ago

Try it on 3.1, not 3.0.

Actions #7

Updated by hsbt (Hiroshi SHIBATA) 17 days ago

  • Status changed from Open to Assigned
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0