Skip to content

Optimize the ABI boundary of wasm-compiled proc macros #14

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
merged 5 commits into from
Oct 30, 2019

Conversation

alexcrichton
Copy link
Collaborator

This is a culmination of the following set of ideas:

I figured these are all large enough changes that this'll want to eventually be bumped to 0.2, so I've started pruning APIs exposed by watt in this PR as well. This updates the README with general high-level docs of how to use watt as well.

This should inch us closer to a "level playing field" between natively compiled procedural macros and wasm-compiled procedural macros when using a JIT!

This commit switches to per-API function calls into the host runtime to
instead minimizing the amount of times a wasm blob calls the host
runtime. This requires a bulk transfer of the entire `TokenStream` up
front into the wasm blob, along with a bulk transfer from wasm back into
the native runtime afterwards.

Current a bincode-like encoding is used to serialize and deserialize
`TokenStream`, with the data format duplicated across a few
`{encode,decode}.rs` files. Eventually it'd probably be good to use a
macro_rules macro or similar to avoid this duplication, but for now it's
not a whole lot of code anyway.

This makes the wasm proc macro sort of hard for now, but I hope to
improve that in subsequent commits.

Additionally the `proc-macro2` shadow crate has been updated to more
closely match the fallback of `proc-macro2` itself, storing most
information in-memory as opposed to storing handles.
Use a small macro which looks like `#[proc_macro]` and friends which
automatically does the translation for us. Additionally there's no need
to set the panic hook any more because that'll automatically get
registered.
No need for these with a scoped import module
Copy link
Owner

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@dtolnay dtolnay merged commit 10d82dc into dtolnay:master Oct 30, 2019
@alexcrichton alexcrichton deleted the new-abi branch October 30, 2019 19:50
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