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
Problem when method returns Regexp capture group using special variable $1 #5503
Comments
I can get this to happen with --dev so this has to involve more than just JIT. Weirdly with -X+C I can get it to happen with no repetition in the front whereas --dev passes. So maybe 2 things wrong? This is pretty serious regression :| |
This is a problem in IR when adding frame push/pop instructions. The pop is happening before the value has been captured, so it ends up nil (or actually, it gets whatever the next-highest heap frame has for From the IR along the "then" path for the if:
|
This logic was used to ensure that any heap-scoped variable loads happened before the "pop" logic for those scopes. However another type of variable, frame-locals like $~ and $_, did not get the same treatment. This patch ensures that any frame or binding requirement triggers the return value copy fixup. Fixes jruby#5503.
Pushed a PR that should fix this. I have not written a test yet. I do not know when this change was introduced, but it might never have worked right in the optimized "call protocol" execution modes. The problem was that frame-local implicit variables like $~ and $_ were not captured (in some circumstances) before the frame got popped, resulting in reading those values from a previous frame when they were returned. Only "binding" variables (those stored on the heap in DynamicScope instances) were safely captured before pop. |
This was introduced in 8a04861 back in 2015. We may have been moving the frame variables |
@subbuss Can you review my patch? I already merged it since I'm pretty sure it's correct, but you originally removed the This will add an additional Copy instruction to all returns of a non-temp or literal from a method with a heap frame. I'm not sure how much of an impact this really is, since most non-trivial data loads go immediately into a temp variable. |
Left a comment on the patch. |
Environment
Initially we found the problem using Jruby 9.2.1.0, but it's also actual in 9.1.7.0 and in the latest version.
uname -a
)Other relevant info you may wish to add:
N/A
N/A
N/A
Test code:
Expected Behavior
test_match
call always returns value (as in Ruby MRI or ifmatch
is used instead of=~
):Actual Behavior
After some iterations returned result always is
nil
:Full console output:
test_script.log
The text was updated successfully, but these errors were encountered: