Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NODE_LIT is not used anymore #10447

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,16 +551,15 @@ node_children(rb_ast_t *ast, const NODE *node)
name[1] = (char)RNODE_BACK_REF(node)->nd_nth;
name[2] = '\0';
return rb_ary_new_from_args(1, ID2SYM(rb_intern(name)));
case NODE_MATCH:
return rb_ary_new_from_args(1, rb_node_regx_string_val(node));
case NODE_MATCH2:
if (RNODE_MATCH2(node)->nd_args) {
return rb_ary_new_from_node_args(ast, 3, RNODE_MATCH2(node)->nd_recv, RNODE_MATCH2(node)->nd_value, RNODE_MATCH2(node)->nd_args);
}
return rb_ary_new_from_node_args(ast, 2, RNODE_MATCH2(node)->nd_recv, RNODE_MATCH2(node)->nd_value);
case NODE_MATCH3:
return rb_ary_new_from_node_args(ast, 2, RNODE_MATCH3(node)->nd_recv, RNODE_MATCH3(node)->nd_value);
case NODE_MATCH:
case NODE_LIT:
return rb_ary_new_from_args(1, RNODE_LIT(node)->nd_lit);
case NODE_STR:
case NODE_XSTR:
return rb_ary_new_from_args(1, rb_node_str_string_val(node));
Expand Down
64 changes: 4 additions & 60 deletions compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1927,9 +1927,6 @@ iseq_set_arguments_keywords(rb_iseq_t *iseq, LINK_ANCHOR *const optargs,
}
else {
switch (nd_type(val_node)) {
case NODE_LIT:
dv = RNODE_LIT(val_node)->nd_lit;
break;
case NODE_SYM:
dv = rb_node_sym_string_val(val_node);
break;
Expand Down Expand Up @@ -4510,7 +4507,6 @@ compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *ret, const NODE *cond,
else_label = NEW_LABEL(nd_line(cond));
}
goto again;
case NODE_LIT: /* NODE_LIT is always true */
case NODE_SYM:
case NODE_LINE:
case NODE_FILE:
Expand Down Expand Up @@ -4591,8 +4587,6 @@ static VALUE
get_symbol_value(rb_iseq_t *iseq, const NODE *node)
{
switch (nd_type(node)) {
case NODE_LIT:
return RNODE_LIT(node)->nd_lit;
case NODE_SYM:
return rb_node_sym_string_val(node);
default:
Expand Down Expand Up @@ -4641,10 +4635,7 @@ compile_keyword_arg(rb_iseq_t *iseq, LINK_ANCHOR *const ret,
seen_nodes++;

RUBY_ASSERT(nd_type_p(node, NODE_LIST));
if (key_node && nd_type_p(key_node, NODE_LIT) && SYMBOL_P(RNODE_LIT(key_node)->nd_lit)) {
/* can be keywords */
}
else if (key_node && nd_type_p(key_node, NODE_SYM)) {
if (key_node && nd_type_p(key_node, NODE_SYM)) {
/* can be keywords */
}
else {
Expand Down Expand Up @@ -4729,7 +4720,6 @@ static inline bool
static_literal_node_p(const NODE *node, const rb_iseq_t *iseq, bool hash_key)
{
switch (nd_type(node)) {
case NODE_LIT:
case NODE_SYM:
case NODE_REGX:
case NODE_LINE:
Expand Down Expand Up @@ -4788,8 +4778,6 @@ static_literal_value(const NODE *node, rb_iseq_t *iseq)
else {
return rb_fstring(get_string_value(node));
}
case NODE_LIT:
return RNODE_LIT(node)->nd_lit;
default:
rb_bug("unexpected node: %s", ruby_node_name(nd_type(node)));
}
Expand Down Expand Up @@ -5068,7 +5056,7 @@ compile_hash(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, int meth
FLUSH_CHUNK();

const NODE *kw = RNODE_LIST(RNODE_LIST(node)->nd_next)->nd_head;
int empty_kw = nd_type_p(kw, NODE_LIT) && RB_TYPE_P(RNODE_LIT(kw)->nd_lit, T_HASH); /* foo( ..., **{}, ...) */
int empty_kw = nd_type_p(kw, NODE_HASH) && (!RNODE_HASH(kw)->nd_head); /* foo( ..., **{}, ...) */
int first_kw = first_chunk && stack_len == 0; /* foo(1,2,3, **kw, ...) */
int last_kw = !RNODE_LIST(RNODE_LIST(node)->nd_next)->nd_next; /* foo( ..., **kw) */
int only_kw = last_kw && first_kw; /* foo(1,2,3, **kw) */
Expand Down Expand Up @@ -5133,13 +5121,6 @@ VALUE
rb_node_case_when_optimizable_literal(const NODE *const node)
{
switch (nd_type(node)) {
case NODE_LIT: {
VALUE v = RNODE_LIT(node)->nd_lit;
if (SYMBOL_P(v)) {
return v;
}
break;
}
case NODE_INTEGER:
return rb_node_integer_literal_val(node);
case NODE_FLOAT: {
Expand Down Expand Up @@ -5815,7 +5796,6 @@ defined_expr0(rb_iseq_t *iseq, LINK_ANCHOR *const ret,
}
/* fall through */
case NODE_STR:
case NODE_LIT:
case NODE_SYM:
case NODE_REGX:
case NODE_LINE:
Expand Down Expand Up @@ -6399,8 +6379,6 @@ optimizable_range_item_p(const NODE *n)
{
if (!n) return FALSE;
switch (nd_type(n)) {
case NODE_LIT:
return RB_INTEGER_TYPE_P(RNODE_LIT(n)->nd_lit);
case NODE_LINE:
return TRUE;
case NODE_INTEGER:
Expand All @@ -6416,8 +6394,6 @@ static VALUE
optimized_range_item(const NODE *n)
{
switch (nd_type(n)) {
case NODE_LIT:
return RNODE_LIT(n)->nd_lit;
case NODE_LINE:
return rb_node_line_lineno_val(n);
case NODE_INTEGER:
Expand Down Expand Up @@ -7243,7 +7219,6 @@ iseq_compile_pattern_each(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *c
ADD_INSNL(ret, line_node, jump, unmatched);
break;
}
case NODE_LIT:
case NODE_SYM:
case NODE_REGX:
case NODE_LINE:
Expand Down Expand Up @@ -8645,9 +8620,6 @@ compile_builtin_attr(rb_iseq_t *iseq, const NODE *node)
case NODE_SYM:
symbol = rb_node_sym_string_val(node);
break;
case NODE_LIT:
symbol = RNODE_LIT(node)->nd_lit;
break;
default:
goto bad_arg;
}
Expand Down Expand Up @@ -8694,9 +8666,6 @@ compile_builtin_arg(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, c
case NODE_SYM:
name = rb_node_sym_string_val(node);
break;
case NODE_LIT:
name = RNODE_LIT(node)->nd_lit;
break;
default:
goto bad_arg;
}
Expand Down Expand Up @@ -8935,20 +8904,7 @@ compile_call(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, co
labels_table = st_init_numtable();
ISEQ_COMPILE_DATA(iseq)->labels_table = labels_table;
}
if (nd_type_p(node->nd_args->nd_head, NODE_LIT) &&
SYMBOL_P(node->nd_args->nd_head->nd_lit)) {

label_name = node->nd_args->nd_head->nd_lit;
if (!st_lookup(labels_table, (st_data_t)label_name, &data)) {
label = NEW_LABEL(nd_line(line_node));
label->position = nd_line(line_node);
st_insert(labels_table, (st_data_t)label_name, (st_data_t)label);
}
else {
label = (LABEL *)data;
}
}
else {
{
COMPILE_ERROR(ERROR_ARGS "invalid goto/label format");
return COMPILE_NG;
}
Expand Down Expand Up @@ -9834,8 +9790,7 @@ compile_kw_arg(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node,
COMPILE_ERROR(ERROR_ARGS "unreachable");
return COMPILE_NG;
}
else if (nd_type_p(default_value, NODE_LIT) ||
nd_type_p(default_value, NODE_SYM) ||
else if (nd_type_p(default_value, NODE_SYM) ||
nd_type_p(default_value, NODE_REGX) ||
nd_type_p(default_value, NODE_LINE) ||
nd_type_p(default_value, NODE_INTEGER) ||
Expand Down Expand Up @@ -10075,9 +10030,6 @@ compile_shareable_literal_constant(rb_iseq_t *iseq, LINK_ANCHOR *ret, enum rb_pa
case NODE_NIL:
*value_p = Qnil;
goto compile;
case NODE_LIT:
*value_p = RNODE_LIT(node)->nd_lit;
goto compile;
case NODE_SYM:
*value_p = rb_node_sym_string_val(node);
goto compile;
Expand Down Expand Up @@ -10664,14 +10616,6 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const no
case NODE_MATCH3:
CHECK(compile_match(iseq, ret, node, popped, type));
break;
case NODE_LIT:{
debugp_param("lit", RNODE_LIT(node)->nd_lit);
if (!popped) {
ADD_INSN1(ret, node, putobject, RNODE_LIT(node)->nd_lit);
RB_OBJ_WRITTEN(iseq, Qundef, RNODE_LIT(node)->nd_lit);
}
break;
}
case NODE_SYM:{
if (!popped) {
ADD_INSN1(ret, node, putobject, rb_node_sym_string_val(node));
Expand Down
2 changes: 0 additions & 2 deletions misc/lldb_rb/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,6 @@ def inspect(self, val):
self._append_expression("*(struct RNode_MATCH2 *) %0#x" % val.GetValueAsUnsigned())
elif nd_type == self.ruby_globals["NODE_MATCH3"]:
self._append_expression("*(struct RNode_MATCH3 *) %0#x" % val.GetValueAsUnsigned())
elif nd_type == self.ruby_globals["NODE_LIT"]:
self._append_expression("*(struct RNode_LIT *) %0#x" % val.GetValueAsUnsigned())
elif nd_type == self.ruby_globals["NODE_STR"]:
self._append_expression("*(struct RNode_STR *) %0#x" % val.GetValueAsUnsigned())
elif nd_type == self.ruby_globals["NODE_DSTR"]:
Expand Down
26 changes: 1 addition & 25 deletions node.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,7 @@ RBIMPL_ATTR_PURE()
static bool
nodetype_markable_p(enum node_type type)
{
switch (type) {
case NODE_LIT:
return true;
default:
return false;
}
return false;
}

NODE *
Expand Down Expand Up @@ -389,29 +384,10 @@ iterate_node_values(rb_ast_t *ast, node_buffer_list_t *nb, node_itr_t * func, vo
}
}

static void
mark_and_move_ast_value(rb_ast_t *ast, void *ctx, NODE *node)
{
#ifdef UNIVERSAL_PARSER
bug_report_func rb_bug = ast->node_buffer->config->bug;
#endif

switch (nd_type(node)) {
case NODE_LIT:
rb_gc_mark_and_move(&RNODE_LIT(node)->nd_lit);
break;
default:
rb_bug("unreachable node %s", ruby_node_name(nd_type(node)));
}
}

void
rb_ast_mark_and_move(rb_ast_t *ast, bool reference_updating)
{
if (ast->node_buffer) {
node_buffer_t *nb = ast->node_buffer;
iterate_node_values(ast, &nb->markable, mark_and_move_ast_value, NULL);

if (ast->body.script_lines) rb_gc_mark_and_move(&ast->body.script_lines);
}
}
Expand Down
6 changes: 0 additions & 6 deletions node_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,12 +724,6 @@ dump_node(VALUE buf, VALUE indent, int comment, const NODE * node)
F_NODE(nd_value, RNODE_MATCH3, "regexp (argument)");
return;

case NODE_LIT:
ANN("literal");
ANN("format: [nd_lit]");
ANN("example: :sym, /foo/");
F_LIT(nd_lit, RNODE_LIT, "literal");
return;
case NODE_STR:
ANN("string literal");
ANN("format: [nd_lit]");
Expand Down
20 changes: 0 additions & 20 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -2642,9 +2642,6 @@ rb_parser_tokens_free(rb_parser_t *p, rb_parser_ary_t *tokens)
case NODE_IMAGINARY:
rb_parser_printf(p, "%+"PRIsVALUE, rb_node_imaginary_literal_val($$));
break;
case NODE_LIT:
rb_parser_printf(p, "%+"PRIsVALUE, RNODE_LIT($$)->nd_lit);
break;
default:
break;
}
Expand Down Expand Up @@ -6848,7 +6845,6 @@ singleton : var_ref
case NODE_DXSTR:
case NODE_REGX:
case NODE_DREGX:
case NODE_LIT:
case NODE_SYM:
case NODE_LINE:
case NODE_FILE:
Expand Down Expand Up @@ -14222,7 +14218,6 @@ void_expr(struct parser_params *p, NODE *node)
case NODE_CONST:
useless = "a constant";
break;
case NODE_LIT:
case NODE_SYM:
case NODE_LINE:
case NODE_FILE:
Expand Down Expand Up @@ -14368,7 +14363,6 @@ is_static_content(NODE *node)
do {
if (!is_static_content(RNODE_LIST(node)->nd_head)) return 0;
} while ((node = RNODE_LIST(node)->nd_next) != 0);
case NODE_LIT:
case NODE_SYM:
case NODE_REGX:
case NODE_LINE:
Expand Down Expand Up @@ -14503,23 +14497,9 @@ cond0(struct parser_params *p, NODE *node, enum cond_type type, const YYLTYPE *l

case NODE_SYM:
case NODE_DSYM:
warn_symbol:
SWITCH_BY_COND_TYPE(type, warning, "symbol ");
break;

case NODE_LIT:
if (RNODE_LIT(node)->nd_lit == Qtrue ||
RNODE_LIT(node)->nd_lit == Qfalse) {
/* booleans are OK, e.g., while true */
}
else if (SYMBOL_P(RNODE_LIT(node)->nd_lit)) {
goto warn_symbol;
}
else {
SWITCH_BY_COND_TYPE(type, warning, "");
}
break;

case NODE_LINE:
SWITCH_BY_COND_TYPE(type, warning, "");
break;
Expand Down
8 changes: 0 additions & 8 deletions rubyparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ enum node_type {
NODE_MATCH,
NODE_MATCH2,
NODE_MATCH3,
NODE_LIT,
NODE_INTEGER,
NODE_FLOAT,
NODE_RATIONAL,
Expand Down Expand Up @@ -675,12 +674,6 @@ typedef struct RNode_MATCH3 {
struct RNode *nd_value;
} rb_node_match3_t;

typedef struct RNode_LIT {
NODE node;

VALUE nd_lit;
} rb_node_lit_t;

typedef struct RNode_INTEGER {
NODE node;

Expand Down Expand Up @@ -1131,7 +1124,6 @@ typedef struct RNode_ERROR {
#define RNODE_MATCH(node) ((struct RNode_MATCH *)(node))
#define RNODE_MATCH2(node) ((struct RNode_MATCH2 *)(node))
#define RNODE_MATCH3(node) ((struct RNode_MATCH3 *)(node))
#define RNODE_LIT(node) ((struct RNode_LIT *)(node))
#define RNODE_INTEGER(node) ((struct RNode_INTEGER *)(node))
#define RNODE_FLOAT(node) ((struct RNode_FLOAT *)(node))
#define RNODE_RATIONAL(node) ((struct RNode_RATIONAL *)(node))
Expand Down