Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into dev/gc-mmtk
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzhu2118 committed Oct 18, 2024
2 parents 864bc90 + 6b1268c commit 9451a19
Show file tree
Hide file tree
Showing 97 changed files with 2,703 additions and 909 deletions.
17 changes: 9 additions & 8 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ Note: We're only listing outstanding class updates.

## Stdlib updates

The following default gem is added.

* win32-registry 0.0.1

* Tempfile

* The keyword argument `anonymous: true` is implemented for Tempfile.create.
Expand All @@ -75,6 +71,10 @@ The following default gem is added.
* This library is now extracted from the Ruby repository to [ruby/net-http-sspi].
[[Feature #20775]]
The following default gem is added.
* win32-registry 0.0.1
The following default gems are updated.
* RubyGems 3.6.0.dev
Expand All @@ -94,10 +94,15 @@ The following default gems are updated.
* resolv 0.4.0
* stringio 3.1.2.dev
* strscan 3.1.1.dev
* syntax_suggest 2.0.1
* time 0.4.0
* uri 0.13.1
* zlib 3.1.1
The following bundled gem is added.
* repl_type_completor 0.1.7
The following bundled gems are updated.
* minitest 5.25.1
Expand Down Expand Up @@ -129,10 +134,6 @@ The following bundled gems are promoted from default gems.
* syslog 0.1.2
* csv 3.3.0
The following bundled gem is added.
* repl_type_completor 0.1.7
See GitHub releases like [GitHub Releases of Logger] or changelog for
details of the default gems or bundled gems.
Expand Down
175 changes: 78 additions & 97 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -3352,43 +3352,12 @@ sort_2(const void *ap, const void *bp, void *dummy)

/*
* call-seq:
* array.sort! -> self
* array.sort! {|a, b| ... } -> self
* sort! -> self
* sort! {|a, b| ... } -> self
*
* Returns +self+ with its elements sorted in place.
*
* With no block, compares elements using operator <tt>#<=></tt>
* (see Comparable):
*
* a = 'abcde'.split('').shuffle
* a # => ["e", "b", "d", "a", "c"]
* a.sort!
* a # => ["a", "b", "c", "d", "e"]
*
* With a block, calls the block with each element pair;
* for each element pair +a+ and +b+, the block should return an integer:
*
* - Negative when +b+ is to follow +a+.
* - Zero when +a+ and +b+ are equivalent.
* - Positive when +a+ is to follow +b+.
*
* Example:
*
* a = 'abcde'.split('').shuffle
* a # => ["e", "b", "d", "a", "c"]
* a.sort! {|a, b| a <=> b }
* a # => ["a", "b", "c", "d", "e"]
* a.sort! {|a, b| b <=> a }
* a # => ["e", "d", "c", "b", "a"]
*
* When the block returns zero, the order for +a+ and +b+ is indeterminate,
* and may be unstable:
*
* a = 'abcde'.split('').shuffle
* a # => ["e", "b", "d", "a", "c"]
* a.sort! {|a, b| 0 }
* a # => ["d", "e", "c", "a", "b"]
* Like Array#sort, but returns +self+ with its elements sorted in place.
*
* Related: see {Methods for Assigning}[rdoc-ref:Array@Methods+for+Assigning].
*/

VALUE
Expand Down Expand Up @@ -3455,44 +3424,33 @@ rb_ary_sort_bang(VALUE ary)

/*
* call-seq:
* array.sort -> new_array
* array.sort {|a, b| ... } -> new_array
* sort -> new_array
* sort {|a, b| ... } -> new_array
*
* Returns a new +Array+ whose elements are those from +self+, sorted.
* Returns a new array containing the elements of +self+, sorted.
*
* With no block, compares elements using operator <tt>#<=></tt>
* (see Comparable):
* With no block given, compares elements using operator <tt>#<=></tt>
* (see Object#<=>):
*
* a = 'abcde'.split('').shuffle
* a # => ["e", "b", "d", "a", "c"]
* a1 = a.sort
* a1 # => ["a", "b", "c", "d", "e"]
* [0, 2, 3, 1].sort # => [0, 1, 2, 3]
*
* With a block, calls the block with each element pair;
* for each element pair +a+ and +b+, the block should return an integer:
* With a block given, calls the block with each combination of pairs of elements from +self+;
* for each pair +a+ and +b+, the block should return a numeric:
*
* - Negative when +b+ is to follow +a+.
* - Zero when +a+ and +b+ are equivalent.
* - Positive when +a+ is to follow +b+.
*
* Example:
*
* a = 'abcde'.split('').shuffle
* a # => ["e", "b", "d", "a", "c"]
* a1 = a.sort {|a, b| a <=> b }
* a1 # => ["a", "b", "c", "d", "e"]
* a2 = a.sort {|a, b| b <=> a }
* a2 # => ["e", "d", "c", "b", "a"]
* a = [3, 2, 0, 1]
* a.sort {|a, b| a <=> b } # => [0, 1, 2, 3]
* a.sort {|a, b| b <=> a } # => [3, 2, 1, 0]
*
* When the block returns zero, the order for +a+ and +b+ is indeterminate,
* and may be unstable:
* and may be unstable.
*
* a = 'abcde'.split('').shuffle
* a # => ["e", "b", "d", "a", "c"]
* a1 = a.sort {|a, b| 0 }
* a1 # => ["c", "e", "b", "d", "a"]
*
* Related: Enumerable#sort_by.
* Related: see {Methods for Fetching}[rdoc-ref:Array@Methods+for+Fetching].
*/

VALUE
Expand Down Expand Up @@ -4145,71 +4103,94 @@ ary_slice_bang_by_rb_ary_splice(VALUE ary, long pos, long len)

/*
* call-seq:
* array.slice!(n) -> object or nil
* array.slice!(start, length) -> new_array or nil
* array.slice!(range) -> new_array or nil
* slice!(index) -> object or nil
* slice!(start, length) -> new_array or nil
* slice!(range) -> new_array or nil
*
* Removes and returns elements from +self+.
*
* When the only argument is an Integer +n+,
* removes and returns the _nth_ element in +self+:
* With numeric argument +index+ given,
* removes and returns the element at offset +index+:
*
* a = [:foo, 'bar', 2]
* a.slice!(1) # => "bar"
* a # => [:foo, 2]
* a = ['a', 'b', 'c', 'd']
* a.slice!(2) # => "c"
* a # => ["a", "b", "d"]
* a.slice!(2.1) # => "d"
* a # => ["a", "b"]
*
* If +n+ is negative, counts backwards from the end of +self+:
* If +index+ is negative, counts backwards from the end of +self+:
*
* a = [:foo, 'bar', 2]
* a.slice!(-1) # => 2
* a # => [:foo, "bar"]
* a = ['a', 'b', 'c', 'd']
* a.slice!(-2) # => "c"
* a # => ["a", "b", "d"]
*
* If +n+ is out of range, returns +nil+.
* If +index+ is out of range, returns +nil+.
*
* When the only arguments are Integers +start+ and +length+,
* removes +length+ elements from +self+ beginning at offset +start+;
* returns the deleted objects in a new +Array+:
* With numeric arguments +start+ and +length+ given,
* removes +length+ elements from +self+ beginning at zero-based offset +start+;
* returns the removed objects in a new array:
*
* a = [:foo, 'bar', 2]
* a.slice!(0, 2) # => [:foo, "bar"]
* a # => [2]
* a = ['a', 'b', 'c', 'd']
* a.slice!(1, 2) # => ["b", "c"]
* a # => ["a", "d"]
* a.slice!(0.1, 1.1) # => ["a"]
* a # => ["d"]
*
* If +start+ is negative, counts backwards from the end of +self+:
*
* a = ['a', 'b', 'c', 'd']
* a.slice!(-2, 1) # => ["c"]
* a # => ["a", "b", "d"]
*
* If +start+ is out-of-range, returns +nil+:
*
* a = ['a', 'b', 'c', 'd']
* a.slice!(5, 1) # => nil
* a.slice!(-5, 1) # => nil
*
* If <tt>start + length</tt> exceeds the array size,
* removes and returns all elements from offset +start+ to the end:
*
* a = [:foo, 'bar', 2]
* a.slice!(1, 50) # => ["bar", 2]
* a # => [:foo]
* a = ['a', 'b', 'c', 'd']
* a.slice!(2, 50) # => ["c", "d"]
* a # => ["a", "b"]
*
* If <tt>start == a.size</tt> and +length+ is non-negative,
* returns a new empty +Array+.
* returns a new empty array.
*
* If +length+ is negative, returns +nil+.
*
* When the only argument is a Range object +range+,
* treats <tt>range.min</tt> as +start+ above and <tt>range.size</tt> as +length+ above:
* With Range argument +range+ given,
* treats <tt>range.min</tt> as +start+ (as above)
* and <tt>range.size</tt> as +length+ (as above):
*
* a = [:foo, 'bar', 2]
* a.slice!(1..2) # => ["bar", 2]
* a # => [:foo]
* a = ['a', 'b', 'c', 'd']
* a.slice!(1..2) # => ["b", "c"]
* a # => ["a", "d"]
*
* If <tt>range.start == a.size</tt>, returns a new empty +Array+.
* If <tt>range.start == a.size</tt>, returns a new empty array:
*
* If <tt>range.start</tt> is larger than the array size, returns +nil+.
* a = ['a', 'b', 'c', 'd']
* a.slice!(4..5) # => []
*
* If <tt>range.end</tt> is negative, counts backwards from the end of the array:
* If <tt>range.start</tt> is larger than the array size, returns +nil+:
*
* a = [:foo, 'bar', 2]
* a.slice!(0..-2) # => [:foo, "bar"]
* a # => [2]
* a = ['a', 'b', 'c', 'd']
a.slice!(5..6) # => nil
*
* If <tt>range.start</tt> is negative,
* calculates the start index backwards from the end of the array:
* calculates the start index by counting backwards from the end of +self+:
*
* a = [:foo, 'bar', 2]
* a.slice!(-2..2) # => ["bar", 2]
* a # => [:foo]
* a = ['a', 'b', 'c', 'd']
* a.slice!(-2..2) # => ["c"]
*
* If <tt>range.end</tt> is negative,
* calculates the end index by counting backwards from the end of +self+:
*
* a = ['a', 'b', 'c', 'd']
* a.slice!(0..-2) # => ["a", "b", "c"]
*
* Related: see {Methods for Deleting}[rdoc-ref:Array@Methods+for+Deleting].
*/

static VALUE
Expand Down
25 changes: 17 additions & 8 deletions array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,30 @@ def each
#
# The object given with keyword argument +random+ is used as the random number generator.
#
# Related: see {Methods for Fetching}[rdoc-ref:Array@Methods+for+Fetching].
# Related: see {Methods for Assigning}[rdoc-ref:Array@Methods+for+Assigning].
def shuffle!(random: Random)
Primitive.rb_ary_shuffle_bang(random)
end

# call-seq:
# array.shuffle(random: Random) -> new_ary
# shuffle(random: Random) -> new_array
#
# Returns a new array containing all elements from +self+ in a random order,
# as selected by the object given by keyword argument +random+:
#
# a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# a.shuffle # => [0, 8, 1, 9, 6, 3, 4, 7, 2, 5]
# a.shuffle # => [8, 9, 0, 5, 1, 2, 6, 4, 7, 3]
#
# Duplicate elements are included:
#
# Returns a new array with elements of +self+ shuffled.
# a = [1, 2, 3] #=> [1, 2, 3]
# a.shuffle #=> [2, 3, 1]
# a #=> [1, 2, 3]
# a = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]
# a.shuffle # => [1, 0, 1, 1, 0, 0, 1, 0, 0, 1]
# a.shuffle # => [1, 1, 0, 0, 0, 1, 1, 0, 0, 1]
#
# The optional +random+ argument will be used as the random number generator:
# a.shuffle(random: Random.new(1)) #=> [1, 3, 2]
# The object given with keyword argument +random+ is used as the random number generator.
#
# Related: see {Methods for Fetching}[rdoc-ref:Array@Methods+for+Fetching].
def shuffle(random: Random)
Primitive.rb_ary_shuffle(random)
end
Expand Down
3 changes: 2 additions & 1 deletion doc/maintainers.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ have commit right, others don't.

#### lib/prism.rb
* Kevin Newton (kddnewton)
* Jemma Issroff (jemmaissroff)
* Eileen Uchitelle (eileencodes)
* Aaron Patterson (tenderlove)
* https://github.com/ruby/prism
* https://rubygems.org/gems/prism

Expand Down
8 changes: 8 additions & 0 deletions doc/yjit/yjit.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ You can dump statistics about compilation and execution by running YJIT with the
./miniruby --yjit-stats myscript.rb
```

You can see what YJIT has compiled by running YJIT with the `--yjit-log` command-line option:

```sh
./miniruby --yjit-log myscript.rb
```

The machine code generated for a given method can be printed by adding `puts RubyVM::YJIT.disasm(method(:method_name))` to a Ruby script. Note that no code will be generated if the method is not compiled.

<h3 id="command-line-options">Command-Line Options</h3>
Expand All @@ -181,6 +187,8 @@ YJIT supports all command-line options supported by upstream CRuby, but also add
compiled, lower values mean less code is compiled (default 200K)
- `--yjit-stats`: print statistics after the execution of a program (incurs a run-time cost)
- `--yjit-stats=quiet`: gather statistics while running a program but don't print them. Stats are accessible through `RubyVM::YJIT.runtime_stats`. (incurs a run-time cost)
- `--yjit-log[=file|dir]`: log all compilation events to the specified file or directory. If no name is supplied, the last 1024 log entries will be printed to stderr when the application exits.
- `--yjit-log=quiet`: gather a circular buffer of recent YJIT compilations. The compilation log entries are accessible through `RubyVM::YJIT.log` and old entries will be discarded if the buffer is not drained quickly. (incurs a run-time cost)
- `--yjit-disable`: disable YJIT despite other `--yjit*` flags for lazily enabling it with `RubyVM::YJIT.enable`
- `--yjit-code-gc`: enable code GC (disabled by default as of Ruby 3.3).
It will cause all machine code to be discarded when the executable memory size limit is hit, meaning JIT compilation will then start over.
Expand Down
12 changes: 12 additions & 0 deletions ext/etc/etc.c
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,16 @@ etc_getgrent(VALUE obj)
VALUE rb_w32_special_folder(int type);
UINT rb_w32_system_tmpdir(WCHAR *path, UINT len);
VALUE rb_w32_conv_from_wchar(const WCHAR *wstr, rb_encoding *enc);
#elif defined(LOAD_RELATIVE)
static inline VALUE
rbconfig(void)
{
VALUE config;
rb_require("rbconfig");
config = rb_const_get(rb_path2class("RbConfig"), rb_intern("CONFIG"));
Check_Type(config, T_HASH);
return config;
}
#endif

/* call-seq:
Expand All @@ -710,6 +720,8 @@ etc_sysconfdir(VALUE obj)
{
#ifdef _WIN32
return rb_w32_special_folder(CSIDL_COMMON_APPDATA);
#elif defined(LOAD_RELATIVE)
return rb_hash_aref(rbconfig(), rb_str_new_lit("sysconfdir"));
#else
return rb_filesystem_str_new_cstr(SYSCONFDIR);
#endif
Expand Down
Loading

0 comments on commit 9451a19

Please sign in to comment.