[2.1] Refinements
headius opened this issue · comments
Refinements have been pared back to a much more reasonable form that does not have performance implications for unrefined code. They will ship as an official feature in 2.1.
We need to implement refinements in JRuby, at least as an experiment, as soon as possible to know whether they have undiscovered issues. Once they ship in 2.1 it will be much harder to fix them.
I'm marking this for 1.7.6, since I want to do the experiment ASAP.
https://bugs.ruby-lang.org/projects/ruby-trunk/wiki/RefinementsSpec
I realized if I land this in its current 50%+ working state it will not work in JIT since in this form it still has a refinedcallinstr vs using a refinedcallsite. Even had I made that change the JIT would still need some work so I am deferring this until next 9k release.
At the point of pre2 we are passing a substantial portion of refinement tests but we have quite a few significant failing tests (see test/mri). So more work to do before RC
Any progress on this?
I've hit some strange behaviour trying to use refinements with version 9.0.4.0:
module Refinement
refine Object do
def new_method
'new method!'
end
end
end
class Thing
using Refinement
p in_class_definition: Object.new.new_method
def test
p in_method: Object.new.new_method
end
end
Thing.new.test
outputs
{:in_class_definition=>"new method!"}
NoMethodError: undefined method `new_method' for #<Object:0xcfa9dbf>
test at test.rb:15
<top> at test.rb:19
It seems like there's something amiss with the lexical scoping of the method; in MRI, methods defined with the lexical scope where a refinement is activated can make use of that refinement. Is this expected behaviour in JRuby as of 9.0.4.0?
Another related issue: #2977.