Skip to content

loader: assorted fixes - #222

Merged
alexcrichton merged 6 commits into
bytecodealliance:mainfrom
whitequark:loader-fixes2
Apr 4, 2024
Merged

alexcrichton merged 6 commits into
bytecodealliance:mainfrom
whitequark:loader-fixes2

Conversation

@whitequark

@whitequark whitequark commented Apr 3, 2024 •

Copy link
Copy Markdown
Contributor

Depends on #221.

This is an incremental but substantial improvement, to the point where I'd say I consider this implementation correct, or very close to correct, according to my understanding of the importlib hooks involved.

It is however still not thread-safe, I will likely address that after adding component support.

@whitequark
whitequark marked this pull request as draft April 3, 2024 23:13
@whitequark
whitequark marked this pull request as ready for review April 3, 2024 23:50
@whitequark

Copy link
Copy Markdown
Contributor Author

@alexcrichton I have a prototype of an importlib loader for components that builds on top of these fixes but I'll probably hold off submitting it until you've had a chance to review #221 and #222.

There's basically no reason to do this as nothing in Python ecosystem
attempts to load `.wasm` or `.wat` files except for wasmtime, and it is
[recommended] in the docs to use `.append()` for adding a finder.

[recommended]: https://docs.python.org/3/library/importlib.html#setting-up-an-importer
This approach has the advantage of not having the `func` argument in
the signature of the method, which is visible in e.g. `help()`.
The `spec_from_file_location` helper includes a lot of indirection and
code that we really don't care about; creating the right `ModuleSpec`
directly here makes the semantics obvious.
@whitequark

Copy link
Copy Markdown
Contributor Author

Rebased.

@alexcrichton

Copy link
Copy Markdown
Member

Thank you very much for this! All looks great to me and I'm glad this has a better pair of eyes on it than my own "not very Python trained" eyes.

@alexcrichton
alexcrichton merged commit 857700f into bytecodealliance:main Apr 4, 2024
@whitequark

Copy link
Copy Markdown
Contributor Author

I'm glad this has a better pair of eyes on it than my own "not very Python trained" eyes.

Honestly, this particular bit of the Python library has almost nobody trained in it, and it's definitely one of the most advanced of advanced topics any Python programmer will ever explore, save for perhaps the more obscure FFI-related ones. It was really quite difficult for me to get my head around it, partly due to how obscure it is, partly due to the peculiar state of the docs, and I've spent basically a workday or two reading sources of the Python internals and comparing them across versions.

@whitequark
whitequark deleted the loader-fixes2 branch April 4, 2024 19:53
@alexcrichton

Copy link
Copy Markdown
Member

IIRC the initial bits here were copy/pasted from assorted blogs/stack overflow posts, so I suspect you've done much more studying already than I initially did!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants