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 Nov 24, 2023
2 parents a208de4 + e3b4852 commit ae1dfa8
Show file tree
Hide file tree
Showing 719 changed files with 8,998 additions and 7,010 deletions.
25 changes: 22 additions & 3 deletions .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ jobs:
env:
RUBY_TESTOPTS: '-q --tty=no'
GITPULLOPTIONS: --no-tags origin ${{ github.ref }}
WASI_SDK_VERSION_MAJOR: 14
WASI_SDK_VERSION_MAJOR: 20
WASI_SDK_VERSION_MINOR: 0
BINARYEN_VERSION: 109
WASMTIME_VERSION: v0.33.0
BINARYEN_VERSION: 113
WASMTIME_VERSION: v15.0.0

runs-on: ubuntu-20.04

Expand Down Expand Up @@ -102,10 +102,20 @@ jobs:
run: |
echo "WASI_SDK_PATH=/opt/wasi-sdk" >> $GITHUB_ENV
- name: Build baseruby
run: |
set -ex
mkdir ../baseruby
pushd ../baseruby
../src/configure --prefix=$PWD/install
make
make install
- name: Run configure
run: |
../src/configure \
--host wasm32-unknown-wasi \
--with-baseruby=$PWD/../baseruby/install/bin/ruby \
--with-static-linked-ext \
--with-ext=bigdecimal,cgi/escape,continuation,coverage,date,dbm,digest/bubblebabble,digest,digest/md5,digest/rmd160,digest/sha1,digest/sha2,etc,fcntl,fiber,gdbm,json,json/generator,json/parser,nkf,objspace,pathname,racc/cparse,rbconfig/sizeof,ripper,stringio,strscan,monitor \
LDFLAGS=" \
Expand All @@ -119,6 +129,15 @@ jobs:
# miniruby may not be built when cross-compling
- run: make mini ruby

- run: make install DESTDIR=$PWD/../install
- run: tar cfz ../install.tar.gz -C ../install .

- name: Upload artifacts
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: ruby-wasm-install
path: ${{ github.workspace }}/install.tar.gz

- name: Run basictest
run: wasmtime run ./../build/miniruby --mapdir /::./ -- basictest/test.rb
working-directory: src
Expand Down
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ matrix:
include:
- <<: *arm64-linux
- <<: *ppc64le-linux
- <<: *s390x-linux
# The s390x builds are not starting.
# - <<: *s390x-linux
# FIXME: lib/rubygems/util.rb:104 glob_files_in_dir -
# <internal:dir>:411:in glob: File name too long - (Errno::ENAMETOOLONG)
# https://github.com/rubygems/rubygems/issues/7132
Expand All @@ -113,7 +114,7 @@ matrix:
# Allow failures for the unstable jobs.
# - name: arm64-linux
# - name: ppc64le-linux
# - name: s390x-linux
- name: s390x-linux
# The 2nd arm64 pipeline may be unstable.
# - name: arm32-linux
fast_finish: true
Expand Down
8 changes: 4 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Note: We're only listing outstanding class updates.

The following default gem is added.

* prism 0.17.1
* prism 0.18.0

The following default gems are updated.

Expand All @@ -138,7 +138,7 @@ The following default gems are updated.
* find 0.2.0
* getoptlong 0.2.1
* io-console 0.6.1.dev.1
* irb 1.9.0
* irb 1.9.1
* logger 1.6.0
* mutex_m 0.2.0
* net-http 0.4.0
Expand Down Expand Up @@ -187,9 +187,9 @@ The following bundled gems are updated.
* test-unit 3.6.1
* rexml 3.2.6
* rss 0.3.0
* net-imap 0.4.5
* net-imap 0.4.6
* net-smtp 0.4.0
* rbs 3.3.0
* rbs 3.3.2
* typeprof 0.21.8
* debug 1.8.0

Expand Down
35 changes: 12 additions & 23 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -6297,16 +6297,9 @@ rb_ary_count(int argc, VALUE *argv, VALUE ary)
static VALUE
flatten(VALUE ary, int level)
{
static const rb_data_type_t flatten_memo_data_type = {
.wrap_struct_name = "array_flatten_memo_data_type",
.function = { NULL, (RUBY_DATA_FUNC)st_free_table },
NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
};

long i;
VALUE stack, result, tmp = 0, elt, vmemo;
st_table *memo = 0;
st_data_t id;
VALUE stack, result, tmp = 0, elt;
VALUE memo = Qfalse;

for (i = 0; i < RARRAY_LEN(ary); i++) {
elt = RARRAY_AREF(ary, i);
Expand All @@ -6328,10 +6321,9 @@ flatten(VALUE ary, int level)
rb_ary_push(stack, LONG2NUM(i + 1));

if (level < 0) {
memo = st_init_numtable();
vmemo = TypedData_Wrap_Struct(0, &flatten_memo_data_type, memo);
st_insert(memo, (st_data_t)ary, (st_data_t)Qtrue);
st_insert(memo, (st_data_t)tmp, (st_data_t)Qtrue);
memo = rb_obj_hide(rb_ident_hash_new());
rb_hash_aset(memo, ary, Qtrue);
rb_hash_aset(memo, tmp, Qtrue);
}

ary = tmp;
Expand All @@ -6346,9 +6338,8 @@ flatten(VALUE ary, int level)
}
tmp = rb_check_array_type(elt);
if (RBASIC(result)->klass) {
if (memo) {
RB_GC_GUARD(vmemo);
st_clear(memo);
if (RTEST(memo)) {
rb_hash_clear(memo);
}
rb_raise(rb_eRuntimeError, "flatten reentered");
}
Expand All @@ -6357,12 +6348,11 @@ flatten(VALUE ary, int level)
}
else {
if (memo) {
id = (st_data_t)tmp;
if (st_is_member(memo, id)) {
st_clear(memo);
if (rb_hash_aref(memo, tmp) == Qtrue) {
rb_hash_clear(memo);
rb_raise(rb_eArgError, "tried to flatten recursive array");
}
st_insert(memo, id, (st_data_t)Qtrue);
rb_hash_aset(memo, tmp, Qtrue);
}
rb_ary_push(stack, ary);
rb_ary_push(stack, LONG2NUM(i));
Expand All @@ -6374,16 +6364,15 @@ flatten(VALUE ary, int level)
break;
}
if (memo) {
id = (st_data_t)ary;
st_delete(memo, &id, 0);
rb_hash_delete(memo, ary);
}
tmp = rb_ary_pop(stack);
i = NUM2LONG(tmp);
ary = rb_ary_pop(stack);
}

if (memo) {
st_clear(memo);
rb_hash_clear(memo);
}

RBASIC_SET_CLASS(result, rb_cArray);
Expand Down
34 changes: 34 additions & 0 deletions bootstraptest/test_yjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,33 @@ def foo
Foo.new.foo
}

# getinstancevariable with shape too complex
assert_normal_exit %q{
class Foo
def initialize
@a = 1
end
def getter
@foobar
end
end
# Initialize ivars in changing order, making the Foo
# class have shape too complex
100.times do |x|
foo = Foo.new
foo.instance_variable_set(:"@a#{x}", 1)
foo.instance_variable_set(:"@foobar", 777)
# The getter method eventually sees shape too complex
r = foo.getter
if r != 777
raise "error"
end
end
}

assert_equal '0', %q{
# This is a regression test for incomplete invalidation from
# opt_setinlinecache. This test might be brittle, so
Expand Down Expand Up @@ -4217,3 +4244,10 @@ def entry = putobject(nil)
def entry = yield
entry { true }
}

assert_normal_exit %q{
ivars = 1024.times.map { |i| "@iv_#{i} = #{i}\n" }.join
Foo = Class.new
Foo.class_eval "def initialize() #{ivars} end"
Foo.new
}
5 changes: 5 additions & 0 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ PRISM_FILES = prism/api_node.$(OBJEXT) \
prism/api_pack.$(OBJEXT) \
prism/diagnostic.$(OBJEXT) \
prism/enc/pm_big5.$(OBJEXT) \
prism/enc/pm_cp949.$(OBJEXT) \
prism/enc/pm_cp51932.$(OBJEXT) \
prism/enc/pm_euc_jp.$(OBJEXT) \
prism/enc/pm_gbk.$(OBJEXT) \
Expand Down Expand Up @@ -11754,6 +11755,10 @@ prism/enc/pm_big5.$(OBJEXT): $(top_srcdir)/prism/defines.h
prism/enc/pm_big5.$(OBJEXT): $(top_srcdir)/prism/enc/pm_big5.c
prism/enc/pm_big5.$(OBJEXT): $(top_srcdir)/prism/enc/pm_encoding.h
prism/enc/pm_big5.$(OBJEXT): {$(VPATH)}config.h
prism/enc/pm_cp949.$(OBJEXT): $(top_srcdir)/prism/defines.h
prism/enc/pm_cp949.$(OBJEXT): $(top_srcdir)/prism/enc/pm_cp949.c
prism/enc/pm_cp949.$(OBJEXT): $(top_srcdir)/prism/enc/pm_encoding.h
prism/enc/pm_cp949.$(OBJEXT): {$(VPATH)}config.h
prism/enc/pm_cp51932.$(OBJEXT): $(top_srcdir)/prism/defines.h
prism/enc/pm_cp51932.$(OBJEXT): $(top_srcdir)/prism/enc/pm_cp51932.c
prism/enc/pm_cp51932.$(OBJEXT): $(top_srcdir)/prism/enc/pm_encoding.h
Expand Down
19 changes: 7 additions & 12 deletions compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -11152,15 +11152,13 @@ pinned_list_mark(void *ptr)
}
}

static size_t
pinned_list_memsize(const void *ptr)
{
return 0;
}

static const rb_data_type_t pinned_list_type = {
"pinned_list",
{pinned_list_mark, RUBY_DEFAULT_FREE, pinned_list_memsize,},
{
pinned_list_mark,
RUBY_DEFAULT_FREE,
NULL, // No external memory to report,
},
0, 0, RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_EMBEDDABLE
};

Expand Down Expand Up @@ -13196,14 +13194,13 @@ ibf_dump_free(void *ptr)
st_free_table(dump->iseq_table);
dump->iseq_table = 0;
}
ruby_xfree(dump);
}

static size_t
ibf_dump_memsize(const void *ptr)
{
struct ibf_dump *dump = (struct ibf_dump *)ptr;
size_t size = sizeof(*dump);
size_t size = 0;
if (dump->iseq_table) size += st_memsize(dump->iseq_table);
if (dump->global_buffer.obj_table) size += st_memsize(dump->global_buffer.obj_table);
return size;
Expand All @@ -13212,7 +13209,7 @@ ibf_dump_memsize(const void *ptr)
static const rb_data_type_t ibf_dump_type = {
"ibf_dump",
{ibf_dump_mark, ibf_dump_free, ibf_dump_memsize,},
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_EMBEDDABLE
};

static void
Expand Down Expand Up @@ -13275,8 +13272,6 @@ rb_iseq_ibf_dump(const rb_iseq_t *iseq, VALUE opt)
ibf_dump_overwrite(dump, &header, sizeof(header), 0);

str = dump->global_buffer.str;
ibf_dump_free(dump);
DATA_PTR(dump_obj) = NULL;
RB_GC_GUARD(dump_obj);
return str;
}
Expand Down
86 changes: 86 additions & 0 deletions complex.c
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,84 @@ f_reciprocal(VALUE x)
return f_quo(ONE, x);
}

static VALUE
zero_for(VALUE x)
{
if (RB_FLOAT_TYPE_P(x))
return DBL2NUM(0);
if (RB_TYPE_P(x, T_RATIONAL))
return rb_rational_new(INT2FIX(0), INT2FIX(1));

return INT2FIX(0);
}

static VALUE
complex_pow_for_special_angle(VALUE self, VALUE other)
{
if (!rb_integer_type_p(other)) {
return Qundef;
}

get_dat1(self);
VALUE x = Qundef;
int dir;
if (f_zero_p(dat->imag)) {
x = dat->real;
dir = 0;
}
else if (f_zero_p(dat->real)) {
x = dat->imag;
dir = 2;
}
else if (f_eqeq_p(dat->real, dat->imag)) {
x = dat->real;
dir = 1;
}
else if (f_eqeq_p(dat->real, f_negate(dat->imag))) {
x = dat->imag;
dir = 3;
}

if (x == Qundef) return x;

if (f_negative_p(x)) {
x = f_negate(x);
dir += 4;
}

VALUE zx;
if (dir % 2 == 0) {
zx = rb_num_pow(x, other);
}
else {
zx = rb_num_pow(
rb_funcall(rb_int_mul(TWO, x), '*', 1, x),
rb_int_div(other, TWO)
);
if (rb_int_odd_p(other)) {
zx = rb_funcall(zx, '*', 1, x);
}
}
static const int dirs[][2] = {
{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}
};
int z_dir = FIX2INT(rb_int_modulo(rb_int_mul(INT2FIX(dir), other), INT2FIX(8)));

VALUE zr = Qfalse, zi = Qfalse;
switch (dirs[z_dir][0]) {
case 0: zr = zero_for(zx); break;
case 1: zr = zx; break;
case -1: zr = f_negate(zx); break;
}
switch (dirs[z_dir][1]) {
case 0: zi = zero_for(zx); break;
case 1: zi = zx; break;
case -1: zi = f_negate(zx); break;
}
return nucomp_s_new_internal(CLASS_OF(self), zr, zi);
}


/*
* call-seq:
* cmp ** numeric -> complex
Expand All @@ -1007,6 +1085,14 @@ rb_complex_pow(VALUE self, VALUE other)
other = dat->real; /* c14n */
}

if (other == ONE) {
get_dat1(self);
return nucomp_s_new_internal(CLASS_OF(self), dat->real, dat->imag);
}

VALUE result = complex_pow_for_special_angle(self, other);
if (result != Qundef) return result;

if (RB_TYPE_P(other, T_COMPLEX)) {
VALUE r, theta, nr, ntheta;

Expand Down
Loading

0 comments on commit ae1dfa8

Please sign in to comment.