-
-
Couldn't load subscription status.
- Fork 933
Fixes #6563. Rails 6.1.2.x dynamic finders cause Java::JavaLang::ClassCastException #6571
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
Conversation
…er in module bodies?
This was never part of Ruby and a misunderstanding that Ruby does
not support this.
The feature was never hit because people tend to target MRI first
so we never had people doing this. Recent Rails find_by logic exposed
a bug in this feature which would CCE.
Removing this fixes the CCE.
The second part of this commit is raising the RuntimeError pointing
out zsuper is not supported in blocks.
This uses a faulty heuristic that can be changed if we realize someone
somehow is doing something which breaks the heuristic. We will raise
if we see a closure which is attached to a method call which is
define_method in the presence of existing in a method scope. This means
if someone happens to have a zsuper in another method called define_method
in a def then we will not properly invoke the zsuper.
This also exposes an issue I think with our bytecode generation of
RaiseException which can be seen by running:
```ruby
def test_define_method
a = Object.new
lambda {
Class.new {
define_method(:a) {super}
}.new.a
}.call
end
test_define_method
```
So a followup commit will come to address that and possibly also expanding
the above heuristic to define_singleton_method.
Interpreter was unwrapping and getting an exception object to throw with throwExceptionIstr. The JIT was only working with actual exceptions. This commit aligns the interpreter with the JIT and the only two uses which would not work just become dynamic calls to Kernel#raise. This is fine because it does not complicate JIT by making throwinstr more complicated and the dynamic calls only occur extremely extremely rarely to raise errors. The second fix is that define_method can sometimes convert itself from being a closure to being a method. This conversion did not care whether zsuper was present or not. We will now mark zsuper in the closure scope and not perform this optimization in that case.
Reverted this logic. The define_method and flip flop are stil dyncalls but there is clearly more going on here. Interesting too since the JIT would crash if it received an IRubyObject instead of a Throwable. It must handle some of this differently in the JIT.
| return zsuperResult; | ||
| } | ||
| }; | ||
| private boolean isMethodDefine() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not isDefineMethod?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I yoda named that for no reason. I will change that.
| runtime.newSymbol("raise"), | ||
| kernel, | ||
| new Operand[] { exception }, | ||
| null)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could just call this as Kernel.raise WhateverException, "message" rather than doing the call to new.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure. I can make this change...less generated instrs + bytecode.
|
Spurious failure on travis on some MT test writing IO. Unrelated to this. |
fix define_method+super calls due to jruby/jruby#6571
* master: [tests] change super to super() - jruby/jruby#6571
fix define_method+super calls due to jruby/jruby#6571
fix define_method+super calls due to jruby/jruby#6571 (cherry picked from commit 9643a33)
fix define_method+super calls due to jruby/jruby#6571 (cherry picked from commit 9643a33)
Fixes #6563
90% of the changes here are for JRuby to dynamically raise an exception if we try and use zsuper from within a define_method block.
The important part is instead of building up a list of argument operands at each level so we can support zsuper we just delete all that. So removing the logic we should not have been doing in the first place means we do not hit a bug in that code in the first place.