-
Notifications
You must be signed in to change notification settings - Fork 803
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
Refactor the host <-> runtime interface machinery #7375
Open
s0me0ne-unkn0wn
wants to merge
38
commits into
master
Choose a base branch
from
master_runtime_interface_refactoring
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,954
−1,963
Conversation
This file contains 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
…rface_refactoring
…rface_refactoring
…rface_refactoring
…rface_refactoring
…rface_refactoring
…rface_refactoring
All GitHub workflows were cancelled due to failure one of the required jobs. |
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.
Keep calm and stand still, it's a hijacking of PR #3689 by @koute. The original description follows; please refer to the original PR for the past discussions.
--- 8< --- cut here --- 8< ---
This PR refactors the way the host functions are defined.
Previously the way a given type was marshalled through the host <-> runtime boundary was hardcoded for every type by the virtue of it implementing the relevant conversion traits.
This had two major consequences:
Option<u32>
was done through the SCALE codec and involved extra memory allocations!)So this PR disentangles this mess and makes the marshalling strategies explicit. This makes it much more clear how a given type in a given host function is marshalled, and also makes it possible to use different marshalling strategies for the same type in different host functions.
Before this PR you'd define a host function like this:
and after this PR you'll define it like this:
In this case the strategy for passing the
&str
is now explicitly specified (PassFatPointerAndRead
). Note that the actual API generated by this macro and the way arguments are accessed is completely unchanged! The#[runtime_interface]
machinery automatically "strips" away the marshalling strategy wrappers, so neither the body of thesay_hello_world
function here nor its callers need to be changed.This is a breaking change only for people who use
#[runtime_interface]
to define their own custom host functions.