From: marcandre-ruby-core@... Date: 2020-12-16T19:54:19+00:00 Subject: [ruby-core:101476] [Ruby master Feature#17397] `shareable_constant_value: literal` should check at runtime, not at parse time Issue #17397 has been updated by marcandre (Marc-Andre Lafortune). After discussion with ko1, the following options came up: (1) raises an error for non-literals on parse time (current) (2) raises an error for unshareable non-literals on runtime (my proposal) (3) just ignore non-literals (4) = (3) + (1) with `literal-strict` (5) = (3) + (2) with `literal-strict` I like all options that do not include (1). Solution 2 is as I presented. Solution 3 is more permissive. Potential downsides include: ```ruby # shareable_constant_value: literal FOO = [1, 2, 3] BAR = [4, 5, 6, 7, 8, 9, 10] BAZ = FOO + BAR # => not frozen / shareable QUX = Set[11, 12, 13] # => not frozen / shareable ``` It would be easy to call `ractor.send(BAZ) # or QUX` and assume that no copy is being made. My opinion remains that many rubyists will want all their constants to be immutable, so option (2) would be a good way to do this and enforce it at the same time. I expect that global registry / cache are better implemented as attributes of singleton class. ---------------------------------------- Feature #17397: `shareable_constant_value: literal` should check at runtime, not at parse time https://bugs.ruby-lang.org/issues/17397#change-89253 * Author: marcandre (Marc-Andre Lafortune) * Status: Open * Priority: Normal * Assignee: ko1 (Koichi Sasada) ---------------------------------------- I think `shareable_constant_value: literal` is too strict because it has too crude checks at parse time. I wish the following code would parse and run: ```ruby # shareable_constant_value: literal class Foo < RuntimeError end # Similar code, but does not parse: Bar = Class.new(RuntimeError) # => unshareable expression Baz = Ractor.make_shareable(anything_here) # => unshareable expression Qux = Set[1, 2, 3].freeze # => unshareable expression ``` Could we instead raise some sort of RuntimeError when an assignment is made that is not shareable? -- https://bugs.ruby-lang.org/ Unsubscribe: