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

Directly free structure managed by imemo tmpbuf #8493

Merged
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
45 changes: 20 additions & 25 deletions node.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@

#define NODE_BUF_DEFAULT_LEN 16

typedef void node_itr_t(rb_ast_t *ast, void *ctx, NODE * node);
static void iterate_node_values(rb_ast_t *ast, node_buffer_list_t *nb, node_itr_t * func, void *ctx);

/* Setup NODE structure.
* NODE is not an object managed by GC, but it imitates an object
* so that it can work with `RB_TYPE_P(obj, T_NODE)`.
Expand Down Expand Up @@ -161,9 +164,26 @@ struct rb_ast_local_table_link {
// }
};

static void
free_ast_value(rb_ast_t *ast, void *ctx, NODE * node)
{
switch (nd_type(node)) {
case NODE_ARGS:
xfree(node->nd_ainfo);
break;
case NODE_ARYPTN:
xfree(node->nd_apinfo);
break;
case NODE_FNDPTN:
xfree(node->nd_fpinfo);
break;
}
}

static void
rb_node_buffer_free(rb_ast_t *ast, node_buffer_t *nb)
{
iterate_node_values(ast, &nb->unmarkable, free_ast_value, NULL);
node_buffer_list_free(ast, &nb->unmarkable);
node_buffer_list_free(ast, &nb->markable);
struct rb_ast_local_table_link *local_table = nb->local_tables;
Expand Down Expand Up @@ -204,9 +224,6 @@ nodetype_markable_p(enum node_type type)
case NODE_DXSTR:
case NODE_DREGX:
case NODE_DSYM:
case NODE_ARGS:
case NODE_ARYPTN:
case NODE_FNDPTN:
return true;
default:
return false;
Expand Down Expand Up @@ -284,8 +301,6 @@ rb_ast_new(void)
}
#endif

typedef void node_itr_t(rb_ast_t *ast, void *ctx, NODE * node);

static void
iterate_buffer_elements(rb_ast_t *ast, node_buffer_elem_t *nbe, long len, node_itr_t *func, void *ctx)
{
Expand Down Expand Up @@ -318,12 +333,6 @@ mark_ast_value(rb_ast_t *ast, void *ctx, NODE * node)
#endif

switch (nd_type(node)) {
case NODE_ARGS:
{
struct rb_args_info *args = node->nd_ainfo;
rb_gc_mark_movable(args->imemo);
break;
}
case NODE_MATCH:
case NODE_LIT:
case NODE_STR:
Expand All @@ -334,10 +343,6 @@ mark_ast_value(rb_ast_t *ast, void *ctx, NODE * node)
case NODE_DSYM:
rb_gc_mark_movable(node->nd_lit);
break;
case NODE_ARYPTN:
case NODE_FNDPTN:
rb_gc_mark_movable(node->nd_rval);
break;
default:
rb_bug("unreachable node %s", ruby_node_name(nd_type(node)));
}
Expand All @@ -351,12 +356,6 @@ update_ast_value(rb_ast_t *ast, void *ctx, NODE * node)
#endif

switch (nd_type(node)) {
case NODE_ARGS:
{
struct rb_args_info *args = node->nd_ainfo;
args->imemo = rb_gc_location(args->imemo);
break;
}
case NODE_MATCH:
case NODE_LIT:
case NODE_STR:
Expand All @@ -367,10 +366,6 @@ update_ast_value(rb_ast_t *ast, void *ctx, NODE * node)
case NODE_DSYM:
node->nd_lit = rb_gc_location(node->nd_lit);
break;
case NODE_ARYPTN:
case NODE_FNDPTN:
node->nd_rval = rb_gc_location(node->nd_rval);
break;
default:
rb_bug("unreachable");
}
Expand Down
22 changes: 6 additions & 16 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -12721,13 +12721,9 @@ static NODE*
new_args_tail(struct parser_params *p, NODE *kw_args, ID kw_rest_arg, ID block, const YYLTYPE *kw_rest_loc)
{
int saved_line = p->ruby_sourceline;
NODE *node;
VALUE tmpbuf = rb_imemo_tmpbuf_auto_free_pointer();
NODE *node = NEW_NODE(NODE_ARGS, 0, 0, 0, &NULL_LOC);
struct rb_args_info *args = ZALLOC(struct rb_args_info);
rb_imemo_tmpbuf_set_ptr(tmpbuf, args);
args->imemo = tmpbuf;
node = NEW_NODE(NODE_ARGS, 0, 0, args, &NULL_LOC);
RB_OBJ_WRITTEN(p->ast, Qnil, tmpbuf);
node->nd_ainfo = args;
if (p->error_p) return node;

args->block_arg = block;
Expand Down Expand Up @@ -12818,12 +12814,9 @@ static NODE*
new_array_pattern_tail(struct parser_params *p, NODE *pre_args, int has_rest, NODE *rest_arg, NODE *post_args, const YYLTYPE *loc)
{
int saved_line = p->ruby_sourceline;
NODE *node;
VALUE tmpbuf = rb_imemo_tmpbuf_auto_free_pointer();
NODE *node = NEW_NODE(NODE_ARYPTN, 0, 0, 0, loc);
struct rb_ary_pattern_info *apinfo = ZALLOC(struct rb_ary_pattern_info);
rb_imemo_tmpbuf_set_ptr(tmpbuf, apinfo);
node = NEW_NODE(NODE_ARYPTN, 0, tmpbuf, apinfo, loc);
RB_OBJ_WRITTEN(p->ast, Qnil, tmpbuf);
node->nd_apinfo = apinfo;

apinfo->pre_args = pre_args;

Expand Down Expand Up @@ -12852,12 +12845,9 @@ static NODE*
new_find_pattern_tail(struct parser_params *p, NODE *pre_rest_arg, NODE *args, NODE *post_rest_arg, const YYLTYPE *loc)
{
int saved_line = p->ruby_sourceline;
NODE *node;
VALUE tmpbuf = rb_imemo_tmpbuf_auto_free_pointer();
NODE *node = NEW_NODE(NODE_FNDPTN, 0, 0, 0, loc);
struct rb_fnd_pattern_info *fpinfo = ZALLOC(struct rb_fnd_pattern_info);
rb_imemo_tmpbuf_set_ptr(tmpbuf, fpinfo);
node = NEW_NODE(NODE_FNDPTN, 0, tmpbuf, fpinfo, loc);
RB_OBJ_WRITTEN(p->ast, Qnil, tmpbuf);
node->nd_fpinfo = fpinfo;

fpinfo->pre_rest_arg = pre_rest_arg ? pre_rest_arg : NODE_SPECIAL_NO_NAME_REST;
fpinfo->args = args;
Expand Down
2 changes: 0 additions & 2 deletions ruby_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,6 @@ rb_parser_config_initialize(rb_parser_config_t *config)

config->new_strterm = new_strterm;
config->strterm_is_heredoc = strterm_is_heredoc;
config->tmpbuf_auto_free_pointer = rb_imemo_tmpbuf_auto_free_pointer;
config->tmpbuf_set_ptr = rb_imemo_tmpbuf_set_ptr;
config->tmpbuf_parser_heap = tmpbuf_parser_heap;
config->ast_new = ast_new;

Expand Down
4 changes: 0 additions & 4 deletions rubyparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@ struct rb_args_info {
unsigned int no_kwarg: 1;
unsigned int ruby2_keywords: 1;
unsigned int forwarding: 1;

VALUE imemo;
};

struct rb_ary_pattern_info {
Expand Down Expand Up @@ -364,8 +362,6 @@ typedef struct rb_parser_config_struct {
// TODO: Should it return `rb_strterm_t *'?
VALUE (*new_strterm)(VALUE v1, VALUE v2, VALUE v3, VALUE v0, int heredoc);
int (*strterm_is_heredoc)(VALUE strterm);
VALUE (*tmpbuf_auto_free_pointer)(void);
void *(*tmpbuf_set_ptr)(VALUE v, void *ptr);
rb_imemo_tmpbuf_t *(*tmpbuf_parser_heap)(void *buf, rb_imemo_tmpbuf_t *old_heap, size_t cnt);
rb_ast_t *(*ast_new)(VALUE nb);

Expand Down
2 changes: 0 additions & 2 deletions universal_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ struct rb_imemo_tmpbuf_struct {

#define new_strterm p->config->new_strterm
#define strterm_is_heredoc p->config->strterm_is_heredoc
#define rb_imemo_tmpbuf_auto_free_pointer p->config->tmpbuf_auto_free_pointer
#define rb_imemo_tmpbuf_set_ptr p->config->tmpbuf_set_ptr
#define rb_imemo_tmpbuf_parser_heap p->config->tmpbuf_parser_heap

#define compile_callback p->config->compile_callback
Expand Down