diff --git a/.github/workflows/check_sast.yml b/.github/workflows/check_sast.yml index 6fed88a6e6d8cc..b02f6fb76ad047 100644 --- a/.github/workflows/check_sast.yml +++ b/.github/workflows/check_sast.yml @@ -95,17 +95,17 @@ jobs: run: sudo rm /usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb - name: Initialize CodeQL - uses: github/codeql-action/init@c793b717bc78562f491db7b0e93a3a178b099162 # v4.32.5 + uses: github/codeql-action/init@0d579ffd059c29b07949a3cce3983f0780820c98 # v4.32.6 with: languages: ${{ matrix.language }} trap-caching: false debug: true - name: Autobuild - uses: github/codeql-action/autobuild@c793b717bc78562f491db7b0e93a3a178b099162 # v4.32.5 + uses: github/codeql-action/autobuild@0d579ffd059c29b07949a3cce3983f0780820c98 # v4.32.6 - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@c793b717bc78562f491db7b0e93a3a178b099162 # v4.32.5 + uses: github/codeql-action/analyze@0d579ffd059c29b07949a3cce3983f0780820c98 # v4.32.6 with: category: '/language:${{ matrix.language }}' upload: False @@ -135,7 +135,7 @@ jobs: continue-on-error: true - name: Upload SARIF - uses: github/codeql-action/upload-sarif@c793b717bc78562f491db7b0e93a3a178b099162 # v4.32.5 + uses: github/codeql-action/upload-sarif@0d579ffd059c29b07949a3cce3983f0780820c98 # v4.32.6 with: sarif_file: sarif-results/${{ matrix.language }}.sarif continue-on-error: true diff --git a/.github/workflows/scorecards.yml b/.github/workflows/scorecards.yml index 907519cb4d6621..8c061b16dcfb0b 100644 --- a/.github/workflows/scorecards.yml +++ b/.github/workflows/scorecards.yml @@ -73,6 +73,6 @@ jobs: # Upload the results to GitHub's code scanning dashboard (optional). # Commenting out will disable upload of results to your repo's Code Scanning dashboard - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@c793b717bc78562f491db7b0e93a3a178b099162 # v4.32.5 + uses: github/codeql-action/upload-sarif@0d579ffd059c29b07949a3cce3983f0780820c98 # v4.32.6 with: sarif_file: results.sarif diff --git a/bignum.c b/bignum.c index c39f74576a2c31..f5c58ab74312a4 100644 --- a/bignum.c +++ b/bignum.c @@ -2964,7 +2964,7 @@ int rb_cmpint(VALUE val, VALUE a, VALUE b) { if (NIL_P(val)) { - rb_cmperr(a, b); + rb_cmperr_reason(a, b, "comparator returned nil"); } if (FIXNUM_P(val)) { long l = FIX2LONG(val); diff --git a/compar.c b/compar.c index 142cb12a0cfe77..1ab2520f1e6638 100644 --- a/compar.c +++ b/compar.c @@ -24,8 +24,8 @@ rb_cmp(VALUE x, VALUE y) return rb_funcallv(x, idCmp, 1, &y); } -void -rb_cmperr(VALUE x, VALUE y) +static VALUE +cmperr_subject(VALUE y) { VALUE classname; @@ -35,10 +35,25 @@ rb_cmperr(VALUE x, VALUE y) else { classname = rb_obj_class(y); } + return classname; +} + +void +rb_cmperr(VALUE x, VALUE y) +{ + VALUE classname = cmperr_subject(y); rb_raise(rb_eArgError, "comparison of %"PRIsVALUE" with %"PRIsVALUE" failed", rb_obj_class(x), classname); } +void +rb_cmperr_reason(VALUE x, VALUE y, const char *reason) +{ + VALUE classname = cmperr_subject(y); + rb_raise(rb_eArgError, "comparison of %"PRIsVALUE" with %"PRIsVALUE" failed: %s", + rb_obj_class(x), classname, reason); +} + static VALUE invcmp_recursive(VALUE x, VALUE y, int recursive) { diff --git a/configure.ac b/configure.ac index 05e2e9aca26ddf..1b59942463bad6 100644 --- a/configure.ac +++ b/configure.ac @@ -715,7 +715,7 @@ AS_IF([test "$fdeclspec" = yes], [ RUBY_APPEND_OPTIONS(cflags, -fdeclspec) RUBY_APPEND_OPTIONS(orig_cflags, -fdeclspec) ]) -RUBY_TRY_CXXFLAGS(-fdeclspec, [fdeclspec=yes], [fdeclspec=no]) +RUBY_TRY_CXXFLAGS(-fdeclspec, [fdeclspec=yes], [fdeclspec=no], [@%:@include ]) AS_IF([test "$fdeclspec" = yes], [ RUBY_APPEND_OPTIONS(CXXFLAGS, -fdeclspec) ]) diff --git a/depend b/depend index ced1dfd6ad8a75..f04e40e16f705d 100644 --- a/depend +++ b/depend @@ -287,6 +287,7 @@ ast.$(OBJEXT): $(top_srcdir)/internal/basic_operators.h ast.$(OBJEXT): $(top_srcdir)/internal/bignum.h ast.$(OBJEXT): $(top_srcdir)/internal/bits.h ast.$(OBJEXT): $(top_srcdir)/internal/box.h +ast.$(OBJEXT): $(top_srcdir)/internal/compar.h ast.$(OBJEXT): $(top_srcdir)/internal/compilers.h ast.$(OBJEXT): $(top_srcdir)/internal/complex.h ast.$(OBJEXT): $(top_srcdir)/internal/fixnum.h @@ -530,6 +531,7 @@ bignum.$(OBJEXT): $(top_srcdir)/internal/bignum.h bignum.$(OBJEXT): $(top_srcdir)/internal/bits.h bignum.$(OBJEXT): $(top_srcdir)/internal/box.h bignum.$(OBJEXT): $(top_srcdir)/internal/class.h +bignum.$(OBJEXT): $(top_srcdir)/internal/compar.h bignum.$(OBJEXT): $(top_srcdir)/internal/compilers.h bignum.$(OBJEXT): $(top_srcdir)/internal/complex.h bignum.$(OBJEXT): $(top_srcdir)/internal/fixnum.h @@ -1627,6 +1629,7 @@ compile.$(OBJEXT): $(top_srcdir)/internal/bignum.h compile.$(OBJEXT): $(top_srcdir)/internal/bits.h compile.$(OBJEXT): $(top_srcdir)/internal/box.h compile.$(OBJEXT): $(top_srcdir)/internal/class.h +compile.$(OBJEXT): $(top_srcdir)/internal/compar.h compile.$(OBJEXT): $(top_srcdir)/internal/compile.h compile.$(OBJEXT): $(top_srcdir)/internal/compilers.h compile.$(OBJEXT): $(top_srcdir)/internal/complex.h @@ -1895,6 +1898,7 @@ complex.$(OBJEXT): $(top_srcdir)/internal/bignum.h complex.$(OBJEXT): $(top_srcdir)/internal/bits.h complex.$(OBJEXT): $(top_srcdir)/internal/box.h complex.$(OBJEXT): $(top_srcdir)/internal/class.h +complex.$(OBJEXT): $(top_srcdir)/internal/compar.h complex.$(OBJEXT): $(top_srcdir)/internal/compilers.h complex.$(OBJEXT): $(top_srcdir)/internal/complex.h complex.$(OBJEXT): $(top_srcdir)/internal/error.h @@ -4885,6 +4889,7 @@ enumerator.$(OBJEXT): $(top_srcdir)/internal/bignum.h enumerator.$(OBJEXT): $(top_srcdir)/internal/bits.h enumerator.$(OBJEXT): $(top_srcdir)/internal/box.h enumerator.$(OBJEXT): $(top_srcdir)/internal/class.h +enumerator.$(OBJEXT): $(top_srcdir)/internal/compar.h enumerator.$(OBJEXT): $(top_srcdir)/internal/compilers.h enumerator.$(OBJEXT): $(top_srcdir)/internal/enumerator.h enumerator.$(OBJEXT): $(top_srcdir)/internal/error.h @@ -5815,6 +5820,7 @@ gc.$(OBJEXT): $(top_srcdir)/internal/bignum.h gc.$(OBJEXT): $(top_srcdir)/internal/bits.h gc.$(OBJEXT): $(top_srcdir)/internal/box.h gc.$(OBJEXT): $(top_srcdir)/internal/class.h +gc.$(OBJEXT): $(top_srcdir)/internal/compar.h gc.$(OBJEXT): $(top_srcdir)/internal/compile.h gc.$(OBJEXT): $(top_srcdir)/internal/compilers.h gc.$(OBJEXT): $(top_srcdir)/internal/complex.h @@ -6966,6 +6972,7 @@ io.$(OBJEXT): $(top_srcdir)/internal/bignum.h io.$(OBJEXT): $(top_srcdir)/internal/bits.h io.$(OBJEXT): $(top_srcdir)/internal/box.h io.$(OBJEXT): $(top_srcdir)/internal/class.h +io.$(OBJEXT): $(top_srcdir)/internal/compar.h io.$(OBJEXT): $(top_srcdir)/internal/compilers.h io.$(OBJEXT): $(top_srcdir)/internal/encoding.h io.$(OBJEXT): $(top_srcdir)/internal/error.h @@ -7197,6 +7204,7 @@ io_buffer.$(OBJEXT): $(top_srcdir)/internal/basic_operators.h io_buffer.$(OBJEXT): $(top_srcdir)/internal/bignum.h io_buffer.$(OBJEXT): $(top_srcdir)/internal/bits.h io_buffer.$(OBJEXT): $(top_srcdir)/internal/box.h +io_buffer.$(OBJEXT): $(top_srcdir)/internal/compar.h io_buffer.$(OBJEXT): $(top_srcdir)/internal/compilers.h io_buffer.$(OBJEXT): $(top_srcdir)/internal/error.h io_buffer.$(OBJEXT): $(top_srcdir)/internal/fixnum.h @@ -7413,6 +7421,7 @@ iseq.$(OBJEXT): $(top_srcdir)/internal/bignum.h iseq.$(OBJEXT): $(top_srcdir)/internal/bits.h iseq.$(OBJEXT): $(top_srcdir)/internal/box.h iseq.$(OBJEXT): $(top_srcdir)/internal/class.h +iseq.$(OBJEXT): $(top_srcdir)/internal/compar.h iseq.$(OBJEXT): $(top_srcdir)/internal/compile.h iseq.$(OBJEXT): $(top_srcdir)/internal/compilers.h iseq.$(OBJEXT): $(top_srcdir)/internal/complex.h @@ -7919,6 +7928,7 @@ load.$(OBJEXT): $(top_srcdir)/internal/basic_operators.h load.$(OBJEXT): $(top_srcdir)/internal/bignum.h load.$(OBJEXT): $(top_srcdir)/internal/bits.h load.$(OBJEXT): $(top_srcdir)/internal/box.h +load.$(OBJEXT): $(top_srcdir)/internal/compar.h load.$(OBJEXT): $(top_srcdir)/internal/compilers.h load.$(OBJEXT): $(top_srcdir)/internal/complex.h load.$(OBJEXT): $(top_srcdir)/internal/dir.h @@ -8675,6 +8685,7 @@ marshal.$(OBJEXT): $(top_srcdir)/internal/bignum.h marshal.$(OBJEXT): $(top_srcdir)/internal/bits.h marshal.$(OBJEXT): $(top_srcdir)/internal/box.h marshal.$(OBJEXT): $(top_srcdir)/internal/class.h +marshal.$(OBJEXT): $(top_srcdir)/internal/compar.h marshal.$(OBJEXT): $(top_srcdir)/internal/compilers.h marshal.$(OBJEXT): $(top_srcdir)/internal/encoding.h marshal.$(OBJEXT): $(top_srcdir)/internal/error.h @@ -9284,6 +9295,7 @@ miniinit.$(OBJEXT): $(top_srcdir)/internal/basic_operators.h miniinit.$(OBJEXT): $(top_srcdir)/internal/bignum.h miniinit.$(OBJEXT): $(top_srcdir)/internal/bits.h miniinit.$(OBJEXT): $(top_srcdir)/internal/box.h +miniinit.$(OBJEXT): $(top_srcdir)/internal/compar.h miniinit.$(OBJEXT): $(top_srcdir)/internal/compilers.h miniinit.$(OBJEXT): $(top_srcdir)/internal/complex.h miniinit.$(OBJEXT): $(top_srcdir)/internal/eval.h @@ -9757,6 +9769,7 @@ node_dump.$(OBJEXT): $(top_srcdir)/internal/bignum.h node_dump.$(OBJEXT): $(top_srcdir)/internal/bits.h node_dump.$(OBJEXT): $(top_srcdir)/internal/box.h node_dump.$(OBJEXT): $(top_srcdir)/internal/class.h +node_dump.$(OBJEXT): $(top_srcdir)/internal/compar.h node_dump.$(OBJEXT): $(top_srcdir)/internal/compilers.h node_dump.$(OBJEXT): $(top_srcdir)/internal/complex.h node_dump.$(OBJEXT): $(top_srcdir)/internal/fixnum.h @@ -9974,6 +9987,7 @@ numeric.$(OBJEXT): $(top_srcdir)/internal/bignum.h numeric.$(OBJEXT): $(top_srcdir)/internal/bits.h numeric.$(OBJEXT): $(top_srcdir)/internal/box.h numeric.$(OBJEXT): $(top_srcdir)/internal/class.h +numeric.$(OBJEXT): $(top_srcdir)/internal/compar.h numeric.$(OBJEXT): $(top_srcdir)/internal/compilers.h numeric.$(OBJEXT): $(top_srcdir)/internal/complex.h numeric.$(OBJEXT): $(top_srcdir)/internal/enumerator.h @@ -10196,6 +10210,7 @@ object.$(OBJEXT): $(top_srcdir)/internal/bignum.h object.$(OBJEXT): $(top_srcdir)/internal/bits.h object.$(OBJEXT): $(top_srcdir)/internal/box.h object.$(OBJEXT): $(top_srcdir)/internal/class.h +object.$(OBJEXT): $(top_srcdir)/internal/compar.h object.$(OBJEXT): $(top_srcdir)/internal/compilers.h object.$(OBJEXT): $(top_srcdir)/internal/error.h object.$(OBJEXT): $(top_srcdir)/internal/eval.h @@ -10424,6 +10439,7 @@ pack.$(OBJEXT): $(top_srcdir)/internal/basic_operators.h pack.$(OBJEXT): $(top_srcdir)/internal/bignum.h pack.$(OBJEXT): $(top_srcdir)/internal/bits.h pack.$(OBJEXT): $(top_srcdir)/internal/box.h +pack.$(OBJEXT): $(top_srcdir)/internal/compar.h pack.$(OBJEXT): $(top_srcdir)/internal/compilers.h pack.$(OBJEXT): $(top_srcdir)/internal/fixnum.h pack.$(OBJEXT): $(top_srcdir)/internal/gc.h @@ -10640,6 +10656,7 @@ parse.$(OBJEXT): $(top_srcdir)/internal/basic_operators.h parse.$(OBJEXT): $(top_srcdir)/internal/bignum.h parse.$(OBJEXT): $(top_srcdir)/internal/bits.h parse.$(OBJEXT): $(top_srcdir)/internal/box.h +parse.$(OBJEXT): $(top_srcdir)/internal/compar.h parse.$(OBJEXT): $(top_srcdir)/internal/compile.h parse.$(OBJEXT): $(top_srcdir)/internal/compilers.h parse.$(OBJEXT): $(top_srcdir)/internal/complex.h @@ -12680,6 +12697,7 @@ process.$(OBJEXT): $(top_srcdir)/internal/bignum.h process.$(OBJEXT): $(top_srcdir)/internal/bits.h process.$(OBJEXT): $(top_srcdir)/internal/box.h process.$(OBJEXT): $(top_srcdir)/internal/class.h +process.$(OBJEXT): $(top_srcdir)/internal/compar.h process.$(OBJEXT): $(top_srcdir)/internal/compilers.h process.$(OBJEXT): $(top_srcdir)/internal/dir.h process.$(OBJEXT): $(top_srcdir)/internal/error.h @@ -12912,6 +12930,7 @@ ractor.$(OBJEXT): $(top_srcdir)/internal/basic_operators.h ractor.$(OBJEXT): $(top_srcdir)/internal/bignum.h ractor.$(OBJEXT): $(top_srcdir)/internal/bits.h ractor.$(OBJEXT): $(top_srcdir)/internal/box.h +ractor.$(OBJEXT): $(top_srcdir)/internal/compar.h ractor.$(OBJEXT): $(top_srcdir)/internal/compilers.h ractor.$(OBJEXT): $(top_srcdir)/internal/complex.h ractor.$(OBJEXT): $(top_srcdir)/internal/error.h @@ -13145,6 +13164,7 @@ random.$(OBJEXT): $(top_srcdir)/internal/basic_operators.h random.$(OBJEXT): $(top_srcdir)/internal/bignum.h random.$(OBJEXT): $(top_srcdir)/internal/bits.h random.$(OBJEXT): $(top_srcdir)/internal/box.h +random.$(OBJEXT): $(top_srcdir)/internal/compar.h random.$(OBJEXT): $(top_srcdir)/internal/compilers.h random.$(OBJEXT): $(top_srcdir)/internal/fixnum.h random.$(OBJEXT): $(top_srcdir)/internal/gc.h @@ -13557,6 +13577,7 @@ rational.$(OBJEXT): $(top_srcdir)/internal/bignum.h rational.$(OBJEXT): $(top_srcdir)/internal/bits.h rational.$(OBJEXT): $(top_srcdir)/internal/box.h rational.$(OBJEXT): $(top_srcdir)/internal/class.h +rational.$(OBJEXT): $(top_srcdir)/internal/compar.h rational.$(OBJEXT): $(top_srcdir)/internal/compilers.h rational.$(OBJEXT): $(top_srcdir)/internal/complex.h rational.$(OBJEXT): $(top_srcdir)/internal/error.h @@ -14990,6 +15011,7 @@ ruby.$(OBJEXT): $(top_srcdir)/internal/bits.h ruby.$(OBJEXT): $(top_srcdir)/internal/box.h ruby.$(OBJEXT): $(top_srcdir)/internal/class.h ruby.$(OBJEXT): $(top_srcdir)/internal/cmdlineopt.h +ruby.$(OBJEXT): $(top_srcdir)/internal/compar.h ruby.$(OBJEXT): $(top_srcdir)/internal/compilers.h ruby.$(OBJEXT): $(top_srcdir)/internal/complex.h ruby.$(OBJEXT): $(top_srcdir)/internal/cont.h @@ -15239,8 +15261,10 @@ ruby.$(OBJEXT): {$(VPATH)}vm_opts.h ruby.$(OBJEXT): {$(VPATH)}yjit.h ruby_parser.$(OBJEXT): $(hdrdir)/ruby/ruby.h ruby_parser.$(OBJEXT): $(top_srcdir)/internal/array.h +ruby_parser.$(OBJEXT): $(top_srcdir)/internal/basic_operators.h ruby_parser.$(OBJEXT): $(top_srcdir)/internal/bignum.h ruby_parser.$(OBJEXT): $(top_srcdir)/internal/bits.h +ruby_parser.$(OBJEXT): $(top_srcdir)/internal/compar.h ruby_parser.$(OBJEXT): $(top_srcdir)/internal/compilers.h ruby_parser.$(OBJEXT): $(top_srcdir)/internal/complex.h ruby_parser.$(OBJEXT): $(top_srcdir)/internal/error.h @@ -16445,9 +16469,11 @@ signal.$(OBJEXT): {$(VPATH)}vm_debug.h signal.$(OBJEXT): {$(VPATH)}vm_opts.h sprintf.$(OBJEXT): $(hdrdir)/ruby/ruby.h sprintf.$(OBJEXT): $(hdrdir)/ruby/version.h +sprintf.$(OBJEXT): $(top_srcdir)/internal/basic_operators.h sprintf.$(OBJEXT): $(top_srcdir)/internal/bignum.h sprintf.$(OBJEXT): $(top_srcdir)/internal/bits.h sprintf.$(OBJEXT): $(top_srcdir)/internal/class.h +sprintf.$(OBJEXT): $(top_srcdir)/internal/compar.h sprintf.$(OBJEXT): $(top_srcdir)/internal/compilers.h sprintf.$(OBJEXT): $(top_srcdir)/internal/error.h sprintf.$(OBJEXT): $(top_srcdir)/internal/fixnum.h @@ -20475,6 +20501,7 @@ yjit.$(OBJEXT): $(top_srcdir)/internal/bignum.h yjit.$(OBJEXT): $(top_srcdir)/internal/bits.h yjit.$(OBJEXT): $(top_srcdir)/internal/box.h yjit.$(OBJEXT): $(top_srcdir)/internal/class.h +yjit.$(OBJEXT): $(top_srcdir)/internal/compar.h yjit.$(OBJEXT): $(top_srcdir)/internal/compile.h yjit.$(OBJEXT): $(top_srcdir)/internal/compilers.h yjit.$(OBJEXT): $(top_srcdir)/internal/cont.h @@ -20732,6 +20759,7 @@ zjit.$(OBJEXT): $(top_srcdir)/internal/bignum.h zjit.$(OBJEXT): $(top_srcdir)/internal/bits.h zjit.$(OBJEXT): $(top_srcdir)/internal/box.h zjit.$(OBJEXT): $(top_srcdir)/internal/class.h +zjit.$(OBJEXT): $(top_srcdir)/internal/compar.h zjit.$(OBJEXT): $(top_srcdir)/internal/compile.h zjit.$(OBJEXT): $(top_srcdir)/internal/compilers.h zjit.$(OBJEXT): $(top_srcdir)/internal/cont.h diff --git a/ext/-test-/integer/depend b/ext/-test-/integer/depend index 0ea007e814128d..d0589b5e5dd8a8 100644 --- a/ext/-test-/integer/depend +++ b/ext/-test-/integer/depend @@ -159,8 +159,11 @@ core_ext.o: $(hdrdir)/ruby/missing.h core_ext.o: $(hdrdir)/ruby/ruby.h core_ext.o: $(hdrdir)/ruby/st.h core_ext.o: $(hdrdir)/ruby/subst.h +core_ext.o: $(top_srcdir)/internal.h +core_ext.o: $(top_srcdir)/internal/basic_operators.h core_ext.o: $(top_srcdir)/internal/bignum.h core_ext.o: $(top_srcdir)/internal/bits.h +core_ext.o: $(top_srcdir)/internal/compar.h core_ext.o: $(top_srcdir)/internal/compilers.h core_ext.o: $(top_srcdir)/internal/fixnum.h core_ext.o: $(top_srcdir)/internal/numeric.h diff --git a/ext/-test-/rational/depend b/ext/-test-/rational/depend index 56d6ab77d6c36a..d949fca66bcc88 100644 --- a/ext/-test-/rational/depend +++ b/ext/-test-/rational/depend @@ -163,8 +163,11 @@ rat.o: $(hdrdir)/ruby/missing.h rat.o: $(hdrdir)/ruby/ruby.h rat.o: $(hdrdir)/ruby/st.h rat.o: $(hdrdir)/ruby/subst.h +rat.o: $(top_srcdir)/internal.h +rat.o: $(top_srcdir)/internal/basic_operators.h rat.o: $(top_srcdir)/internal/bignum.h rat.o: $(top_srcdir)/internal/bits.h +rat.o: $(top_srcdir)/internal/compar.h rat.o: $(top_srcdir)/internal/compilers.h rat.o: $(top_srcdir)/internal/fixnum.h rat.o: $(top_srcdir)/internal/gc.h diff --git a/ext/ripper/depend b/ext/ripper/depend index 944da25ee94f38..96d41c87b89ac0 100644 --- a/ext/ripper/depend +++ b/ext/ripper/depend @@ -586,6 +586,7 @@ ripper.o: $(top_srcdir)/internal/basic_operators.h ripper.o: $(top_srcdir)/internal/bignum.h ripper.o: $(top_srcdir)/internal/bits.h ripper.o: $(top_srcdir)/internal/box.h +ripper.o: $(top_srcdir)/internal/compar.h ripper.o: $(top_srcdir)/internal/compile.h ripper.o: $(top_srcdir)/internal/compilers.h ripper.o: $(top_srcdir)/internal/complex.h @@ -812,8 +813,10 @@ ripper_init.o: $(hdrdir)/ruby/st.h ripper_init.o: $(hdrdir)/ruby/subst.h ripper_init.o: $(top_srcdir)/internal.h ripper_init.o: $(top_srcdir)/internal/array.h +ripper_init.o: $(top_srcdir)/internal/basic_operators.h ripper_init.o: $(top_srcdir)/internal/bignum.h ripper_init.o: $(top_srcdir)/internal/bits.h +ripper_init.o: $(top_srcdir)/internal/compar.h ripper_init.o: $(top_srcdir)/internal/compilers.h ripper_init.o: $(top_srcdir)/internal/complex.h ripper_init.o: $(top_srcdir)/internal/fixnum.h diff --git a/internal/compar.h b/internal/compar.h index 9115e4bd63a8e4..5eb5e8714e7483 100644 --- a/internal/compar.h +++ b/internal/compar.h @@ -25,5 +25,6 @@ /* compar.c */ VALUE rb_invcmp(VALUE, VALUE); +NORETURN(void rb_cmperr_reason(VALUE, VALUE, const char*)); #endif /* INTERNAL_COMPAR_H */ diff --git a/internal/numeric.h b/internal/numeric.h index 6391b1e9bc0f5c..280c008952ed7d 100644 --- a/internal/numeric.h +++ b/internal/numeric.h @@ -10,9 +10,9 @@ */ #include "internal/bignum.h" /* for BIGNUM_POSITIVE_P */ #include "internal/bits.h" /* for RUBY_BIT_ROTL */ +#include "internal/compar.h" /* for rb_cmperr_reason */ #include "internal/fixnum.h" /* for FIXNUM_POSITIVE_P */ #include "internal/vm.h" /* for rb_method_basic_definition_p */ -#include "ruby/intern.h" /* for rb_cmperr */ #include "ruby/ruby.h" /* for USE_FLONUM */ #define ROUND_TO(mode, even, up, down) \ @@ -210,7 +210,7 @@ rb_num_compare_with_zero(VALUE num, ID mid) VALUE zero = INT2FIX(0); VALUE r = rb_check_funcall(num, mid, 1, &zero); if (RB_UNDEF_P(r)) { - rb_cmperr(num, zero); + rb_cmperr_reason(num, zero, "unable to compare with zero"); } return r; } diff --git a/numeric.c b/numeric.c index 10ce7358e7a370..226a47f7b8f38b 100644 --- a/numeric.c +++ b/numeric.c @@ -492,7 +492,7 @@ rb_num_coerce_cmp(VALUE x, VALUE y, ID func) static VALUE ensure_cmp(VALUE c, VALUE x, VALUE y) { - if (NIL_P(c)) rb_cmperr(x, y); + if (NIL_P(c)) rb_cmperr_reason(x, y, "comparator returned nil"); return c; } @@ -502,7 +502,7 @@ rb_num_coerce_relop(VALUE x, VALUE y, ID func) VALUE x0 = x, y0 = y; if (!do_coerce(&x, &y, FALSE)) { - rb_cmperr(x0, y0); + rb_cmperr_reason(x0, y0, "coercion was not possible"); UNREACHABLE_RETURN(Qnil); } return ensure_cmp(rb_funcall(x, func, 1, y), x0, y0); @@ -5911,7 +5911,7 @@ int_downto(VALUE from, VALUE to) rb_yield(i); i = rb_funcall(i, '-', 1, INT2FIX(1)); } - if (NIL_P(c)) rb_cmperr(i, to); + ensure_cmp(c, i, to); } return from; } diff --git a/range.c b/range.c index c3b3813cb1eef7..041cd93f73ee4e 100644 --- a/range.c +++ b/range.c @@ -200,11 +200,10 @@ range_eq(VALUE range, VALUE obj) static int r_less(VALUE a, VALUE b) { - VALUE r = rb_funcall(a, id_cmp, 1, b); - - if (NIL_P(r)) - return INT_MAX; - return rb_cmpint(r, a, b); + VALUE r; +#define rb_cmpint(cmp, a, b) (NIL_P(r = (cmp)) ? INT_MAX : rb_cmpint(r, (a), (b))) + return OPTIMIZED_CMP(a, b); +#undef rb_cmpint } static VALUE diff --git a/spec/ruby/core/comparable/lt_spec.rb b/spec/ruby/core/comparable/lt_spec.rb index bca95f8d252bce..3c73e410ea14ed 100644 --- a/spec/ruby/core/comparable/lt_spec.rb +++ b/spec/ruby/core/comparable/lt_spec.rb @@ -43,7 +43,7 @@ it "raises an argument error with a message containing the value" do -> { ("foo" < 7) }.should raise_error(ArgumentError) { |e| - e.message.should == "comparison of String with 7 failed" + e.message.should.include? "String with 7 failed" } end end diff --git a/test/rubygems/test_gem_commands_push_command.rb b/test/rubygems/test_gem_commands_push_command.rb index 1477a749471443..978ed3ada88e8c 100644 --- a/test/rubygems/test_gem_commands_push_command.rb +++ b/test/rubygems/test_gem_commands_push_command.rb @@ -487,6 +487,7 @@ def test_with_webauthn_enabled_success end def test_with_webauthn_enabled_failure + pend "Flaky on TruffleRuby" if RUBY_ENGINE == "truffleruby" response_success = "Successfully registered gem: freewill (1.0.0)" server = Gem::MockTCPServer.new error = Gem::WebauthnVerificationError.new("Something went wrong") diff --git a/zjit/src/hir.rs b/zjit/src/hir.rs index a71946b3c915e3..3382747db71353 100644 --- a/zjit/src/hir.rs +++ b/zjit/src/hir.rs @@ -5318,6 +5318,28 @@ impl Function { } } + /// Remove duplicate CheckInterrupts instructions within each basic block. + /// Only the first CheckInterrupts in a block is needed unless an intervening + /// instruction writes to InterruptFlag (e.g. a call), which resets tracking. + fn remove_duplicate_check_interrupts(&mut self) { + for block_id in self.rpo() { + let mut seen = false; + let insns = std::mem::take(&mut self.blocks[block_id.0].insns); + let mut new_insns = Vec::with_capacity(insns.len()); + for insn_id in insns { + let insn = &self.insns[insn_id.0]; + if matches!(insn, Insn::CheckInterrupts { .. }) { + if seen { continue; } + seen = true; + } else if insn.effects_of().write_bits().overlaps(abstract_heaps::InterruptFlag) { + seen = false; + } + new_insns.push(insn_id); + } + self.blocks[block_id.0].insns = new_insns; + } + } + /// Return a list that has entry_block and then jit_entry_blocks fn entry_blocks(&self) -> Vec { let mut entry_blocks = self.jit_entry_blocks.clone(); @@ -5545,6 +5567,8 @@ impl Function { Counter::compile_hir_clean_cfg_time_ns } else if ident_equal!($name, remove_redundant_patch_points) { Counter::compile_hir_remove_redundant_patch_points_time_ns + } else if ident_equal!($name, remove_duplicate_check_interrupts) { + Counter::compile_hir_remove_duplicate_check_interrupts_time_ns } else if ident_equal!($name, eliminate_dead_code) { Counter::compile_hir_eliminate_dead_code_time_ns } else { @@ -5573,6 +5597,7 @@ impl Function { run_pass!(fold_constants); run_pass!(clean_cfg); run_pass!(remove_redundant_patch_points); + run_pass!(remove_duplicate_check_interrupts); run_pass!(eliminate_dead_code); if should_dump { diff --git a/zjit/src/hir/opt_tests.rs b/zjit/src/hir/opt_tests.rs index 239e3c65949860..440d8a5d17d83a 100644 --- a/zjit/src/hir/opt_tests.rs +++ b/zjit/src/hir/opt_tests.rs @@ -53,9 +53,7 @@ mod hir_opt_tests { bb3(v8:BasicObject, v9:NilClass): v13:TrueClass = Const Value(true) CheckInterrupts - v22:TrueClass = RefineType v13, Truthy v25:Fixnum[3] = Const Value(3) - CheckInterrupts Return v25 "); } @@ -87,9 +85,7 @@ mod hir_opt_tests { bb3(v8:BasicObject, v9:NilClass): v13:FalseClass = Const Value(false) CheckInterrupts - v20:FalseClass = RefineType v13, Falsy v35:Fixnum[4] = Const Value(4) - CheckInterrupts Return v35 "); } @@ -681,7 +677,6 @@ mod hir_opt_tests { IncrCounter inline_cfunc_optimized_send_count CheckInterrupts v24:Fixnum[3] = Const Value(3) - CheckInterrupts Return v24 "); } @@ -714,11 +709,8 @@ mod hir_opt_tests { v60:TrueClass = Const Value(true) IncrCounter inline_cfunc_optimized_send_count CheckInterrupts - v62:TrueClass = Const Value(true) IncrCounter inline_cfunc_optimized_send_count - CheckInterrupts v37:Fixnum[3] = Const Value(3) - CheckInterrupts Return v37 "); } @@ -752,7 +744,6 @@ mod hir_opt_tests { IncrCounter inline_cfunc_optimized_send_count CheckInterrupts v24:Fixnum[3] = Const Value(3) - CheckInterrupts Return v24 "); } @@ -785,11 +776,8 @@ mod hir_opt_tests { v60:TrueClass = Const Value(true) IncrCounter inline_cfunc_optimized_send_count CheckInterrupts - v62:TrueClass = Const Value(true) IncrCounter inline_cfunc_optimized_send_count - CheckInterrupts v37:Fixnum[3] = Const Value(3) - CheckInterrupts Return v37 "); } @@ -823,7 +811,6 @@ mod hir_opt_tests { IncrCounter inline_cfunc_optimized_send_count CheckInterrupts v33:Fixnum[4] = Const Value(4) - CheckInterrupts Return v33 "); } @@ -857,7 +844,6 @@ mod hir_opt_tests { IncrCounter inline_cfunc_optimized_send_count CheckInterrupts v24:Fixnum[3] = Const Value(3) - CheckInterrupts Return v24 "); } @@ -892,7 +878,6 @@ mod hir_opt_tests { IncrCounter inline_cfunc_optimized_send_count CheckInterrupts v24:Fixnum[3] = Const Value(3) - CheckInterrupts Return v24 "); } @@ -927,7 +912,6 @@ mod hir_opt_tests { IncrCounter inline_cfunc_optimized_send_count CheckInterrupts v33:Fixnum[4] = Const Value(4) - CheckInterrupts Return v33 "); } @@ -4283,7 +4267,6 @@ mod hir_opt_tests { v50:NilClass = Const Value(nil) IncrCounter inline_cfunc_optimized_send_count CheckInterrupts - CheckInterrupts Return v46 "); } @@ -4321,7 +4304,6 @@ mod hir_opt_tests { PatchPoint MethodRedefined(C@0x1008, initialize@0x1038, cme:0x1040) v52:BasicObject = SendDirect v49, 0x1068, :initialize (0x1078), v15 CheckInterrupts - CheckInterrupts Return v49 "); } @@ -4354,7 +4336,6 @@ mod hir_opt_tests { v50:NilClass = Const Value(nil) IncrCounter inline_cfunc_optimized_send_count CheckInterrupts - CheckInterrupts Return v46 "); } @@ -4387,7 +4368,6 @@ mod hir_opt_tests { v50:NilClass = Const Value(nil) IncrCounter inline_cfunc_optimized_send_count CheckInterrupts - CheckInterrupts Return v46 "); } @@ -4418,7 +4398,6 @@ mod hir_opt_tests { IncrCounter complex_arg_pass_param_block v19:BasicObject = Send v46, :initialize # SendFallbackReason: Complex argument passing CheckInterrupts - CheckInterrupts Return v46 "); assert_snapshot!(inspect("test"), @"{}"); @@ -4483,7 +4462,6 @@ mod hir_opt_tests { v49:SetExact = GuardType v17, SetExact v50:BasicObject = CCallVariadic v49, :Set#initialize@0x1068 CheckInterrupts - CheckInterrupts Return v17 "); } @@ -4547,7 +4525,6 @@ mod hir_opt_tests { PatchPoint MethodRedefined(Regexp@0x1008, initialize@0x1048, cme:0x1050) v54:BasicObject = CCallVariadic v50, :Regexp#initialize@0x1078, v16 CheckInterrupts - CheckInterrupts Return v50 "); } @@ -5914,7 +5891,6 @@ mod hir_opt_tests { v13:NilClass = Const Value(nil) CheckInterrupts v21:NilClass = Const Value(nil) - CheckInterrupts Return v21 "); } @@ -5946,7 +5922,6 @@ mod hir_opt_tests { v23:Fixnum[1] = RefineType v13, NotNil PatchPoint MethodRedefined(Integer@0x1000, itself@0x1008, cme:0x1010) IncrCounter inline_cfunc_optimized_send_count - CheckInterrupts Return v23 "); } @@ -12110,7 +12085,6 @@ mod hir_opt_tests { IncrCounter inline_cfunc_optimized_send_count CheckInterrupts v26:StaticSymbol[:CORRECT] = Const Value(VALUE(0x10a8)) - CheckInterrupts Return v26 "); } @@ -13509,11 +13483,7 @@ mod hir_opt_tests { IfFalse v16, bb6(v9, v17) v19:Truthy = RefineType v10, Truthy CheckInterrupts - v27:Truthy = RefineType v19, Truthy - CheckInterrupts - v35:Truthy = RefineType v27, Truthy v38:Fixnum[3] = Const Value(3) - CheckInterrupts Return v38 bb6(v43:BasicObject, v44:Falsy): v48:Fixnum[6] = Const Value(6) diff --git a/zjit/src/stats.rs b/zjit/src/stats.rs index 42dd39fdd047e9..aca4ae8051657b 100644 --- a/zjit/src/stats.rs +++ b/zjit/src/stats.rs @@ -171,6 +171,7 @@ make_counters! { compile_hir_fold_constants_time_ns, compile_hir_clean_cfg_time_ns, compile_hir_remove_redundant_patch_points_time_ns, + compile_hir_remove_duplicate_check_interrupts_time_ns, compile_hir_eliminate_dead_code_time_ns, compile_lir_time_ns, }