-
Notifications
You must be signed in to change notification settings - Fork 688
[RFC][DRAFT][VM] Function pointer support in VM #989
base: aptos-main
Are you sure you want to change the base?
[RFC][DRAFT][VM] Function pointer support in VM #989
Conversation
let a: u64; | ||
label b0: | ||
func = get_function_pointer(M.sum); | ||
a = call_function_pointer<|u64, u64| (u64)>(0, 1, move(func)); |
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.
Please refer to this example for how to use function pointer!
coin2 = BasicCoin1.mint<CoinType.Foo>(20); | ||
interface = BasicCoin1.coin_interface<CoinType.Foo>(); | ||
|
||
v = GenericAdder.add_coins<BasicCoin1.Coin<CoinType.Foo>>(&interface, &coin1, &coin2); |
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.
This is an example for how to implement interface with function pointer provided.
@@ -50,6 +50,7 @@ pub enum Type { | |||
U16, | |||
U32, | |||
U256, | |||
Function, |
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.
Hmm... no type parameters?
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.
So I intentionally hided them because the runtime already carried the type information so there's no need to duplicate it.
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 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
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:
FunctionHandle
into a function pointer value on top of the stackFunctionInstantiation
into 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