Skip to content

Commit

Permalink
Merge branch 'master' into yjit-threshold1-timeout-bump
Browse files Browse the repository at this point in the history
  • Loading branch information
XrXr authored May 31, 2024
2 parents 01f6627 + 10c256f commit 9262fa2
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 39 deletions.
6 changes: 4 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ Note that each entry is kept to a minimum, see links for details.
`**nil` is treated similarly to `**{}`, passing no keywords,
and not calling any conversion methods. [[Bug #20064]]

* Block passing is no longer allowed in index. [[Bug #19918]]
* Block passing is no longer allowed in index assignment
(e.g. `a[0, &b] = 1`). [[Bug #19918]]

* Keyword arguments are no longer allowed in index. [[Bug #20218]]
* Keyword arguments are no longer allowed in index assignment
(e.g. `a[0, kw: 1] = 2`). [[Bug #20218]]

## Core classes updates

Expand Down
13 changes: 13 additions & 0 deletions lib/rubygems/basic_specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,19 @@ def full_name
end
end

##
# Returns the full name of this Gem (see `Gem::BasicSpecification#full_name`).
# Information about where the gem is installed is also included if not
# installed in the default GEM_HOME.

def full_name_with_location
if base_dir != Gem.dir
"#{full_name} in #{base_dir}"
else
full_name
end
end

##
# Full paths in the gem to add to <code>$LOAD_PATH</code> when this gem is
# activated.
Expand Down
6 changes: 3 additions & 3 deletions lib/rubygems/commands/pristine_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def execute
end

unless spec.extensions.empty? || options[:extensions] || options[:only_executables] || options[:only_plugins]
say "Skipped #{spec.full_name}, it needs to compile an extension"
say "Skipped #{spec.full_name_with_location}, it needs to compile an extension"
next
end

Expand All @@ -157,7 +157,7 @@ def execute
unless File.exist?(gem) || options[:only_executables] || options[:only_plugins]
require_relative "../remote_fetcher"

say "Cached gem for #{spec.full_name} not found, attempting to fetch..."
say "Cached gem for #{spec.full_name_with_location} not found, attempting to fetch..."

dep = Gem::Dependency.new spec.name, spec.version
found, _ = Gem::SpecFetcher.fetcher.spec_for_dependency dep
Expand Down Expand Up @@ -201,7 +201,7 @@ def execute
installer.install
end

say "Restored #{spec.full_name}"
say "Restored #{spec.full_name_with_location}"
end
end
end
1 change: 0 additions & 1 deletion lib/rubygems/specification_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def stubs_for_pattern(pattern, match_platform = true)
installed_stubs = installed_stubs(pattern)
installed_stubs.select! {|s| Gem::Platform.match_spec? s } if match_platform
stubs = installed_stubs + Gem::Specification.default_stubs(pattern)
stubs = stubs.uniq(&:full_name)
Gem::Specification._resort!(stubs)
stubs
end
Expand Down
21 changes: 21 additions & 0 deletions lib/rubygems/stub_specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,25 @@ def valid?
def stubbed?
data.is_a? StubLine
end

def ==(other) # :nodoc:
self.class === other &&
name == other.name &&
version == other.version &&
platform == other.platform
end

alias_method :eql?, :== # :nodoc:

def hash # :nodoc:
name.hash ^ version.hash ^ platform.hash
end

def <=>(other) # :nodoc:
sort_obj <=> other.sort_obj
end

def sort_obj # :nodoc:
[name, version, Gem::Platform.sort_priority(platform)]
end
end
23 changes: 12 additions & 11 deletions lib/rubygems/uninstaller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ def uninstall

list = []

dirs =
Gem::Specification.dirs +
[Gem.default_specifications_dir]

Gem::Specification.each_spec dirs do |spec|
specification_record.stubs.each do |spec|
next unless dependency.matches_spec? spec

list << spec
Expand All @@ -102,7 +98,7 @@ def uninstall

default_specs, list = list.partition(&:default_gem?)
warn_cannot_uninstall_default_gems(default_specs - list)
@default_specs_matching_uninstall_params = default_specs
@default_specs_matching_uninstall_params = default_specs.map(&:to_spec)

list, other_repo_specs = list.partition do |spec|
@gem_home == spec.base_dir ||
Expand All @@ -126,7 +122,7 @@ def uninstall
remove_all list

elsif list.size > 1
gem_names = list.map(&:full_name)
gem_names = list.map(&:full_name_with_location)
gem_names << "All versions"

say
Expand All @@ -147,7 +143,9 @@ def uninstall
##
# Uninstalls gem +spec+

def uninstall_gem(spec)
def uninstall_gem(stub)
spec = stub.to_spec

@spec = spec

unless dependencies_ok? spec
Expand All @@ -165,6 +163,8 @@ def uninstall_gem(spec)
remove_plugins @spec
remove @spec

specification_record.remove_spec(stub)

regenerate_plugins

Gem.post_uninstall_hooks.each do |hook|
Expand Down Expand Up @@ -275,8 +275,6 @@ def remove(spec)

safe_delete { FileUtils.rm_r gemspec }
announce_deletion_of(spec)

Gem::Specification.reset
end

##
Expand All @@ -292,7 +290,6 @@ def remove_plugins(spec) # :nodoc:
# Regenerates plugin wrappers after removal.

def regenerate_plugins
specification_record = @install_dir ? Gem::SpecificationRecord.from_path(@install_dir) : Gem::Specification.specification_record
latest = specification_record.latest_spec_for(@spec.name)
return if latest.nil?

Expand Down Expand Up @@ -381,6 +378,10 @@ def safe_delete(&block)

private

def specification_record
@specification_record ||= @install_dir ? Gem::SpecificationRecord.from_path(@install_dir) : Gem::Specification.specification_record
end

def announce_deletion_of(spec)
name = spec.full_name
say "Successfully uninstalled #{name}"
Expand Down
4 changes: 2 additions & 2 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -13658,10 +13658,10 @@ aryset_check(struct parser_params *p, NODE *args)
}
}
if (kwds && nd_type_p(kwds, NODE_HASH) && !RNODE_HASH(kwds)->nd_brace) {
yyerror1(&kwds->nd_loc, "keyword arg given in index");
yyerror1(&kwds->nd_loc, "keyword arg given in index assignment");
}
if (block) {
yyerror1(&block->nd_loc, "block arg given in index");
yyerror1(&block->nd_loc, "block arg given in index assignment");
}
}

Expand Down
4 changes: 2 additions & 2 deletions prism/templates/src/diagnostic.c.erb
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
[PM_ERR_UNDEF_ARGUMENT] = { "invalid argument being passed to `undef`; expected a bare word, constant, or symbol argument", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_UNARY_RECEIVER] = { "unexpected %s, expected a receiver for unary `%c`", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_UNEXPECTED_BLOCK_ARGUMENT] = { "block argument should not be given", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_UNEXPECTED_INDEX_BLOCK] = { "unexpected block arg given in index; blocks are not allowed in index expressions", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_UNEXPECTED_INDEX_KEYWORDS] = { "unexpected keyword arg given in index; keywords are not allowed in index expressions", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_UNEXPECTED_INDEX_BLOCK] = { "unexpected block arg given in index assignment; blocks are not allowed in index assignment expressions", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_UNEXPECTED_INDEX_KEYWORDS] = { "unexpected keyword arg given in index assignment; keywords are not allowed in index assignment expressions", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_UNEXPECTED_SAFE_NAVIGATION] = { "&. inside multiple assignment destination", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_UNEXPECTED_TOKEN_CLOSE_CONTEXT] = { "unexpected %s, assuming it is closing the parent %s", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_UNEXPECTED_TOKEN_IGNORE] = { "unexpected %s, ignoring it", PM_ERROR_LEVEL_SYNTAX },
Expand Down
6 changes: 3 additions & 3 deletions test/ruby/test_call.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def []=(*a, **b, &c) @set = [a, b, c] end
# Prevent "assigned but unused variable" warnings
_ = [h, a, kw, b]

message = /keyword arg given in index/
message = /keyword arg given in index assignment/

# +=, without block, non-popped
assert_syntax_error(%q{h[**kw] += 1}, message)
Expand Down Expand Up @@ -270,7 +270,7 @@ def test_kwsplat_block_order_op_asgn
def o.[](...) 2 end
def o.[]=(...) end

message = /keyword arg given in index/
message = /keyword arg given in index assignment/

assert_syntax_error(%q{o[kw: 1] += 1}, message)
assert_syntax_error(%q{o[**o] += 1}, message)
Expand All @@ -292,7 +292,7 @@ def [](*a, **b)
def []=(*a, **b) @set = [a, b] end
end.new

message = /keyword arg given in index/
message = /keyword arg given in index assignment/

a = []
kw = {}
Expand Down
4 changes: 2 additions & 2 deletions test/ruby/test_parse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -512,12 +512,12 @@ def t.[]=(_, _)
def t.dummy(_)
end

assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /block arg given in index/)
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /block arg given in index assignment/)
begin;
t[42, &blk] ||= 42
end;

assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /block arg given in index/)
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /block arg given in index assignment/)
begin;
t[42, &blk] ||= t.dummy 42 # command_asgn test
end;
Expand Down
10 changes: 5 additions & 5 deletions test/rubygems/test_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1562,20 +1562,20 @@ def test_gem_path_ordering
assert_equal m1.gem_dir, File.join(Gem.user_dir, "gems", "m-1")

tests = [
[:dir0, [Gem.dir, Gem.user_dir], m0],
[:dir1, [Gem.user_dir, Gem.dir], m1],
[:dir0, [Gem.dir, Gem.user_dir]],
[:dir1, [Gem.user_dir, Gem.dir]],
]

tests.each do |name, paths, expected|
tests.each do |name, paths|
Gem.use_paths paths.first, paths
Gem.searcher = nil

assert_equal Gem::Dependency.new("m","1").to_specs,
Gem::Dependency.new("m","1").to_specs.sort

assert_equal \
[expected.gem_dir],
Gem::Dependency.new("m","1").to_specs.map(&:gem_dir).sort,
[m0.gem_dir, m1.gem_dir],
Gem::Dependency.new("m","1").to_specs.map(&:gem_dir).uniq.sort,
"Wrong specs for #{name}"

spec = Gem::Dependency.new("m","1").to_spec
Expand Down
11 changes: 6 additions & 5 deletions test/rubygems/test_gem_commands_pristine_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def test_execute_user_install
out = @ui.output.split("\n")

assert_equal "Restoring gems to pristine condition...", out.shift
assert_equal "Restored #{a.full_name}", out.shift
assert_equal "Restored #{a.full_name} in #{Gem.user_dir}", out.shift
assert_empty out, out.inspect
ensure
FileUtils.chmod(0o755, @gemhome)
Expand Down Expand Up @@ -404,7 +404,7 @@ def test_execute_many_multi_repo
out = @ui.output.split "\n"

assert_equal "Restoring gems to pristine condition...", out.shift
assert_equal "Restored #{a.full_name}", out.shift
assert_equal "Restored #{a.full_name} in #{@gemhome}", out.shift
assert_equal "Restored #{b.full_name}", out.shift
assert_empty out, out.inspect

Expand Down Expand Up @@ -476,8 +476,9 @@ def test_execute_missing_cache_gem_when_multi_repo

[
"Restoring gems to pristine condition...",
"Cached gem for a-1 not found, attempting to fetch...",
"Restored a-1",
"Cached gem for a-1 in #{@gemhome} not found, attempting to fetch...",
"Restored a-1 in #{@gemhome}",
"Restored b-1 in #{@gemhome}",
"Cached gem for b-1 not found, attempting to fetch...",
"Restored b-1",
].each do |line|
Expand All @@ -495,7 +496,7 @@ def test_execute_missing_cache_gem_when_multi_repo
assert_path_exist File.join(gemhome2, "cache", "b-1.gem")
assert_path_not_exist File.join(@gemhome, "cache", "b-2.gem")
assert_path_exist File.join(gemhome2, "gems", "b-1")
assert_path_not_exist File.join(@gemhome, "gems", "b-1")
assert_path_exist File.join(@gemhome, "gems", "b-1")
end

def test_execute_no_gem
Expand Down
2 changes: 1 addition & 1 deletion test/rubygems/test_gem_commands_uninstall_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_execute_all_named
@cmd.execute
end

assert_equal %w[a_evil-9 b-2 c-1.2 default-1 dep_x-1 pl-1-x86-linux x-1],
assert_equal %w[a-4 a_evil-9 b-2 c-1.2 default-1 dep_x-1 pl-1-x86-linux x-1],
Gem::Specification.all_names.sort
end

Expand Down
2 changes: 0 additions & 2 deletions test/rubygems/test_gem_uninstaller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ def setup
@user_spec = @user_installer.spec
end
end

Gem::Specification.reset
end

def test_initialize_expand_path
Expand Down

0 comments on commit 9262fa2

Please sign in to comment.