Skip to content

gh-146058: Fix _GUARD_CODE_VERSION_*#146060

Merged
Fidget-Spinner merged 7 commits intopython:mainfrom
Fidget-Spinner:opt_guard_code_version
Mar 17, 2026
Merged

gh-146058: Fix _GUARD_CODE_VERSION_*#146060
Fidget-Spinner merged 7 commits intopython:mainfrom
Fidget-Spinner:opt_guard_code_version

Conversation

@Fidget-Spinner
Copy link
Member

@Fidget-Spinner Fidget-Spinner commented Mar 17, 2026

@Fidget-Spinner
Copy link
Member Author

@markshannon

@Fidget-Spinner
Copy link
Member Author

PYTHON_JIT_STRESS=1 ./python -m test test_dataclasses passes on my system.

Copy link
Member

@markshannon markshannon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for getting to this so quickly.

I would rather we do the fix now, and then add any new optimizations in a later PR.

I think it is OK to match the optimizations already done for the equivalent _GUARD_IP uops in this PR, but no more.

@bedevere-app
Copy link

bedevere-app bot commented Mar 17, 2026

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@Fidget-Spinner
Copy link
Member Author

I have made the requested changes; please review again.

@bedevere-app
Copy link

bedevere-app bot commented Mar 17, 2026

Thanks for making the requested changes!

@markshannon: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from markshannon March 17, 2026 15:26
@markshannon
Copy link
Member

I have made the requested changes; please review again.

You still have the new optimizations in, which I think are wrong.

@Fidget-Spinner
Copy link
Member Author

I have made the requested changes; please review again.

You still have the new optimizations in, which I think are wrong.

Ok will remove them.

@bedevere-app
Copy link

bedevere-app bot commented Mar 17, 2026

Thanks for making the requested changes!

@markshannon: please review the changes made to this pull request.

@Fidget-Spinner Fidget-Spinner changed the title gh-146058: Fix and optimize _GUARD_CODE_VERSION_* gh-146058: Fix _GUARD_CODE_VERSION_* Mar 17, 2026
Copy link
Member

@markshannon markshannon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks good thanks.

Regarding the optimizations, we should add the symbol of the function to the abstract frame, and use that to optimize _GUARD_CODE_VERSION__PUSH_FRAME and _GUARD_IP__PUSH_FRAME

The other _GUARD_CODE_VERSION_ variants can be optimized exactly the same as the existing _GUARD_IP_ variants.

@markshannon
Copy link
Member

It is also possible to use a code watcher to strengthen the IP guard to eliminate the code guard.
If we are at the right IP and the code object has not been deleted, then this must be the right code object.

@Fidget-Spinner Fidget-Spinner merged commit 966fc81 into python:main Mar 17, 2026
76 of 77 checks passed
@Fidget-Spinner Fidget-Spinner deleted the opt_guard_code_version branch March 17, 2026 17:19
@Fidget-Spinner
Copy link
Member Author

That looks good thanks.

Regarding the optimizations, we should add the symbol of the function to the abstract frame, and use that to optimize _GUARD_CODE_VERSION__PUSH_FRAME and _GUARD_IP__PUSH_FRAME

The other _GUARD_CODE_VERSION_ variants can be optimized exactly the same as the existing _GUARD_IP_ variants.

I'm not too clear how this works, so please bear with me, I was under the impression that if the symbol points to a valid function and has a valid version it should be safe?

@markshannon
Copy link
Member

I was under the impression that if the symbol points to a valid function and has a valid version it should be safe?

Yes, that's right.
But, the function and code objects currently stored in the abstract frame, point to the objects seen during tracing, telling us nothing about the future objects, which is why we need to use symbols.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants