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-1
  • Loading branch information
rm155 committed Sep 8, 2023
2 parents b58276d + d9ede18 commit 99c174f
Show file tree
Hide file tree
Showing 257 changed files with 2,972 additions and 1,614 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ jobs:
${{ steps.find-patch.outputs.needs }}
if: ${{ steps.find-patch.outputs.needs != '' }}

- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
- uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2
with:
path: C:\vcpkg\downloads
key: ${{ runner.os }}-vcpkg-download-${{ env.OS_VER }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-vcpkg-download-${{ env.OS_VER }}-
${{ runner.os }}-vcpkg-download-
- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
- uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2
with:
path: C:\vcpkg\installed
key: ${{ runner.os }}-vcpkg-installed-${{ env.OS_VER }}-${{ github.sha }}
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ env:
- &ppc64le-linux
name: ppc64le-linux
arch: ppc64le
<<: *gcc-10
compiler: gcc

- &s390x-linux
name: s390x-linux
arch: s390x
<<: *gcc-10
compiler: gcc

- &arm32-linux
name: arm32-linux
Expand Down
4 changes: 2 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ The following default gems are updated.
* time 0.2.2
* timeout 0.4.0
* uri 0.12.2
* yarp 0.10.0
* yarp 0.11.0

The following bundled gems are updated.

* minitest 5.19.0
* minitest 5.20.0
* test-unit 3.6.1
* rexml 3.2.6
* rss 0.3.0
Expand Down
4 changes: 2 additions & 2 deletions addr2line.c
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,7 @@ addr_header_init(obj_info_t *obj, addr_header_t *header) {

header->ptr = p;

if (!p) return false;
if (!p) return true;

header->unit_length = *(uint32_t *)p;
p += sizeof(uint32_t);
Expand Down Expand Up @@ -1539,7 +1539,7 @@ static bool
rnglists_header_init(obj_info_t *obj, rnglists_header_t *header) {
const char *p = obj->debug_rnglists.ptr;

if (!p) return false;
if (!p) return true;

header->unit_length = *(uint32_t *)p;
p += sizeof(uint32_t);
Expand Down
18 changes: 18 additions & 0 deletions bootstraptest/test_yjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1832,6 +1832,24 @@ def jittable_method
jittable_method
}

# test getbyte on string class
assert_equal '[97, :nil, 97, :nil, :raised]', %q{
def getbyte(s, i)
byte = begin
s.getbyte(i)
rescue TypeError
:raised
end
byte || :nil
end
getbyte("a", 0)
getbyte("a", 0)
[getbyte("a", 0), getbyte("a", 1), getbyte("a", -1), getbyte("a", -2), getbyte("a", "a")]
} unless defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled? # Not yet working on RJIT

# Test << operator on string subclass
assert_equal 'abab', %q{
class MyString < String; end
Expand Down
1 change: 0 additions & 1 deletion error.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ rb_warning_category_enabled_p(rb_warning_category_t category)
* deprecation warnings
* * assignment of non-nil value to <code>$,</code> and <code>$;</code>
* * keyword arguments
* * proc/lambda without block
* etc.
*
* +:experimental+ ::
Expand Down
8 changes: 4 additions & 4 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ typedef struct rb_objspace {
unsigned int during_compacting : 1;
unsigned int during_reference_updating : 1;
unsigned int gc_stressful: 1;
unsigned int has_hook: 1;
unsigned int has_newobj_hook: 1;
unsigned int during_minor_gc : 1;
unsigned int during_global_gc : 1;
unsigned int during_incremental_marking : 1;
Expand Down Expand Up @@ -2926,7 +2926,7 @@ rb_objspace_set_event_hook(const rb_event_flag_t event)
{
rb_objspace_t *objspace = &rb_objspace;
objspace->hook_events = event & RUBY_INTERNAL_EVENT_OBJSPACE_MASK;
objspace->flags.has_hook = (objspace->hook_events != 0);
objspace->flags.has_newobj_hook = !!(objspace->hook_events & RUBY_INTERNAL_EVENT_NEWOBJ);
}

static void
Expand All @@ -2936,7 +2936,7 @@ gc_event_hook_body(rb_execution_context_t *ec, rb_objspace_t *objspace, const rb
EXEC_EVENT_HOOK(ec, event, ec->cfp->self, 0, 0, 0, data);
}

#define gc_event_hook_available_p(objspace) ((objspace)->flags.has_hook)
#define gc_event_newobj_hook_needed_p(objspace) ((objspace)->flags.has_newobj_hook)
#define gc_event_hook_needed_p(objspace, event) ((objspace)->hook_events & (event))

#define gc_event_hook_prep(objspace, event, data, prep) do { \
Expand Down Expand Up @@ -3467,7 +3467,7 @@ newobj_of0(VALUE klass, VALUE flags, int wb_protected, rb_ractor_t *cr, size_t a

if (!UNLIKELY(during_gc ||
ruby_gc_stressful ||
gc_event_hook_available_p(objspace)) &&
gc_event_newobj_hook_needed_p(objspace)) &&
wb_protected) {
obj = UNLIKELY(borrowing) ? newobj_alloc_borrowing(objspace, cr, size_pool_idx, false) : newobj_alloc(objspace, cr, size_pool_idx, false);
newobj_init(klass, flags, wb_protected, objspace, obj);
Expand Down
4 changes: 2 additions & 2 deletions gems/bundled_gems
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# - repository-url: URL from where clone for test
# - revision: revision in repository-url to test
# if `revision` is not given, "v"+`version` or `version` will be used.
minitest 5.19.0 https://github.com/minitest/minitest
minitest 5.20.0 https://github.com/minitest/minitest
power_assert 2.0.3 https://github.com/ruby/power_assert
rake 13.0.6 https://github.com/ruby/rake
test-unit 3.6.1 https://github.com/test-unit/test-unit
Expand All @@ -19,5 +19,5 @@ matrix 0.4.2 https://github.com/ruby/matrix
prime 0.1.2 https://github.com/ruby/prime
rbs 3.2.1 https://github.com/ruby/rbs
typeprof 0.21.8 https://github.com/ruby/typeprof
debug 1.8.0 https://github.com/ruby/debug
debug 1.8.0 https://github.com/ruby/debug 927587afb6aac69b358b86a01f602d207053e8d2
racc 1.7.1 https://github.com/ruby/racc
34 changes: 33 additions & 1 deletion include/ruby/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,41 @@ void *rb_nogvl(void *(*func)(void *), void *data1,
*/
#define RUBY_CALL_WO_GVL_FLAG_SKIP_CHECK_INTS_

#define RUBY_INTERNAL_THREAD_EVENT_STARTED 1 << 0 /** thread started */
/**
* Triggered when a new thread is started.
*
* @note The callback will be called *without* the GVL held.
*/
#define RUBY_INTERNAL_THREAD_EVENT_STARTED 1 << 0

/**
* Triggered when a thread attempt to acquire the GVL.
*
* @note The callback will be called *without* the GVL held.
*/
#define RUBY_INTERNAL_THREAD_EVENT_READY 1 << 1 /** acquiring GVL */

/**
* Triggered when a thread successfuly acquired the GVL.
*
* @note The callback will be called *with* the GVL held.
*/
#define RUBY_INTERNAL_THREAD_EVENT_RESUMED 1 << 2 /** acquired GVL */

/**
* Triggered when a thread released the GVL.
*
* @note The callback will be called *without* the GVL held.
*/
#define RUBY_INTERNAL_THREAD_EVENT_SUSPENDED 1 << 3 /** released GVL */

/**
* Triggered when a thread exits.
*
* @note The callback will be called *without* the GVL held.
*/
#define RUBY_INTERNAL_THREAD_EVENT_EXITED 1 << 4 /** thread terminated */

#define RUBY_INTERNAL_THREAD_EVENT_MASK 0xff /** All Thread events */

typedef void rb_internal_thread_event_data_t; // for future extension.
Expand All @@ -212,6 +242,8 @@ typedef struct rb_internal_thread_event_hook rb_internal_thread_event_hook_t;
* @param[in] data Passed as-is to `func`.
* @return An opaque pointer to the hook, to unregister it later.
* @note This functionality is a noop on Windows.
* @note The callback will be called without the GVL held, except for the
RESUMED event.
* @warning This function MUST not be called from a thread event callback.
*/
rb_internal_thread_event_hook_t *rb_internal_thread_add_event_hook(
Expand Down
57 changes: 41 additions & 16 deletions lib/bundler/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def self.build
i
end

attr_reader :specs, :all_specs, :sources
protected :specs, :all_specs
attr_reader :specs, :duplicates, :sources
protected :specs, :duplicates

RUBY = "ruby"
NULL = "\0"
Expand All @@ -20,20 +20,20 @@ def initialize
@sources = []
@cache = {}
@specs = Hash.new {|h, k| h[k] = {} }
@all_specs = Hash.new {|h, k| h[k] = EMPTY_SEARCH }
@duplicates = {}
end

def initialize_copy(o)
@sources = o.sources.dup
@cache = {}
@specs = Hash.new {|h, k| h[k] = {} }
@all_specs = Hash.new {|h, k| h[k] = EMPTY_SEARCH }
@duplicates = {}

o.specs.each do |name, hash|
@specs[name] = hash.dup
end
o.all_specs.each do |name, array|
@all_specs[name] = array.dup
o.duplicates.each do |name, array|
@duplicates[name] = array.dup
end
end

Expand All @@ -47,7 +47,9 @@ def empty?
end

def search_all(name)
all_matches = local_search(name) + @all_specs[name]
all_matches = specs_by_name(name) # always returns a new Array
dupes = @duplicates[name]
all_matches.concat(dupes) if dupes
@sources.each do |source|
all_matches.concat(source.search_all(name))
end
Expand Down Expand Up @@ -78,10 +80,11 @@ def local_search(query)

alias_method :[], :search

def <<(spec)
def add(spec)
@specs[spec.name][spec.full_name] = spec
spec
end
alias_method :<<, :add

def each(&blk)
return enum_for(:each) unless blk
Expand Down Expand Up @@ -115,15 +118,25 @@ def dependency_names
names.uniq
end

def use(other, override_dupes = false)
# Combines indexes proritizing existing specs, like `Hash#reverse_merge!`
# Duplicate specs found in `other` are stored in `@duplicates`.
def use(other)
return unless other
other.each do |s|
if (dupes = search_by_spec(s)) && !dupes.empty?
# safe to << since it's a new array when it has contents
@all_specs[s.name] = dupes << s
next unless override_dupes
other.each do |spec|
exist?(spec) ? add_duplicate(spec) : add(spec)
end
self
end

# Combines indexes proritizing specs from `other`, like `Hash#merge!`
# Duplicate specs found in `self` are saved in `@duplicates`.
def merge!(other)
return unless other
other.each do |spec|
if existing = find_by_spec(spec)
add_duplicate(existing)
end
self << s
add spec
end
self
end
Expand Down Expand Up @@ -157,6 +170,10 @@ def add_source(index)

private

def add_duplicate(spec)
(@duplicates[spec.name] ||= []) << spec
end

def specs_by_name_and_version(name, version)
specs_by_name(name).select {|spec| spec.version == version }
end
Expand All @@ -168,8 +185,16 @@ def specs_by_name(name)
EMPTY_SEARCH = [].freeze

def search_by_spec(spec)
spec = @specs[spec.name][spec.full_name]
spec = find_by_spec(spec)
spec ? [spec] : EMPTY_SEARCH
end

def find_by_spec(spec)
@specs[spec.name][spec.full_name]
end

def exist?(spec)
@specs[spec.name].key?(spec.full_name)
end
end
end
28 changes: 14 additions & 14 deletions lib/bundler/source/rubygems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ def identifier
def specs
@specs ||= begin
# remote_specs usually generates a way larger Index than the other
# sources, and large_idx.use small_idx is way faster than
# small_idx.use large_idx.
idx = @allow_remote ? remote_specs.dup : Index.new
idx.use(cached_specs, :override_dupes) if @allow_cached || @allow_remote
idx.use(installed_specs, :override_dupes) if @allow_local
idx
# sources, and large_idx.merge! small_idx is way faster than
# small_idx.merge! large_idx.
index = @allow_remote ? remote_specs.dup : Index.new
index.merge!(cached_specs) if @allow_cached || @allow_remote
index.merge!(installed_specs) if @allow_local
index
end
end

Expand Down Expand Up @@ -274,9 +274,9 @@ def double_check_for(unmet_dependency_names)

Bundler.ui.debug "Double checking for #{unmet_dependency_names || "all specs (due to the size of the request)"} in #{self}"

fetch_names(api_fetchers, unmet_dependency_names, remote_specs, false)
fetch_names(api_fetchers, unmet_dependency_names, remote_specs)

specs.use(remote_specs, false)
specs.use remote_specs
end

def dependency_names_to_double_check
Expand Down Expand Up @@ -380,7 +380,7 @@ def installed_specs

def cached_specs
@cached_specs ||= begin
idx = @allow_local ? installed_specs.dup : Index.new
idx = Index.new

Dir["#{cache_path}/*.gem"].each do |gemfile|
s ||= Bundler.rubygems.spec_from_gem(gemfile)
Expand All @@ -401,22 +401,22 @@ def remote_specs
index_fetchers = fetchers - api_fetchers

if index_fetchers.empty?
fetch_names(api_fetchers, dependency_names, idx, false)
fetch_names(api_fetchers, dependency_names, idx)
else
fetch_names(fetchers, nil, idx, false)
fetch_names(fetchers, nil, idx)
end
end
end

def fetch_names(fetchers, dependency_names, index, override_dupes)
def fetch_names(fetchers, dependency_names, index)
fetchers.each do |f|
if dependency_names
Bundler.ui.info "Fetching gem metadata from #{URICredentialsFilter.credential_filtered_uri(f.uri)}", Bundler.ui.debug?
index.use f.specs_with_retry(dependency_names, self), override_dupes
index.use f.specs_with_retry(dependency_names, self)
Bundler.ui.info "" unless Bundler.ui.debug? # new line now that the dots are over
else
Bundler.ui.info "Fetching source index from #{URICredentialsFilter.credential_filtered_uri(f.uri)}"
index.use f.specs_with_retry(nil, self), override_dupes
index.use f.specs_with_retry(nil, self)
end
end
end
Expand Down
Loading

0 comments on commit 99c174f

Please sign in to comment.