From: marcandre-ruby-core@... Date: 2020-12-17T03:59:33+00:00 Subject: [ruby-core:101491] [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). nobu (Nobuyoshi Nakada) wrote in #note-5: > Your proposal seems `shareable_constant_value: everything` (it's prefixed with `experimental_` now though). No, that value deep-freezes implicitly all constants. Non-literals are not frozen in my proposal. Here's a code summary of the differences (scenarios 2, 3 or 5 == 2+3): ```ruby # shareable_constant_value: experimental_everything (current, ok) X = [1, 2, 3] p X.frozen? # => true Y = Set[4, 5, 6] p Y.frozen? # => true # shareable_constant_value: literal (2) or literal_strict (5) X = [1, 2, 3] p X.frozen? # => true (Y = Set[4, 5, 6]) rescue :error # => :error (at runtime, currently at parse time) Z = Set[8, 9].freeze # => no error (currently parse error) # shareable_constant_value: literal (3 or 5) X = [1, 2, 3] p X.frozen? # => true Y = Set[4, 5, 6] # => no error (currently parse error) p Y.frozen? # => false ``` ---------------------------------------- Feature #17397: `shareable_constant_value: literal` should check at runtime, not at parse time https://bugs.ruby-lang.org/issues/17397#change-89269 * 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: