Skip to content

Commit 9c3eeec

Browse files
authored
Merge pull request ruby#205 from Shopify/noah_aref_aset
Port aref and aset functions
2 parents 931200c + 89a95c0 commit 9c3eeec

File tree

5 files changed

+148
-78
lines changed

5 files changed

+148
-78
lines changed

yjit.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,12 @@ rb_get_cme_def_body_optimized_type(rb_callable_method_entry_t* cme)
351351
return cme->def->body.optimized.type;
352352
}
353353

354+
unsigned int
355+
rb_get_cme_def_body_optimized_index(rb_callable_method_entry_t* cme)
356+
{
357+
return cme->def->body.optimized.index;
358+
}
359+
354360
rb_method_cfunc_t*
355361
rb_get_cme_def_body_cfunc(rb_callable_method_entry_t* cme)
356362
{
@@ -534,6 +540,13 @@ rb_yarv_str_eql_internal(VALUE str1, VALUE str2)
534540
return rb_str_eql_internal(str1, str2);
535541
}
536542

543+
// YJIT needs this function to never allocate and never raise
544+
VALUE
545+
rb_yarv_ary_entry_internal(VALUE ary, long offset)
546+
{
547+
return rb_ary_entry_internal(ary, offset);
548+
}
549+
537550
// The FL_TEST() macro
538551
VALUE
539552
rb_FL_TEST(VALUE obj, VALUE flags)
@@ -561,6 +574,21 @@ rb_GET_IC_SERIAL(const struct iseq_inline_constant_cache_entry *ice)
561574
return GET_IC_SERIAL(ice);
562575
}
563576

577+
long
578+
rb_RSTRUCT_LEN(VALUE st)
579+
{
580+
return RSTRUCT_LEN(st);
581+
}
582+
583+
// There are RSTRUCT_SETs in ruby/internal/core/rstruct.h and internal/struct.h
584+
// with different types (int vs long) for k. Here we use the one from ruby/internal/core/rstruct.h,
585+
// which takes an int.
586+
void
587+
rb_RSTRUCT_SET(VALUE st, int k, VALUE v)
588+
{
589+
RSTRUCT_SET(st, k, v);
590+
}
591+
564592
const struct rb_callinfo*
565593
rb_get_call_data_ci(struct rb_call_data* cd) {
566594
return cd->ci;

yjit/bindgen/src/main.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,13 @@ fn main() {
5656

5757
// From include/ruby/internal/intern/hash.h
5858
.allowlist_function("rb_hash_aset")
59+
.allowlist_function("rb_hash_aref")
5960
.allowlist_function("rb_hash_bulk_insert")
6061

6162
// From include/ruby/internal/intern/array.h
6263
.allowlist_function("rb_ary_resurrect")
6364
.allowlist_function("rb_ary_clear")
65+
.allowlist_function("rb_ary_store")
6466

6567
// From internal/array.h
6668
.allowlist_function("rb_ec_ary_new_from_values")
@@ -84,16 +86,19 @@ fn main() {
8486
.allowlist_var("rb_cFloat")
8587
.allowlist_var("rb_cString")
8688
.allowlist_var("rb_cThread")
89+
.allowlist_var("rb_cArray")
90+
.allowlist_var("rb_cHash")
8791

8892
// From ruby/internal/globals.h
8993
.allowlist_var("rb_mKernel")
9094

9195
// From vm_callinfo.h
92-
.allowlist_type("VM_CALL.*") // This doesn't work, possibly due to the odd structure of the #defines
93-
.allowlist_type("vm_call_flag_bits") // So instead we include the other enum and do the bit-shift ourselves
94-
.blocklist_type("rb_call_data")
95-
.opaque_type("rb_call_data")
96-
.blocklist_type("rb_callinfo_kwarg") // Contains a VALUE[] array of undefined size
96+
.allowlist_type("VM_CALL.*") // This doesn't work, possibly due to the odd structure of the #defines
97+
.allowlist_type("vm_call_flag_bits") // So instead we include the other enum and do the bit-shift ourselves.
98+
.allowlist_type("rb_call_data")
99+
.blocklist_type("rb_callcache.*") // Not used yet - opaque to make it easy to import rb_call_data
100+
.opaque_type("rb_callcache.*")
101+
.blocklist_type("rb_callinfo_kwarg") // Contains a VALUE[] array of undefined size, so we don't import
97102
.opaque_type("rb_callinfo_kwarg")
98103
.allowlist_type("rb_callinfo")
99104

@@ -151,6 +156,8 @@ fn main() {
151156
.allowlist_function("rb_method_entry_at")
152157
.allowlist_type("rb_method_entry_t")
153158
.blocklist_type("rb_method_cfunc_t")
159+
.blocklist_type("rb_method_definition_.*") // Large struct with a bitfield and union of many types - don't import (yet?)
160+
.opaque_type("rb_method_definition_.*")
154161

155162
// From vm_core.h
156163
.allowlist_type("ruby_basic_operators")
@@ -168,9 +175,7 @@ fn main() {
168175
.allowlist_type("iseq_inline_iv_cache_entry")
169176
.allowlist_type("ICVARC") // pointer to iseq_inline_cvar_cache_entry
170177
.allowlist_type("iseq_inline_cvar_cache_entry")
171-
.blocklist_type("rb_method_definition_.*")
172-
.opaque_type("rb_method_definition_.*")
173-
.blocklist_type("rb_execution_context_.*")
178+
.blocklist_type("rb_execution_context_.*") // Large struct with various-type fields and an ifdef, so we don't import
174179
.opaque_type("rb_execution_context_.*")
175180
.blocklist_type("rb_control_frame_struct")
176181
.opaque_type("rb_control_frame_struct")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy