This repository was archived by the owner on May 4, 2024. It is now read-only.
[RFC][DRAFT][VM] Function pointer support in VM#989
Draft
runtian-zhou wants to merge 11 commits intomove-language:aptos-mainfrom
Draft
[RFC][DRAFT][VM] Function pointer support in VM#989runtian-zhou wants to merge 11 commits intomove-language:aptos-mainfrom
runtian-zhou wants to merge 11 commits intomove-language:aptos-mainfrom
Conversation
runtian-zhou
commented
Mar 21, 2023
| let a: u64; | ||
| label b0: | ||
| func = get_function_pointer(M.sum); | ||
| a = call_function_pointer<|u64, u64| (u64)>(0, 1, move(func)); |
Member
Author
There was a problem hiding this comment.
Please refer to this example for how to use function pointer!
runtian-zhou
commented
Mar 21, 2023
| coin2 = BasicCoin1.mint<CoinType.Foo>(20); | ||
| interface = BasicCoin1.coin_interface<CoinType.Foo>(); | ||
|
|
||
| v = GenericAdder.add_coins<BasicCoin1.Coin<CoinType.Foo>>(&interface, &coin1, &coin2); |
Member
Author
There was a problem hiding this comment.
This is an example for how to implement interface with function pointer provided.
vgao1996
reviewed
Mar 22, 2023
| U16, | ||
| U32, | ||
| U256, | ||
| Function, |
Member
Author
There was a problem hiding this comment.
So I intentionally hided them because the runtime already carried the type information so there's no need to duplicate it.
Member
There was a problem hiding this comment.
I feel like this may not be the right thing to do. Type is being used by native functions and should represent the full name of a type.
1c522a4 to
ca06b3f
Compare
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Motivation
This is the very first initial draft of how MoveVM can potentially support function pointer. We believe function pointer could be a very important corner stone of how interface should be implemented in the future.
In this implemetnation, we add three new opcodes and one more SignatureToken type:
FunctionHandleinto a function pointer value on top of the stackFunctionInstantiationinto a function pointer value on top of the stackRight now it has the following limitations:
Have you read the Contributing Guidelines on pull requests?
Yes.
Test Plan
This implementation only passed compilation and is no way close to merging into main. The intention of this PR is just to assess the safety of this change and to collect usability feedbacks. I'll try to see how I can mod the IR to try the new feature out in the compiler