Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ The following bundled gems are updated.
* rbs 3.9.5
* debug 1.11.0
* base64 0.3.0
* bigdecimal 3.2.2
* bigdecimal 3.3.1
* drb 2.2.3
* syslog 0.3.0
* csv 3.3.5
Expand Down
6 changes: 2 additions & 4 deletions concurrent_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,7 @@ rb_concurrent_set_find_or_insert(VALUE *set_obj_ptr, VALUE key, void *data)
VALUE
rb_concurrent_set_delete_by_identity(VALUE set_obj, VALUE key)
{
// Assume locking and barrier (which there is no assert for).
ASSERT_vm_locking();
ASSERT_vm_locking_with_barrier();

struct concurrent_set *set = RTYPEDDATA_GET_DATA(set_obj);

Expand Down Expand Up @@ -391,8 +390,7 @@ rb_concurrent_set_delete_by_identity(VALUE set_obj, VALUE key)
void
rb_concurrent_set_foreach_with_replace(VALUE set_obj, int (*callback)(VALUE *key, void *data), void *data)
{
// Assume locking and barrier (which there is no assert for).
ASSERT_vm_locking();
ASSERT_vm_locking_with_barrier();

struct concurrent_set *set = RTYPEDDATA_GET_DATA(set_obj);

Expand Down
2 changes: 0 additions & 2 deletions gc/default/default.c
Original file line number Diff line number Diff line change
Expand Up @@ -6633,8 +6633,6 @@ gc_enter(rb_objspace_t *objspace, enum gc_enter_event event, unsigned int *lock_

switch (event) {
case gc_enter_event_rest:
if (!is_marking(objspace)) break;
// fall through
case gc_enter_event_start:
case gc_enter_event_continue:
// stop other ractors
Expand Down
2 changes: 1 addition & 1 deletion gems/bundled_gems
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ racc 1.8.1 https://github.com/ruby/racc
mutex_m 0.3.0 https://github.com/ruby/mutex_m
getoptlong 0.2.1 https://github.com/ruby/getoptlong
base64 0.3.0 https://github.com/ruby/base64
bigdecimal 3.2.2 https://github.com/ruby/bigdecimal
bigdecimal 3.3.1 https://github.com/ruby/bigdecimal
observer 0.1.2 https://github.com/ruby/observer
abbrev 0.1.2 https://github.com/ruby/abbrev
resolv-replace 0.1.1 https://github.com/ruby/resolv-replace
Expand Down
10 changes: 6 additions & 4 deletions spec/ruby/library/bigdecimal/BigDecimal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@
BigDecimal("-12345.6E-1").should == -reference
end

it "raises ArgumentError when Float is used without precision" do
-> { BigDecimal(1.0) }.should raise_error(ArgumentError)
version_is BigDecimal::VERSION, "3.3.0" do
it "allows Float without precision" do
BigDecimal(1.2).should == BigDecimal("1.2")
end
end

it "returns appropriate BigDecimal zero for signed zero" do
Expand Down Expand Up @@ -259,8 +261,8 @@ def to_s; "cheese"; end
end

it "produces the expected result" do
@c.should == BigDecimal("-0.666667e-9")
@c.to_s.should == "-0.666667e-9"
@c.round(15).should == BigDecimal("-0.666667e-9")
@c.round(15).to_s.should == "-0.666667e-9"
end

it "produces the correct class for other arithmetic operators" do
Expand Down
8 changes: 0 additions & 8 deletions spec/ruby/library/bigdecimal/add_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@
# BigDecimal("0.88").add(0.0, 1).should == BigDecimal("0.9")
# end

describe "with Object" do
it "tries to coerce the other operand to self" do
object = mock("Object")
object.should_receive(:coerce).with(@frac_3).and_return([@frac_3, @frac_4])
@frac_3.add(object, 1).should == BigDecimal("0.1E16")
end
end

describe "with Rational" do
it "produces a BigDecimal" do
(@three + Rational(500, 2)).should == BigDecimal("0.253e3")
Expand Down
7 changes: 5 additions & 2 deletions spec/ruby/library/bigdecimal/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@

describe "BigDecimal#log" do
it "handles high-precision Rational arguments" do
result = BigDecimal('0.22314354220170971436137296411949880462556361100856391620766259404746040597133837784E0')
# log(BigDecimal(r, 50), 50)
result1 = BigDecimal('0.22314354220170971436137296411949880462556361100856e0')
# log(BigDecimal(r, 1000), 50)
result2 = BigDecimal('0.22314354220170971436137296411949880462556361100853e0')
r = Rational(1_234_567_890, 987_654_321)
BigMath.log(r, 50).should == result
[result1, result2].should include(BigMath.log(r, 50).mult(1, 50))
end
end

Expand Down
19 changes: 13 additions & 6 deletions spec/ruby/library/bigdecimal/divmod_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,19 @@ class BigDecimal
end
end

it "returns an array of zero and the dividend if the divisor is Infinity" do
@regular_vals.each do |val|
array = val.divmod(@infinity)
array.length.should == 2
array[0].should == @zero
array[1].should == val
version_is BigDecimal::VERSION, "3.3.0" do
it "returns an array of zero and the dividend or minus one and Infinity if the divisor is Infinity" do
@regular_vals.each do |val|
array = val.divmod(@infinity)
array.length.should == 2
if val >= 0
array[0].should == @zero
array[1].should == val
else
array[0].should == @one_minus
array[1].should == @infinity
end
end
end
end

Expand Down
8 changes: 0 additions & 8 deletions spec/ruby/library/bigdecimal/mult_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,4 @@
@e.mult(@one, 1).should be_close(@one, @tolerance)
@e3_minus.mult(@one, 1).should be_close(0, @tolerance2)
end

describe "with Object" do
it "tries to coerce the other operand to self" do
object = mock("Object")
object.should_receive(:coerce).with(@e3_minus).and_return([@e3_minus, @e3_plus])
@e3_minus.mult(object, 1).should == BigDecimal("9")
end
end
end
8 changes: 5 additions & 3 deletions spec/ruby/library/bigdecimal/remainder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
@neg_int.remainder(@pos_frac).should == @neg_int - @pos_frac * (@neg_int / @pos_frac).truncate
end

it "returns NaN used with zero" do
@mixed.remainder(@zero).should.nan?
@zero.remainder(@zero).should.nan?
version_is BigDecimal::VERSION, "3.3.0" do
it "raises ZeroDivisionError used with zero" do
-> { @mixed.remainder(@zero) }.should raise_error(ZeroDivisionError)
-> { @zero.remainder(@zero) }.should raise_error(ZeroDivisionError)
end
end

it "returns zero if used on zero" do
Expand Down
14 changes: 10 additions & 4 deletions spec/ruby/library/bigdecimal/shared/modulo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,16 @@
@infinity_minus.send(@method, @infinity).should.nan?
end

it "returns the dividend if the divisor is Infinity" do
@one.send(@method, @infinity).should == @one
@one.send(@method, @infinity_minus).should == @one
@frac_2.send(@method, @infinity_minus).should == @frac_2
version_is BigDecimal::VERSION, "3.3.0" do
it "returns the dividend if the divisor is Infinity and signs are same" do
@one.send(@method, @infinity).should == @one
(-@frac_2).send(@method, @infinity_minus).should == -@frac_2
end

it "returns the divisor if the divisor is Infinity and signs are different" do
(-@one).send(@method, @infinity).should == @infinity
@frac_2.send(@method, @infinity_minus).should == @infinity_minus
end
end

it "raises TypeError if the argument cannot be coerced to BigDecimal" do
Expand Down
4 changes: 2 additions & 2 deletions spec/ruby/library/bigdecimal/shared/power.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
e = BigDecimal("1.00000000000000000000123456789")
one = BigDecimal("1")
ten = BigDecimal("10")
# The tolerance is dependent upon the size of BASE_FIG
tolerance = BigDecimal("1E-70")
# Accuracy is at least ndigits(== 30) + DOUBLE_FIG(== 16)
tolerance = BigDecimal("1E-46")
ten_powers = BigDecimal("1E10000")
pi = BigDecimal("3.14159265358979")
e3_minus.send(@method, 2).should == e3_minus_power_2
Expand Down
8 changes: 0 additions & 8 deletions spec/ruby/library/bigdecimal/sub_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@
@frac_1.sub(@frac_1, 1000000).should == @zero
end

describe "with Object" do
it "tries to coerce the other operand to self" do
object = mock("Object")
object.should_receive(:coerce).with(@frac_3).and_return([@frac_3, @frac_4])
@frac_3.sub(object, 1).should == BigDecimal("-0.9E15")
end
end

describe "with Rational" do
it "produces a BigDecimal" do
(@three - Rational(500, 2)).should == BigDecimal('-0.247e3')
Expand Down
3 changes: 1 addition & 2 deletions string.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,7 @@ rb_obj_is_fstring_table(VALUE obj)
void
rb_gc_free_fstring(VALUE obj)
{
// Assume locking and barrier (which there is no assert for)
ASSERT_vm_locking();
ASSERT_vm_locking_with_barrier();

rb_concurrent_set_delete_by_identity(fstring_table_obj, obj);

Expand Down
8 changes: 8 additions & 0 deletions test/ruby/test_zjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,14 @@ def test = [1,2,3]
}
end

def test_array_fixnum_aref
assert_compiles '3', %q{
def test(x) = [1,2,3][x]
test(2)
test(2)
}, call_threshold: 2, insns: [:opt_aref]
end

def test_new_range_inclusive
assert_compiles '1..5', %q{
def test(a, b) = a..b
Expand Down
14 changes: 14 additions & 0 deletions vm_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ RUBY_ASSERT_vm_locking(void)
}
}

void
RUBY_ASSERT_vm_locking_with_barrier(void)
{
if (rb_multi_ractor_p()) {
rb_vm_t *vm = GET_VM();
VM_ASSERT(vm_locked(vm));

if (vm->ractor.cnt > 1) {
/* Written to only when holding both ractor.sync and ractor.sched lock */
VM_ASSERT(vm->ractor.sched.barrier_waiting);
}
}
}

void
RUBY_ASSERT_vm_unlocking(void)
{
Expand Down
3 changes: 3 additions & 0 deletions vm_sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,14 @@ rb_vm_lock_leave_cr(struct rb_ractor_struct *cr, unsigned int *levp, const char

#if RUBY_DEBUG > 0
void RUBY_ASSERT_vm_locking(void);
void RUBY_ASSERT_vm_locking_with_barrier(void);
void RUBY_ASSERT_vm_unlocking(void);
#define ASSERT_vm_locking() RUBY_ASSERT_vm_locking()
#define ASSERT_vm_locking_with_barrier() RUBY_ASSERT_vm_locking_with_barrier()
#define ASSERT_vm_unlocking() RUBY_ASSERT_vm_unlocking()
#else
#define ASSERT_vm_locking()
#define ASSERT_vm_locking_with_barrier()
#define ASSERT_vm_unlocking()
#endif

Expand Down
1 change: 1 addition & 0 deletions zjit/bindgen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ fn main() {
.allowlist_function("rb_ary_unshift_m")
.allowlist_function("rb_ec_ary_new_from_values")
.allowlist_function("rb_ary_tmp_new_from_values")
.allowlist_function("rb_ary_entry")
.allowlist_function("rb_class_attached_object")
.allowlist_function("rb_singleton_class")
.allowlist_function("rb_define_class")
Expand Down
11 changes: 11 additions & 0 deletions zjit/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ fn gen_insn(cb: &mut CodeBlock, jit: &mut JITState, asm: &mut Assembler, functio
Insn::NewRange { low, high, flag, state } => gen_new_range(jit, asm, opnd!(low), opnd!(high), *flag, &function.frame_state(*state)),
Insn::NewRangeFixnum { low, high, flag, state } => gen_new_range_fixnum(asm, opnd!(low), opnd!(high), *flag, &function.frame_state(*state)),
Insn::ArrayDup { val, state } => gen_array_dup(asm, opnd!(val), &function.frame_state(*state)),
Insn::ArrayArefFixnum { array, index, .. } => gen_aref_fixnum(asm, opnd!(array), opnd!(index)),
Insn::ObjectAlloc { val, state } => gen_object_alloc(jit, asm, opnd!(val), &function.frame_state(*state)),
&Insn::ObjectAllocClass { class, state } => gen_object_alloc_class(asm, class, &function.frame_state(state)),
Insn::StringCopy { val, chilled, state } => gen_string_copy(asm, opnd!(val), *chilled, &function.frame_state(*state)),
Expand Down Expand Up @@ -1241,6 +1242,16 @@ fn gen_new_array(
new_array
}

/// Compile array access (array[index])
fn gen_aref_fixnum(
asm: &mut Assembler,
array: Opnd,
index: Opnd,
) -> lir::Opnd {
let unboxed_idx = asm.rshift(index, Opnd::UImm(1));
asm_ccall!(asm, rb_ary_entry, array, unboxed_idx)
}

/// Compile a new hash instruction
fn gen_new_hash(
jit: &mut JITState,
Expand Down
1 change: 1 addition & 0 deletions zjit/src/cruby_bindings.inc.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading