-
Notifications
You must be signed in to change notification settings - Fork 824
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
Add support for const function signatures #1911
Conversation
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.
I like the idea. I don't see exactly how it improves Wasmer itself, but I can understand how it can be convenient for the user!
I'm approving this, but I would appreciate another feedback on this from @syrusakbary, @nlewycky, @MarkMcCaskey or @jubianchi before merging :-).
impl From<&FunctionType> for FunctionType { | ||
fn from(as_ref: &FunctionType) -> Self { | ||
as_ref.clone() | ||
} | ||
} |
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.
👍
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.
Looks good to me!
bors r+ |
1911: Add support for const function signatures r=syrusakbary a=webmaster128 # Description `FunctionType` contains variable length vectors and I'm sure there is a good reason for this design. However, it makes creating them a bit annoying since it connot be done in constants. With this PR I propose a representation that uses a tuple of arrays, which can be converted into `FunctionType` on demand. This allows developers to use constant signatures and push them to a better place in their code. In https://github.com/CosmWasm/cosmwasm/pull/659/files you see a demonstration of how this deduplicates code and pushes the definitions out of my way. Since the conversion `&FunctionType` to `FunctionType` is implemented here, this should no be breaking anyone's code. In cases where you can pass an owned `FunctionType` instead of `&FunctionType` you save one clone. # Review - [ ] Add a short description of the the change to the CHANGELOG.md file Co-authored-by: Simon Warta <[email protected]> Co-authored-by: Syrus Akbary <[email protected]>
Build failed: |
6329073
to
8c73ec8
Compare
yo bors, I rebased this PR to lastest master and fixed the compile error |
bors r+ |
Merge conflict. |
bors r+ |
1911: Add support for const function signatures r=Hywan a=webmaster128 # Description `FunctionType` contains variable length vectors and I'm sure there is a good reason for this design. However, it makes creating them a bit annoying since it connot be done in constants. With this PR I propose a representation that uses a tuple of arrays, which can be converted into `FunctionType` on demand. This allows developers to use constant signatures and push them to a better place in their code. In https://github.com/CosmWasm/cosmwasm/pull/659/files you see a demonstration of how this deduplicates code and pushes the definitions out of my way. Since the conversion `&FunctionType` to `FunctionType` is implemented here, this should no be breaking anyone's code. In cases where you can pass an owned `FunctionType` instead of `&FunctionType` you save one clone. # Review - [x] Add a short description of the the change to the CHANGELOG.md file Co-authored-by: Simon Warta <[email protected]> Co-authored-by: Ivan Enderlin <[email protected]>
Build failed: |
Oh, the failing test now shows we are using some
|
I'll take care of this now |
e33202a
to
8a8e8dc
Compare
Rebased to latest master and 1 commit added (8a8e8dc) |
bors try |
bors r+ |
Could you restart this job? https://github.com/wasmerio/wasmer/runs/1551129968 Seems like it never started |
Random follow up but I wanted to ping you, @webmaster128 , to make sure you know about We just had another issue where someone missed that, so I wanted to make sure you knew about it too in case the docs aren't clear here. |
Thank you @MarkMcCaskey, much appreciated. This was not clear to me indeed for a long time, especially when upgrading from statically typed |
I'm very open to discuss if this PR is more destructive than helpful. Does it encourage users to follow the wrong path? Could all those testing dummies be replaced with statically typed closures? CosmWasm/cosmwasm@65a7d1f |
@webmaster128 Yeah, it seems like those examples could be made into "native" functions if you wanted to! Don't worry about it, I think this PR is a good change, it's nice to have the ability to avoid heap allocations. I've updated the docs locally to make it more clear what the options are! Just wanted to make sure you knew about it in case you didn't! |
Alright cool. One thought why this might be tricky for people who are migrating: it seems like the default chained from native to dynamic. To me |
Description
FunctionType
contains variable length vectors and I'm sure there is a good reason for this design. However, it makes creating them a bit annoying since it connot be done in constants. With this PR I propose a representation that uses a tuple of arrays, which can be converted intoFunctionType
on demand. This allows developers to use constant signatures and push them to a better place in their code.In https://github.com/CosmWasm/cosmwasm/pull/659/files you see a demonstration of how this deduplicates code and pushes the definitions out of my way.
Since the conversion
&FunctionType
toFunctionType
is implemented here, this should no be breaking anyone's code. In cases where you can pass an ownedFunctionType
instead of&FunctionType
you save one clone.Review