Skip to content

Commit

Permalink
Merge pull request ruby#72 from ruby/master
Browse files Browse the repository at this point in the history
[pull] master from ruby:master
  • Loading branch information
Kadir Selçuk committed Aug 11, 2022
2 parents fb11310 + cfb9624 commit 4ff56a7
Show file tree
Hide file tree
Showing 139 changed files with 1,904 additions and 937 deletions.
1 change: 1 addition & 0 deletions .github/workflows/compilers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ jobs:
- { name: disable-dln, env: { append_configure: '--disable-dln' } }
- { name: enable-mkmf-verbose, env: { append_configure: '--enable-mkmf-verbose' } }
- { name: disable-rubygems, env: { append_configure: '--disable-rubygems' } }
- { name: RUBY_DEVEL, env: { append_configure: '--enable-devel' } }

- { name: OPT_THREADED_CODE=1, env: { cppflags: '-DOPT_THREADED_CODE=1' } }
- { name: OPT_THREADED_CODE=2, env: { cppflags: '-DOPT_THREADED_CODE=2' } }
Expand Down
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ Note: We're only listing outstanding class updates.
* bigdecimal 3.1.2
* bundler 2.4.0.dev
* cgi 0.3.2
* date 3.2.3
* error_highlight 0.4.0
* etc 1.4.0
* io-console 0.5.11
* io-nonblock 0.1.1
Expand All @@ -178,7 +180,7 @@ Note: We're only listing outstanding class updates.
* net-imap 0.2.3
* rbs 2.6.0
* typeprof 0.21.3
* debug 1.6.1
* debug 1.6.2
* The following default gems are now bundled gems.

## Compatibility issues
Expand Down
5 changes: 4 additions & 1 deletion array.c
Original file line number Diff line number Diff line change
Expand Up @@ -1373,13 +1373,16 @@ ary_make_partial_step(VALUE ary, VALUE klass, long offset, long len, long step)
const VALUE *values = RARRAY_CONST_PTR_TRANSIENT(ary);
const long orig_len = len;

if ((step > 0 && step >= len) || (step < 0 && (step < -len))) {
if (step > 0 && step >= len) {
VALUE result = ary_new(klass, 1);
VALUE *ptr = (VALUE *)ARY_EMBED_PTR(result);
RB_OBJ_WRITE(result, ptr, values[offset]);
ARY_SET_EMBED_LEN(result, 1);
return result;
}
else if (step < 0 && step < -len) {
step = -len;
}

long ustep = (step < 0) ? -step : step;
len = (len + ustep - 1) / ustep;
Expand Down
17 changes: 9 additions & 8 deletions benchmark/buffer_get.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
prelude: |
# frozen_string_literal: true
Warning[:experimental] = false
buffer = IO::Buffer.new(32, IO::Buffer::MAPPED)
string = "\0" * 32
benchmark:
- name: buffer.get
prelude: buffer = IO::Buffer.new(32, IO::Buffer::MAPPED)
script: buffer.get(:U32, 0)
loop_count: 20000000
- name: string.unpack
prelude: string = "\0" * 32
script: string.unpack("C")
loop_count: 20000000
buffer.get_value: |
buffer.get_value(:U32, 0)
string.unpack1: |
string.unpack1("N")
26 changes: 25 additions & 1 deletion benchmark/masgn.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
prelude: |
a = [nil] * 3
b = Class.new{attr_writer :a, :b, :c}.new
c, d, e, f = nil, nil, nil, nil
c = d = e = f = g = h = i = nil
benchmark:
array2_2: "c = (a[0], a[1] = 1, 2)"
array2_3: "c = (a[0], a[1] = 1, 2, 3)"
Expand All @@ -27,3 +27,27 @@ benchmark:
lvar2_3p: "(d, e = 1, 2, 3; nil)"
lvar3_2p: "(d, e, f = 1, 2; nil)"
lvar3_3p: "(d, e, f = 1, 2, 3; nil)"
array2_2lv: "c = (a[0], a[1] = g, h)"
array2_ilv: "c = (a[0], a[1] = g, h, i)"
arrayi_2lv: "c = (a[0], a[1], a[2] = g, h)"
arrayi_ilv: "c = (a[0], a[1], a[2] = g, h, i)"
attr2_2lv: "c = (b.a, b.b = g, h)"
attr2_ilv: "c = (b.a, b.b = g, h, i)"
attri_2lv: "c = (b.a, b.b, b.c = g, h)"
attri_ilv: "c = (b.a, b.b, b.c = g, h, i)"
lvar2_2lv: "c = (d, e = g, h)"
lvar2_ilv: "c = (d, e = g, h, i)"
lvari_2lv: "c = (d, e, f = g, h)"
lvari_ilv: "c = (d, e, f = g, h, i)"
array2_2plv: "(a[0], a[1] = g, h; nil)"
array2_iplv: "(a[0], a[1] = g, h, i; nil)"
arrayi_2plv: "(a[0], a[1], a[2] = g, h; nil)"
arrayi_iplv: "(a[0], a[1], a[2] = g, h, i; nil)"
attr2_2plv: "(b.a, b.b = g, h; nil)"
attr2_iplv: "(b.a, b.b = g, h, i; nil)"
attri_2plv: "(b.a, b.b, b.c = g, h; nil)"
attri_iplv: "(b.a, b.b, b.c = g, h, i; nil)"
lvar2_2plv: "(d, e = g, h; nil)"
lvar2_iplv: "(d, e = g, h, i; nil)"
lvari_2plv: "(d, e, f = g, h; nil)"
lvari_iplv: "(d, e, f = g, h, i; nil)"
12 changes: 6 additions & 6 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -687,18 +687,18 @@ realclean-platform: distclean-platform
realclean-spec: distclean-spec
realclean-rubyspec: realclean-spec

clean-ext:: ext/clean gems/clean timestamp/clean
distclean-ext:: ext/distclean gems/distclean timestamp/distclean
realclean-ext:: ext/realclean gems/realclean timestamp/realclean
clean-ext:: ext/clean .bundle/clean timestamp/clean
distclean-ext:: ext/distclean .bundle/distclean timestamp/distclean
realclean-ext:: ext/realclean .bundle/realclean timestamp/realclean

ext/clean.mk ext/distclean.mk ext/realclean.mk::
ext/clean:: ext/clean.mk
ext/distclean:: ext/distclean.mk
ext/realclean:: ext/realclean.mk

timestamp/clean:: ext/clean gems/clean
timestamp/distclean:: ext/distclean gems/distclean
timestamp/realclean:: ext/realclean gems/realclean
timestamp/clean:: ext/clean .bundle/clean
timestamp/distclean:: ext/distclean .bundle/distclean
timestamp/realclean:: ext/realclean .bundle/realclean

timestamp/clean timestamp/distclean timestamp/realclean::
$(Q)$(RM) $(TIMESTAMPDIR)/.*.time $(TIMESTAMPDIR)/$(arch)/.time
Expand Down
78 changes: 78 additions & 0 deletions compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -3332,6 +3332,84 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
}
}

if (IS_INSN_ID(iobj, newarray)) {
LINK_ELEMENT *next = iobj->link.next;
if (IS_INSN(next) && IS_INSN_ID(next, expandarray) &&
OPERAND_AT(next, 1) == INT2FIX(0)) {
VALUE op1, op2;
op1 = OPERAND_AT(iobj, 0);
op2 = OPERAND_AT(next, 0);
ELEM_REMOVE(next);

if (op1 == op2) {
/*
* newarray 2
* expandarray 2, 0
* =>
* swap
*/
if (op1 == INT2FIX(2)) {
INSN_OF(iobj) = BIN(swap);
iobj->operand_size = 0;
}
/*
* newarray X
* expandarray X, 0
* =>
* opt_reverse X
*/
else {
INSN_OF(iobj) = BIN(opt_reverse);
}
}
else {
NODE dummy_line_node = generate_dummy_line_node(iobj->insn_info.line_no, iobj->insn_info.node_id);
long diff = FIX2LONG(op1) - FIX2LONG(op2);
INSN_OF(iobj) = BIN(opt_reverse);
OPERAND_AT(iobj, 0) = OPERAND_AT(next, 0);

if (op1 > op2) {
/* X > Y
* newarray X
* expandarray Y, 0
* =>
* pop * (Y-X)
* opt_reverse Y
*/
for (; diff > 0; diff--) {
INSERT_BEFORE_INSN(iobj, &dummy_line_node, pop);
}
}
else { /* (op1 < op2) */
/* X < Y
* newarray X
* expandarray Y, 0
* =>
* putnil * (Y-X)
* opt_reverse Y
*/
for (; diff < 0; diff++) {
INSERT_BEFORE_INSN(iobj, &dummy_line_node, putnil);
}
}
}
}
}

if (IS_INSN_ID(iobj, duparray)) {
LINK_ELEMENT *next = iobj->link.next;
/*
* duparray obj
* expandarray X, 0
* =>
* putobject obj
* expandarray X, 0
*/
if (IS_INSN(next) && IS_INSN_ID(next, expandarray)) {
INSN_OF(iobj) = BIN(putobject);
}
}

if (IS_INSN_ID(iobj, anytostring)) {
LINK_ELEMENT *next = iobj->link.next;
/*
Expand Down
11 changes: 7 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,13 @@ AS_IF([test "$fdeclspec" = yes], [
RUBY_APPEND_OPTIONS(CXXFLAGS, -fdeclspec)
])

AS_CASE([$RUBY_PATCHLEVEL], [-*],
[RUBY_DEVEL=yes], [RUBY_DEVEL=no])
particular_werror_flags=$RUBY_DEVEL
AC_ARG_ENABLE(devel,
AS_HELP_STRING([--enable-devel], [enable development build]),
[RUBY_DEVEL=$enableval],
[AS_IF([test "x${RUBY_DEVEL-no}" != xyes], [RUBY_DEVEL=])]
)dnl
AC_SUBST(RUBY_DEVEL)
particular_werror_flags=${RUBY_DEVEL:-no}
AC_ARG_ENABLE(werror,
AS_HELP_STRING([--disable-werror],
[don't make warnings into errors
Expand Down Expand Up @@ -868,7 +872,6 @@ AS_IF([test "$GCC" = yes], [
test "${debugflags+set}" || {RUBY_TRY_CFLAGS(-g3, [debugflags=-g3])}
])
test $ac_cv_prog_cc_g = yes && : ${debugflags=-g}
AS_IF([test "x$RUBY_DEVEL" = xyes], [RUBY_APPEND_OPTION(XCFLAGS, -DRUBY_DEVEL=1)])

AS_IF([test "$GCC" = ""], [
AS_CASE(["$target_os"],[aix*],[warnflags="$warnflags -qinfo=por" rb_cv_warnflags="$rb_cv_warnflags -qinfo=por"])
Expand Down
62 changes: 62 additions & 0 deletions doc/date/calendars.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
== Julian and Gregorian Calendars

The difference between the
{Julian calendar}[https://en.wikipedia.org/wiki/Julian_calendar]
and the
{Gregorian calendar}[https://en.wikipedia.org/wiki/Gregorian_calendar]
may matter to your program if it uses dates before the switchovers.

- October 15, 1582.
- September 14, 1752.

A date will be different in the two calendars, in general.

=== Different switchover dates

The reasons for the difference are religious/political histories.

- On October 15, 1582, several countries changed
from the Julian calendar to the Gregorian calendar;
these included Italy, Poland, Portugal, and Spain.
Other contries in the Western world retained the Julian calendar.
- On September 14, 1752, most of the British empire
changed from the Julian calendar to the Gregorian calendar.

When your code uses a date before these switchover dates,
it will matter whether it considers the switchover date
to be the earlier date or the later date (or neither).

See also {a concrete example here}[rdoc-ref:DateTime@When+should+you+use+DateTime+and+when+should+you+use+Time-3F].

=== Argument +start+

Certain methods in class \Date handle differences in the
{Julian and Gregorian calendars}[rdoc-ref:calendars.rdoc@Julian+and+Gregorian+Calendars]
by accepting an optional argument +start+, whose value may be:

- Date::ITALY (the default): the created date is Julian
if before October 15, 1582, Gregorian otherwise:

d = Date.new(1582, 10, 15)
d.prev_day.julian? # => true
d.julian? # => false
d.gregorian? # => true

- Date::ENGLAND: the created date is Julian if before September 14, 1752,
Gregorian otherwise:

d = Date.new(1752, 9, 14, Date::ENGLAND)
d.prev_day.julian? # => true
d.julian? # => false
d.gregorian? # => true

- Date::JULIAN: the created date is Julian regardless of its value:

d = Date.new(1582, 10, 15, Date::JULIAN)
d.julian? # => true

- Date::GREGORIAN: the created date is Gregorian regardless of its value:

d = Date.new(1752, 9, 14, Date::GREGORIAN)
d.prev_day.gregorian? # => true

Loading

0 comments on commit 4ff56a7

Please sign in to comment.