ruby-changes:64285
From: Nobuyoshi <ko1@a...>
Date: Sat, 19 Dec 2020 00:53:21 +0900 (JST)
Subject: [ruby-changes:64285] 19a98a8791 (master): Fixed not to make non-literal expression shareable [Feature #17273]
https://git.ruby-lang.org/ruby.git/commit/?id=19a98a8791 From 19a98a8791f99085aca11413a331811659c8b78c Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sat, 19 Dec 2020 00:34:14 +0900 Subject: Fixed not to make non-literal expression shareable [Feature #17273] Non-literal expression which is not a part of a literal expression is not a subject of `shareable_literal_value: literal`. diff --git a/parse.y b/parse.y index 045a231..839f9c6 100644 --- a/parse.y +++ b/parse.y @@ -11033,8 +11033,11 @@ shareable_literal_value(NODE *node) https://github.com/ruby/ruby/blob/trunk/parse.y#L11033 VALUE rb_ractor_make_shareable(VALUE obj); static NODE * -shareable_literal_constant(struct parser_params *p, NODE *value, enum shareability shareable, const YYLTYPE *loc) +shareable_literal_constant(struct parser_params *p, enum shareability shareable, + NODE *value, const YYLTYPE *loc, size_t level) { +# define shareable_literal_constant_next(n) \ + shareable_literal_constant(p, shareable, (n), &(n)->nd_loc, level+1) VALUE lit; if (!value) return 0; @@ -11062,12 +11065,11 @@ shareable_literal_constant(struct parser_params *p, NODE *value, enum shareabili https://github.com/ruby/ruby/blob/trunk/parse.y#L11065 lit = rb_ary_new(); for (NODE *n = value; n; n = n->nd_next) { NODE *elt = n->nd_head; - if (elt && !(elt = shareable_literal_constant(p, elt, shareable, &elt->nd_loc))) { + if (elt && !(elt = shareable_literal_constant_next(elt))) { if (lit) { rb_ary_clear(lit); lit = Qfalse; } - continue; } if (lit) { VALUE e = shareable_literal_value(elt); @@ -11091,13 +11093,12 @@ shareable_literal_constant(struct parser_params *p, NODE *value, enum shareabili https://github.com/ruby/ruby/blob/trunk/parse.y#L11093 for (NODE *n = value->nd_head; n; n = n->nd_next->nd_next) { NODE *key = n->nd_head; NODE *val = n->nd_next->nd_head; - if ((key && !(key = shareable_literal_constant(p, key, shareable, &key->nd_loc))) || - (val && !(val = shareable_literal_constant(p, val, shareable, &val->nd_loc)))) { + if ((key && !(key = shareable_literal_constant_next(key))) || + (val && !(val = shareable_literal_constant_next(val)))) { if (lit) { rb_hash_clear(lit); lit = Qfalse; } - continue; } if (lit) { VALUE k = shareable_literal_value(key); @@ -11117,11 +11118,12 @@ shareable_literal_constant(struct parser_params *p, NODE *value, enum shareabili https://github.com/ruby/ruby/blob/trunk/parse.y#L11118 break; default: - if (shareable == shareable_literal) + if (shareable == shareable_literal && level > 0) yyerror1(loc, "unshareable expression"); return 0; } return value; +# undef shareable_literal_constant_next } static NODE * @@ -11135,7 +11137,7 @@ shareable_constant_value(struct parser_params *p, NODE *value, enum shareability https://github.com/ruby/ruby/blob/trunk/parse.y#L11137 case shareable_literal: case shareable_everything: { - NODE *lit = shareable_literal_constant(p, value, shareable, loc); + NODE *lit = shareable_literal_constant(p, shareable, value, loc, 0); if (lit) return lit; } break; diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb index 5f8689c..ecacdeb 100644 --- a/test/ruby/test_parse.rb +++ b/test/ruby/test_parse.rb @@ -1189,6 +1189,7 @@ x = __ENCODING__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L1189 B = [[2]] # shareable_constant_value: literal C = [["shareable", "constant#{nil}"]] + D = A [A, B, C] end; -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/