Skip to content

Commit 3ec7bff

Browse files
committed
Use a set_table for rb_vm_struct.unused_block_warning_table
Now that we have a hash-set implementation we can use that instead of a hash-table with a static value.
1 parent 6874b28 commit 3ec7bff

9 files changed

Lines changed: 83 additions & 7 deletions

File tree

common.mk

Lines changed: 55 additions & 0 deletions
Large diffs are not rendered by default.

compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2014,7 +2014,7 @@ iseq_set_use_block(rb_iseq_t *iseq)
20142014

20152015
if (!rb_warning_category_enabled_p(RB_WARN_CATEGORY_STRICT_UNUSED_BLOCK)) {
20162016
st_data_t key = (st_data_t)rb_intern_str(body->location.label); // String -> ID
2017-
st_insert(vm->unused_block_warning_table, key, 1);
2017+
set_insert(vm->unused_block_warning_table, key);
20182018
}
20192019
}
20202020
}

ext/coverage/depend

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ coverage.o: $(top_srcdir)/internal/hash.h
188188
coverage.o: $(top_srcdir)/internal/imemo.h
189189
coverage.o: $(top_srcdir)/internal/sanitizers.h
190190
coverage.o: $(top_srcdir)/internal/serial.h
191+
coverage.o: $(top_srcdir)/internal/set_table.h
191192
coverage.o: $(top_srcdir)/internal/static_assert.h
192193
coverage.o: $(top_srcdir)/internal/thread.h
193194
coverage.o: $(top_srcdir)/internal/variable.h

ext/objspace/depend

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ object_tracing.o: $(top_srcdir)/internal/gc.h
185185
object_tracing.o: $(top_srcdir)/internal/imemo.h
186186
object_tracing.o: $(top_srcdir)/internal/sanitizers.h
187187
object_tracing.o: $(top_srcdir)/internal/serial.h
188+
object_tracing.o: $(top_srcdir)/internal/set_table.h
188189
object_tracing.o: $(top_srcdir)/internal/static_assert.h
189190
object_tracing.o: $(top_srcdir)/internal/vm.h
190191
object_tracing.o: $(top_srcdir)/internal/warnings.h
@@ -393,6 +394,7 @@ objspace.o: $(top_srcdir)/internal/hash.h
393394
objspace.o: $(top_srcdir)/internal/imemo.h
394395
objspace.o: $(top_srcdir)/internal/sanitizers.h
395396
objspace.o: $(top_srcdir)/internal/serial.h
397+
objspace.o: $(top_srcdir)/internal/set_table.h
396398
objspace.o: $(top_srcdir)/internal/static_assert.h
397399
objspace.o: $(top_srcdir)/internal/variable.h
398400
objspace.o: $(top_srcdir)/internal/vm.h
@@ -605,6 +607,7 @@ objspace_dump.o: $(top_srcdir)/internal/imemo.h
605607
objspace_dump.o: $(top_srcdir)/internal/io.h
606608
objspace_dump.o: $(top_srcdir)/internal/sanitizers.h
607609
objspace_dump.o: $(top_srcdir)/internal/serial.h
610+
objspace_dump.o: $(top_srcdir)/internal/set_table.h
608611
objspace_dump.o: $(top_srcdir)/internal/static_assert.h
609612
objspace_dump.o: $(top_srcdir)/internal/string.h
610613
objspace_dump.o: $(top_srcdir)/internal/variable.h

ext/ripper/depend

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ ripper.o: $(top_srcdir)/internal/re.h
598598
ripper.o: $(top_srcdir)/internal/ruby_parser.h
599599
ripper.o: $(top_srcdir)/internal/sanitizers.h
600600
ripper.o: $(top_srcdir)/internal/serial.h
601+
ripper.o: $(top_srcdir)/internal/set_table.h
601602
ripper.o: $(top_srcdir)/internal/static_assert.h
602603
ripper.o: $(top_srcdir)/internal/string.h
603604
ripper.o: $(top_srcdir)/internal/symbol.h

ext/socket/depend

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ ancdata.o: $(top_srcdir)/internal/imemo.h
202202
ancdata.o: $(top_srcdir)/internal/io.h
203203
ancdata.o: $(top_srcdir)/internal/sanitizers.h
204204
ancdata.o: $(top_srcdir)/internal/serial.h
205+
ancdata.o: $(top_srcdir)/internal/set_table.h
205206
ancdata.o: $(top_srcdir)/internal/static_assert.h
206207
ancdata.o: $(top_srcdir)/internal/string.h
207208
ancdata.o: $(top_srcdir)/internal/thread.h
@@ -413,6 +414,7 @@ basicsocket.o: $(top_srcdir)/internal/imemo.h
413414
basicsocket.o: $(top_srcdir)/internal/io.h
414415
basicsocket.o: $(top_srcdir)/internal/sanitizers.h
415416
basicsocket.o: $(top_srcdir)/internal/serial.h
417+
basicsocket.o: $(top_srcdir)/internal/set_table.h
416418
basicsocket.o: $(top_srcdir)/internal/static_assert.h
417419
basicsocket.o: $(top_srcdir)/internal/string.h
418420
basicsocket.o: $(top_srcdir)/internal/thread.h
@@ -624,6 +626,7 @@ constants.o: $(top_srcdir)/internal/imemo.h
624626
constants.o: $(top_srcdir)/internal/io.h
625627
constants.o: $(top_srcdir)/internal/sanitizers.h
626628
constants.o: $(top_srcdir)/internal/serial.h
629+
constants.o: $(top_srcdir)/internal/set_table.h
627630
constants.o: $(top_srcdir)/internal/static_assert.h
628631
constants.o: $(top_srcdir)/internal/string.h
629632
constants.o: $(top_srcdir)/internal/thread.h
@@ -836,6 +839,7 @@ ifaddr.o: $(top_srcdir)/internal/imemo.h
836839
ifaddr.o: $(top_srcdir)/internal/io.h
837840
ifaddr.o: $(top_srcdir)/internal/sanitizers.h
838841
ifaddr.o: $(top_srcdir)/internal/serial.h
842+
ifaddr.o: $(top_srcdir)/internal/set_table.h
839843
ifaddr.o: $(top_srcdir)/internal/static_assert.h
840844
ifaddr.o: $(top_srcdir)/internal/string.h
841845
ifaddr.o: $(top_srcdir)/internal/thread.h
@@ -1047,6 +1051,7 @@ init.o: $(top_srcdir)/internal/imemo.h
10471051
init.o: $(top_srcdir)/internal/io.h
10481052
init.o: $(top_srcdir)/internal/sanitizers.h
10491053
init.o: $(top_srcdir)/internal/serial.h
1054+
init.o: $(top_srcdir)/internal/set_table.h
10501055
init.o: $(top_srcdir)/internal/static_assert.h
10511056
init.o: $(top_srcdir)/internal/string.h
10521057
init.o: $(top_srcdir)/internal/thread.h
@@ -1258,6 +1263,7 @@ ipsocket.o: $(top_srcdir)/internal/imemo.h
12581263
ipsocket.o: $(top_srcdir)/internal/io.h
12591264
ipsocket.o: $(top_srcdir)/internal/sanitizers.h
12601265
ipsocket.o: $(top_srcdir)/internal/serial.h
1266+
ipsocket.o: $(top_srcdir)/internal/set_table.h
12611267
ipsocket.o: $(top_srcdir)/internal/static_assert.h
12621268
ipsocket.o: $(top_srcdir)/internal/string.h
12631269
ipsocket.o: $(top_srcdir)/internal/thread.h
@@ -1469,6 +1475,7 @@ option.o: $(top_srcdir)/internal/imemo.h
14691475
option.o: $(top_srcdir)/internal/io.h
14701476
option.o: $(top_srcdir)/internal/sanitizers.h
14711477
option.o: $(top_srcdir)/internal/serial.h
1478+
option.o: $(top_srcdir)/internal/set_table.h
14721479
option.o: $(top_srcdir)/internal/static_assert.h
14731480
option.o: $(top_srcdir)/internal/string.h
14741481
option.o: $(top_srcdir)/internal/thread.h
@@ -1680,6 +1687,7 @@ raddrinfo.o: $(top_srcdir)/internal/imemo.h
16801687
raddrinfo.o: $(top_srcdir)/internal/io.h
16811688
raddrinfo.o: $(top_srcdir)/internal/sanitizers.h
16821689
raddrinfo.o: $(top_srcdir)/internal/serial.h
1690+
raddrinfo.o: $(top_srcdir)/internal/set_table.h
16831691
raddrinfo.o: $(top_srcdir)/internal/static_assert.h
16841692
raddrinfo.o: $(top_srcdir)/internal/string.h
16851693
raddrinfo.o: $(top_srcdir)/internal/thread.h
@@ -1891,6 +1899,7 @@ socket.o: $(top_srcdir)/internal/imemo.h
18911899
socket.o: $(top_srcdir)/internal/io.h
18921900
socket.o: $(top_srcdir)/internal/sanitizers.h
18931901
socket.o: $(top_srcdir)/internal/serial.h
1902+
socket.o: $(top_srcdir)/internal/set_table.h
18941903
socket.o: $(top_srcdir)/internal/static_assert.h
18951904
socket.o: $(top_srcdir)/internal/string.h
18961905
socket.o: $(top_srcdir)/internal/thread.h
@@ -2102,6 +2111,7 @@ sockssocket.o: $(top_srcdir)/internal/imemo.h
21022111
sockssocket.o: $(top_srcdir)/internal/io.h
21032112
sockssocket.o: $(top_srcdir)/internal/sanitizers.h
21042113
sockssocket.o: $(top_srcdir)/internal/serial.h
2114+
sockssocket.o: $(top_srcdir)/internal/set_table.h
21052115
sockssocket.o: $(top_srcdir)/internal/static_assert.h
21062116
sockssocket.o: $(top_srcdir)/internal/string.h
21072117
sockssocket.o: $(top_srcdir)/internal/thread.h
@@ -2313,6 +2323,7 @@ tcpserver.o: $(top_srcdir)/internal/imemo.h
23132323
tcpserver.o: $(top_srcdir)/internal/io.h
23142324
tcpserver.o: $(top_srcdir)/internal/sanitizers.h
23152325
tcpserver.o: $(top_srcdir)/internal/serial.h
2326+
tcpserver.o: $(top_srcdir)/internal/set_table.h
23162327
tcpserver.o: $(top_srcdir)/internal/static_assert.h
23172328
tcpserver.o: $(top_srcdir)/internal/string.h
23182329
tcpserver.o: $(top_srcdir)/internal/thread.h
@@ -2524,6 +2535,7 @@ tcpsocket.o: $(top_srcdir)/internal/imemo.h
25242535
tcpsocket.o: $(top_srcdir)/internal/io.h
25252536
tcpsocket.o: $(top_srcdir)/internal/sanitizers.h
25262537
tcpsocket.o: $(top_srcdir)/internal/serial.h
2538+
tcpsocket.o: $(top_srcdir)/internal/set_table.h
25272539
tcpsocket.o: $(top_srcdir)/internal/static_assert.h
25282540
tcpsocket.o: $(top_srcdir)/internal/string.h
25292541
tcpsocket.o: $(top_srcdir)/internal/thread.h
@@ -2735,6 +2747,7 @@ udpsocket.o: $(top_srcdir)/internal/imemo.h
27352747
udpsocket.o: $(top_srcdir)/internal/io.h
27362748
udpsocket.o: $(top_srcdir)/internal/sanitizers.h
27372749
udpsocket.o: $(top_srcdir)/internal/serial.h
2750+
udpsocket.o: $(top_srcdir)/internal/set_table.h
27382751
udpsocket.o: $(top_srcdir)/internal/static_assert.h
27392752
udpsocket.o: $(top_srcdir)/internal/string.h
27402753
udpsocket.o: $(top_srcdir)/internal/thread.h
@@ -2946,6 +2959,7 @@ unixserver.o: $(top_srcdir)/internal/imemo.h
29462959
unixserver.o: $(top_srcdir)/internal/io.h
29472960
unixserver.o: $(top_srcdir)/internal/sanitizers.h
29482961
unixserver.o: $(top_srcdir)/internal/serial.h
2962+
unixserver.o: $(top_srcdir)/internal/set_table.h
29492963
unixserver.o: $(top_srcdir)/internal/static_assert.h
29502964
unixserver.o: $(top_srcdir)/internal/string.h
29512965
unixserver.o: $(top_srcdir)/internal/thread.h
@@ -3157,6 +3171,7 @@ unixsocket.o: $(top_srcdir)/internal/imemo.h
31573171
unixsocket.o: $(top_srcdir)/internal/io.h
31583172
unixsocket.o: $(top_srcdir)/internal/sanitizers.h
31593173
unixsocket.o: $(top_srcdir)/internal/serial.h
3174+
unixsocket.o: $(top_srcdir)/internal/set_table.h
31603175
unixsocket.o: $(top_srcdir)/internal/static_assert.h
31613176
unixsocket.o: $(top_srcdir)/internal/string.h
31623177
unixsocket.o: $(top_srcdir)/internal/thread.h

vm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3131,7 +3131,7 @@ ruby_vm_destruct(rb_vm_t *vm)
31313131
rb_vm_postponed_job_free();
31323132

31333133
rb_id_table_free(vm->constant_cache);
3134-
st_free_table(vm->unused_block_warning_table);
3134+
set_free_table(vm->unused_block_warning_table);
31353135

31363136
xfree(th->nt);
31373137
th->nt = NULL;
@@ -4306,7 +4306,7 @@ Init_BareVM(void)
43064306
vm->negative_cme_table = rb_id_table_create(16);
43074307
vm->overloaded_cme_table = st_init_numtable();
43084308
vm->constant_cache = rb_id_table_create(0);
4309-
vm->unused_block_warning_table = st_init_numtable();
4309+
vm->unused_block_warning_table = set_init_numtable();
43104310

43114311
// setup main thread
43124312
th->nt = ZALLOC(struct rb_native_thread);

vm_core.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ extern int ruby_assert_critical_section_entered;
120120
#include "internal/basic_operators.h"
121121
#include "internal/sanitizers.h"
122122
#include "internal/serial.h"
123+
#include "internal/set_table.h"
123124
#include "internal/vm.h"
124125
#include "method.h"
125126
#include "node.h"
@@ -791,7 +792,7 @@ typedef struct rb_vm_struct {
791792
st_table *ci_table;
792793
struct rb_id_table *negative_cme_table;
793794
st_table *overloaded_cme_table; // cme -> overloaded_cme
794-
st_table *unused_block_warning_table;
795+
set_table *unused_block_warning_table;
795796

796797
// This id table contains a mapping from ID to ICs. It does this with ID
797798
// keys and nested st_tables as values. The nested tables have ICs as keys

vm_insnhelper.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3034,7 +3034,7 @@ static void
30343034
warn_unused_block(const rb_callable_method_entry_t *cme, const rb_iseq_t *iseq, void *pc)
30353035
{
30363036
rb_vm_t *vm = GET_VM();
3037-
st_table *dup_check_table = vm->unused_block_warning_table;
3037+
set_table *dup_check_table = vm->unused_block_warning_table;
30383038
st_data_t key;
30393039
bool strict_unused_block = rb_warning_category_enabled_p(RB_WARN_CATEGORY_STRICT_UNUSED_BLOCK);
30403040

@@ -3051,7 +3051,7 @@ warn_unused_block(const rb_callable_method_entry_t *cme, const rb_iseq_t *iseq,
30513051
if (!strict_unused_block) {
30523052
key = (st_data_t)cme->def->original_id;
30533053

3054-
if (st_lookup(dup_check_table, key, NULL)) {
3054+
if (set_lookup(dup_check_table, key)) {
30553055
return;
30563056
}
30573057
}
@@ -3071,7 +3071,7 @@ warn_unused_block(const rb_callable_method_entry_t *cme, const rb_iseq_t *iseq,
30713071
}
30723072

30733073
// duplication check
3074-
if (st_insert(dup_check_table, key, 1)) {
3074+
if (set_insert(dup_check_table, key)) {
30753075
// already shown
30763076
}
30773077
else if (RTEST(ruby_verbose) || strict_unused_block) {

0 commit comments

Comments
 (0)