Skip to content

Commit f3f3e76

Browse files
authored
Extract KW_SPECIFIED_BITS_MAX for JITs (rubyGH-15039)
Rename to `VM_KW_SPECIFIED_BITS_MAX` now that it's in `vm_core.h`.
1 parent cbe65eb commit f3f3e76

File tree

9 files changed

+13
-10
lines changed

9 files changed

+13
-10
lines changed

vm_args.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,6 @@ args_setup_kw_parameters_lookup(const ID key, VALUE *ptr, const VALUE *const pas
318318
return FALSE;
319319
}
320320

321-
#define KW_SPECIFIED_BITS_MAX (32-1) /* TODO: 32 -> Fixnum's max bits */
322-
323321
static void
324322
args_setup_kw_parameters(rb_execution_context_t *const ec, const rb_iseq_t *const iseq, const rb_callable_method_entry_t *cme,
325323
VALUE *const passed_values, const int passed_keyword_len, const VALUE *const passed_keywords,
@@ -355,7 +353,7 @@ args_setup_kw_parameters(rb_execution_context_t *const ec, const rb_iseq_t *cons
355353
if (UNDEF_P(default_values[di])) {
356354
locals[i] = Qnil;
357355

358-
if (LIKELY(i < KW_SPECIFIED_BITS_MAX)) {
356+
if (LIKELY(i < VM_KW_SPECIFIED_BITS_MAX)) {
359357
unspecified_bits |= 0x01 << di;
360358
}
361359
else {
@@ -364,7 +362,7 @@ args_setup_kw_parameters(rb_execution_context_t *const ec, const rb_iseq_t *cons
364362
int j;
365363
unspecified_bits_value = rb_hash_new();
366364

367-
for (j=0; j<KW_SPECIFIED_BITS_MAX; j++) {
365+
for (j=0; j<VM_KW_SPECIFIED_BITS_MAX; j++) {
368366
if (unspecified_bits & (0x01 << j)) {
369367
rb_hash_aset(unspecified_bits_value, INT2FIX(j), Qtrue);
370368
}
@@ -450,7 +448,7 @@ args_setup_kw_parameters_from_kwsplat(rb_execution_context_t *const ec, const rb
450448
if (UNDEF_P(default_values[di])) {
451449
locals[i] = Qnil;
452450

453-
if (LIKELY(i < KW_SPECIFIED_BITS_MAX)) {
451+
if (LIKELY(i < VM_KW_SPECIFIED_BITS_MAX)) {
454452
unspecified_bits |= 0x01 << di;
455453
}
456454
else {
@@ -459,7 +457,7 @@ args_setup_kw_parameters_from_kwsplat(rb_execution_context_t *const ec, const rb
459457
int j;
460458
unspecified_bits_value = rb_hash_new();
461459

462-
for (j=0; j<KW_SPECIFIED_BITS_MAX; j++) {
460+
for (j=0; j<VM_KW_SPECIFIED_BITS_MAX; j++) {
463461
if (unspecified_bits & (0x01 << j)) {
464462
rb_hash_aset(unspecified_bits_value, INT2FIX(j), Qtrue);
465463
}

vm_core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ struct rb_calling_info {
317317
#define VM_ARGC_STACK_MAX 128
318318
#endif
319319

320+
#define VM_KW_SPECIFIED_BITS_MAX (32-1) /* TODO: 32 -> Fixnum's max bits */
321+
320322
# define CALLING_ARGC(calling) ((calling)->heap_argv ? RARRAY_LENINT((calling)->heap_argv) : (calling)->argc)
321323

322324
struct rb_execution_context_struct;

vm_insnhelper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5808,7 +5808,7 @@ vm_check_keyword(lindex_t bits, lindex_t idx, const VALUE *ep)
58085808

58095809
if (FIXNUM_P(kw_bits)) {
58105810
unsigned int b = (unsigned int)FIX2ULONG(kw_bits);
5811-
if ((idx < KW_SPECIFIED_BITS_MAX) && (b & (0x01 << idx)))
5811+
if ((idx < VM_KW_SPECIFIED_BITS_MAX) && (b & (0x01 << idx)))
58125812
return Qfalse;
58135813
}
58145814
else {

yjit/bindgen/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ fn main() {
155155
.opaque_type("rb_callcache.*")
156156
.allowlist_type("rb_callinfo")
157157
.allowlist_var("VM_ENV_DATA_INDEX_ME_CREF")
158+
.allowlist_var("VM_KW_SPECIFIED_BITS_MAX")
158159
.allowlist_var("rb_block_param_proxy")
159160
.allowlist_function("rb_range_new")
160161
.allowlist_function("rb_intern")

yjit/src/codegen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2747,7 +2747,7 @@ fn gen_checkkeyword(
27472747
) -> Option<CodegenStatus> {
27482748
// When a keyword is unspecified past index 32, a hash will be used
27492749
// instead. This can only happen in iseqs taking more than 32 keywords.
2750-
if unsafe { (*get_iseq_body_param_keyword(jit.iseq)).num >= 32 } {
2750+
if unsafe { (*get_iseq_body_param_keyword(jit.iseq)).num >= VM_KW_SPECIFIED_BITS_MAX.try_into().unwrap() } {
27512751
return None;
27522752
}
27532753

yjit/src/cruby_bindings.inc.rs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zjit/bindgen/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ fn main() {
101101
.allowlist_function("rb_shape_get_iv_index")
102102
.allowlist_function("rb_shape_transition_add_ivar_no_warnings")
103103
.allowlist_var("rb_invalid_shape_id")
104+
.allowlist_var("VM_KW_SPECIFIED_BITS_MAX")
104105
.allowlist_var("SHAPE_ID_NUM_BITS")
105106
.allowlist_function("rb_obj_is_kind_of")
106107
.allowlist_function("rb_obj_frozen_p")

zjit/src/cruby_bindings.inc.rs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zjit/src/hir.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4848,8 +4848,7 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
48484848
// When a keyword is unspecified past index 32, a hash will be used instead.
48494849
// This can only happen in iseqs taking more than 32 keywords.
48504850
// In this case, we side exit to the interpreter.
4851-
// TODO(Jacob): Replace the magic number 32 with a named constant. (Can be completed after PR 15039)
4852-
if unsafe {(*rb_get_iseq_body_param_keyword(iseq)).num >= 32} {
4851+
if unsafe {(*rb_get_iseq_body_param_keyword(iseq)).num >= VM_KW_SPECIFIED_BITS_MAX.try_into().unwrap()} {
48534852
fun.push_insn(block, Insn::SideExit { state: exit_id, reason: SideExitReason::TooManyKeywordParameters });
48544853
break;
48554854
}

0 commit comments

Comments
 (0)