-
-
Notifications
You must be signed in to change notification settings - Fork 925
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
define_method with empty body throws RuntimeError in interpreter #3483
Comments
Ah-ha! This makes sense. In 9030 we made a change that converts define_method methods into regular methods. It seems something about this conversion is causing the code to fall off the end of the method. This is definitely enough for us to reproduce and find the problem. You can work around the issue by adding an explicit return to the method, so it seems like this is related to how blocks return. For example, this works:
|
oh i'll try that - thanks! |
And for the record, this is why we're doing what we're doing for testing:
So... one could argue that that's terrible :) |
The addition of the return statement fixes the problem! Thanks very much! |
@annafw I knew it would be something like that...basically stubbing out methods you don't want to make noise. Glad to hear the workaround works. We'll get this fixed up for 9.0.5.0. Thanks for the report! |
Looking into this now. |
This only appears to affect running in the StartupInterpreterEngine:
Here's the full backtrace:
|
Ah-ha...I think I see the problem. In the startup interpreter, blocks are allowed to fall off the end without an explicit return instructions. Here's a screencap from my debug session: So there's a few ways to fix this, and I'm not sure how to proceed.
|
Ok, my naive forcing of a full build did not work. Patch: diff --git a/core/src/main/java/org/jruby/RubyModule.java b/core/src/main/java/org/jruby/RubyModule.java
index d487251..e06610b 100644
--- a/core/src/main/java/org/jruby/RubyModule.java
+++ b/core/src/main/java/org/jruby/RubyModule.java
@@ -1800,6 +1800,9 @@ public class RubyModule extends RubyObject {
// Ask closure to give us a method equivalent.
IRMethod method = closure.convertToMethod(name);
if (method != null) {
+ // Run passes against the method to fix #3483
+ method.prepareFullBuild();
+
newMethod = new DefineMethodMethod(method, visibility, this, context.getFrameBlock());
Helpers.addInstanceMethod(this, name, newMethod, visibility, context, runtime);
return nameSym; NPE:
|
Bleh, ok. I'm stumped for now. |
This should be fully converting to a method where we make a new IRMethod and args and body nodes are being treated as if they were method args and body node. I am guessing some presence of some node in AST is setting a flag in a bad way. We should not need to force full build prep since first access of this new "method" should lazilyAcquire the startup interp instrs and it should also run basic passes on it. If a return is getting stripped it is because of the presence of something normally a method would not have. At least that is my current hunch. |
The weird thing about this bug involved println and displaying the AST. The optimization would compile the argsNode and the bodyNode as if the iternode was a def{n,s}node but def nodes will add an implicitnilnode whereas iter nodes would not if the body is empty. For some reason the ast command would not display nilimplicitnode in the output so it was not possible to see the difference. So adding an implicitnilnode for iternodes empty bodies fixes thing. |
* master: (29 commits) [travis-ci] revert jdk 9 testing from 2fa04aa Eliminate Block.Type arg in BlockBody yield/call signatures Pass Block instead of Binding in BlockBody.yield/call Minor: fix typo in name of runtime helper instr method name Update to jnr-unixsocket 0.10. Improve CamelCase package splitting. Fixes #3493. Update to jnr-unixsocket 0.10-SNAPSHOT for forFD. [Truffle] j+tr: support for passing any extra ruby options each_object(cls.singleton_class) should not walk special classes. This test has been moved to RubySpec. [Truffle] Typo. [Truffle] Tag failing regex specs. [Truffle] Tag failing Time.at spec. The bin200 distribution has grown in size. [Truffle] Fixed two typos of the same word on the same line of code. [Truffle] Simplified the fix in 5446cc2. [Truffle] Fixed an NPE when a SharedMethodInfo has a null argumentsDescriptors. [Truffle] Fixed the interpreter_path when the root JRuby distribution directory is not named "jruby." Fixes #3483. define_method with empty body throws RuntimeError in interpreter Test main on Java 9 ...
Do we know when we are planning on this going live? I believe it's effecting RAKE tasks as well (at least cucumber::task rake tasks) EDIT: I found where the issue was, it's in the cucumber rerun formatter |
If you do the following in jruby 9.0.4.0:
You get this RuntimeError:
I tried the same in jruby-9.0.1.0, and it works as follows:
The text was updated successfully, but these errors were encountered: