-
-
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
Code runs fine on JRuby but crashes after compilation to .class files (Rails / Grape Entity API) #4088
Comments
Very strange. The current JRuby .class compiler basically just compiles the code as our internal IR format, serializes it to a byte array, and stuffs that into the class. It is then loaded on boot and goes through normal interpretation/JIT cycle. So if this is failing it could be a problem with how we're serializing the code in question. |
Here's the IR for the main class body (sans Grape reference and extension):
The two closures constructed here differ in that for lambda, we see a separate call to the The closures themselves are pretty much identitical:
The only difference between the two closures would be that one is executed as a lambda -- which checks arity -- and the other is a normal non-lambda block. I'll look along those lines and see if I find anything. |
Hmm. I'm trying to come up with a reproduction that doesn't depend on Grape, and I'm not succeeding so far. Here's the script I have, based on yours: class MyEntity
def self.expose(a, proc: nil)
if block_given?
yield a, a.to_s.reverse
else
proc.call(a, a.to_s.reverse)
end
end
expose :attribute_a, proc: lambda { |a, b|
p [a,b]
}
expose :attribute_a do |a, b|
p [a,b]
end
end And the results of running it, then precompiling it and running it:
Can you perhaps put together a script or small project repo that we can use to reproduce your issue? |
@tom-mayer can you still test this to see if it is broken? We have fixed a number of fairly random AOT bugs (some of which were us not dumping some instrs properly). |
If we get someone to test this again we should re-open but no details in 4+ years with no repro we can run locally. |
Environment
Provide at least:
Other relevant info you may wish to add:
Expected Behavior
When writing a grape entity (basically a mapping file of what attributes of you JSON you want to expose in the API) different syntaxes are supported:
Both of these should do exactly the same thing.
Actual Behavior
The second (block syntax) dies since inside the block, data and options are nil.
It works fine when I run the code on the jRuby interpreter but fails when I compile it into a class file and run it again.
What I found so far
I did a bit of digging into the grape source and it feels a bit strange since the block and the lambda function are treated the same way:
https://github.com/ruby-grape/grape-entity/blob/master/lib/grape_entity/entity.rb#L162
is where the block is just copied into the options array under the :proc key. From the ruby side these feel pretty similar so it's maybe a deeper issue on how the compiler handles block vs lambdas (although my understanding is they are pretty much the same under the hood).
The text was updated successfully, but these errors were encountered: