Support an alternative calling convention which can take references #52
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 moves the existing
Vm::call
function to beVm::execute
since it returns an execution and replaces the existingcall
withcall
andcall_async
. And allowcall
andcall_async
to take references.Complete test case showcasing the functionality:
These functions take a new trait as arguments called
GuardedArgs
, which has a new unsafe function. Calling this function is able to encode arguments to the stack by wrapping them inAny
which now has an expanded vtable to support wrapping references.Now the contract of
unsafe_into_stack
says the following:Shared<Any>
+ a guard, and once this guard is dropped theShared<Any>
will be "taken", preventing it from being used anywhere else every again.Any
created from a point prevents the type from being de-allocated since it's actually storing a raw pointer now.A major caveat however, is that we have to introduce a soundness panic. If a program right now were to hold ownership of a
Shared<Any>
containing a pointer, at the point the guard is dropped it will panic because it can't take exclusive ownership of the type. If we didn't panic, after the function call was completed other parts of the system might be holding onto the reference (throughOwnedRef<T>
andOwnedMut<T>
).This can be shown using this test case:Edit test case has been updated to showcase that we now instead error if we try to take an owned ref:
Todo
Shared<Any>
if it has been created from a reference to avoid the soundness panic.