From: ko1@... Date: 2020-12-18T20:35:10+00:00 Subject: [ruby-core:101519] [Ruby master Feature#17397] `shareable_constant_value: literal` should check at runtime, not at parse time Issue #17397 has been updated by ko1 (Koichi Sasada). By discussion with Matz and Nobu, we choose "(2) raises an error for unshareable non-literals on runtime (my proposal)". * on compile time: for `FOO = expr` * case `FOO = literal_only` * compile to => `FOO = RubyVM::FrozenCore.make_shareable(literal_only)` * otherwise * compile to => `FOO = RubyVM::FrozenCore.check_shareable(expr)` `RubyVM::FrozenCore.check_shareable(obj)` is `obj.tap{|o| raise Ractor::Error unless Ractor.shareable?(o)}`. One concern was "literal" doesn't mean anything about checking unshareable feature ("otherwise" behavior). We challenged to find out good naming, but we determined to choose "literal" as is. The logic is here: * `shareable_constant_value: none` means there is no checking. Other options force constants are sharable (or an error) * `shareable_constant_value: none` means we do unshareable checking and make all literals sharable. We can list the following possible options: * (default) none: do nothing * (not contained) check: `FOO = RubyVM::FrozenCore.check_shareable(expr)` * literal * if `expr` is literal expr, `FOO = RubyVM::FrozenCore.make_shareable(expr)` * else, `FOO = RubyVM::FrozenCore.check_shareable(expr)` * (not contained) copy: `FOO = RubyVM::FrozenCore.make_shareable(expr, copy: true)` * experimental_everything: `FOO = RubyVM::FrozenCore.make_shareable(expr)` I think "copy" here can be introduced as experimental. ---------------------------------------- Feature #17397: `shareable_constant_value: literal` should check at runtime, not at parse time https://bugs.ruby-lang.org/issues/17397#change-89303 * 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: