-
-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
gh-126599: Refactor the _PyOptimizer
APIs
#126853
base: main
Are you sure you want to change the base?
Conversation
Please do not open unfinished PR. (Alternatively, you can convert it to a draft PR.) |
I disagree. Unfinished PRs are fine as long as they're for discussion. Also they help us lead contributors in the right direction before they put too much effort in. |
I don't object to this kind of behavior, but it should be opened as a draft before it is completed, which will waste review resources. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for picking this up. I think there might be some confusion of what is the API and what isn't so let me try my best to explain:
- The API in CPython refers to what people use externally.
pycore_*
files in general cannot be accessed when including the C API, unless they are included directly.PyAPI_FUNC
exports the symbol on Windows and other platforms.
So the thing we need to do is:
- Make sure the API now lives in
pycore_optimizer.h
- Remove
PyAPI_FUNC
, except for when the JIT compiler needs it (The JIT compiler needs symbols exported for Windows).
So the code in JUMP_BACKWARD
and ENTER_EXECUTOR
shouldn't change either. We need those code for optimizing the JIT!
Include/internal/pycore_optimizer.h
Outdated
PyAPI_FUNC(PyObject *) _PyOptimizer_NewCounter(void); | ||
PyAPI_FUNC(PyObject *) _PyOptimizer_NewUOpOptimizer(void); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory, the only change you need is to remove the PyAPI_FUNC
. That will stop the optimizer from being exported as public API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the header file isn't used elsewhere, we can remove it and keep the signature only in the source file.
(Sorry for the term mobile. I don't look it.)
Edit
I think. A small suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pycore_optimizer.h
is used. Please don't remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 2 APIs are used for _testinternalcapi
for testing. It seems like _testinternalcapi
fails to be imported due to missing symbols after removing the PyAPI_FUNC
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should likely mark them as extern
if they are needed to be exported then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, the APIs used by _testinternalcapi
need to be exported? It seems extern
does not help here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right, it seems that declaring them as extern is not sufficient. So we should probably keep PyAPI_FUNC
. However, you should add a comment "// Export for '_testinternalcapi' shared extension.".
The reason why we advised you to use draft PRs is that you are committing a lot before the code is fine to be reviewed. If a PR is in a state where it should be reviewed (for instance if the CI is green or if there is no code planned to be committed just after), then it's perfectly fine to keep it open. |
There seems to be a little misunderstanding. I think this comment implies that there is still unfinished work :( |
Sorry, I'm still a little confused about the goal of this PR.
Does it mean we should define all JIT related APIs in this file?
It seems that the currently exported APIs in Reverted to bring the tests back. |
@xuantengh Thank you for your efforts on this PR. @Fidget-Spinner who has experience with this area of the code should be able to provide guidance as you move this PR forward. @rruuaanng, Let's try to keep the comments positive and constructive. Please try to encourage other contributors instead of telling them what to do or not do. The goal for PRs are to build understanding during review and iterate to an optimal solution. The solution, as we have discussed before, must consider many factors including backward compatibility, maintainability, security, testing, complexity and code churn. Sometimes a question lends much better results than telling someone what to do. For example, "Would you appreciate feedback on the PR so far?" instead of "Please do not open unfinished PR.". You can trust that the triagers and core developers are working toward creating a productive and healthy contributor experience for all. Please respect the importance of this goal. |
Sorry this got derailed, @xuantengh. It's also a little trickier than I originally assumed. Let's start over. For this PR, can you just remove the "counter" optimizer, and any tests that use it? I think that's a fairly self-contained task, and gives us a better idea of what difficulty remains in extracting the other two. I also don't think it will involve deleting any files. @rruuaanng, I can handle the review from here. I'm not worried about my time spent working with the author to get things in a good state here. |
Sure, I'll try it. Update: the |
2d913a7
to
b51de05
Compare
b51de05
to
4c0e6c0
Compare
Hi this is my draft to remove the
_PyOptimizer_NewCounter
and_PyOptimizer_NewUOpOptimizer
APIs, where the related tests are removed or skipped.For the most challenging
_PyOptimizer_Optimize
, I'm still trying to figure out how to achieve its functionality in generated interpreter. To remove the "artificial boundaries", should we just remove this API call and replace its code in theJUMP_BACKWARD
,_EXIT_TRACE
and_DYNAMIC_EXIT
instruction cases?_PyOptimizer
APIs #126599