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

ruby-changes:57326

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Tue, 27 Aug 2019 18:58:45 +0900 (JST)
Subject: [ruby-changes:57326] 卜部昌平: b8fd2e83e7 (master): decouple compile.c usage of imemo_ifunc

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

From b8fd2e83e7b18fe3c70fc342388b1cb054b22e42 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?=
 <shyouhei@r...>
Date: Mon, 26 Aug 2019 14:25:53 +0900
Subject: decouple compile.c usage of imemo_ifunc

After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is
dangerous and should be extinct.  This commit deletes ANYARGS from
struct vm_ifunc, but in doing so we also have to decouple the usage
of this struct in compile.c, which (I think) is an abuse of ANYARGS.

diff --git a/compile.c b/compile.c
index 008dfc8..29965df 100644
--- a/compile.c
+++ b/compile.c
@@ -615,7 +615,7 @@ validate_labels(rb_iseq_t *iseq, st_table *labels_table) https://github.com/ruby/ruby/blob/trunk/compile.c#L615
 }
 
 VALUE
-rb_iseq_compile_ifunc(rb_iseq_t *iseq, const struct vm_ifunc *ifunc)
+rb_iseq_compile_callback(rb_iseq_t *iseq, const struct rb_iseq_new_with_callback_callback_func * ifunc)
 {
     DECL_ANCHOR(ret);
     INIT_ANCHOR(ret);
@@ -1206,16 +1206,16 @@ new_child_iseq(rb_iseq_t *iseq, const NODE *const node, https://github.com/ruby/ruby/blob/trunk/compile.c#L1206
 }
 
 static rb_iseq_t *
-new_child_iseq_ifunc(rb_iseq_t *iseq, const struct vm_ifunc *ifunc,
+new_child_iseq_with_callback(rb_iseq_t *iseq, const struct rb_iseq_new_with_callback_callback_func *ifunc,
 		     VALUE name, const rb_iseq_t *parent, enum iseq_type type, int line_no)
 {
     rb_iseq_t *ret_iseq;
 
-    debugs("[new_child_iseq_ifunc]> ---------------------------------------\n");
-    ret_iseq = rb_iseq_new_ifunc(ifunc, name,
+    debugs("[new_child_iseq_with_callback]> ---------------------------------------\n");
+    ret_iseq = rb_iseq_new_with_callback(ifunc, name,
 				 rb_iseq_path(iseq), rb_iseq_realpath(iseq),
 				 INT2FIX(line_no), parent, type, ISEQ_COMPILE_DATA(iseq)->option);
-    debugs("[new_child_iseq_ifunc]< ---------------------------------------\n");
+    debugs("[new_child_iseq_with_callback]< ---------------------------------------\n");
     iseq_add_mark_object_compile_time(iseq, (VALUE)ret_iseq);
     return ret_iseq;
 }
@@ -4629,12 +4629,11 @@ defined_expr0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, https://github.com/ruby/ruby/blob/trunk/compile.c#L4629
     }
 }
 
-static VALUE
-build_defined_rescue_iseq(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *unused)
+static void
+build_defined_rescue_iseq(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const void *unused)
 {
     ADD_INSN(ret, 0, putnil);
     iseq_set_exception_local_table(iseq);
-    return Qnil;
 }
 
 static void
@@ -4648,7 +4647,9 @@ defined_expr(rb_iseq_t *iseq, LINK_ANCHOR *const ret, https://github.com/ruby/ruby/blob/trunk/compile.c#L4647
 	LABEL *lstart = NEW_LABEL(line);
 	LABEL *lend = NEW_LABEL(line);
 	const rb_iseq_t *rescue;
-	rescue = new_child_iseq_ifunc(iseq, IFUNC_NEW(build_defined_rescue_iseq, 0, 0),
+        struct rb_iseq_new_with_callback_callback_func *ifunc =
+            rb_iseq_new_with_callback_new_callback(build_defined_rescue_iseq, NULL);
+        rescue = new_child_iseq_with_callback(iseq, ifunc,
 				      rb_str_concat(rb_str_new2("defined guard in "),
 						    iseq->body->location.label),
 				      iseq, ISEQ_TYPE_RESCUE, 0);
@@ -4871,9 +4872,10 @@ setup_args(rb_iseq_t *iseq, LINK_ANCHOR *const args, const NODE *argn, https://github.com/ruby/ruby/blob/trunk/compile.c#L4872
     return ret;
 }
 
-static VALUE
-build_postexe_iseq(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *body)
+static void
+build_postexe_iseq(rb_iseq_t *iseq, LINK_ANCHOR *ret, const void *ptr)
 {
+    const NODE *body = ptr;
     int line = nd_line(body);
     VALUE argc = INT2FIX(0);
     const rb_iseq_t *block = NEW_CHILD_ISEQ(body, make_name_for_block(iseq->body->parent_iseq), ISEQ_TYPE_BLOCK, line);
@@ -4881,7 +4883,6 @@ build_postexe_iseq(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *body) https://github.com/ruby/ruby/blob/trunk/compile.c#L4883
     ADD_INSN1(ret, line, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
     ADD_CALL_WITH_BLOCK(ret, line, id_core_set_postexe, argc, block);
     iseq_set_local_table(iseq, 0);
-    return Qnil;
 }
 
 static void
@@ -8008,8 +8009,10 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in https://github.com/ruby/ruby/blob/trunk/compile.c#L8009
 	 *   ONCE{ rb_mRubyVMFrozenCore::core#set_postexe{ ... } }
 	 */
 	int is_index = body->is_size++;
+        struct rb_iseq_new_with_callback_callback_func *ifunc =
+            rb_iseq_new_with_callback_new_callback(build_postexe_iseq, node->nd_body);
 	const rb_iseq_t *once_iseq =
-	    new_child_iseq_ifunc(iseq, IFUNC_NEW(build_postexe_iseq, node->nd_body, 0),
+            new_child_iseq_with_callback(iseq, ifunc,
 				 rb_fstring(make_name_for_block(iseq)), iseq, ISEQ_TYPE_BLOCK, line);
 
 	ADD_INSN2(ret, line, once, once_iseq, INT2FIX(is_index));
@@ -8978,7 +8981,7 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/compile.c#L8981
 
 static const rb_iseq_t *
 method_for_self(VALUE name, VALUE arg, rb_insn_func_t func,
-		VALUE (*build)(rb_iseq_t *, LINK_ANCHOR *const, VALUE))
+                void (*build)(rb_iseq_t *, LINK_ANCHOR *, const void *))
 {
     VALUE path, realpath;
     accessor_args acc;
@@ -8986,13 +8989,15 @@ method_for_self(VALUE name, VALUE arg, rb_insn_func_t func, https://github.com/ruby/ruby/blob/trunk/compile.c#L8989
     acc.arg = arg;
     acc.func = func;
     acc.line = caller_location(&path, &realpath);
-    return rb_iseq_new_ifunc(IFUNC_NEW(build, (VALUE)&acc, 0),
+    struct rb_iseq_new_with_callback_callback_func *ifunc =
+        rb_iseq_new_with_callback_new_callback(build, &acc);
+    return rb_iseq_new_with_callback(ifunc,
 			     rb_sym2str(name), path, realpath,
 			     INT2FIX(acc.line), 0, ISEQ_TYPE_METHOD, 0);
 }
 
-static VALUE
-for_self_aref(rb_iseq_t *iseq, LINK_ANCHOR *const ret, VALUE a)
+static void
+for_self_aref(rb_iseq_t *iseq, LINK_ANCHOR *ret, const void *a)
 {
     const accessor_args *const args = (void *)a;
     const int line = args->line;
@@ -9004,11 +9009,10 @@ for_self_aref(rb_iseq_t *iseq, LINK_ANCHOR *const ret, VALUE a) https://github.com/ruby/ruby/blob/trunk/compile.c#L9009
 
     ADD_INSN1(ret, line, putobject, args->arg);
     ADD_INSN1(ret, line, opt_call_c_function, (VALUE)args->func);
-    return Qnil;
 }
 
-static VALUE
-for_self_aset(rb_iseq_t *iseq, LINK_ANCHOR *const ret, VALUE a)
+static void
+for_self_aset(rb_iseq_t *iseq, LINK_ANCHOR *ret, const void *a)
 {
     const accessor_args *const args = (void *)a;
     const int line = args->line;
@@ -9023,7 +9027,6 @@ for_self_aset(rb_iseq_t *iseq, LINK_ANCHOR *const ret, VALUE a) https://github.com/ruby/ruby/blob/trunk/compile.c#L9027
     ADD_INSN1(ret, line, putobject, args->arg);
     ADD_INSN1(ret, line, opt_call_c_function, (VALUE)args->func);
     ADD_INSN(ret, line, pop);
-    return Qnil;
 }
 
 /*
diff --git a/internal.h b/internal.h
index d6b762a..01009b6 100644
--- a/internal.h
+++ b/internal.h
@@ -1181,15 +1181,15 @@ struct vm_ifunc_argc { https://github.com/ruby/ruby/blob/trunk/internal.h#L1181
 struct vm_ifunc {
     VALUE flags;
     VALUE reserved;
-    VALUE (*func)(ANYARGS);
+    rb_block_call_func_t func;
     const void *data;
     struct vm_ifunc_argc argc;
 };
 
 #define IFUNC_NEW(a, b, c) ((struct vm_ifunc *)rb_imemo_new(imemo_ifunc, (VALUE)(a), (VALUE)(b), (VALUE)(c), 0))
-struct vm_ifunc *rb_vm_ifunc_new(VALUE (*func)(ANYARGS), const void *data, int min_argc, int max_argc);
+struct vm_ifunc *rb_vm_ifunc_new(rb_block_call_func_t func, const void *data, int min_argc, int max_argc);
 static inline struct vm_ifunc *
-rb_vm_ifunc_proc_new(VALUE (*func)(ANYARGS), const void *data)
+rb_vm_ifunc_proc_new(rb_block_call_func_t func, const void *data)
 {
     return rb_vm_ifunc_new(func, data, 0, UNLIMITED_ARGUMENTS);
 }
diff --git a/iseq.c b/iseq.c
index 86ef5cd..9154001 100644
--- a/iseq.c
+++ b/iseq.c
@@ -809,9 +809,11 @@ rb_iseq_new_with_opt(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE rea https://github.com/ruby/ruby/blob/trunk/iseq.c#L809
 }
 
 rb_iseq_t *
-rb_iseq_new_ifunc(const struct vm_ifunc *ifunc, VALUE name, VALUE path, VALUE realpath,
-		       VALUE first_lineno, const rb_iseq_t *parent,
-		       enum iseq_type type, const rb_compile_option_t *option)
+rb_iseq_new_with_callback(
+    const struct rb_iseq_new_with_callback_callback_func * ifunc,
+    VALUE name, VALUE path, VALUE realpath,
+    VALUE first_lineno, const rb_iseq_t *parent,
+    enum iseq_type type, const rb_compile_option_t *option)
 {
     /* TODO: argument check */
     rb_iseq_t *iseq = iseq_alloc();
@@ -819,7 +821,7 @@ rb_iseq_new_ifunc(const struct vm_ifunc *ifunc, VALUE name, VALUE path, VALUE re https://github.com/ruby/ruby/blob/trunk/iseq.c#L821
     if (!option) option = &COMPILE_OPTION_DEFAULT;
     prepare_iseq_build(iseq, name, path, realpath, first_lineno, NULL, -1, parent, type, option);
 
-    rb_iseq_compile_ifunc(iseq, ifunc);
+    rb_iseq_compile_callback(iseq, ifunc);
     finish_iseq_build(iseq);
 
     return iseq_translate(iseq);
diff --git a/iseq.h b/iseq.h
index 0326577..13cbd90 100644
--- a/iseq.h
+++ b/iseq.h
@@ -162,7 +162,7 @@ RUBY_SYMBOL_EXPORT_BEGIN https://github.com/ruby/ruby/blob/trunk/iseq.h#L162
 
 /* compile.c */
 VALUE rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node);
-VALUE rb_iseq_compile_ifunc(rb_iseq_t *iseq, const struct vm_ifunc *ifunc);
+VALUE rb_iseq_compile_callback(rb_iseq_t *iseq, const struct rb_iseq_new_with_callback_callback_func * ifunc);
 int rb_iseq_translate_threaded_code(rb_iseq_t *iseq);
 VALUE *rb_iseq_original_iseq(const rb_iseq_t *iseq);
 void rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE misc,
diff --git a/proc.c b/proc.c
index 810fe79..1c0a5df 100644
--- a/proc.c
+++ b/proc.c
@@ -43,7 +43,7 @@ VALUE rb_cMethod; https://github.com/ruby/ruby/blob/trunk/proc.c#L43
 VALUE rb_cBinding;
 VALUE rb_cProc;
 
-static VALUE bmcall(VALUE, VALUE, int, VALUE *, VALUE);
+static rb_block_call_f (... truncated)

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

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