-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Refactor the internals of Func to remove layers of indirection
#1363
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 internals of Func to remove layers of indirection
#1363
Conversation
At this point `Func` has evolved quite a bit since inception and the `WrappedCallable` trait I don't believe is needed any longer. This should help clean up a few entry points by having fewer traits in play.
This commit removes the `wasmtime::Callable` trait, changing the signature of `Func::new` to take an appropriately typed `Fn`. Additionally the function now always takes `&Caller` like `Func::wrap` optionally can, to empower `Func::new` to have the same capabilities of `Func::wrap`.
Subscribe to Label ActionThis issue or pull request has been labeled: "wasmtime:api" Users Subscribed to "wasmtime:api"To subscribe or unsubscribe from this label, edit the |
Subscribe to Label ActionThis issue or pull request has been labeled: "fuzzing", "wasmtime:c-api" Users Subscribed to "fuzzing"Users Subscribed to "wasmtime:c-api"To subscribe or unsubscribe from this label, edit the |
sunfishcode
left a comment
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 looks like a nice simplification!
crates/api/src/func.rs
Outdated
| // Create our actual trampoline function which translates from a bunch | ||
| // of bit patterns on the stack to actual instances of `Val` being | ||
| // passed to the given function. | ||
| let func = Box::new(move |caller_vmctx, values_vec: *mut i128| { |
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.
We use u128 for values in a lot of places, Is there a reason to prefer i128 here?
Random idea, don't feel obliged to do this here, but we could also introduce a new type, like VMValue or so, which has the size and alignment of a u128, that we could use instead of u128 everywhere, to help document the intent.
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.
Nah this was just carried over from the original implementation, I'll switch it all to u128
0b8ed35 to
2ed2164
Compare
This commit simplifies
Funcand its API through a few avenues:callablemodule is removed in favor of always calling functions through their trampoline (now that we always have one)Callabletrait is removed in favor of just using animpl Fn()argumentFunc::newmethod is now generic and no longer requires an explicitRcallocationFunc::newclosure now takes a leading&Callerargument to empower it with the same capabilities ofFunc::wrap