Skip to content

Commit

Permalink
Automatically detect Ruby 3.1.0-dev's anonymous params bug
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Nov 24, 2021
1 parent b718e07 commit 1aea48e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,5 +1,6 @@
# Unreleased

* Disable compile cache if Ruby 3.0.3's ISeq cache bug is detected.
* Fix `Kernel.load` behavior: before `load 'a'` would load `a.rb` (and other tried extensions) and wouldn't load `a` unless `development_mode: true`, now only `a` would be loaded and files with extensions wouldn't be.

# 1.9.1
Expand Down
35 changes: 29 additions & 6 deletions lib/bootsnap.rb
Expand Up @@ -57,9 +57,15 @@ def self.setup(
"If you use Ruby 2.5 or newer this option is useless, if not upgrading is recommended."
end

if compile_cache_iseq && !iseq_cache_supported?
warn "Ruby 2.5 has a bug that break code tracing when code is loaded from cache. It is recommened " \
"to turn `compile_cache_iseq` off on Ruby 2.5"
if compile_cache_iseq
if iseq_cache_tracing_bug?
warn "Ruby 2.5 has a bug that break code tracing when code is loaded from cache. It is recommended " \
"to turn `compile_cache_iseq` off on Ruby 2.5"
end

if iseq_cache_anonymous_params_bug?
warn "Your version of Ruby 3.1.0-dev has a bug that break bytecode caching (https://github.com/ruby/ruby/pull/4961)."
end
end

Bootsnap::LoadPathCache.setup(
Expand All @@ -75,11 +81,28 @@ def self.setup(
)
end

def self.iseq_cache_supported?
return @iseq_cache_supported if defined? @iseq_cache_supported
def self.iseq_cache_tracing_bug?
return @iseq_cache_tracing_bug if defined? @iseq_cache_tracing_bug

ruby_version = Gem::Version.new(RUBY_VERSION)
@iseq_cache_supported = ruby_version < Gem::Version.new('2.5.0') || ruby_version >= Gem::Version.new('2.6.0')
@iseq_cache_tracing_bug = ruby_version < Gem::Version.new('2.5.0') || ruby_version >= Gem::Version.new('2.6.0')
end

def self.iseq_cache_anonymous_params_bug?
return @iseq_cache_anonymous_params_bug if defined? @iseq_cache_anonymous_params_bug
begin
if defined? RubyVM::InstructionSequence
RubyVM::InstructionSequence.compile("def foo(*); ->{ super }; end").to_binary
RubyVM::InstructionSequence.compile("def foo(**); ->{ super }; end").to_binary
end
false
rescue TypeError
true
end
end

def self.iseq_cache_supported?
!(iseq_cache_tracing_bug? || iseq_cache_anonymous_params_bug?)
end

def self.default_setup
Expand Down

0 comments on commit 1aea48e

Please sign in to comment.