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

ruby-changes:48525

From: mame <ko1@a...>
Date: Sat, 4 Nov 2017 19:02:49 +0900 (JST)
Subject: [ruby-changes:48525] mame:r60640 (trunk): Remove NODE-related pieces of code from GC

mame	2017-11-04 19:02:43 +0900 (Sat, 04 Nov 2017)

  New Revision: 60640

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60640

  Log:
    Remove NODE-related pieces of code from GC

  Modified files:
    trunk/gc.c
    trunk/node.c
    trunk/node.h
Index: gc.c
===================================================================
--- gc.c	(revision 60639)
+++ gc.c	(revision 60640)
@@ -420,7 +420,6 @@ typedef struct RVALUE { https://github.com/ruby/ruby/blob/trunk/gc.c#L420
 	struct RStruct rstruct;
 	struct RBignum bignum;
 	struct RFile   file;
-	struct RNode   node;
 	struct RMatch  match;
 	struct RRational rational;
 	struct RComplex complex;
@@ -2001,14 +2000,6 @@ rb_newobj_of(VALUE klass, VALUE flags) https://github.com/ruby/ruby/blob/trunk/gc.c#L2000
     return newobj_of(klass, flags & ~FL_WB_PROTECTED, 0, 0, 0, flags & FL_WB_PROTECTED);
 }
 
-NODE*
-rb_node_newnode(enum node_type type, VALUE a0, VALUE a1, VALUE a2)
-{
-    NODE *n = (NODE *)newobj_of(0, T_NODE, a0, a1, a2, FALSE); /* TODO: node also should be wb protected */
-    nd_set_type(n, type);
-    return n;
-}
-
 #undef rb_imemo_new
 
 VALUE
@@ -2329,8 +2320,9 @@ obj_free(rb_objspace_t *objspace, VALUE https://github.com/ruby/ruby/blob/trunk/gc.c#L2320
 	break;
 
       case T_NODE:
-	rb_gc_free_node(obj);
-	break;			/* no need to free iv_tbl */
+	rb_bug("obj_free(): GC does not handle T_NODE 0x%x(%p) 0x%"PRIxVALUE,
+	       BUILTIN_TYPE(obj), (void*)obj, RBASIC(obj)->flags);
+	break;
 
       case T_STRUCT:
 	if ((RBASIC(obj)->flags & RSTRUCT_EMBED_LEN_MASK) == 0 &&
@@ -2533,10 +2525,13 @@ internal_object_p(VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L2525
 
     if (p->as.basic.flags) {
 	switch (BUILTIN_TYPE(p)) {
+	  case T_NODE:
+	      rb_bug("internal_object_p(): GC does not handle T_NODE 0x%x(%p) 0x%"PRIxVALUE,
+		      BUILTIN_TYPE(obj), (void*)obj, RBASIC(obj)->flags);
+	      break;
 	  case T_NONE:
 	  case T_IMEMO:
 	  case T_ICLASS:
-	  case T_NODE:
 	  case T_ZOMBIE:
 	    break;
 	  case T_CLASS:
@@ -3307,7 +3302,8 @@ obj_memsize_of(VALUE obj, int use_all_ty https://github.com/ruby/ruby/blob/trunk/gc.c#L3302
 	break;
 
       case T_NODE:
-	if (use_all_types) size += rb_node_memsize(obj);
+	rb_bug("obj_memsize_of(): GC does not handle T_NODE 0x%x(%p) 0x%"PRIxVALUE,
+		BUILTIN_TYPE(obj), (void*)obj, RBASIC(obj)->flags);
 	break;
 
       case T_STRUCT:
@@ -3449,7 +3445,6 @@ count_objects(int argc, VALUE *argv, VAL https://github.com/ruby/ruby/blob/trunk/gc.c#L3445
 	    COUNT_TYPE(T_FIXNUM);
 	    COUNT_TYPE(T_IMEMO);
 	    COUNT_TYPE(T_UNDEF);
-	    COUNT_TYPE(T_NODE);
 	    COUNT_TYPE(T_ICLASS);
 	    COUNT_TYPE(T_ZOMBIE);
 #undef COUNT_TYPE
@@ -4573,9 +4568,9 @@ gc_mark_children(rb_objspace_t *objspace https://github.com/ruby/ruby/blob/trunk/gc.c#L4568
 	break;
 
       case T_NODE:
-	obj = rb_gc_mark_node(&any->as.node);
-	if (obj) gc_mark(objspace, obj);
-	return;			/* no need to mark class. */
+	rb_bug("rb_gc_mark(): GC does not handle T_NODE 0x%x(%p) 0x%"PRIxVALUE,
+		BUILTIN_TYPE(obj), (void*)obj, RBASIC(obj)->flags);
+	break;
 
       case T_IMEMO:
 	gc_mark_imemo(objspace, obj);
@@ -9228,7 +9223,6 @@ type_name(int type, VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L9223
 	    TYPE_NAME(T_FIXNUM);
 	    TYPE_NAME(T_UNDEF);
 	    TYPE_NAME(T_IMEMO);
-	    TYPE_NAME(T_NODE);
 	    TYPE_NAME(T_ICLASS);
 	    TYPE_NAME(T_ZOMBIE);
       case T_DATA:
@@ -9333,8 +9327,8 @@ rb_raw_obj_info(char *buff, const int bu https://github.com/ruby/ruby/blob/trunk/gc.c#L9327
 
 	switch (type) {
 	  case T_NODE:
-	    snprintf(buff, buff_size, "%s (%s)", buff,
-		     ruby_node_name(nd_type(obj)));
+	    rb_bug("rb_raw_obj_info(): GC does not handle T_NODE 0x%x(%p) 0x%"PRIxVALUE,
+		    BUILTIN_TYPE(obj), (void*)obj, RBASIC(obj)->flags);
 	    break;
 	  case T_ARRAY:
 	    snprintf(buff, buff_size, "%s [%s%s] len: %d", buff,
Index: node.c
===================================================================
--- node.c	(revision 60639)
+++ node.c	(revision 60640)
@@ -1048,179 +1048,23 @@ rb_parser_dump_tree(NODE *node, int comm https://github.com/ruby/ruby/blob/trunk/node.c#L1048
     return buf;
 }
 
-void
-rb_gc_free_node(VALUE obj)
-{
-    switch (nd_type(obj)) {
-      case NODE_SCOPE:
-	if (RNODE(obj)->nd_tbl) {
-	    xfree(RNODE(obj)->nd_tbl);
-	}
-	break;
-      case NODE_ARGS:
-	if (RNODE(obj)->nd_ainfo) {
-	    xfree(RNODE(obj)->nd_ainfo);
-	}
-	break;
-    }
-}
-
+/* Setup NODE strucutre.
+ * 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)`.
+ * This dirty hack is needed because Ripper jumbles NODEs and other type
+ * objects.
+ */
 void
 rb_node_init(NODE *n, enum node_type type, VALUE a0, VALUE a1, VALUE a2)
 {
-    VALUE klass = 0;
     n->flags = T_NODE;
-    RBASIC_SET_CLASS_RAW((VALUE)n, klass);
+    n->nd_location = 0;
     n->u1.value = a0;
     n->u2.value = a1;
     n->u3.value = a2;
     nd_set_type(n, type);
 }
 
-size_t
-rb_node_memsize(VALUE obj)
-{
-    size_t size = 0;
-    switch (nd_type(obj)) {
-      case NODE_SCOPE:
-	if (RNODE(obj)->nd_tbl) {
-	    size += (RNODE(obj)->nd_tbl[0]+1) * sizeof(*RNODE(obj)->nd_tbl);
-	}
-	break;
-      case NODE_ARGS:
-	if (RNODE(obj)->nd_ainfo) {
-	    size += sizeof(*RNODE(obj)->nd_ainfo);
-	}
-	break;
-    }
-    return size;
-}
-
-VALUE
-rb_gc_mark_node(NODE *obj)
-{
-    switch (nd_type(obj)) {
-      case NODE_IF:		/* 1,2,3 */
-      case NODE_FOR:
-      case NODE_ITER:
-      case NODE_WHEN:
-      case NODE_MASGN:
-      case NODE_RESCUE:
-      case NODE_RESBODY:
-      case NODE_CLASS:
-      case NODE_MATCH2:
-	rb_gc_mark(RNODE(obj)->u2.value);
-	/* fall through */
-      case NODE_BLOCK:	/* 1,3 */
-      case NODE_ARRAY:
-      case NODE_DSTR:
-      case NODE_DXSTR:
-      case NODE_DREGX:
-      case NODE_ENSURE:
-      case NODE_CALL:
-      case NODE_DEFS:
-      case NODE_OP_ASGN1:
-	rb_gc_mark(RNODE(obj)->u1.value);
-	/* fall through */
-      case NODE_SUPER:	/* 3 */
-      case NODE_FCALL:
-      case NODE_DEFN:
-      case NODE_ARGS_AUX:
-	return RNODE(obj)->u3.value;
-
-      case NODE_WHILE:	/* 1,2 */
-      case NODE_UNTIL:
-      case NODE_AND:
-      case NODE_OR:
-      case NODE_CASE:
-      case NODE_CASE2:
-      case NODE_SCLASS:
-      case NODE_DOT2:
-      case NODE_DOT3:
-      case NODE_FLIP2:
-      case NODE_FLIP3:
-      case NODE_MATCH3:
-      case NODE_OP_ASGN_OR:
-      case NODE_OP_ASGN_AND:
-      case NODE_MODULE:
-      case NODE_ALIAS:
-      case NODE_VALIAS:
-      case NODE_ARGSCAT:
-      case NODE_BLOCK_PASS:
-	rb_gc_mark(RNODE(obj)->u1.value);
-	/* fall through */
-      case NODE_GASGN:	/* 2 */
-      case NODE_LASGN:
-      case NODE_DASGN:
-      case NODE_DASGN_CURR:
-      case NODE_IASGN:
-      case NODE_CVASGN:
-      case NODE_COLON3:
-      case NODE_EVSTR:
-      case NODE_UNDEF:
-      case NODE_POSTEXE:
-	return RNODE(obj)->u2.value;
-
-      case NODE_HASH:	/* 1 */
-      case NODE_LIT:
-      case NODE_STR:
-      case NODE_XSTR:
-      case NODE_DEFINED:
-      case NODE_MATCH:
-      case NODE_RETURN:
-      case NODE_BREAK:
-      case NODE_NEXT:
-      case NODE_YIELD:
-      case NODE_COLON2:
-      case NODE_SPLAT:
-	return RNODE(obj)->u1.value;
-
-      case NODE_SCOPE:	/* 2,3 */
-      case NODE_CDECL:
-      case NODE_OPT_ARG:
-	rb_gc_mark(RNODE(obj)->u3.value);
-	return RNODE(obj)->u2.value;
-
-      case NODE_ARGS:	/* custom */
-	{
-	    struct rb_args_info *args = obj->u3.args;
-	    if (args) {
-		if (args->pre_init)    rb_gc_mark((VALUE)args->pre_init);
-		if (args->post_init)   rb_gc_mark((VALUE)args->post_init);
-		if (args->opt_args)    rb_gc_mark((VALUE)args->opt_args);
-		if (args->kw_args)     rb_gc_mark((VALUE)args->kw_args);
-		if (args->kw_rest_arg) rb_gc_mark((VALUE)args->kw_rest_arg);
-	    }
-	}
-	return RNODE(obj)->u2.value;
-
-      case NODE_ZARRAY:	/* - */
-      case NODE_ZSUPER:
-      case NODE_VCALL:
-      case NODE_GVAR:
-      case NODE_LVAR:
-      case NODE_DVAR:
-      case NODE_IVAR:
-      case NODE_CVAR:
-      case NODE_NTH_REF:
-      case NODE_BACK_REF:
-      case NODE_REDO:
-      case NODE_RETRY:
-      case NODE_SELF:
-      case NODE_NIL:
-      case NODE_TRUE:
-      case NODE_FALSE:
-      case NODE_ERRINFO:
-	break;
-
-      default:		/* unlisted NODE */
-	rb_gc_mark_maybe(RNODE(obj)->u1.value);
-	rb_gc_mark_maybe(RNODE(obj)->u2.value);
-	rb_gc_mark_maybe(RNODE(obj)->u3.value);
-    }
-    return 0;
-}
-
 typedef struct node_buffer_elem_struct {
     struct node_buffer_elem_struct *next;
     NODE buf[1]; /* flexible array */
Index: node.h
===================================================================
--- node.h	(revision 60639)
+++ node.h	(revision 60640)
@@ -484,10 +484,6 @@ rb_ast_t *rb_compile_string(const char*, https://github.com/ruby/ruby/blob/trunk/node.h#L484
 rb_ast_t *rb_compile_file(const char*, VALUE, int);
 
 void rb_node_init(NODE *n, enum node_type type, VALUE a0, VALUE a1, VALUE a2);
-NODE *rb_node_newnode(enum node_type,VALUE,VALUE,VALUE);
-void rb_gc_free_node(VALUE obj);
-size_t rb_node_memsize(VALUE obj);
-VALUE rb_gc_mark_node(NODE *obj);
 
 const struct kwtable *rb_reserved_word(const char *, unsigned int);
 

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

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