Skip to content
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

Fix bug involving .send and overwritten methods. #6752

Merged

Conversation

jimmyhmiller
Copy link
Contributor

@casperisfine reporting a bug in this gist https://gist.github.com/casperisfine/d59e297fba38eb3905a3d7152b9e9350

After investigating I found it was caused by a combination of send and a c_func that we have overwritten in the JIT. For send calls, we need to do some stack manipulation before making the call. Because of the way exits works, we need to do that stack manipulation at the last possible moment. In this case, we weren't doing that stack manipulation at all. Unfortunately, with how the code is structured there isn't a great place to do that stack manipulation for our overridden C funcs.

Each overridden C func can return a boolean stating that it shouldn't be used. We would need to do the stack manipulation after all of those checks are done. We could pass a lambda(?) or separate out the logic for "can I run this override" from "now generate the code for it". Since we are coming up on a release, I went with the path of least resistence and just decided to not use these overrides if we are in a send call.

We definitely should revist this in the future.

@jimmyhmiller jimmyhmiller marked this pull request as ready for review November 17, 2022 19:02
@matzbot matzbot requested a review from a team November 17, 2022 19:02
@k0kubun
Copy link
Member

k0kubun commented Nov 17, 2022

Now that you know how it happens, is it possible to convert https://gist.github.com/casperisfine/d59e297fba38eb3905a3d7152b9e9350 to a small repro in our YJIT test cases?

@casperisfine reporting a bug in this gist https://gist.github.com/casperisfine/d59e297fba38eb3905a3d7152b9e9350

After investigating I found it was caused by a combination of send and a c_func that we have overwritten in the JIT. For send calls, we need to do some stack manipulation before making the call. Because of the way exits works, we need to do that stack manipulation at the last possible moment. In this case, we weren't doing that stack manipulation at all. Unfortunately, with how the code is structured there isn't a great place to do that stack manipulation for our overridden C funcs.

Each overridden C func can return a boolean stating that it shouldn't be used. We would need to do the stack manipulation after all of those checks are done. We could pass a lambda(?) or separate out the logic for "can I run this override" from "now generate the code for it". Since we are coming up on a release, I went with the path of least resistence and just decided to not use these overrides if we are in a send call.

We definitely should revist this in the future.
@jimmyhmiller jimmyhmiller force-pushed the no-optimize-send-for-overwritten-methods branch from 22095a7 to eeb40f7 Compare November 17, 2022 20:53
@jimmyhmiller
Copy link
Contributor Author

@k0kubun Done

@maximecb maximecb merged commit 98e9165 into ruby:master Nov 18, 2022
@maximecb maximecb deleted the no-optimize-send-for-overwritten-methods branch November 18, 2022 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants