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

ruby-changes:73288

From: Alan <ko1@a...>
Date: Tue, 30 Aug 2022 01:07:56 +0900 (JST)
Subject: [ruby-changes:73288] 2f9df46654 (master): Use bindgen for old manual extern declarations (https://github.com/Shopify/ruby/pull/404)

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

From 2f9df466546263028ece7757cb6f813800d2d6b5 Mon Sep 17 00:00:00 2001
From: Alan Wu <XrXr@u...>
Date: Mon, 15 Aug 2022 11:25:49 -0400
Subject: Use bindgen for old manual extern declarations
 (https://github.com/Shopify/ruby/pull/404)

We have a large extern block in cruby.rs leftover from the port. We can
use bindgen for it now and reserve the manual declaration for just a
handful of vm_insnhelper.c functions.

Fixup a few minor discrepencies bindgen found between the C declaration
and the manual declaration. Mostly missing `const` on the C side.
---
 yjit.c                         |  60 +++++------
 yjit/bindgen/src/main.rs       |  56 ++++++++++
 yjit/src/codegen.rs            |  10 +-
 yjit/src/cruby.rs              | 231 +++++++++++------------------------------
 yjit/src/cruby_bindings.inc.rs | 187 +++++++++++++++++++++++++++++++++
 5 files changed, 337 insertions(+), 207 deletions(-)

diff --git a/yjit.c b/yjit.c
index 584f909473..70b98d4844 100644
--- a/yjit.c
+++ b/yjit.c
@@ -472,61 +472,61 @@ rb_get_cikw_keywords_idx(const struct rb_callinfo_kwarg *cikw, int idx) https://github.com/ruby/ruby/blob/trunk/yjit.c#L472
 }
 
 rb_method_visibility_t
-rb_METHOD_ENTRY_VISI(rb_callable_method_entry_t *me)
+rb_METHOD_ENTRY_VISI(const rb_callable_method_entry_t *me)
 {
     return METHOD_ENTRY_VISI(me);
 }
 
 rb_method_type_t
-rb_get_cme_def_type(rb_callable_method_entry_t *cme)
+rb_get_cme_def_type(const rb_callable_method_entry_t *cme)
 {
     return cme->def->type;
 }
 
 ID
-rb_get_cme_def_body_attr_id(rb_callable_method_entry_t *cme)
+rb_get_cme_def_body_attr_id(const rb_callable_method_entry_t *cme)
 {
     return cme->def->body.attr.id;
 }
 
 enum method_optimized_type
-rb_get_cme_def_body_optimized_type(rb_callable_method_entry_t *cme)
+rb_get_cme_def_body_optimized_type(const rb_callable_method_entry_t *cme)
 {
     return cme->def->body.optimized.type;
 }
 
 unsigned int
-rb_get_cme_def_body_optimized_index(rb_callable_method_entry_t *cme)
+rb_get_cme_def_body_optimized_index(const rb_callable_method_entry_t *cme)
 {
     return cme->def->body.optimized.index;
 }
 
 rb_method_cfunc_t *
-rb_get_cme_def_body_cfunc(rb_callable_method_entry_t *cme)
+rb_get_cme_def_body_cfunc(const rb_callable_method_entry_t *cme)
 {
     return UNALIGNED_MEMBER_PTR(cme->def, body.cfunc);
 }
 
 uintptr_t
-rb_get_def_method_serial(rb_method_definition_t *def)
+rb_get_def_method_serial(const rb_method_definition_t *def)
 {
     return def->method_serial;
 }
 
 ID
-rb_get_def_original_id(rb_method_definition_t *def)
+rb_get_def_original_id(const rb_method_definition_t *def)
 {
     return def->original_id;
 }
 
 int
-rb_get_mct_argc(rb_method_cfunc_t *mct)
+rb_get_mct_argc(const rb_method_cfunc_t *mct)
 {
     return mct->argc;
 }
 
 void *
-rb_get_mct_func(rb_method_cfunc_t *mct)
+rb_get_mct_func(const rb_method_cfunc_t *mct)
 {
     return (void*)mct->func; // this field is defined as type VALUE (*func)(ANYARGS)
 }
@@ -537,104 +537,104 @@ rb_get_def_iseq_ptr(rb_method_definition_t *def) https://github.com/ruby/ruby/blob/trunk/yjit.c#L537
     return def_iseq_ptr(def);
 }
 
-rb_iseq_t *
-rb_get_iseq_body_local_iseq(rb_iseq_t  *iseq)
+const rb_iseq_t *
+rb_get_iseq_body_local_iseq(const rb_iseq_t *iseq)
 {
     return iseq->body->local_iseq;
 }
 
 unsigned int
-rb_get_iseq_body_local_table_size(rb_iseq_t *iseq)
+rb_get_iseq_body_local_table_size(const rb_iseq_t *iseq)
 {
     return iseq->body->local_table_size;
 }
 
 VALUE *
-rb_get_iseq_body_iseq_encoded(rb_iseq_t *iseq)
+rb_get_iseq_body_iseq_encoded(const rb_iseq_t *iseq)
 {
     return iseq->body->iseq_encoded;
 }
 
 bool
-rb_get_iseq_body_builtin_inline_p(rb_iseq_t *iseq)
+rb_get_iseq_body_builtin_inline_p(const rb_iseq_t *iseq)
 {
     return iseq->body->builtin_inline_p;
 }
 
 unsigned
-rb_get_iseq_body_stack_max(rb_iseq_t *iseq)
+rb_get_iseq_body_stack_max(const rb_iseq_t *iseq)
 {
     return iseq->body->stack_max;
 }
 
 bool
-rb_get_iseq_flags_has_opt(rb_iseq_t *iseq)
+rb_get_iseq_flags_has_opt(const rb_iseq_t *iseq)
 {
     return iseq->body->param.flags.has_opt;
 }
 
 bool
-rb_get_iseq_flags_has_kw(rb_iseq_t *iseq)
+rb_get_iseq_flags_has_kw(const rb_iseq_t *iseq)
 {
     return iseq->body->param.flags.has_kw;
 }
 
 bool
-rb_get_iseq_flags_has_post(rb_iseq_t *iseq)
+rb_get_iseq_flags_has_post(const rb_iseq_t *iseq)
 {
     return iseq->body->param.flags.has_post;
 }
 
 bool
-rb_get_iseq_flags_has_kwrest(rb_iseq_t *iseq)
+rb_get_iseq_flags_has_kwrest(const rb_iseq_t *iseq)
 {
     return iseq->body->param.flags.has_kwrest;
 }
 
 bool
-rb_get_iseq_flags_has_rest(rb_iseq_t *iseq)
+rb_get_iseq_flags_has_rest(const rb_iseq_t *iseq)
 {
     return iseq->body->param.flags.has_rest;
 }
 
 bool
-rb_get_iseq_flags_has_block(rb_iseq_t *iseq)
+rb_get_iseq_flags_has_block(const rb_iseq_t *iseq)
 {
     return iseq->body->param.flags.has_block;
 }
 
 bool
-rb_get_iseq_flags_has_accepts_no_kwarg(rb_iseq_t *iseq)
+rb_get_iseq_flags_has_accepts_no_kwarg(const rb_iseq_t *iseq)
 {
     return iseq->body->param.flags.accepts_no_kwarg;
 }
 
 const rb_seq_param_keyword_struct *
-rb_get_iseq_body_param_keyword(rb_iseq_t *iseq)
+rb_get_iseq_body_param_keyword(const rb_iseq_t *iseq)
 {
     return iseq->body->param.keyword;
 }
 
 unsigned
-rb_get_iseq_body_param_size(rb_iseq_t *iseq)
+rb_get_iseq_body_param_size(const rb_iseq_t *iseq)
 {
     return iseq->body->param.size;
 }
 
 int
-rb_get_iseq_body_param_lead_num(rb_iseq_t *iseq)
+rb_get_iseq_body_param_lead_num(const rb_iseq_t *iseq)
 {
     return iseq->body->param.lead_num;
 }
 
 int
-rb_get_iseq_body_param_opt_num(rb_iseq_t *iseq)
+rb_get_iseq_body_param_opt_num(const rb_iseq_t *iseq)
 {
     return iseq->body->param.opt_num;
 }
 
 const VALUE *
-rb_get_iseq_body_param_opt_table(rb_iseq_t *iseq)
+rb_get_iseq_body_param_opt_table(const rb_iseq_t *iseq)
 {
     return iseq->body->param.opt_table;
 }
@@ -669,7 +669,7 @@ rb_yjit_str_simple_append(VALUE str1, VALUE str2) https://github.com/ruby/ruby/blob/trunk/yjit.c#L669
 }
 
 struct rb_control_frame_struct *
-rb_get_ec_cfp(rb_execution_context_t *ec)
+rb_get_ec_cfp(const rb_execution_context_t *ec)
 {
     return ec->cfp;
 }
@@ -803,7 +803,7 @@ rb_RSTRUCT_SET(VALUE st, int k, VALUE v) https://github.com/ruby/ruby/blob/trunk/yjit.c#L803
 }
 
 const struct rb_callinfo *
-rb_get_call_data_ci(struct rb_call_data *cd)
+rb_get_call_data_ci(const struct rb_call_data *cd)
 {
     return cd->ci;
 }
diff --git a/yjit/bindgen/src/main.rs b/yjit/bindgen/src/main.rs
index f8d87aeec8..a4c0b98504 100644
--- a/yjit/bindgen/src/main.rs
+++ b/yjit/bindgen/src/main.rs
@@ -311,6 +311,62 @@ fn main() { https://github.com/ruby/ruby/blob/trunk/yjit/bindgen/src/main.rs#L311
         // From include/ruby/debug.h
         .allowlist_function("rb_profile_frames")
 
+        // Functions used for code generation
+        .allowlist_function("rb_insn_name")
+        .allowlist_function("rb_insn_len")
+        .allowlist_function("rb_yarv_class_of")
+        .allowlist_function("rb_get_ec_cfp")
+        .allowlist_function("rb_get_cfp_pc")
+        .allowlist_function("rb_get_cfp_sp")
+        .allowlist_function("rb_get_cfp_self")
+        .allowlist_function("rb_get_cfp_ep")
+        .allowlist_function("rb_get_cfp_ep_level")
+        .allowlist_function("rb_get_cme_def_type")
+        .allowlist_function("rb_get_cme_def_body_attr_id")
+        .allowlist_function("rb_get_cme_def_body_optimized_type")
+        .allowlist_function("rb_get_cme_def_body_optimized_index")
+        .allowlist_function("rb_get_cme_def_body_cfunc")
+        .allowlist_function("rb_get_def_method_serial")
+        .allowlist_function("rb_get_def_original_id")
+        .allowlist_function("rb_get_mct_argc")
+        .allowlist_function("rb_get_mct_func")
+        .allowlist_function("rb_get_def_iseq_ptr")
+        .allowlist_function("rb_iseq_encoded_size")
+        .allowlist_function("rb_get_iseq_body_local_iseq")
+        .allowlist_function("rb_get_iseq_body_iseq_encoded")
+        .allowlist_function("rb_get_iseq_body_stack_max")
+        .allowlist_function("rb_get_iseq_flags_has_opt")
+        .allowlist_function("rb_get_iseq_flags_has_kw")
+        .allowlist_function("rb_get_iseq_flags_has_rest")
+        .allowlist_function("rb_get_iseq_flags_has_post")
+        .allowlist_function("rb_get_iseq_flags_has_kwrest")
+        .allowlist_function("rb_get_iseq_flags_has_block")
+        .allowlist_function("rb_get_iseq_flags_has_accepts_no_kwarg")
+        .allowlist_function("rb_get_iseq_body_local_table_size")
+        .allowlist_function("rb_get_iseq_body_param_keyword")
+        .allowlist_function("rb_get_iseq_body_param_size")
+        .allowlist_function("rb_get_iseq_body_param_lead_num")
+        .allowlist_function("rb_get_iseq_body_param_opt_num")
+        .allowlist_function("rb_get_iseq_body_param_opt_table")
+        .allowlist_function("rb_get_cikw_keyword_len")
+        .allowlist_function("rb_get_cikw_keywords_idx")
+        .allowlist_function("rb_get_call_data_ci")
+        .allowlist_function("rb_yarv_str_eql_internal")
+        .allowlist_function("rb_yarv_ary_entry_internal")
+        .allowlist_function("rb_yarv_fix_mod_fix")
+        .allowlist_function("rb_FL_TEST")
+        .allowlist_function("rb_FL_TEST_RAW")
+        .allowlist_function("rb_RB_TYPE_P")
+        .allowlist_function("rb_BASIC_OP_UNREDEFINED_P")
+        .allowlist_function("rb_RSTRUCT_LEN")
+        .allowlist_function("rb_RSTRUCT_SET")
+        .allowlist_function("rb_vm_ci_argc")
+        .allowlist_function("rb_vm_ci_mid")
+        .allowlist_function("rb_vm_ci_flag")
+        .allowlist_function("rb_vm_ci_kwarg")
+        .allowlist_function("rb_METHOD_ENTRY_VISI")
+        .allowlist_function("rb_RCLASS_ORIGIN")
+
         // We define VALUE manually, don't import it
         .blocklist_type("VALUE")
 
diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs
index 08806f84bf..3428466297 100644
--- a/yjit/src/codegen.rs
+ (... truncated)

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

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