diff options
author | NARUSE, Yui <[email protected]> | 2021-02-01 19:21:03 +0900 |
---|---|---|
committer | NARUSE, Yui <[email protected]> | 2021-02-01 19:21:03 +0900 |
commit | 42f02a0bac2c037b4e00a9811c5548c5ec7d28a7 (patch) | |
tree | b8369210f34cdfeef3071489f83e81b22b776730 | |
parent | 1b0622d7a9451dbeaadccc1f416b71a98271e097 (diff) |
merge revision(s) 6bcc4664bdaebbf9b28a762ae63f476a1ec6cfb2,bb40c5cbe977de9f36a2a739e94e9b2fd4496b6e,c060bdc2b4ab8eeef5374f4174f5de48ab936d74: [Backport #17541]
Return new NODE_LIT
As NODE_ZLIST/NODE_LIST are not markable, cannot be reused as
NODE_LIT.
---
parse.y | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
Ensure symbol list node is either NODE_STR or NODE_DSTR
---
parse.y | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
NODE markability should not change by nd_set_type
---
node.c | 31 +++++++++++++++++++++++++------
node.h | 12 ++++++++++++
2 files changed, 37 insertions(+), 6 deletions(-)
-rw-r--r-- | node.c | 31 | ||||
-rw-r--r-- | node.h | 12 | ||||
-rw-r--r-- | parse.y | 18 | ||||
-rw-r--r-- | version.h | 2 |
4 files changed, 48 insertions, 15 deletions
@@ -1139,7 +1139,7 @@ void rb_node_init(NODE *n, enum node_type type, VALUE a0, VALUE a1, VALUE a2) { n->flags = T_NODE; - nd_set_type(n, type); + nd_init_type(n, type); n->u1.value = a0; n->u2.value = a1; n->u3.value = a2; @@ -1238,10 +1238,10 @@ ast_newnode_in_bucket(node_buffer_list_t *nb) return &nb->head->buf[nb->idx++]; } -NODE * -rb_ast_newnode(rb_ast_t *ast, enum node_type type) +RBIMPL_ATTR_PURE() +static bool +nodetype_markable_p(enum node_type type) { - node_buffer_t *nb = ast->node_buffer; switch (type) { case NODE_MATCH: case NODE_LIT: @@ -1254,9 +1254,28 @@ rb_ast_newnode(rb_ast_t *ast, enum node_type type) case NODE_ARGS: case NODE_ARYPTN: case NODE_FNDPTN: - return ast_newnode_in_bucket(&nb->markable); + return true; default: - return ast_newnode_in_bucket(&nb->unmarkable); + return false; + } +} + +NODE * +rb_ast_newnode(rb_ast_t *ast, enum node_type type) +{ + node_buffer_t *nb = ast->node_buffer; + node_buffer_list_t *bucket = + (nodetype_markable_p(type) ? &nb->markable : &nb->unmarkable); + return ast_newnode_in_bucket(bucket); +} + +void +rb_ast_node_type_change(NODE *n, enum node_type type) +{ + enum node_type old_type = nd_type(n); + if (nodetype_markable_p(old_type) != nodetype_markable_p(type)) { + rb_bug("node type changed: %s -> %s", + ruby_node_name(old_type), ruby_node_name(type)); } } @@ -187,6 +187,8 @@ typedef struct RNode { #define nd_type(n) ((int) (((n)->flags & NODE_TYPEMASK)>>NODE_TYPESHIFT)) #define nd_set_type(n,t) \ + rb_node_set_type(n, t) +#define nd_init_type(n,t) \ (n)->flags=(((n)->flags&~NODE_TYPEMASK)|((((unsigned long)(t))<<NODE_TYPESHIFT)&NODE_TYPEMASK)) #define NODE_LSHIFT (NODE_TYPESHIFT+7) @@ -471,9 +473,19 @@ void *rb_parser_realloc(struct parser_params *, void *, size_t); void *rb_parser_calloc(struct parser_params *, size_t, size_t); void rb_parser_free(struct parser_params *, void *); PRINTF_ARGS(void rb_parser_printf(struct parser_params *parser, const char *fmt, ...), 2, 3); +void rb_ast_node_type_change(NODE *n, enum node_type type); RUBY_SYMBOL_EXPORT_END +static inline VALUE +rb_node_set_type(NODE *n, enum node_type t) +{ +#if RUBY_DEBUG + rb_ast_node_type_change(n, t); +#endif + return nd_init_type(n, t); +} + #if defined(__cplusplus) #if 0 { /* satisfy cc-mode */ @@ -10352,12 +10352,17 @@ new_defined(struct parser_params *p, NODE *expr, const YYLTYPE *loc) static NODE* symbol_append(struct parser_params *p, NODE *symbols, NODE *symbol) { - if (nd_type(symbol) == NODE_DSTR) { + enum node_type type = nd_type(symbol); + switch (type) { + case NODE_DSTR: nd_set_type(symbol, NODE_DSYM); - } - else { + break; + case NODE_STR: nd_set_type(symbol, NODE_LIT); RB_OBJ_WRITTEN(p->ast, Qnil, symbol->nd_lit = rb_str_intern(symbol->nd_lit)); + break; + default: + compile_error(p, "unexpected node as symbol: %s", ruby_node_name(type)); } return list_append(p, symbols, symbol); } @@ -11133,9 +11138,7 @@ shareable_literal_constant(struct parser_params *p, enum shareability shareable, case NODE_ZLIST: lit = rb_ary_new(); OBJ_FREEZE_RAW(lit); - nd_set_type(value, NODE_LIT); - RB_OBJ_WRITE(p->ast, &value->nd_lit, lit); - return value; + return NEW_LIT(lit, loc); case NODE_LIST: lit = rb_ary_new(); @@ -11220,8 +11223,7 @@ shareable_literal_constant(struct parser_params *p, enum shareability shareable, value = make_shareable_node(p, value, false, loc); } else { - nd_set_type(value, NODE_LIT); - RB_OBJ_WRITE(p->ast, &value->nd_lit, rb_ractor_make_shareable(lit)); + value = NEW_LIT(rb_ractor_make_shareable(lit), loc); } return value; @@ -12,7 +12,7 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 0 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 18 +#define RUBY_PATCHLEVEL 19 #define RUBY_RELEASE_YEAR 2021 #define RUBY_RELEASE_MONTH 2 |