Loosely integrate implements into bindgen!#13497
Open
alexcrichton wants to merge 1 commit into
Open
Conversation
This commit is the next step in fleshing out bytecodealliance#12698 and following in the footsteps of bytecodealliance#13361 to integrate the `(implements ...)` directive into `bindgen!`. Notably this world: world foo { import a: thing; import b: thing; } will only generate a single trait for `thing::Host` as opposed to the previous 2 traits that were generated. This enables hosts to use the same trait implementation for both, or customize as appropriate. Additionally the `add_to_linker`-generated methods for interfaces are now refactored to additionally have an `add_to_linker_instance` entrypoint. This new entrypoint takes a `LinkerInstance` instead of a `Linker` and fills in the provided instance directly. This is in-turn used to fill out a linker for the `foo` world above. Notably, however, embedders can call `add_to_linker_instance` with distinct closures accessing different parts of `T`, the store's state, meaning that it's possible to have two distinct implementations for `a` and `b` above. Many golden tests were updated with this new `add_to_linker_instance` method, and codegen/runtime tests were added for a simple world as well showcasing the bindings modes that are possible. The (rarely used) top-level world `add_to_linker` only uses a single trait implementation, but invoking `add_to_linker_instance` enables passing in two separate implementations.
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
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 next step in fleshing out #12698 and following in the footsteps of #13361 to integrate the
(implements ...)directive intobindgen!. Notably this world:will only generate a single trait for
thing::Hostas opposed to the previous 2 traits that were generated. This enables hosts to use the same trait implementation for both, or customize as appropriate.Additionally the
add_to_linker-generated methods for interfaces are now refactored to additionally have anadd_to_linker_instanceentrypoint. This new entrypoint takes aLinkerInstanceinstead of aLinkerand fills in the provided instance directly. This is in-turn used to fill out a linker for thefooworld above.Notably, however, embedders can call
add_to_linker_instancewith distinct closures accessing different parts ofT, the store's state, meaning that it's possible to have two distinct implementations foraandbabove.Many golden tests were updated with this new
add_to_linker_instancemethod, and codegen/runtime tests were added for a simple world as well showcasing the bindings modes that are possible. The (rarely used) top-level worldadd_to_linkeronly uses a single trait implementation, but invokingadd_to_linker_instanceenables passing in two separate implementations.