Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into Ractor-Local-GC-v…
Browse files Browse the repository at this point in the history
…ersion-2
  • Loading branch information
rm155 committed Mar 18, 2024
2 parents 9e07589 + 802e857 commit 5748f36
Show file tree
Hide file tree
Showing 318 changed files with 3,053 additions and 3,005 deletions.
5 changes: 0 additions & 5 deletions .github/actions/launchable/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ inputs:
Directory to (re-)checkout source codes. Launchable retrives the commit information
from the directory.
outputs:
enable-launchable:
description: "The boolean value indicating whether Launchable is enabled or not"
value: ${{ steps.enable-launchable.outputs.enable-launchable }}

runs:
using: composite

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ jobs:
if: ${{ matrix.test_task == 'check' && matrix.skipped_tests }}

- name: Set up Launchable
id: enable-launchable
uses: ./.github/actions/launchable/setup
with:
os: ${{ matrix.os }}
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ jobs:
if: ${{ matrix.test_task == 'check' && matrix.skipped_tests }}

- name: Set up Launchable
id: enable-launchable
uses: ./.github/actions/launchable/setup
with:
os: ${{ matrix.os }}
Expand Down
11 changes: 11 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@ Note that each entry is kept to a minimum, see links for details.
and not calling any conversion methods.
[[Bug #20064]]

* Block passing is no longer allowed in index. [[Bug #19918]]

* Keyword arguments are no longer allowed in index. [[Bug #20218]]

## Core classes updates

Note: We're only listing outstanding class updates.

* Exception

* Exception#set_backtrace now accepts arrays of `Thread::Backtrace::Location`.
`Kernel#raise`, `Thread#raise` and `Fiber#raise` also accept this new format. [Feature #13557]

## Stdlib updates

The following default gems are updated.
Expand Down Expand Up @@ -95,6 +104,8 @@ See GitHub releases like [GitHub Releases of Logger](https://github.com/ruby/log
[Feature #16495]: https://bugs.ruby-lang.org/issues/16495
[Feature #18980]: https://bugs.ruby-lang.org/issues/18980
[Feature #19117]: https://bugs.ruby-lang.org/issues/19117
[Bug #19918]: https://bugs.ruby-lang.org/issues/19918
[Bug #20064]: https://bugs.ruby-lang.org/issues/20064
[Feature #20182]: https://bugs.ruby-lang.org/issues/20182
[Bug #20218]: https://bugs.ruby-lang.org/issues/20218
[Feature #20265]: https://bugs.ruby-lang.org/issues/20265
82 changes: 12 additions & 70 deletions bignum.c
Original file line number Diff line number Diff line change
Expand Up @@ -6878,63 +6878,11 @@ BDIGIT rb_bdigit_dbl_isqrt(BDIGIT_DBL);
# define BDIGIT_DBL_TO_DOUBLE(n) (double)(n)
#endif

static BDIGIT *
estimate_initial_sqrt(VALUE *xp, const size_t xn, const BDIGIT *nds, size_t len)
{
enum {dbl_per_bdig = roomof(DBL_MANT_DIG,BITSPERDIG)};
const int zbits = nlz(nds[len-1]);
VALUE x = *xp = bignew_1(0, xn, 1); /* division may release the GVL */
BDIGIT *xds = BDIGITS(x);
BDIGIT_DBL d = bary2bdigitdbl(nds+len-dbl_per_bdig, dbl_per_bdig);
BDIGIT lowbits = 1;
int rshift = (int)((BITSPERDIG*2-zbits+(len&BITSPERDIG&1) - DBL_MANT_DIG + 1) & ~1);
double f;

if (rshift > 0) {
lowbits = (BDIGIT)d & ~(~(BDIGIT)1U << rshift);
d >>= rshift;
}
else if (rshift < 0) {
d <<= -rshift;
d |= nds[len-dbl_per_bdig-1] >> (BITSPERDIG+rshift);
}
f = sqrt(BDIGIT_DBL_TO_DOUBLE(d));
d = (BDIGIT_DBL)ceil(f);
if (BDIGIT_DBL_TO_DOUBLE(d) == f) {
if (lowbits || (lowbits = !bary_zero_p(nds, len-dbl_per_bdig)))
++d;
}
else {
lowbits = 1;
}
rshift /= 2;
rshift += (2-(len&1))*BITSPERDIG/2;
if (rshift >= 0) {
if (nlz((BDIGIT)d) + rshift >= BITSPERDIG) {
/* (d << rshift) does cause overflow.
* example: Integer.sqrt(0xffff_ffff_ffff_ffff ** 2)
*/
d = ~(BDIGIT_DBL)0;
}
else {
d <<= rshift;
}
}
BDIGITS_ZERO(xds, xn-2);
bdigitdbl2bary(&xds[xn-2], 2, d);

if (!lowbits) return NULL; /* special case, exact result */
return xds;
}

VALUE
rb_big_isqrt(VALUE n)
{
BDIGIT *nds = BDIGITS(n);
size_t len = BIGNUM_LEN(n);
size_t xn = (len+1) / 2;
VALUE x;
BDIGIT *xds;

if (len <= 2) {
BDIGIT sq = rb_bdigit_dbl_isqrt(bary2bdigitdbl(nds, len));
Expand All @@ -6944,25 +6892,19 @@ rb_big_isqrt(VALUE n)
return ULONG2NUM(sq);
#endif
}
else if ((xds = estimate_initial_sqrt(&x, xn, nds, len)) != 0) {
size_t tn = xn + BIGDIVREM_EXTRA_WORDS;
VALUE t = bignew_1(0, tn, 1);
BDIGIT *tds = BDIGITS(t);
tn = BIGNUM_LEN(t);

/* t = n/x */
while (bary_divmod_branch(tds, tn, NULL, 0, nds, len, xds, xn),
bary_cmp(tds, tn, xds, xn) < 0) {
int carry;
BARY_TRUNC(tds, tn);
/* x = (x+t)/2 */
carry = bary_add(xds, xn, xds, xn, tds, tn);
bary_small_rshift(xds, xds, xn, 1, carry);
tn = BIGNUM_LEN(t);
}
else {
size_t shift = FIX2LONG(rb_big_bit_length(n)) / 4;
VALUE n2 = rb_int_rshift(n, SIZET2NUM(2 * shift));
VALUE x = FIXNUM_P(n2) ? LONG2FIX(rb_ulong_isqrt(FIX2ULONG(n2))) : rb_big_isqrt(n2);
/* x = (x+n/x)/2 */
x = rb_int_plus(rb_int_lshift(x, SIZET2NUM(shift - 1)), rb_int_idiv(rb_int_rshift(n, SIZET2NUM(shift + 1)), x));
VALUE xx = rb_int_mul(x, x);
while (rb_int_gt(xx, n)) {
xx = rb_int_minus(xx, rb_int_minus(rb_int_plus(x, x), INT2FIX(1)));
x = rb_int_minus(x, INT2FIX(1));
}
return x;
}
RBASIC_SET_CLASS_RAW(x, rb_cInteger);
return x;
}

#if USE_GMP
Expand Down
2 changes: 1 addition & 1 deletion bootstraptest/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def get_result_string(opt = '', **argh)
end
end

def make_srcfile(frozen_string_literal: true)
def make_srcfile(frozen_string_literal: nil)
filename = "bootstraptest.#{self.path}_#{self.lineno}_#{self.id}.rb"
File.open(filename, 'w') {|f|
f.puts "#frozen_string_literal:#{frozen_string_literal}" unless frozen_string_literal.nil?
Expand Down
31 changes: 31 additions & 0 deletions bootstraptest/test_eval.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,34 @@ def kaboom!
end
}, 'check escaping the internal value th->base_block'

assert_equal "false", <<~RUBY, "literal strings are mutable", "--disable-frozen-string-literal"
eval("'test'").frozen?
RUBY

assert_equal "false", <<~RUBY, "literal strings are mutable", "--disable-frozen-string-literal", frozen_string_literal: true
eval("'test'").frozen?
RUBY

assert_equal "true", <<~RUBY, "literal strings are frozen", "--enable-frozen-string-literal"
eval("'test'").frozen?
RUBY

assert_equal "true", <<~RUBY, "literal strings are frozen", "--enable-frozen-string-literal", frozen_string_literal: false
eval("'test'").frozen?
RUBY

assert_equal "false", <<~RUBY, "__FILE__ is mutable", "--disable-frozen-string-literal"
eval("__FILE__").frozen?
RUBY

assert_equal "false", <<~RUBY, "__FILE__ is mutable", "--disable-frozen-string-literal", frozen_string_literal: true
eval("__FILE__").frozen?
RUBY

assert_equal "true", <<~RUBY, "__FILE__ is frozen", "--enable-frozen-string-literal"
eval("__FILE__").frozen?
RUBY

assert_equal "true", <<~RUBY, "__FILE__ is frozen", "--enable-frozen-string-literal", frozen_string_literal: false
eval("__FILE__").frozen?
RUBY
23 changes: 0 additions & 23 deletions bootstraptest/test_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,24 +340,6 @@ def method_missing(mid, *args, &block) block end
assert_equal '1', %q( class C; def m() 1 end; private :m end
C.new.send(:m) )

# with block
assert_equal '[[:ok1, :foo], [:ok2, :foo, :bar]]',
%q{
class C
def [](a)
$ary << [yield, a]
end
def []=(a, b)
$ary << [yield, a, b]
end
end
$ary = []
C.new[:foo, &lambda{:ok1}]
C.new[:foo, &lambda{:ok2}] = :bar
$ary
}

# with
assert_equal '[:ok1, [:ok2, 11]]', %q{
class C
Expand Down Expand Up @@ -404,7 +386,6 @@ def m(*args, &b)

# aset and splat
assert_equal '4', %q{class Foo;def []=(a,b,c,d);end;end;Foo.new[1,*a=[2,3]]=4}
assert_equal '4', %q{class Foo;def []=(a,b,c,d);end;end;def m(&blk)Foo.new[1,*a=[2,3],&blk]=4;end;m{}}

# post test
assert_equal %q{[1, 2, :o1, :o2, [], 3, 4, NilClass, nil, nil]}, %q{
Expand Down Expand Up @@ -1107,10 +1088,6 @@ class C
'ok'
end
}
assert_equal 'ok', %q{
[0][0, &proc{}] += 21
'ok'
}, '[ruby-core:30534]'

# should not cache when splat
assert_equal 'ok', %q{
Expand Down
2 changes: 1 addition & 1 deletion bootstraptest/test_ractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ class C
}

# TracePoint with normal Proc should be Ractor local
assert_equal '[7, 11]', %q{
assert_equal '[6, 10]', %q{
rs = []
TracePoint.new(:line){|tp| rs << tp.lineno if tp.path == __FILE__}.enable do
Ractor.new{ # line 5
Expand Down
32 changes: 32 additions & 0 deletions bootstraptest/test_syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -904,3 +904,35 @@ def foo(&block)
Class
end
}, '[ruby-core:30293]'

assert_equal "false", <<~RUBY, "literal strings are mutable", "--disable-frozen-string-literal"
'test'.frozen?
RUBY

assert_equal "true", <<~RUBY, "literal strings are frozen", "--disable-frozen-string-literal", frozen_string_literal: true
'test'.frozen?
RUBY

assert_equal "true", <<~RUBY, "literal strings are frozen", "--enable-frozen-string-literal"
'test'.frozen?
RUBY

assert_equal "false", <<~RUBY, "literal strings are mutable", "--enable-frozen-string-literal", frozen_string_literal: false
'test'.frozen?
RUBY

assert_equal "false", <<~RUBY, "__FILE__ is mutable", "--disable-frozen-string-literal"
__FILE__.frozen?
RUBY

assert_equal "true", <<~RUBY, "__FILE__ is frozen", "--disable-frozen-string-literal", frozen_string_literal: true
__FILE__.frozen?
RUBY

assert_equal "true", <<~RUBY, "__FILE__ is frozen", "--enable-frozen-string-literal"
__FILE__.frozen?
RUBY

assert_equal "false", <<~RUBY, "__FILE__ is mutable", "--enable-frozen-string-literal", frozen_string_literal: false
__FILE__.frozen?
RUBY
16 changes: 16 additions & 0 deletions bootstraptest/test_yjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4678,3 +4678,19 @@ def test(klass, args)
test(KwInit, [Hash.ruby2_keywords_hash({1 => 1})])
}

# arity=-2 cfuncs
assert_equal '["", "1/2", [0, [:ok, 1]]]', %q{
def test_cases(file, chain)
new_chain = chain.allocate # to call initialize directly
new_chain.send(:initialize, [0], ok: 1)
[
file.join,
file.join("1", "2"),
new_chain.to_a,
]
end
test_cases(File, Enumerator::Chain)
}
Loading

0 comments on commit 5748f36

Please sign in to comment.