Skip to content

Commit 0e8219f

Browse files
committed
make functions static
These functions are used from within a compilation unit so we can make them static, for better binary size. This changeset reduces the size of generated ruby binary from 26,590,128 bytes to 26,584,472 bytes on my macihne.
1 parent 78e266d commit 0e8219f

16 files changed

+38
-42
lines changed

array.c

+2
Original file line numberDiff line numberDiff line change
@@ -1532,6 +1532,8 @@ rb_ary_subseq(VALUE ary, long beg, long len)
15321532
return ary_make_partial(ary, klass, beg, len);
15331533
}
15341534

1535+
static VALUE rb_ary_aref2(VALUE ary, VALUE b, VALUE e);
1536+
15351537
/*
15361538
* call-seq:
15371539
* ary[index] -> obj or nil

bignum.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -3990,6 +3990,8 @@ str2big_gmp(
39903990
}
39913991
#endif
39923992

3993+
static VALUE rb_cstr_parse_inum(const char *str, ssize_t len, char **endp, int base);
3994+
39933995
/*
39943996
* Parse +str+ as Ruby Integer, i.e., underscores, 0d and 0b prefixes.
39953997
*
@@ -4233,7 +4235,7 @@ rb_int_parse_cstr(const char *str, ssize_t len, char **endp, size_t *ndigits,
42334235
return bignorm(z);
42344236
}
42354237

4236-
VALUE
4238+
static VALUE
42374239
rb_cstr_parse_inum(const char *str, ssize_t len, char **endp, int base)
42384240
{
42394241
return rb_int_parse_cstr(str, len, endp, NULL, base,

compile.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node)
755755
return iseq_setup(iseq, ret);
756756
}
757757

758-
int
758+
static int
759759
rb_iseq_translate_threaded_code(rb_iseq_t *iseq)
760760
{
761761
#if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE

error.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ rb_warning_s_warn(VALUE mod, VALUE str)
159159
* printing the warning to $stderr.
160160
*/
161161

162-
VALUE
162+
static VALUE
163163
rb_warning_warn(VALUE mod, VALUE str)
164164
{
165165
return rb_funcallv(mod, id_warn, 1, &str);
@@ -1169,6 +1169,8 @@ exc_backtrace(VALUE exc)
11691169
return obj;
11701170
}
11711171

1172+
static VALUE rb_check_backtrace(VALUE);
1173+
11721174
VALUE
11731175
rb_get_backtrace(VALUE exc)
11741176
{
@@ -1212,7 +1214,7 @@ exc_backtrace_locations(VALUE exc)
12121214
return obj;
12131215
}
12141216

1215-
VALUE
1217+
static VALUE
12161218
rb_check_backtrace(VALUE bt)
12171219
{
12181220
long i;
@@ -1506,6 +1508,8 @@ name_err_initialize(int argc, VALUE *argv, VALUE self)
15061508
return self;
15071509
}
15081510

1511+
static VALUE rb_name_err_mesg_new(VALUE mesg, VALUE recv, VALUE method);
1512+
15091513
static VALUE
15101514
name_err_init(VALUE exc, VALUE mesg, VALUE recv, VALUE method)
15111515
{
@@ -1636,7 +1640,7 @@ static const rb_data_type_t name_err_mesg_data_type = {
16361640
};
16371641

16381642
/* :nodoc: */
1639-
VALUE
1643+
static VALUE
16401644
rb_name_err_mesg_new(VALUE mesg, VALUE recv, VALUE method)
16411645
{
16421646
VALUE result = TypedData_Wrap_Struct(rb_cNameErrorMesg, &name_err_mesg_data_type, 0);

gc.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -1747,6 +1747,8 @@ heap_unlink_page(rb_objspace_t *objspace, rb_heap_t *heap, struct heap_page *pag
17471747
heap->total_slots -= page->total_slots;
17481748
}
17491749

1750+
static void rb_aligned_free(void *ptr);
1751+
17501752
static void
17511753
heap_page_free(rb_objspace_t *objspace, struct heap_page *page)
17521754
{
@@ -2302,7 +2304,7 @@ rb_imemo_tmpbuf_new(VALUE v1, VALUE v2, VALUE v3, VALUE v0)
23022304
return newobj_of(v0, flags, v1, v2, v3, FALSE);
23032305
}
23042306

2305-
VALUE
2307+
static VALUE
23062308
rb_imemo_tmpbuf_auto_free_maybe_mark_buffer(void *buf, size_t cnt)
23072309
{
23082310
return rb_imemo_tmpbuf_new((VALUE)buf, 0, (VALUE)cnt, 0);
@@ -9624,7 +9626,7 @@ rb_aligned_malloc(size_t alignment, size_t size)
96249626
return res;
96259627
}
96269628

9627-
void
9629+
static void
96289630
rb_aligned_free(void *ptr)
96299631
{
96309632
#if defined __MINGW32__

hash.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ rb_hash(VALUE obj)
146146
return hval;
147147
}
148148

149-
long rb_objid_hash(st_index_t index);
149+
static long rb_objid_hash(st_index_t index);
150150

151151
static st_index_t
152152
dbl_to_index(double d)
@@ -264,7 +264,7 @@ key64_hash(uint64_t key, uint32_t seed)
264264
/* Should cast down the result for each purpose */
265265
#define st_index_hash(index) key64_hash(rb_hash_start(index), prime2)
266266

267-
long
267+
static long
268268
rb_objid_hash(st_index_t index)
269269
{
270270
return (long)st_index_hash(index);
@@ -4153,6 +4153,8 @@ rb_hash_compact_bang(VALUE hash)
41534153
return Qnil;
41544154
}
41554155

4156+
static st_table *rb_init_identtable_with_size(st_index_t size);
4157+
41564158
/*
41574159
* call-seq:
41584160
* hsh.compare_by_identity -> hsh
@@ -4227,7 +4229,7 @@ rb_init_identtable(void)
42274229
return st_init_table(&identhash);
42284230
}
42294231

4230-
st_table *
4232+
static st_table *
42314233
rb_init_identtable_with_size(st_index_t size)
42324234
{
42334235
return st_init_table_with_size(&identhash, size);

internal.h

-18
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,6 @@ typedef struct rb_imemo_tmpbuf_struct {
12061206
} rb_imemo_tmpbuf_t;
12071207

12081208
#define rb_imemo_tmpbuf_auto_free_pointer() rb_imemo_new(imemo_tmpbuf, 0, 0, 0, 0)
1209-
VALUE rb_imemo_tmpbuf_auto_free_maybe_mark_buffer(void *buf, size_t cnt);
12101209
rb_imemo_tmpbuf_t *rb_imemo_tmpbuf_parser_heap(void *buf, rb_imemo_tmpbuf_t *old_heap, size_t cnt);
12111210

12121211
#define RB_IMEMO_TMPBUF_PTR(v) \
@@ -1364,7 +1363,6 @@ void rb_ary_delete_same(VALUE, VALUE);
13641363
VALUE rb_ary_tmp_new_fill(long capa);
13651364
VALUE rb_ary_at(VALUE, VALUE);
13661365
VALUE rb_ary_aref1(VALUE ary, VALUE i);
1367-
VALUE rb_ary_aref2(VALUE ary, VALUE b, VALUE e);
13681366
size_t rb_ary_memsize(VALUE);
13691367
VALUE rb_to_array_type(VALUE obj);
13701368
VALUE rb_check_to_array(VALUE ary);
@@ -1425,7 +1423,6 @@ VALUE rb_big_even_p(VALUE);
14251423
size_t rb_big_size(VALUE);
14261424
VALUE rb_integer_float_cmp(VALUE x, VALUE y);
14271425
VALUE rb_integer_float_eq(VALUE x, VALUE y);
1428-
VALUE rb_cstr_parse_inum(const char *str, ssize_t len, char **endp, int base);
14291426
VALUE rb_str_convert_to_inum(VALUE str, int base, int badcheck, int raise_exception);
14301427
VALUE rb_big_comp(VALUE x);
14311428
VALUE rb_big_aref(VALUE x, VALUE y);
@@ -1516,7 +1513,6 @@ extern VALUE rb_eEAGAIN;
15161513
extern VALUE rb_eEWOULDBLOCK;
15171514
extern VALUE rb_eEINPROGRESS;
15181515
void rb_report_bug_valist(VALUE file, int line, const char *fmt, va_list args);
1519-
VALUE rb_check_backtrace(VALUE);
15201516
NORETURN(void rb_async_bug_errno(const char *,int));
15211517
const char *rb_builtin_type_name(int t);
15221518
const char *rb_builtin_class_name(VALUE x);
@@ -1541,7 +1537,6 @@ VALUE rb_nomethod_err_new(VALUE mesg, VALUE recv, VALUE method, VALUE args, int
15411537
VALUE rb_key_err_new(VALUE mesg, VALUE recv, VALUE name);
15421538
#define rb_key_err_raise(mesg, recv, name) \
15431539
rb_exc_raise(rb_key_err_new(mesg, recv, name))
1544-
VALUE rb_warning_warn(VALUE mod, VALUE str);
15451540
PRINTF_ARGS(VALUE rb_warning_string(const char *fmt, ...), 1, 2);
15461541
NORETURN(void rb_vraise(VALUE, const char *, va_list));
15471542

@@ -1635,7 +1630,6 @@ __attribute__((__alloc_align__(1)))
16351630
#endif
16361631
#endif
16371632
void *rb_aligned_malloc(size_t, size_t) RUBY_ATTR_MALLOC RUBY_ATTR_ALLOC_SIZE((2));
1638-
void rb_aligned_free(void *);
16391633

16401634
size_t rb_size_mul_or_raise(size_t, size_t, VALUE); /* used in compile.c */
16411635
size_t rb_size_mul_add_or_raise(size_t, size_t, size_t, VALUE); /* used in iseq.h */
@@ -1657,10 +1651,8 @@ VALUE rb_hash_new_with_size(st_index_t size);
16571651
VALUE rb_hash_has_key(VALUE hash, VALUE key);
16581652
VALUE rb_hash_default_value(VALUE hash, VALUE key);
16591653
VALUE rb_hash_set_default_proc(VALUE hash, VALUE proc);
1660-
long rb_objid_hash(st_index_t index);
16611654
long rb_dbl_long_hash(double d);
16621655
st_table *rb_init_identtable(void);
1663-
st_table *rb_init_identtable_with_size(st_index_t size);
16641656
VALUE rb_hash_compare_by_id_p(VALUE hash);
16651657
VALUE rb_to_hash_type(VALUE obj);
16661658
VALUE rb_hash_key_str(VALUE);
@@ -1714,7 +1706,6 @@ VALUE rb_math_hypot(VALUE, VALUE);
17141706
VALUE rb_math_log(int argc, const VALUE *argv);
17151707
VALUE rb_math_sin(VALUE);
17161708
VALUE rb_math_sinh(VALUE);
1717-
VALUE rb_math_sqrt(VALUE);
17181709

17191710
/* mjit.c */
17201711

@@ -1768,7 +1759,6 @@ int ruby_float_step(VALUE from, VALUE to, VALUE step, int excl, int allow_endles
17681759
double ruby_float_mod(double x, double y);
17691760
int rb_num_negative_p(VALUE);
17701761
VALUE rb_int_succ(VALUE num);
1771-
VALUE rb_int_pred(VALUE num);
17721762
VALUE rb_int_uminus(VALUE num);
17731763
VALUE rb_float_uminus(VALUE num);
17741764
VALUE rb_int_plus(VALUE x, VALUE y);
@@ -1779,9 +1769,7 @@ VALUE rb_float_mul(VALUE x, VALUE y);
17791769
VALUE rb_float_div(VALUE x, VALUE y);
17801770
VALUE rb_int_idiv(VALUE x, VALUE y);
17811771
VALUE rb_int_modulo(VALUE x, VALUE y);
1782-
VALUE rb_int_round(VALUE num, int ndigits, enum ruby_num_rounding_mode mode);
17831772
VALUE rb_int2str(VALUE num, int base);
1784-
VALUE rb_dbl_hash(double d);
17851773
VALUE rb_fix_plus(VALUE x, VALUE y);
17861774
VALUE rb_fix_aref(VALUE fix, VALUE idx);
17871775
VALUE rb_int_gt(VALUE x, VALUE y);
@@ -2280,7 +2268,6 @@ VALUE rb_check_funcall_with_hook_kw(VALUE recv, ID mid, int argc, const VALUE *a
22802268
rb_check_funcall_hook *hook, VALUE arg, int kw_splat);
22812269
const char *rb_type_str(enum ruby_value_type type);
22822270
VALUE rb_check_funcall_default(VALUE, ID, int, const VALUE *, VALUE);
2283-
VALUE rb_check_funcall_default_kw(VALUE, ID, int, const VALUE *, VALUE, int);
22842271
VALUE rb_yield_1(VALUE val);
22852272
VALUE rb_yield_force_blockarg(VALUE values);
22862273
VALUE rb_lambda_call(VALUE obj, ID mid, int argc, const VALUE *argv,
@@ -2403,11 +2390,6 @@ const char *rb_objspace_data_type_name(VALUE obj);
24032390
/* Temporary. This API will be removed (renamed). */
24042391
VALUE rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd);
24052392

2406-
/* array.c (export) */
2407-
void rb_ary_detransient(VALUE a);
2408-
VALUE *rb_ary_ptr_use_start(VALUE ary);
2409-
void rb_ary_ptr_use_end(VALUE ary);
2410-
24112393
/* bignum.c (export) */
24122394
VALUE rb_big_mul_normal(VALUE x, VALUE y);
24132395
VALUE rb_big_mul_balance(VALUE x, VALUE y);

iseq.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ set_compile_option_from_hash(rb_compile_option_t *option, VALUE opt)
690690
#undef SET_COMPILE_OPTION_NUM
691691
}
692692

693-
void
693+
static void
694694
rb_iseq_make_compile_option(rb_compile_option_t *option, VALUE opt)
695695
{
696696
Check_Type(opt, T_HASH);
@@ -963,7 +963,7 @@ rb_iseq_load(VALUE data, VALUE parent, VALUE opt)
963963
return iseq_load(data, RTEST(parent) ? (rb_iseq_t *)parent : NULL, opt);
964964
}
965965

966-
rb_iseq_t *
966+
static rb_iseq_t *
967967
rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE realpath, VALUE line, VALUE opt)
968968
{
969969
rb_iseq_t *iseq = NULL;

iseq.h

-2
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ RUBY_SYMBOL_EXPORT_BEGIN
172172
/* compile.c */
173173
VALUE rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node);
174174
VALUE rb_iseq_compile_callback(rb_iseq_t *iseq, const struct rb_iseq_new_with_callback_callback_func * ifunc);
175-
int rb_iseq_translate_threaded_code(rb_iseq_t *iseq);
176175
VALUE *rb_iseq_original_iseq(const rb_iseq_t *iseq);
177176
void rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE misc,
178177
VALUE locals, VALUE args,
@@ -303,7 +302,6 @@ enum defined_type {
303302
};
304303

305304
VALUE rb_iseq_defined_string(enum defined_type type);
306-
void rb_iseq_make_compile_option(struct rb_compile_option_struct *option, VALUE opt);
307305

308306
/* vm.c */
309307
VALUE rb_iseq_local_variables(const rb_iseq_t *iseq);

math.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,8 @@ math_log10(VALUE unused_obj, VALUE x)
573573
return DBL2NUM(log10(d) + numbits * log10(2)); /* log10(d * 2 ** numbits) */
574574
}
575575

576+
static VALUE rb_math_sqrt(VALUE x);
577+
576578
/*
577579
* call-seq:
578580
* Math.sqrt(x) -> Float
@@ -630,7 +632,7 @@ f_signbit(VALUE x)
630632
return f_negative_p(x);
631633
}
632634

633-
VALUE
635+
static VALUE
634636
rb_math_sqrt(VALUE x)
635637
{
636638
double d;

method.h

-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ const rb_method_entry_t *rb_method_entry_with_refinements(VALUE klass, ID id, VA
202202
const rb_method_entry_t *rb_method_entry_without_refinements(VALUE klass, ID id, VALUE *defined_class);
203203
const rb_method_entry_t *rb_resolve_refined_method(VALUE refinements, const rb_method_entry_t *me);
204204
RUBY_SYMBOL_EXPORT_BEGIN
205-
const rb_callable_method_entry_t *rb_resolve_refined_method_callable(VALUE refinements, const rb_callable_method_entry_t *me);
206205
const rb_method_entry_t *rb_resolve_me_location(const rb_method_entry_t *, VALUE[5]);
207206
RUBY_SYMBOL_EXPORT_END
208207

numeric.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,7 @@ rb_float_equal(VALUE x, VALUE y)
14041404
}
14051405

14061406
#define flo_eq rb_float_equal
1407+
static VALUE rb_dbl_hash(double d);
14071408

14081409
/*
14091410
* call-seq:
@@ -1420,7 +1421,7 @@ flo_hash(VALUE num)
14201421
return rb_dbl_hash(RFLOAT_VALUE(num));
14211422
}
14221423

1423-
VALUE
1424+
static VALUE
14241425
rb_dbl_hash(double d)
14251426
{
14261427
return LONG2FIX(rb_dbl_long_hash(d));
@@ -2099,7 +2100,7 @@ int_half_p_half_down(VALUE num, VALUE n, VALUE f)
20992100
/*
21002101
* Assumes num is an Integer, ndigits <= 0
21012102
*/
2102-
VALUE
2103+
static VALUE
21032104
rb_int_round(VALUE num, int ndigits, enum ruby_num_rounding_mode mode)
21042105
{
21052106
VALUE n, f, h, r;
@@ -3342,7 +3343,7 @@ rb_int_succ(VALUE num)
33423343
* (-1).pred #=> -2
33433344
*/
33443345

3345-
VALUE
3346+
static VALUE
33463347
rb_int_pred(VALUE num)
33473348
{
33483349
if (FIXNUM_P(num)) {

vm_args.c

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ NORETURN(static void argument_kw_error(rb_execution_context_t *ec, const rb_iseq
1414
VALUE rb_keyword_error_new(const char *error, VALUE keys); /* class.c */
1515
static VALUE method_missing(VALUE obj, ID id, int argc, const VALUE *argv,
1616
enum method_missing_reason call_status, int kw_splat);
17+
#if !defined(_MSC_VER) || !defined(MJIT_HEADER)
18+
MJIT_FUNC_EXPORTED const rb_callable_method_entry_t *rb_resolve_refined_method_callable(VALUE refinements, const rb_callable_method_entry_t *me);
19+
#endif
1720

1821
struct args_info {
1922
/* basic args info */

vm_core.h

-4
Original file line numberDiff line numberDiff line change
@@ -1027,9 +1027,6 @@ rb_iseq_t *rb_iseq_new_with_callback(const struct rb_iseq_new_with_callback_call
10271027
VALUE name, VALUE path, VALUE realpath, VALUE first_lineno,
10281028
const rb_iseq_t *parent, enum iseq_type, const rb_compile_option_t*);
10291029

1030-
/* src -> iseq */
1031-
rb_iseq_t *rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE realpath, VALUE line, VALUE opt);
1032-
10331030
VALUE rb_iseq_disasm(const rb_iseq_t *iseq);
10341031
int rb_iseq_disasm_insn(VALUE str, const VALUE *iseqval, size_t pos, const rb_iseq_t *iseq, VALUE child);
10351032

@@ -1708,7 +1705,6 @@ typedef int rb_backtrace_iter_func(void *, VALUE, int, VALUE);
17081705
rb_control_frame_t *rb_vm_get_ruby_level_next_cfp(const rb_execution_context_t *ec, const rb_control_frame_t *cfp);
17091706
rb_control_frame_t *rb_vm_get_binding_creatable_next_cfp(const rb_execution_context_t *ec, const rb_control_frame_t *cfp);
17101707
int rb_vm_get_sourceline(const rb_control_frame_t *);
1711-
VALUE rb_name_err_mesg_new(VALUE mesg, VALUE recv, VALUE method);
17121708
void rb_vm_stack_to_heap(rb_execution_context_t *ec);
17131709
void ruby_thread_init_stack(rb_thread_t *th);
17141710
int rb_vm_control_frame_id_and_class(const rb_control_frame_t *cfp, ID *idp, ID *called_idp, VALUE *klassp);

vm_eval.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ check_funcall_missing(rb_execution_context_t *ec, VALUE klass, VALUE recv, ID mi
496496
return ret;
497497
}
498498

499+
static VALUE rb_check_funcall_default_kw(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE def, int kw_splat);
500+
499501
VALUE
500502
rb_check_funcall_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
501503
{
@@ -508,7 +510,7 @@ rb_check_funcall(VALUE recv, ID mid, int argc, const VALUE *argv)
508510
return rb_check_funcall_default_kw(recv, mid, argc, argv, Qundef, RB_NO_KEYWORDS);
509511
}
510512

511-
VALUE
513+
static VALUE
512514
rb_check_funcall_default_kw(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE def, int kw_splat)
513515
{
514516
VALUE klass = CLASS_OF(recv);

vm_method.c

+1
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,7 @@ rb_resolve_refined_method(VALUE refinements, const rb_method_entry_t *me)
961961
return resolve_refined_method(refinements, me, NULL);
962962
}
963963

964+
MJIT_FUNC_EXPORTED
964965
const rb_callable_method_entry_t *
965966
rb_resolve_refined_method_callable(VALUE refinements, const rb_callable_method_entry_t *me)
966967
{

0 commit comments

Comments
 (0)