ruby-changes:64148
From: Nobuyoshi <ko1@a...>
Date: Mon, 14 Dec 2020 19:29:52 +0900 (JST)
Subject: [ruby-changes:64148] dc1cc33d69 (master): Determine shareable-ness after assignment operator
https://git.ruby-lang.org/ruby.git/commit/?id=dc1cc33d69 From dc1cc33d691faacccd2c12ce3ca75b24cc89dbf9 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sat, 10 Oct 2020 00:44:14 +0900 Subject: Determine shareable-ness after assignment operator diff --git a/parse.y b/parse.y index 986c67c..0c192b6 100644 --- a/parse.y +++ b/parse.y @@ -521,12 +521,12 @@ static NODE *aryset(struct parser_params*,NODE*,NODE*,const YYLTYPE*); https://github.com/ruby/ruby/blob/trunk/parse.y#L521 static NODE *attrset(struct parser_params*,NODE*,ID,ID,const YYLTYPE*); static void rb_backref_error(struct parser_params*,NODE*); -static NODE *node_assign(struct parser_params*,NODE*,NODE*,const YYLTYPE*); +static NODE *node_assign(struct parser_params*,NODE*,NODE*,int,const YYLTYPE*); -static NODE *new_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, const YYLTYPE *loc); +static NODE *new_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, int shareable, const YYLTYPE *loc); static NODE *new_ary_op_assign(struct parser_params *p, NODE *ary, NODE *args, ID op, NODE *rhs, const YYLTYPE *args_loc, const YYLTYPE *loc); static NODE *new_attr_op_assign(struct parser_params *p, NODE *lhs, ID atype, ID attr, ID op, NODE *rhs, const YYLTYPE *loc); -static NODE *new_const_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, const YYLTYPE *loc); +static NODE *new_const_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, int shareable, const YYLTYPE *loc); static NODE *new_bodystmt(struct parser_params *p, NODE *head, NODE *rescue, NODE *rescue_else, NODE *ensure, const YYLTYPE *loc); static NODE *const_decl(struct parser_params *p, NODE* path, const YYLTYPE *loc); @@ -1181,6 +1181,7 @@ static int looking_at_eol_p(struct parser_params *p); https://github.com/ruby/ruby/blob/trunk/parse.y#L1181 %type <id> f_kwrest f_label f_arg_asgn call_op call_op2 reswords relop dot_or_colon %type <id> p_rest p_kwrest p_kwnorest p_any_kwrest p_kw_label %type <id> f_no_kwarg f_any_kwrest args_forward excessed_comma +%type <num> shareable %token END_OF_INPUT 0 "end-of-input" %token <id> '.' /* escaped chars, should be ignored otherwise */ @@ -1519,99 +1520,99 @@ stmt : keyword_alias fitem {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem https://github.com/ruby/ruby/blob/trunk/parse.y#L1520 /*% ripper: END!($3) %*/ } | command_asgn - | mlhs '=' command_call + | mlhs '=' shareable command_call { /*%%%*/ - value_expr($3); - $$ = node_assign(p, $1, $3, &@$); + value_expr($4); + $$ = node_assign(p, $1, $4, $3, &@$); /*% %*/ - /*% ripper: massign!($1, $3) %*/ + /*% ripper: massign!($1, $4) %*/ } - | lhs '=' mrhs + | lhs '=' shareable mrhs { /*%%%*/ - value_expr($3); - $$ = node_assign(p, $1, $3, &@$); + value_expr($4); + $$ = node_assign(p, $1, $4, $3, &@$); /*% %*/ - /*% ripper: assign!($1, $3) %*/ + /*% ripper: assign!($1, $4) %*/ } - | mlhs '=' mrhs_arg modifier_rescue stmt + | mlhs '=' shareable mrhs_arg modifier_rescue stmt { /*%%%*/ - YYLTYPE loc = code_loc_gen(&@4, &@5); - value_expr($3); - $$ = node_assign(p, $1, NEW_RESCUE($3, NEW_RESBODY(0, remove_begin($5), 0, &loc), 0, &@$), &@$); + YYLTYPE loc = code_loc_gen(&@5, &@6); + value_expr($4); + $$ = node_assign(p, $1, NEW_RESCUE($4, NEW_RESBODY(0, remove_begin($6), 0, &loc), 0, &@$), $3, &@$); /*% %*/ - /*% ripper: massign!($1, rescue_mod!($3, $5)) %*/ + /*% ripper: massign!($1, rescue_mod!($4, $6)) %*/ } - | mlhs '=' mrhs_arg + | mlhs '=' shareable mrhs_arg { /*%%%*/ - $$ = node_assign(p, $1, $3, &@$); + $$ = node_assign(p, $1, $4, $3, &@$); /*% %*/ - /*% ripper: massign!($1, $3) %*/ + /*% ripper: massign!($1, $4) %*/ } | expr ; -command_asgn : lhs '=' command_rhs +command_asgn : lhs '=' shareable command_rhs { /*%%%*/ - $$ = node_assign(p, $1, $3, &@$); + $$ = node_assign(p, $1, $4, $3, &@$); /*% %*/ - /*% ripper: assign!($1, $3) %*/ + /*% ripper: assign!($1, $4) %*/ } - | var_lhs tOP_ASGN command_rhs + | var_lhs tOP_ASGN shareable command_rhs { /*%%%*/ - $$ = new_op_assign(p, $1, $2, $3, &@$); + $$ = new_op_assign(p, $1, $2, $4, $3, &@$); /*% %*/ - /*% ripper: opassign!($1, $2, $3) %*/ + /*% ripper: opassign!($1, $2, $4) %*/ } - | primary_value '[' opt_call_args rbracket tOP_ASGN command_rhs + | primary_value '[' opt_call_args rbracket tOP_ASGN shareable command_rhs { /*%%%*/ - $$ = new_ary_op_assign(p, $1, $3, $5, $6, &@3, &@$); + $$ = new_ary_op_assign(p, $1, $3, $5, $7, &@3, &@$); /*% %*/ - /*% ripper: opassign!(aref_field!($1, escape_Qundef($3)), $5, $6) %*/ + /*% ripper: opassign!(aref_field!($1, escape_Qundef($3)), $5, $7) %*/ } - | primary_value call_op tIDENTIFIER tOP_ASGN command_rhs + | primary_value call_op tIDENTIFIER tOP_ASGN shareable command_rhs { /*%%%*/ - $$ = new_attr_op_assign(p, $1, $2, $3, $4, $5, &@$); + $$ = new_attr_op_assign(p, $1, $2, $3, $4, $6, &@$); /*% %*/ - /*% ripper: opassign!(field!($1, $2, $3), $4, $5) %*/ + /*% ripper: opassign!(field!($1, $2, $3), $4, $6) %*/ } - | primary_value call_op tCONSTANT tOP_ASGN command_rhs + | primary_value call_op tCONSTANT tOP_ASGN shareable command_rhs { /*%%%*/ - $$ = new_attr_op_assign(p, $1, $2, $3, $4, $5, &@$); + $$ = new_attr_op_assign(p, $1, $2, $3, $4, $6, &@$); /*% %*/ - /*% ripper: opassign!(field!($1, $2, $3), $4, $5) %*/ + /*% ripper: opassign!(field!($1, $2, $3), $4, $6) %*/ } - | primary_value tCOLON2 tCONSTANT tOP_ASGN command_rhs + | primary_value tCOLON2 tCONSTANT tOP_ASGN shareable command_rhs { /*%%%*/ YYLTYPE loc = code_loc_gen(&@1, &@3); - $$ = new_const_op_assign(p, NEW_COLON2($1, $3, &loc), $4, $5, &@$); + $$ = new_const_op_assign(p, NEW_COLON2($1, $3, &loc), $4, $6, $5, &@$); /*% %*/ - /*% ripper: opassign!(const_path_field!($1, $3), $4, $5) %*/ + /*% ripper: opassign!(const_path_field!($1, $3), $4, $6) %*/ } - | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_rhs + | primary_value tCOLON2 tIDENTIFIER tOP_ASGN shareable command_rhs { /*%%%*/ - $$ = new_attr_op_assign(p, $1, ID2VAL(idCOLON2), $3, $4, $5, &@$); + $$ = new_attr_op_assign(p, $1, ID2VAL(idCOLON2), $3, $4, $6, &@$); /*% %*/ - /*% ripper: opassign!(field!($1, ID2VAL(idCOLON2), $3), $4, $5) %*/ + /*% ripper: opassign!(field!($1, ID2VAL(idCOLON2), $3), $4, $6) %*/ } - | backref tOP_ASGN command_rhs + | backref tOP_ASGN shareable command_rhs { /*%%%*/ rb_backref_error(p, $1); $$ = NEW_BEGIN(0, &@$); /*% %*/ - /*% ripper[error]: assign_error!(assign!(var_field(p, $1), $3)) %*/ + /*% ripper[error]: assign_error!(assign!(var_field(p, $1), $4)) %*/ } ; @@ -2253,70 +2254,70 @@ reswords : keyword__LINE__ | keyword__FILE__ | keyword__ENCODING__ https://github.com/ruby/ruby/blob/trunk/parse.y#L2254 | keyword_while | keyword_until ; -arg : lhs '=' arg_rhs +arg : lhs '=' shareable arg_rhs { /*%%%*/ - $$ = node_assign(p, $1, $3, &@$); + $$ = node_assign(p, $1, $4, $3, &@$); /*% %*/ - /*% ripper: assign!($1, $3) %*/ + /*% ripper: assign!($1, $4) %*/ } - | var_lhs tOP_ASGN arg_rhs + | var_lhs tOP_ASGN shareable arg_rhs { /*%%%*/ - $$ = new_op_assign(p, $1, $2, $3, &@$); + $$ = new_op_assign(p, $1, $2, $4, $3, &@$); /*% %*/ - /*% ripper: opassign!($1, $2, $3) %*/ + /*% ripper: opassign!($1, $2, $4) %*/ } - | primary_value '[' opt_call_args rbracket tOP_ASGN arg_rhs + | primary_value '[' opt_call_args rbracket tOP_ASGN shareable arg_rhs { /*%%%*/ - $$ = new_ary_op_assign(p, $1, $3, $5, $6, &@3, &@$); + $$ = new_ary_op_assign(p, $1, $3, $5, $7, &@3, &@$); /*% %*/ - /*% ripper: opassign!(aref_field!($1, escape_Qundef($3)), $5, $6) %*/ + /*% ripper: opassign!(aref_field!($1, escape_Qundef($3)), $5, $7) %*/ } - | primary_value call_op tIDENTIFIER tOP_ASGN arg_rhs + | primary_value call_op tIDENTIFIER tOP_ASGN shareable arg_rhs { /*%%%*/ - $$ = new_attr_op_assign(p, $1, $2, $3, $4, $5, &@$); + $$ = new_attr_op_assign(p, $1, $2, $3, $4, $6, &@$); /*% %*/ - /*% ripper: opassign!(field!($1, $2, $3), $4, $5) %*/ + /*% ripper: opassign!(field!($1, $2, $3), $4, $6) %*/ } - | primary_value call_op tCONSTANT tOP_ASGN arg_rhs + | primary_value call_op tCONSTANT tOP_ASGN shareable arg_rhs { /*%%%*/ - $$ = new_attr_op_assign(p, $1, $2, $3, $4, $5, &@$); + $$ = new_attr_op_assign(p, $1, $2, $3, $4, $6, &@$); /*% %*/ - /*% ripper: opassign!(field!($1, $2, $3), $4, $5) %*/ + /*% ripper: opassign!(field!($1, $2, $3), $4, $6) %*/ } - | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg_rhs + | primary_value tCOLON2 tIDENTIFIER tOP_ASGN shareable arg_rhs { /*%%%*/ - $$ = new_attr_op_assign(p, $1, ID2VAL(idCOLON2), $3, $4, $5, &@$); + $$ = new_attr_op_assign(p, $1, ID2VAL(idCOLON2), $3, $4, $6, &@$); /*% %*/ - /*% ripper: opassign!(field!($1, ID2VAL(idCOLON2), $3), $4, $5) %*/ + /*% ripper: opassign!(field!($1, ID2VAL(idCOLON2), $3), $4, $6) %*/ } - | primary_value tCOLON2 tCONSTANT tOP_ASGN arg_rhs + | primary_value tCOLON2 tCONSTANT tOP_ASGN shareable arg_rhs { /*%%%*/ YYLTYPE loc = code_loc_gen(&@1, &@3); - $$ = new_const_op_assign(p, NEW_COLON2($1, $3, &loc), $4, $5, &@$); + $$ = new_const_op_assign(p, N (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/