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

gh-117953: Refactor Import Machinery Code for Extension Modules #118116

Conversation

ericsnowcurrently
Copy link
Member

@ericsnowcurrently ericsnowcurrently commented Apr 20, 2024

This is a large change that involves refactoring the code that loads extension modules. The objective is partly to improve the clarity of the code, but mostly it's so that I can execute a subset of the constituent operations in a subsequent PR.

The changes include:

  • ...

While this aligns with the sort of thing I've wanted to do for a long time, the main motivation at the moment is to drastically reduce the likelihood of problems from loading a single-phase init extension module in an isolated subinterpreter. Nearly all the changes here come from what I found I needed for a (relatively) simple solution to the isolation problem. Consequently, much of the refactoring follows the natural divisions in the flow of operations when loading an extension module.

For the sake of reducing the burden of code review for such a large change, I have purposefully avoided changing any behavior in this PR, regardless of how benign it might seem. That said, if it's still too much I'm okay with splitting this up.

For context, this is the first of 3 branches in a chain. Here are the other two, in order:

@ericsnowcurrently
Copy link
Member Author

@encukou, content aside, do you think this change is too big, considering that it's mostly moving things around and adding a few data structures to help with that? I'd be glad to split this up if that would help, but would rather not. 😄

Don't spend much time on an answer. I'm not sure what my own answer would be yet, other than I think it's fine in priniciple. I just wanted to see if you had a quick opinion, given your experience with the code I'm changing.

FWIW, I'm going to let this sit over the weekend and give myself a review on Monday.

@encukou
Copy link
Member

encukou commented Apr 22, 2024

Don't spend much time on an answer.

It's giant! :)

Do you see some parts that would be an improvement on their own, which could be split out and reviewed separately? Perhaps some mechanical stuff like replacing MODULES with get_modules_dict would make the big patch more focused (though if it's only that, it won't help much).

If you don't, this patch is certainly reviewable -- over a few days. I sent a similar giant patch recently, where I couldn't figure out how to break it down further.

@ericsnowcurrently
Copy link
Member Author

Sounds good. I'm splitting this up into 6 different PRs. They should all be up by tomorrow.

ericsnowcurrently added a commit that referenced this pull request Apr 23, 2024
)

This is a collection of very basic cleanups I've pulled out of gh-118116.  It is mostly renaming variables and moving a couple bits of code in functionally equivalent ways.
ericsnowcurrently added a commit that referenced this pull request Apr 24, 2024
These are cleanups I've pulled out of gh-118116.  Mostly, this change moves code around to align with some future changes and to improve clarity a little.  There is one very small change in behavior: we now add the module to the per-interpreter caches after updating the global state, rather than before.
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.

None yet

2 participants