-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ruby 3 support #85
Ruby 3 support #85
Conversation
Hi! Thanks for reaching out, I am currently on holidays, so I'll be able to look into this in about 10 days. Happy holidays! |
@swiknaba do you know the reason why that spec is failing for Ruby 3.0? As much as I understand it fails after relaxing the required ruby version. |
@swiknaba whenever you get a chance to answer here, we can proceed with this work. Thanks! |
I thought, possibly # see spec/lib/fasterer/analyzer/24_gsub_vs_tr_spec.rb
require 'benchmark'
petar = "petar"
n = 5_000_000
Benchmark.bm do |benchmark|
benchmark.report("gsub") do
n.times do
petar.gsub('r', 'k')
end
end
benchmark.report("tr") do
n.times do
petar.tr('r', 'k')
end
end
end however, running this under Ruby 3 yields
so
all result in The following example is not recognized under Ruby 3: class Hello
def hihi
'alfabet'.gsub('r', 'b'.gsub('a', 'z'))
end
end (the one it recognizes is checking the parsed result to see if the parser has some issue: s(:class, :Hello, nil, s(:defn, :hihi, s(:args), s(:call, s(:str, "alfabet"), :gsub, s(:str, "r"), s(:call, s(:str, "b"), :gsub, s(:str, "a"), s(:str, "z"))))) ruby 3.0.0 s(:class, :Hello, nil, s(:defn, :hihi, s(:args), s(:call, s(:str, "alfabet"), :gsub, s(:str, "r"), s(:call, s(:str, "b"), :gsub, s(:str, "a"), s(:str, "z"))))) => same result. |
trimmed down this file to the problematic example: # spec/support/analyzer/24_gsub_vs_tr.rb
class Hello
def hihi
'alfabet'.gsub('r', 'b'.gsub('a', 'z'))
end
end running Ruby 2.7.2:
However, in Ruby 3.0.0 this
which is no offense. The problem is here# lib/fasterer/analyzer.rb
case token
when :call, :iter
method_call = MethodCall.new(sexp_tree)
binding.pry
traverse_sexp_tree(method_call.arguments_element)
traverse_sexp_tree(method_call.receiver_element) if method_call.receiver_element
traverse_sexp_tree(method_call.block_body) if method_call.has_block?
else
sexp_tree.each { |element| traverse_sexp_tree(element) }
end
end
s(:call, s(:str, "alfabet"), :gsub, s(:str, "r"), s(:call, s(:str, "b"), :gsub, s(:str, "a"), s(:str, "z"))) while with Ruby 3.0.0 this is an array:
Digging deeper, it seems that in |
@DamirSvrtan I've opened an issue here: seattlerb/ruby_parser#313 since this problem is related to Ruby Parser (I think :D). Unsure how to fix this, or how to work around this. Any idea? |
@DamirSvrtan solution here: seattlerb/ruby_parser#313 (comment) let's use Sexp#sexp_body rather than |
ping 🙂 |
Thanks for pinging, it slipped my radar! |
Excellent 👍 Can we get a new gem cut please? |
I've released Ruby 3.0 support in fasterer version 0.9.0. Thanks @swiknaba for the contribution! |
closes #84
~> 2.2
to=> 2.2
(which will allow upgrading to Ruby 3 --obviously^^)The CI is failing since this commit: aebf173 from Mar 2, 2020.
If you are OK, I suggest dropping support for 2.2 entirely, and set the required Ruby version to
=> 2.3
, since 2.3 is the oldest version that you can download from the official website. Also, Ruby 2.3 was released in 2015, 5 years ago.I've run RSpec locally against all Ruby versions that I have compiled on my machine:
✅ Ruby 2.3.8:
92 examples, 0 failures, 1 pending
✅ Ruby 2.5.8:
92 examples, 0 failures, 1 pending
✅ Ruby 2.6.6:
92 examples, 0 failures, 1 pending
✅ Ruby 2.7.2:
92 examples, 0 failures, 1 pending
✅ Ruby 3.0.0:
92 examples, 0 failures, 1 pending
❌ Ruby 3.0.0:=> should we:* keep the current restriction ( 🙁 )* wait for a fix* fix Ruby 3 in this PR* merge this, then fix Ruby 3 separatelyupdate: ✅ fixed. see comments below.
=> I've created a follow-up issue so that the failing specs can be addressed separately:
closes #86