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

ruby-changes:61736

From: Nobuyoshi <ko1@a...>
Date: Tue, 16 Jun 2020 18:59:41 +0900 (JST)
Subject: [ruby-changes:61736] 318d52e820 (master): Revert "Replaced accessors of `Struct` with `invokebuiltin`"

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

From 318d52e820c9ed1bc4c12aa97af49a89953649bc Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Tue, 16 Jun 2020 18:44:58 +0900
Subject: Revert "Replaced accessors of `Struct` with `invokebuiltin`"

This reverts commit 19cabe8b09d92d033c244f32ff622b8e513375f1,
which didn't support tool/lib/iseq_loader_checker.rb.

diff --git a/common.mk b/common.mk
index 6353b24..937d6bf 100644
--- a/common.mk
+++ b/common.mk
@@ -13168,7 +13168,6 @@ struct.$(OBJEXT): {$(VPATH)}backward/2/r_cast.h https://github.com/ruby/ruby/blob/trunk/common.mk#L13168
 struct.$(OBJEXT): {$(VPATH)}backward/2/rmodule.h
 struct.$(OBJEXT): {$(VPATH)}backward/2/stdalign.h
 struct.$(OBJEXT): {$(VPATH)}backward/2/stdarg.h
-struct.$(OBJEXT): {$(VPATH)}builtin.h
 struct.$(OBJEXT): {$(VPATH)}config.h
 struct.$(OBJEXT): {$(VPATH)}defines.h
 struct.$(OBJEXT): {$(VPATH)}encoding.h
diff --git a/compile.c b/compile.c
index f522954..9fba24f 100644
--- a/compile.c
+++ b/compile.c
@@ -9681,19 +9681,19 @@ caller_location(VALUE *path, VALUE *realpath) https://github.com/ruby/ruby/blob/trunk/compile.c#L9681
 
 typedef struct {
     VALUE arg;
-    VALUE func;
+    rb_insn_func_t func;
     int line;
 } accessor_args;
 
 static const rb_iseq_t *
-method_for_self(VALUE name, VALUE arg, const struct rb_builtin_function *func,
+method_for_self(VALUE name, VALUE arg, rb_insn_func_t func,
                 void (*build)(rb_iseq_t *, LINK_ANCHOR *, const void *))
 {
     VALUE path, realpath;
     accessor_args acc;
 
     acc.arg = arg;
-    acc.func = (VALUE)func;
+    acc.func = func;
     acc.line = caller_location(&path, &realpath);
     struct rb_iseq_new_with_callback_callback_func *ifunc =
         rb_iseq_new_with_callback_new_callback(build, &acc);
@@ -9714,7 +9714,7 @@ for_self_aref(rb_iseq_t *iseq, LINK_ANCHOR *ret, const void *a) https://github.com/ruby/ruby/blob/trunk/compile.c#L9714
     body->param.size = 0;
 
     ADD_INSN1(ret, line, putobject, args->arg);
-    ADD_INSN1(ret, line, invokebuiltin, args->func);
+    ADD_INSN1(ret, line, opt_call_c_function, (VALUE)args->func);
 }
 
 static void
@@ -9731,23 +9731,24 @@ for_self_aset(rb_iseq_t *iseq, LINK_ANCHOR *ret, const void *a) https://github.com/ruby/ruby/blob/trunk/compile.c#L9731
 
     ADD_GETLOCAL(ret, line, numberof(vars)-1, 0);
     ADD_INSN1(ret, line, putobject, args->arg);
-    ADD_INSN1(ret, line, invokebuiltin, args->func);
+    ADD_INSN1(ret, line, opt_call_c_function, (VALUE)args->func);
+    ADD_INSN(ret, line, pop);
 }
 
 /*
  * func (index) -> (value)
  */
 const rb_iseq_t *
-rb_method_for_self_aref(VALUE name, VALUE arg, const struct rb_builtin_function *func)
+rb_method_for_self_aref(VALUE name, VALUE arg, rb_insn_func_t func)
 {
     return method_for_self(name, arg, func, for_self_aref);
 }
 
 /*
- * func (index, value) -> (value)
+ * func (index, value) -> (index, value)
  */
 const rb_iseq_t *
-rb_method_for_self_aset(VALUE name, VALUE arg, const struct rb_builtin_function *func)
+rb_method_for_self_aset(VALUE name, VALUE arg, rb_insn_func_t func)
 {
     return method_for_self(name, arg, func, for_self_aset);
 }
diff --git a/struct.c b/struct.c
index 41349f7..be742fb 100644
--- a/struct.c
+++ b/struct.c
@@ -20,7 +20,6 @@ https://github.com/ruby/ruby/blob/trunk/struct.c#L20
 #include "internal/symbol.h"
 #include "transient_heap.h"
 #include "vm_core.h"
-#include "builtin.h"
 
 /* only for struct[:field] access */
 enum {
@@ -28,8 +27,8 @@ enum { https://github.com/ruby/ruby/blob/trunk/struct.c#L27
     AREF_HASH_THRESHOLD = 10
 };
 
-const rb_iseq_t *rb_method_for_self_aref(VALUE name, VALUE arg, const struct rb_builtin_function *func);
-const rb_iseq_t *rb_method_for_self_aset(VALUE name, VALUE arg, const struct rb_builtin_function *func);
+const rb_iseq_t *rb_method_for_self_aref(VALUE name, VALUE arg, rb_insn_func_t func);
+const rb_iseq_t *rb_method_for_self_aset(VALUE name, VALUE arg, rb_insn_func_t func);
 
 VALUE rb_cStruct;
 static ID id_members, id_back_members, id_keyword_init;
@@ -289,41 +288,11 @@ new_struct(VALUE name, VALUE super) https://github.com/ruby/ruby/blob/trunk/struct.c#L288
     return rb_define_class_id_under(super, id, super);
 }
 
-NORETURN(static void invalid_struct_pos(VALUE s, VALUE idx));
-
-static inline long
-struct_pos_num(VALUE s, VALUE idx)
-{
-    long i = NUM2INT(idx);
-    if (i < 0 || i >= RSTRUCT_LEN(s)) invalid_struct_pos(s, idx);
-    return i;
-}
-
-static VALUE
-opt_struct_aref(rb_execution_context_t *ec, VALUE self, VALUE idx)
-{
-    long i = struct_pos_num(self, idx);
-    return RSTRUCT_GET(self, i);
-}
-
-static VALUE
-opt_struct_aset(rb_execution_context_t *ec, VALUE self, VALUE val, VALUE idx)
-{
-    long i = struct_pos_num(self, idx);
-    rb_struct_modify(self);
-    RSTRUCT_SET(self, i, val);
-    return val;
-}
-
-static const struct rb_builtin_function struct_aref_builtin =
-    RB_BUILTIN_FUNCTION(0, struct_aref, opt_struct_aref, 1);
-static const struct rb_builtin_function struct_aset_builtin =
-    RB_BUILTIN_FUNCTION(1, struct_aref, opt_struct_aset, 2);
-
 static void
 define_aref_method(VALUE nstr, VALUE name, VALUE off)
 {
-    const rb_iseq_t *iseq = rb_method_for_self_aref(name, off, &struct_aref_builtin);
+    rb_control_frame_t *FUNC_FASTCALL(rb_vm_opt_struct_aref)(rb_execution_context_t *, rb_control_frame_t *);
+    const rb_iseq_t *iseq = rb_method_for_self_aref(name, off, rb_vm_opt_struct_aref);
 
     rb_add_method_iseq(nstr, SYM2ID(name), iseq, NULL, METHOD_VISI_PUBLIC);
 }
@@ -331,7 +300,8 @@ define_aref_method(VALUE nstr, VALUE name, VALUE off) https://github.com/ruby/ruby/blob/trunk/struct.c#L300
 static void
 define_aset_method(VALUE nstr, VALUE name, VALUE off)
 {
-    const rb_iseq_t *iseq = rb_method_for_self_aset(name, off, &struct_aset_builtin);
+    rb_control_frame_t *FUNC_FASTCALL(rb_vm_opt_struct_aset)(rb_execution_context_t *, rb_control_frame_t *);
+    const rb_iseq_t *iseq = rb_method_for_self_aset(name, off, rb_vm_opt_struct_aset);
 
     rb_add_method_iseq(nstr, SYM2ID(name), iseq, NULL, METHOD_VISI_PUBLIC);
 }
@@ -1053,6 +1023,7 @@ rb_struct_pos(VALUE s, VALUE *name) https://github.com/ruby/ruby/blob/trunk/struct.c#L1023
     }
 }
 
+NORETURN(static void invalid_struct_pos(VALUE s, VALUE idx));
 static void
 invalid_struct_pos(VALUE s, VALUE idx)
 {
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 8f1b6e7..611739e 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -3621,6 +3621,20 @@ vm_once_clear(VALUE data) https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L3621
     return Qnil;
 }
 
+rb_control_frame_t *
+FUNC_FASTCALL(rb_vm_opt_struct_aref)(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp)
+{
+    TOPN(0) = rb_struct_aref(GET_SELF(), TOPN(0));
+    return reg_cfp;
+}
+
+rb_control_frame_t *
+FUNC_FASTCALL(rb_vm_opt_struct_aset)(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp)
+{
+    rb_struct_aset(GET_SELF(), TOPN(0), TOPN(1));
+    return reg_cfp;
+}
+
 /* defined insn */
 
 static enum defined_type
-- 
cgit v0.10.2


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

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