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 2, 2024
2 parents 5d68564 + 75ab01f commit 2cbecd4
Show file tree
Hide file tree
Showing 43 changed files with 473 additions and 288 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ The following bundled gems are updated.
* net-ftp 0.3.7
* net-imap 0.4.16
* net-smtp 0.5.0
* rbs 3.5.3
* rbs 3.6.0
* typeprof 0.21.11
* debug 1.9.2
* racc 1.8.1
Expand Down
36 changes: 18 additions & 18 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -2908,31 +2908,32 @@ rb_ary_join(VALUE ary, VALUE sep)

/*
* call-seq:
* array.join ->new_string
* array.join(separator = $,) -> new_string
*
* Returns the new String formed by joining the array elements after conversion.
* For each element +element+:
* Returns the new string formed by joining the converted elements of +self+;
* for each element +element+:
*
* - Uses <tt>element.to_s</tt> if +element+ is not a <tt>kind_of?(Array)</tt>.
* - Uses recursive <tt>element.join(separator)</tt> if +element+ is a <tt>kind_of?(Array)</tt>.
* - Converts recursively using <tt>element.join(separator)</tt>
* if +element+ is a <tt>kind_of?(Array)</tt>.
* - Otherwise, converts using <tt>element.to_s</tt>.
*
* With no argument, joins using the output field separator, <tt>$,</tt>:
* With no argument given, joins using the output field separator, <tt>$,</tt>:
*
* a = [:foo, 'bar', 2]
* $, # => nil
* a.join # => "foobar2"
*
* With \string argument +separator+, joins using that separator:
* With string argument +separator+ given, joins using that separator:
*
* a = [:foo, 'bar', 2]
* a.join("\n") # => "foo\nbar\n2"
*
* Joins recursively for nested Arrays:
* Joins recursively for nested arrays:
*
* a = [:foo, [:bar, [:baz, :bat]]]
* a.join # => "foobarbazbat"
*
* Related: see {Methods for Converting}[rdoc-ref:Array@Methods+for+Converting].
*/
static VALUE
rb_ary_join_m(int argc, VALUE *argv, VALUE ary)
Expand Down Expand Up @@ -2969,14 +2970,15 @@ inspect_ary(VALUE ary, VALUE dummy, int recur)

/*
* call-seq:
* array.inspect -> new_string
* inspect -> new_string
*
* Returns the new String formed by calling method <tt>#inspect</tt>
* Returns the new string formed by calling method <tt>#inspect</tt>
* on each array element:
*
* a = [:foo, 'bar', 2]
* a.inspect # => "[:foo, \"bar\", 2]"
*
* Related: see {Methods for Querying}[rdoc-ref:Array@Methods+for+Querying].
*/

static VALUE
Expand Down Expand Up @@ -3970,20 +3972,18 @@ rb_ary_select_bang(VALUE ary)

/*
* call-seq:
* array.keep_if {|element| ... } -> self
* array.keep_if -> new_enumeration
* keep_if {|element| ... } -> self
* keep_if -> new_enumerator
*
* Retains those elements for which the block returns a truthy value;
* deletes all other elements; returns +self+:
* With a block given, calls the block with each element of +self+;
* removes the element from +self+ if the block does not return a truthy value:
*
* a = [:foo, 'bar', 2, :bam]
* a.keep_if {|element| element.to_s.start_with?('b') } # => ["bar", :bam]
*
* Returns a new Enumerator if no block given:
*
* a = [:foo, 'bar', 2, :bam]
* a.keep_if # => #<Enumerator: [:foo, "bar", 2, :bam]:keep_if>
* With no block given, returns a new Enumerator.
*
* Related: see {Methods for Deleting}[rdoc-ref:Array@Methods+for+Deleting].
*/

static VALUE
Expand Down
29 changes: 11 additions & 18 deletions array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,36 +150,29 @@ def first n = unspecified = true
end

# call-seq:
# array.last -> object or nil
# array.last(n) -> new_array
# last -> last_object or nil
# last(n) -> new_array
#
# Returns elements from +self+; +self+ is not modified.
# Returns elements from +self+, or +nil+; +self+ is not modified.
#
# When no argument is given, returns the last element:
# With no argument given, returns the last element, or +nil+ if +self+ is empty:
#
# a = [:foo, 'bar', 2]
# a.last # => 2
# a # => [:foo, "bar", 2]
# [].last # => nil
#
# If +self+ is empty, returns +nil+.
#
# When non-negative Integer argument +n+ is given,
# returns the last +n+ elements in a new +Array+:
#
# a = [:foo, 'bar', 2]
# a.last(2) # => ["bar", 2]
#
# If <tt>n >= array.size</tt>, returns all elements:
# With non-negative integer argument +n+ is given,
# returns a new array containing the trailing +n+ elements of +self+, as available:
#
# a = [:foo, 'bar', 2]
# a.last(2) # => ["bar", 2]
# a.last(50) # => [:foo, "bar", 2]
# a.last(0) # => []
# [].last(3) # => []
#
# If <tt>n == 0</tt>, returns an new empty +Array+:
#
# a = [:foo, 'bar', 2]
# a.last(0) # []
#
# Related: #first.
# Related: see {Methods for Fetching}[rdoc-ref:Array@Methods+for+Fetching].
def last n = unspecified = true
if Primitive.mandatory_only?
Primitive.attr! :leaf
Expand Down
1 change: 1 addition & 0 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19528,6 +19528,7 @@ version.$(OBJEXT): $(top_srcdir)/internal/cmdlineopt.h
version.$(OBJEXT): $(top_srcdir)/internal/compilers.h
version.$(OBJEXT): $(top_srcdir)/internal/gc.h
version.$(OBJEXT): $(top_srcdir)/internal/imemo.h
version.$(OBJEXT): $(top_srcdir)/internal/parse.h
version.$(OBJEXT): $(top_srcdir)/internal/sanitizers.h
version.$(OBJEXT): $(top_srcdir)/internal/serial.h
version.$(OBJEXT): $(top_srcdir)/internal/static_assert.h
Expand Down
2 changes: 1 addition & 1 deletion doc/forwardable.rd.ja
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- forwatable.rb
-- forwardable.rb
$Release Version: 1.1 $
$Revision$

Expand Down
2 changes: 1 addition & 1 deletion gems/bundled_gems
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ net-pop 0.1.2 https://github.com/ruby/net-pop
net-smtp 0.5.0 https://github.com/ruby/net-smtp
matrix 0.4.2 https://github.com/ruby/matrix
prime 0.1.2 https://github.com/ruby/prime
rbs 3.5.3 https://github.com/ruby/rbs
rbs 3.6.0 https://github.com/ruby/rbs
typeprof 0.21.11 https://github.com/ruby/typeprof 167263ca3a634b61df0445f1a6b3e259a5d47f94
debug 1.9.2 https://github.com/ruby/debug
racc 1.8.1 https://github.com/ruby/racc
Expand Down
14 changes: 9 additions & 5 deletions internal/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@
#include "internal/static_assert.h"

// The default parser to use for Ruby code.
// 0: parse.y
// 1: Prism
#ifndef RB_DEFAULT_PARSER
#define RB_DEFAULT_PARSER 1
#endif
typedef enum {
RB_DEFAULT_PARSER_PARSE_Y,
RB_DEFAULT_PARSER_PRISM,
} ruby_default_parser_enum;

ruby_default_parser_enum rb_ruby_default_parser(void);
void rb_ruby_default_parser_set(ruby_default_parser_enum parser);

#define rb_ruby_prism_p() (rb_ruby_default_parser() == RB_DEFAULT_PARSER_PRISM)

#ifdef UNIVERSAL_PARSER
#define rb_encoding const void
Expand Down
10 changes: 6 additions & 4 deletions iseq.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,13 @@ rb_iseq_mark_and_move(rb_iseq_t *iseq, bool reference_updating)
}
}

if (body->param.flags.has_kw && ISEQ_COMPILE_DATA(iseq) == NULL) {
if (body->param.flags.has_kw && body->param.keyword != NULL) {
const struct rb_iseq_param_keyword *const keyword = body->param.keyword;

for (int j = 0, i = keyword->required_num; i < keyword->num; i++, j++) {
rb_gc_mark_and_move(&keyword->default_values[j]);
if (keyword->default_values != NULL) {
for (int j = 0, i = keyword->required_num; i < keyword->num; i++, j++) {
rb_gc_mark_and_move(&keyword->default_values[j]);
}
}
}

Expand Down Expand Up @@ -1564,7 +1566,7 @@ iseqw_s_compile_parser(int argc, VALUE *argv, VALUE self, bool prism)
static VALUE
iseqw_s_compile(int argc, VALUE *argv, VALUE self)
{
return iseqw_s_compile_parser(argc, argv, self, *rb_ruby_prism_ptr());
return iseqw_s_compile_parser(argc, argv, self, rb_ruby_prism_p());
}

/*
Expand Down
31 changes: 4 additions & 27 deletions kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ def tap
# require 'open-uri'
# require 'json'
#
# construct_url(arguments).
# then {|url| URI(url).read }.
# then {|response| JSON.parse(response) }
# construct_url(arguments)
# .then {|url| URI(url).read }
# .then {|response| JSON.parse(response) }
#
# When called without block, the method returns +Enumerator+,
# which can be used, for example, for conditional
Expand All @@ -118,15 +118,6 @@ def tap
# # does not meet condition, drop value
# 2.then.detect(&:odd?) # => nil
#
# Good usage for +then+ is value piping in method chains:
#
# require 'open-uri'
# require 'json'
#
# construct_url(arguments).
# then {|url| URI(url).read }.
# then {|response| JSON.parse(response) }
#
def then
Primitive.attr! :inline_block
unless defined?(yield)
Expand All @@ -135,21 +126,7 @@ def then
yield(self)
end

#
# call-seq:
# obj.yield_self {|x| block } -> an_object
#
# Yields self to the block and returns the result of the block.
#
# "my string".yield_self {|s| s.upcase } #=> "MY STRING"
#
def yield_self
Primitive.attr! :inline_block
unless defined?(yield)
return Primitive.cexpr! 'SIZED_ENUMERATOR(self, 0, 0, rb_obj_size)'
end
yield(self)
end
alias yield_self then

module_function

Expand Down
50 changes: 29 additions & 21 deletions lib/bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -384,28 +384,12 @@ def clean_env

# @return [Hash] Environment with all bundler-related variables removed
def unbundled_env
env = original_env

if env.key?("BUNDLER_ORIG_MANPATH")
env["MANPATH"] = env["BUNDLER_ORIG_MANPATH"]
end

env.delete_if {|k, _| k[0, 7] == "BUNDLE_" }

if env.key?("RUBYOPT")
rubyopt = env["RUBYOPT"].split(" ")
rubyopt.delete("-r#{File.expand_path("bundler/setup", __dir__)}")
rubyopt.delete("-rbundler/setup")
env["RUBYOPT"] = rubyopt.join(" ")
end

if env.key?("RUBYLIB")
rubylib = env["RUBYLIB"].split(File::PATH_SEPARATOR)
rubylib.delete(__dir__)
env["RUBYLIB"] = rubylib.join(File::PATH_SEPARATOR)
end
unbundle_env(original_env)
end

env
# Remove all bundler-related variables from ENV
def unbundle_env!
ENV.replace(unbundle_env(ENV))
end

# Run block with environment present before Bundler was activated
Expand Down Expand Up @@ -651,6 +635,30 @@ def self_manager

private

def unbundle_env(env)
if env.key?("BUNDLER_ORIG_MANPATH")
env["MANPATH"] = env["BUNDLER_ORIG_MANPATH"]
end

env.delete_if {|k, _| k[0, 7] == "BUNDLE_" }
env.delete("BUNDLER_SETUP")

if env.key?("RUBYOPT")
rubyopt = env["RUBYOPT"].split(" ")
rubyopt.delete("-r#{File.expand_path("bundler/setup", __dir__)}")
rubyopt.delete("-rbundler/setup")
env["RUBYOPT"] = rubyopt.join(" ")
end

if env.key?("RUBYLIB")
rubylib = env["RUBYLIB"].split(File::PATH_SEPARATOR)
rubylib.delete(__dir__)
env["RUBYLIB"] = rubylib.join(File::PATH_SEPARATOR)
end

env
end

def load_marshal(data, marshal_proc: nil)
Marshal.load(data, marshal_proc)
rescue TypeError => e
Expand Down
16 changes: 11 additions & 5 deletions lib/bundler/inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ def gemfile(install = false, options = {}, &gemfile)
Bundler.ui = ui
raise ArgumentError, "Unknown options: #{opts.keys.join(", ")}" unless opts.empty?

Bundler.with_unbundled_env do
old_gemfile = ENV["BUNDLE_GEMFILE"]

Bundler.unbundle_env!

begin
Bundler.instance_variable_set(:@bundle_path, Pathname.new(Gem.dir))
Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", "Gemfile"

Expand Down Expand Up @@ -80,9 +84,11 @@ def gemfile(install = false, options = {}, &gemfile)

runtime.require
end
end

if ENV["BUNDLE_GEMFILE"].nil?
ENV["BUNDLE_GEMFILE"] = ""
ensure
if old_gemfile
ENV["BUNDLE_GEMFILE"] = old_gemfile
else
ENV["BUNDLE_GEMFILE"] = ""
end
end
end
2 changes: 1 addition & 1 deletion lib/irb/debug/ui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def puts str = nil
def readline _
setup_interrupt do
tc = DEBUGGER__::SESSION.instance_variable_get(:@tc)
cmd = @irb.debug_readline(tc.current_frame.binding || TOPLEVEL_BINDING)
cmd = @irb.debug_readline(tc.current_frame.eval_binding || TOPLEVEL_BINDING)

case cmd
when nil # when user types C-d
Expand Down
11 changes: 2 additions & 9 deletions lib/rubygems/command_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,11 @@ def find_command_possibilities(cmd_name)
def load_and_instantiate(command_name)
command_name = command_name.to_s
const_name = command_name.capitalize.gsub(/_(.)/) { $1.upcase } << "Command"
load_error = nil

begin
begin
require "rubygems/commands/#{command_name}_command"
rescue LoadError => e
load_error = e
end
require "rubygems/commands/#{command_name}_command"
Gem::Commands.const_get(const_name).new
rescue StandardError => e
e = load_error if load_error

rescue StandardError, LoadError => e
alert_error clean_text("Loading command: #{command_name} (#{e.class})\n\t#{e}")
ui.backtrace e
end
Expand Down
Loading

0 comments on commit 2cbecd4

Please sign in to comment.