-
Notifications
You must be signed in to change notification settings - Fork 220
Reimplement the host Python generator with worlds #386
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
Merged
alexcrichton
merged 2 commits into
bytecodealliance:main
from
alexcrichton:wasmtime-py-world
Oct 24, 2022
Merged
Reimplement the host Python generator with worlds #386
alexcrichton
merged 2 commits into
bytecodealliance:main
from
alexcrichton:wasmtime-py-world
Oct 24, 2022
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit is the equivalent of bytecodealliance#381 but for Wasmtime Python host bindings. This is a large-scale refactor of the internals of the Python host generator in which I took quite a few liberties in internal restructuring as well as output restructuring. The tests are probably the best to review and better reflect what changed, but there are some aspects of worlds that the tests are not currently exercising which we'll want to add with the introduction of worlds in the future. This means that all host generators are now working with worlds as input rather than individual `*.wit` files, and the only two remaining generators are the C and Java generators for guests (which I hope are easier). The high level summary of the new output is: out_dir/ __init__.py # top-level component exports/definitions types.py # shared type information, currently just `Result` imports/ __init__.py # only here if something is imported foo.py # type and protocol definition per interface exports/ __init__.py # only here if an instance is exported bar.py # one per exported instance "Default exports" will show up on the generated structure in `out_dir/__init__.py` so all runtime tests, for example, do not generate `exports` at this time. Lots of fiddly stuff went into structuring this all right to get past `mypy` and additionally try to avoid name conflicts. It's still somewhat easy to have name conflicts but ideally they're of the more esoteric category rather than "really easy to run into".
pchickey
approved these changes
Oct 21, 2022
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.
awesome! I won't pretend to understand very much of the code generator, but the way the tests got simplified is really great
alexcrichton
added a commit
to alexcrichton/wit-bindgen
that referenced
this pull request
Oct 25, 2022
This commit removes the `Generator` trait impl for the C generator and adds the `WorldGenerator` trait impl to replace it. This is the equivalent of bytecodealliance#386 for the guest C generator. The generated C code is largely the same, except that the entire world is represented in one header file instead of per-interface header files as before. Additionally a tiny amount of "type sharing" is now done where all interfaces share the same string type (namespaced by the world name). More type sharing should come with a more first-class implementation of worlds. There was quite a lot of code movement within the generator as I got it working again, but at the surface level very little has changed and it should largely be the same as before.
alexcrichton
added a commit
to alexcrichton/wit-bindgen
that referenced
this pull request
Oct 25, 2022
This commit removes the `Generator` trait impl for the C generator and adds the `WorldGenerator` trait impl to replace it. This is the equivalent of bytecodealliance#386 for the guest C generator. The generated C code is largely the same, except that the entire world is represented in one header file instead of per-interface header files as before. Additionally a tiny amount of "type sharing" is now done where all interfaces share the same string type (namespaced by the world name). More type sharing should come with a more first-class implementation of worlds. There was quite a lot of code movement within the generator as I got it working again, but at the surface level very little has changed and it should largely be the same as before.
alexcrichton
added a commit
that referenced
this pull request
Oct 25, 2022
This commit removes the `Generator` trait impl for the C generator and adds the `WorldGenerator` trait impl to replace it. This is the equivalent of #386 for the guest C generator. The generated C code is largely the same, except that the entire world is represented in one header file instead of per-interface header files as before. Additionally a tiny amount of "type sharing" is now done where all interfaces share the same string type (namespaced by the world name). More type sharing should come with a more first-class implementation of worlds. There was quite a lot of code movement within the generator as I got it working again, but at the surface level very little has changed and it should largely be the same as before.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit is the equivalent of #381 but for Wasmtime Python host bindings. This is a large-scale refactor of the internals of the Python host generator in which I took quite a few liberties in internal restructuring as well as output restructuring. The tests are probably the best to review and better reflect what changed, but there are some aspects of worlds that the tests are not currently exercising which we'll want to add with the introduction of worlds in the future.
This means that all host generators are now working with worlds as input rather than individual
*.wit
files, and the only two remaining generators are the C and Java generators for guests (which I hope are easier).The high level summary of the new output is:
"Default exports" will show up on the generated structure in
out_dir/__init__.py
so all runtime tests, for example, do not generateexports
at this time. Lots of fiddly stuff went into structuring this all right to get pastmypy
and additionally try to avoid name conflicts. It's still somewhat easy to have name conflicts but ideally they're of the more esoteric category rather than "really easy to run into".