-
Notifications
You must be signed in to change notification settings - Fork 52
Statically initialize PyArg_Parser variables in clinic.py. #281
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
Comments
I have a rough plan of how this can be implemented, and to remove code duplication between deepfreeze and clinic, it can be factored into a separate module. Clinic can generate the static tuple object and since the keywords are identifiers, it can use |
@ericsnowcurrently Have you started working on this or you have a draft branch with using internal APIs? |
Yeah, I've been working on this. However, feel free to take over! 🙂 It sounds like you have a similar understanding to mine on what needs to be done. I have plenty of context at this point and would be glad to talk through any of the details with you. I can also show you my branch if you like. |
Yes, I would like to take a look. thanks |
FWIW, I agree that there is significant overlap between clinic and deepfreeze (as well as other tools like generate_frozen_modules.py). Factoring our common parts may be a good idea. Just remember that the tools aren't as carefully tested as the CPython runtime and that it's easy to introduce bugs when refactoring (especially large-scale refactoring). That doesn't mean it's a bad idea. We just need to be consider the possible downsides seriously. I'll also note that the approach clinic takes a substantially different approach for code generation compared to deepfreeze. Deepfreeze generates the output as it goes, with some structural helpers to simplify the process (@gvanrossum's design). In contrast, clinic does the following (more or less):
The clinic approach makes it much harder to generate concise code for things like statically initialized If you want to give it a shot then I say go for it. Just don't be afraid to fight through the challenge. And don't be afraid to abandon the change if it starts looking like it's too much to handle or if the level of churn to too high relative to the benefit. (You can sometimes get away with a little more churn in tools than in runtime code, but don't push it.) |
python/cpython@main...ericsnowcurrently:global-objects-pyargs-parser-keywords-init I've temporarily dropped all generated code from the branch to make it easier to see the actual changes. |
Also, let's move any further discussion on this to https://bugs.python.org/issue46772. |
The changes so far looks good to me and to reduce the size of the changes perhaps it can be committed as is and improve in later small PRs.
Once python/cpython@main...ericsnowcurrently:global-objects-pyargs-parser-keywords-init lands I'll work on some of these improvements. |
Yeah, all those things make sense doing once all the fields are statically initialized. |
@ericsnowcurrently 3.12 dev has now started so this would be great to get in so that we have more time to improve and fix bugs. I tried your branch and it segfaults when running the test suite in |
I'll do that as soon as I possible, though it probably won't be right away. In the meantime, feel free to copy my branch and merge main if you want to get things rolling faster. |
I have a WIP branch kumaraditya303/cpython#4. There are two things to investigate further:
|
I'll take a look when I get a chance. |
@kumaraditya303 It looks like a missing comma: - .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
+ .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS), |
Okay, after some investigation it seems to be a msvc limitation which does not allow accessing address of dynamically loaded libraries. |
I can think of two solutions at this point:
|
Yeah, because DLLs get relocated on load, it won't statically embed a pointer into a different DLL. You need to add an assignment in code after everything has been loaded (which is basically anywhere apart from a static initializer that's not in a function). |
Looking closer at the code, you might also want to change that module to not bulid with Alternatively, removing argument clinic use from the module should also fix it. |
Thanks for the info, I wanted to know are there any downsides to statically linking all the extension modules on Windows? Slow startup maybe ? |
It will certainly slow down startup when those modules aren't going to be used, as they often reference many more DLLs than are needed by the core. You'd need to convert a whole lot of others into delay loads to make up for it. It also makes it harder to omit functionality (e.g. I can easily make a network-less distro for embedding by leaving out |
We'd certainly want to avoid statically linking test modules into the main build, too. |
|
I'm going to tackle per-interpreter kwtuples in a separate issue. |
Uh oh!
There was an error while loading. Please reload this page.
https://bugs.python.org/issue46772
Changes will be in Tools/clinic/clinic.py.
The text was updated successfully, but these errors were encountered: