[前][次][番号順一覧][スレッド一覧]

ruby-changes:57567

From: Aaron <ko1@a...>
Date: Fri, 6 Sep 2019 02:14:18 +0900 (JST)
Subject: [ruby-changes:57567] f0fd1c0cd8 (master): Stash the imemo buf at the end of the ID list

https://git.ruby-lang.org/ruby.git/commit/?id=f0fd1c0cd8

From f0fd1c0cd8d34b870a3011a36f5179d1b5f3547d Mon Sep 17 00:00:00 2001
From: Aaron Patterson <tenderlove@r...>
Date: Wed, 4 Sep 2019 16:00:19 -0700
Subject: Stash the imemo buf at the end of the ID list

Now we can reach the ID table buffer from the id table itself, so when
SCOPE nodes are marked we can keep the buffers alive.  This eliminates
the need for the "mark array" during normal parse / compile (IOW *not*
Ripper).

diff --git a/node.c b/node.c
index 8a519f2..064ce00 100644
--- a/node.c
+++ b/node.c
@@ -1218,6 +1218,15 @@ static void https://github.com/ruby/ruby/blob/trunk/node.c#L1218
 mark_ast_value(void *ctx, NODE * node)
 {
     switch (nd_type(node)) {
+        case NODE_SCOPE:
+        {
+            ID *buf = node->nd_tbl;
+            if (buf) {
+                unsigned int size = (unsigned int)*buf;
+                rb_gc_mark((VALUE)buf[size + 1]);
+            }
+            break;
+        }
         case NODE_LIT:
         case NODE_STR:
         case NODE_XSTR:
@@ -1226,7 +1235,6 @@ mark_ast_value(void *ctx, NODE * node) https://github.com/ruby/ruby/blob/trunk/node.c#L1235
         case NODE_DREGX:
         case NODE_DSYM:
         case NODE_ARGS:
-        case NODE_FOR:
         case NODE_ARYPTN:
             rb_gc_mark(node->nd_lit);
             break;
diff --git a/parse.y b/parse.y
index 08bedd2..b230ddb 100644
--- a/parse.y
+++ b/parse.y
@@ -298,9 +298,6 @@ struct parser_params { https://github.com/ruby/ruby/blob/trunk/parse.y#L298
 #endif
 };
 
-#define new_tmpbuf() \
-    (rb_imemo_tmpbuf_t *)add_tmpbuf_mark_object(p, rb_imemo_tmpbuf_auto_free_pointer(NULL))
-
 #define intern_cstr(n,l,en) rb_intern3(n,l,en)
 
 #define STR_NEW(ptr,len) rb_enc_str_new((ptr),(len),p->enc)
@@ -337,13 +334,6 @@ rb_discard_node(struct parser_params *p, NODE *n) https://github.com/ruby/ruby/blob/trunk/parse.y#L334
 {
     rb_ast_delete_node(p->ast, n);
 }
-
-static inline VALUE
-add_tmpbuf_mark_object(struct parser_params *p, VALUE obj)
-{
-    rb_ast_add_mark_object(p->ast, obj);
-    return obj;
-}
 #endif
 
 static inline VALUE
@@ -2797,10 +2787,11 @@ primary		: literal https://github.com/ruby/ruby/blob/trunk/parse.y#L2787
 			ID id = internal_id(p);
 			NODE *m = NEW_ARGS_AUX(0, 0, &NULL_LOC);
 			NODE *args, *scope, *internal_var = NEW_DVAR(id, &@2);
-			ID *tbl = ALLOC_N(ID, 2);
+			ID *tbl = ALLOC_N(ID, 3);
 			VALUE tmpbuf = rb_imemo_tmpbuf_auto_free_pointer(tbl);
                         RB_OBJ_WRITTEN(p->ast, Qnil, tmpbuf);
 			tbl[0] = 1 /* length of local var table */; tbl[1] = id /* internal id */;
+                        tbl[2] = tmpbuf;
 
 			switch (nd_type($2)) {
 			  case NODE_LASGN:
@@ -2821,7 +2812,6 @@ primary		: literal https://github.com/ruby/ruby/blob/trunk/parse.y#L2812
 			args = new_args(p, m, 0, id, 0, new_args_tail(p, 0, 0, 0, &@2), &@2);
 			scope = NEW_NODE(NODE_SCOPE, tbl, $5, args, &@$);
 			$$ = NEW_FOR($4, scope, &@$);
-                        $$->nd_lit = tmpbuf;
 			fixpos($$, $2);
 		    /*% %*/
 		    /*% ripper: for!($2, $4, $5) %*/
@@ -11635,11 +11625,9 @@ local_tbl(struct parser_params *p) https://github.com/ruby/ruby/blob/trunk/parse.y#L11625
     int cnt = cnt_args + cnt_vars;
     int i, j;
     ID *buf;
-    rb_imemo_tmpbuf_t *tmpbuf = new_tmpbuf();
 
     if (cnt <= 0) return 0;
-    buf = ALLOC_N(ID, cnt + 1);
-    tmpbuf->ptr = (void *)buf;
+    buf = ALLOC_N(ID, cnt + 2);
     MEMCPY(buf+1, p->lvtbl->args->tbl, ID, cnt_args);
     /* remove IDs duplicated to warn shadowing */
     for (i = 0, j = cnt_args+1; i < cnt_vars; ++i) {
@@ -11648,9 +11636,13 @@ local_tbl(struct parser_params *p) https://github.com/ruby/ruby/blob/trunk/parse.y#L11636
 	    buf[j++] = id;
 	}
     }
-    if (--j < cnt) tmpbuf->ptr = (void *)REALLOC_N(buf, ID, (cnt = j) + 1);
+    if (--j < cnt) REALLOC_N(buf, ID, (cnt = j) + 2);
     buf[0] = cnt;
 
+    VALUE tmpbuf = rb_imemo_tmpbuf_auto_free_pointer(buf);
+    buf[cnt + 1] = (ID)tmpbuf;
+    RB_OBJ_WRITTEN(p->ast, Qnil, tmpbuf);
+
     return buf;
 }
 #endif
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]