Skip to content

Commit 5a954fb

Browse files
committed
Extract KW_SPECIFIED_BITS_MAX and rename to VM_KW_SPECIFIED_BITS_MAX to vm_core.h
1 parent 3578385 commit 5a954fb

10 files changed

Lines changed: 13 additions & 15 deletions

File tree

ext/io/wait/wait.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
* IO wait methods are built in ruby now, just for backward compatibility.
1616
*/
1717

18-
#include "ruby.h"
19-
2018
void
2119
Init_wait(void)
2220
{

jit.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
//
66
// Code specific to YJIT and ZJIT should go to yjit.c and zjit.c respectively.
77

8-
#include "internal.h"
98
#include "vm_core.h"
109
#include "vm_callinfo.h"
1110
#include "builtin.h"
@@ -23,7 +22,7 @@ enum jit_bindgen_constants {
2322
ROBJECT_OFFSET_AS_ARY = offsetof(struct RObject, as.ary),
2423

2524
// Field offsets for the RString struct
26-
RUBY_OFFSET_RSTRING_LEN = offsetof(struct RString, len)
25+
RUBY_OFFSET_RSTRING_LEN = offsetof(struct RString, len),
2726
};
2827

2928
// Manually bound in rust since this is out-of-range of `int`,

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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
#define VMDEBUG 3
4646
#endif
4747

48-
#include "ruby/internal/config.h"
49-
5048
#include <stddef.h>
5149
#include <signal.h>
5250
#include <stdarg.h>
@@ -317,6 +315,8 @@ struct rb_calling_info {
317315
#define VM_ARGC_STACK_MAX 128
318316
#endif
319317

318+
#define VM_KW_SPECIFIED_BITS_MAX (32-1) /* TODO: 32 -> Fixnum's max bits */
319+
320320
# define CALLING_ARGC(calling) ((calling)->heap_argv ? RARRAY_LENINT((calling)->heap_argv) : (calling)->argc)
321321

322322
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/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 > ARGS_KW_SPECIFIED_BITS_MAX as i32 } {
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4766,7 +4766,7 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
47664766
// This can only happen in iseqs taking more than 32 keywords.
47674767
// In this case, we side exit to the interpreter.
47684768
// TODO(Jacob): Replace the magic number 32 with a named constant. (Can be completed after PR 15039)
4769-
if unsafe {(*rb_get_iseq_body_param_keyword(iseq)).num >= 32} {
4769+
if unsafe {(*rb_get_iseq_body_param_keyword(iseq)).num >= VM_KW_SPECIFIED_BITS_MAX.try_into().unwrap()} {
47704770
fun.push_insn(block, Insn::SideExit { state: exit_id, reason: SideExitReason::TooManyKeywordParameters });
47714771
break;
47724772
}

0 commit comments

Comments
 (0)