ruby-changes:64156
From: Nobuyoshi <ko1@a...>
Date: Mon, 14 Dec 2020 19:29:53 +0900 (JST)
Subject: [ruby-changes:64156] 070a990bcb (master): Save and pass lex_context wholely
https://git.ruby-lang.org/ruby.git/commit/?id=070a990bcb From 070a990bcb81ed371fc60e3922f5329b1020aa44 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sat, 10 Oct 2020 16:24:54 +0900 Subject: Save and pass lex_context wholely diff --git a/parse.y b/parse.y index 0c192b6..84a6efd 100644 --- a/parse.y +++ b/parse.y @@ -34,6 +34,8 @@ struct lex_context { https://github.com/ruby/ruby/blob/trunk/parse.y#L34 unsigned int shareable_constant_value: 1; }; +#define NO_LEX_CTXT (struct lex_context){0} + #include "internal.h" #include "internal/compile.h" #include "internal/complex.h" @@ -521,12 +523,12 @@ static NODE *aryset(struct parser_params*,NODE*,NODE*,const YYLTYPE*); https://github.com/ruby/ruby/blob/trunk/parse.y#L523 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*,int,const YYLTYPE*); +static NODE *node_assign(struct parser_params*,NODE*,NODE*,struct lex_context,const YYLTYPE*); -static NODE *new_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, int shareable, const YYLTYPE *loc); +static NODE *new_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, struct lex_context, 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, int shareable, const YYLTYPE *loc); +static NODE *new_const_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, struct lex_context, 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,7 +1183,7 @@ static int looking_at_eol_p(struct parser_params *p); https://github.com/ruby/ruby/blob/trunk/parse.y#L1183 %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 + %type <ctxt> lex_ctxt /* keep <ctxt> in ripper */ %token END_OF_INPUT 0 "end-of-input" %token <id> '.' /* escaped chars, should be ignored otherwise */ @@ -1520,7 +1522,7 @@ stmt : keyword_alias fitem {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem https://github.com/ruby/ruby/blob/trunk/parse.y#L1522 /*% ripper: END!($3) %*/ } | command_asgn - | mlhs '=' shareable command_call + | mlhs '=' lex_ctxt command_call { /*%%%*/ value_expr($4); @@ -1528,7 +1530,7 @@ stmt : keyword_alias fitem {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem https://github.com/ruby/ruby/blob/trunk/parse.y#L1530 /*% %*/ /*% ripper: massign!($1, $4) %*/ } - | lhs '=' shareable mrhs + | lhs '=' lex_ctxt mrhs { /*%%%*/ value_expr($4); @@ -1536,7 +1538,7 @@ stmt : keyword_alias fitem {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem https://github.com/ruby/ruby/blob/trunk/parse.y#L1538 /*% %*/ /*% ripper: assign!($1, $4) %*/ } - | mlhs '=' shareable mrhs_arg modifier_rescue stmt + | mlhs '=' lex_ctxt mrhs_arg modifier_rescue stmt { /*%%%*/ YYLTYPE loc = code_loc_gen(&@5, &@6); @@ -1545,7 +1547,7 @@ stmt : keyword_alias fitem {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem https://github.com/ruby/ruby/blob/trunk/parse.y#L1547 /*% %*/ /*% ripper: massign!($1, rescue_mod!($4, $6)) %*/ } - | mlhs '=' shareable mrhs_arg + | mlhs '=' lex_ctxt mrhs_arg { /*%%%*/ $$ = node_assign(p, $1, $4, $3, &@$); @@ -1555,21 +1557,21 @@ stmt : keyword_alias fitem {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem https://github.com/ruby/ruby/blob/trunk/parse.y#L1557 | expr ; -command_asgn : lhs '=' shareable command_rhs +command_asgn : lhs '=' lex_ctxt command_rhs { /*%%%*/ $$ = node_assign(p, $1, $4, $3, &@$); /*% %*/ /*% ripper: assign!($1, $4) %*/ } - | var_lhs tOP_ASGN shareable command_rhs + | var_lhs tOP_ASGN lex_ctxt command_rhs { /*%%%*/ $$ = new_op_assign(p, $1, $2, $4, $3, &@$); /*% %*/ /*% ripper: opassign!($1, $2, $4) %*/ } - | primary_value '[' opt_call_args rbracket tOP_ASGN shareable command_rhs + | primary_value '[' opt_call_args rbracket tOP_ASGN lex_ctxt command_rhs { /*%%%*/ $$ = new_ary_op_assign(p, $1, $3, $5, $7, &@3, &@$); @@ -1577,21 +1579,21 @@ command_asgn : lhs '=' shareable command_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L1579 /*% ripper: opassign!(aref_field!($1, escape_Qundef($3)), $5, $7) %*/ } - | primary_value call_op tIDENTIFIER tOP_ASGN shareable command_rhs + | primary_value call_op tIDENTIFIER tOP_ASGN lex_ctxt command_rhs { /*%%%*/ $$ = new_attr_op_assign(p, $1, $2, $3, $4, $6, &@$); /*% %*/ /*% ripper: opassign!(field!($1, $2, $3), $4, $6) %*/ } - | primary_value call_op tCONSTANT tOP_ASGN shareable command_rhs + | primary_value call_op tCONSTANT tOP_ASGN lex_ctxt command_rhs { /*%%%*/ $$ = new_attr_op_assign(p, $1, $2, $3, $4, $6, &@$); /*% %*/ /*% ripper: opassign!(field!($1, $2, $3), $4, $6) %*/ } - | primary_value tCOLON2 tCONSTANT tOP_ASGN shareable command_rhs + | primary_value tCOLON2 tCONSTANT tOP_ASGN lex_ctxt command_rhs { /*%%%*/ YYLTYPE loc = code_loc_gen(&@1, &@3); @@ -1599,14 +1601,14 @@ command_asgn : lhs '=' shareable command_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L1601 /*% %*/ /*% ripper: opassign!(const_path_field!($1, $3), $4, $6) %*/ } - | primary_value tCOLON2 tIDENTIFIER tOP_ASGN shareable command_rhs + | primary_value tCOLON2 tIDENTIFIER tOP_ASGN lex_ctxt command_rhs { /*%%%*/ $$ = new_attr_op_assign(p, $1, ID2VAL(idCOLON2), $3, $4, $6, &@$); /*% %*/ /*% ripper: opassign!(field!($1, ID2VAL(idCOLON2), $3), $4, $6) %*/ } - | backref tOP_ASGN shareable command_rhs + | backref tOP_ASGN lex_ctxt command_rhs { /*%%%*/ rb_backref_error(p, $1); @@ -2254,49 +2256,49 @@ reswords : keyword__LINE__ | keyword__FILE__ | keyword__ENCODING__ https://github.com/ruby/ruby/blob/trunk/parse.y#L2256 | keyword_while | keyword_until ; -arg : lhs '=' shareable arg_rhs +arg : lhs '=' lex_ctxt arg_rhs { /*%%%*/ $$ = node_assign(p, $1, $4, $3, &@$); /*% %*/ /*% ripper: assign!($1, $4) %*/ } - | var_lhs tOP_ASGN shareable arg_rhs + | var_lhs tOP_ASGN lex_ctxt arg_rhs { /*%%%*/ $$ = new_op_assign(p, $1, $2, $4, $3, &@$); /*% %*/ /*% ripper: opassign!($1, $2, $4) %*/ } - | primary_value '[' opt_call_args rbracket tOP_ASGN shareable arg_rhs + | primary_value '[' opt_call_args rbracket tOP_ASGN lex_ctxt arg_rhs { /*%%%*/ $$ = new_ary_op_assign(p, $1, $3, $5, $7, &@3, &@$); /*% %*/ /*% ripper: opassign!(aref_field!($1, escape_Qundef($3)), $5, $7) %*/ } - | primary_value call_op tIDENTIFIER tOP_ASGN shareable arg_rhs + | primary_value call_op tIDENTIFIER tOP_ASGN lex_ctxt arg_rhs { /*%%%*/ $$ = new_attr_op_assign(p, $1, $2, $3, $4, $6, &@$); /*% %*/ /*% ripper: opassign!(field!($1, $2, $3), $4, $6) %*/ } - | primary_value call_op tCONSTANT tOP_ASGN shareable arg_rhs + | primary_value call_op tCONSTANT tOP_ASGN lex_ctxt arg_rhs { /*%%%*/ $$ = new_attr_op_assign(p, $1, $2, $3, $4, $6, &@$); /*% %*/ /*% ripper: opassign!(field!($1, $2, $3), $4, $6) %*/ } - | primary_value tCOLON2 tIDENTIFIER tOP_ASGN shareable arg_rhs + | primary_value tCOLON2 tIDENTIFIER tOP_ASGN lex_ctxt arg_rhs { /*%%%*/ $$ = new_attr_op_assign(p, $1, ID2VAL(idCOLON2), $3, $4, $6, &@$); /*% %*/ /*% ripper: opassign!(field!($1, ID2VAL(idCOLON2), $3), $4, $6) %*/ } - | primary_value tCOLON2 tCONSTANT tOP_ASGN shareable arg_rhs + | primary_value tCOLON2 tCONSTANT tOP_ASGN lex_ctxt arg_rhs { /*%%%*/ YYLTYPE loc = code_loc_gen(&@1, &@3); @@ -2304,14 +2306,14 @@ arg : lhs '=' shareable arg_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L2306 /*% %*/ /*% ripper: opassign!(const_path_field!($1, $3), $4, $6) %*/ } - | tCOLON3 tCONSTANT tOP_ASGN shareable arg_rhs + | tCOLON3 tCONSTANT tOP_ASGN lex_ctxt arg_rhs { /*%%%*/ $$ = new_const_op_assign(p, NEW_COLON3($2, &@$), $3, $5, $4, &@$); /*% %*/ /*% ripper: opassign!(top_const_field!($2), $3, $5) %*/ } - | backref tOP_ASGN shareable arg_rhs + | backref tOP_ASGN lex_ctxt arg_rhs { /*%%%*/ rb_backref_error(p, $1); @@ -2551,13 +2553,13 @@ rel_expr : arg relop arg %prec '>' https://github.com/ruby/ruby/blob/trunk/parse.y#L2553 } ; -shareable : tSP +lex_ctxt : tSP { - $$ = p->ctxt.shareable_constant_value; + $$ = p->ctxt; } | none { - $$ = p->ctxt.shareable_constant_value; + $$ = p->ctxt; } ; @@ -3066,10 +3068,10 @@ primary : literal https://github.com/ruby/ruby/blob/trunk/parse.y#L3068 m->nd_next = $2; break; case NODE_MASGN: /* e.each {|*internal_var| a, b, c = (internal_var.length == 1 && Array === (tmp = internal_var[0]) ? tmp : internal_var); ... } */ - m->nd_next = node_assign(p, $2, NEW_FOR_MASGN(internal_var, &@2), 0, &@2); + m->nd_next = node_assign(p, (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/