-
Notifications
You must be signed in to change notification settings - Fork 66
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: improve ergonomics of fn replace #250
refactor: improve ergonomics of fn replace #250
Conversation
8115634
to
91cc935
Compare
Thanks for putting some more thought to this. I was wondering - could we just pass an already-created |
Thanks for the pointer, that's a great idea -- I'll make the change!
|
Hey @guybedford Ran into an issue -- with the changes, I run into an issue where I can't get the The way the other functions work, they don't generate the Here's a snapshot of the problem: // Replace the existing function with a new one with a reversed const value
let new_fn_id = module
.replace_exported_func(original_fn_id, |mut body| {
body.i32_const(4321).drop();
body.local_func(vec![]) // TODO(FIX): Can't move LocalFunction produced here out of deref to body!
})
.expect("function replacement worked"); We want the user to have control over that error[E0507]: cannot move out of dereference of `InstrSeqBuilder<'_>`
--> src/module/functions/mod.rs:706:17
|
706 | body.local_func(vec![]) // TODO(FIX): Can't move LocalFunction produced here out of deref to body!
| ^^^^^^^^^^^^^^^^^^^^^^^ move occurs because value has type `FunctionBuilder`, which does not implement the `Copy` trait This also is an issue if we pass in the full |
Could we just use the same localIds from the original function, passing that list as one of the arguments? |
Ah in that case, we could call |
Unless there are other drawbacks we need to be aware of it seems like that might be the idiomatic pattern to me? The only case I think where it might be restrictive is if you want to pass an already constructed function? |
01e2356
to
41e1c29
Compare
Yeah I think that's right -- IMO being able to pass an already pre-created function is pretty useful, but that's a bridge that we can cross when we get there. I don't know exactly how but , but there's probably a clean way to graft the implementation of an existing
|
b0a24cb
to
76ee5c5
Compare
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 seems good to me, happy to go ahead with the change!
76ee5c5
to
fcac3ea
Compare
Sorry a small formatting issue slipped through, squashed & it's ready when tests pass & you're good to merge 🙇 |
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.
More clearly marking the request for changes per the query in comment #250 (comment).
db07266
to
af96691
Compare
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.
Yeah this looks right to me now! Let's land once the tests are passing.
After trialing `replace_(imported|exported)_func` in WASI-Virt, it's clear that the ergonomics around the builder function need to be improved. `FunctionBuilder` (particularly `FunctionBuilder::new()` is difficult to use without a mutable borrow of the module itself. This commit refactors `replace_(imported|exported)_func` in order to pass through the mutable borrow which makes it easier to use `FunctionBuilder`s. Signed-off-by: Victor Adossi <[email protected]>
af96691
to
f74b185
Compare
Ahhh apologies I forgot to convert some more spots to the new API -- tests have been fixed |
After trialing
replace_(imported|exported)_func
in WASI-Virt, it's clear that the ergonomics around the builder function need to be improved.FunctionBuilder
(particularlyFunctionBuilder::new()
) is difficult to use without a mutable borrow of the module itself.This commit refactors
replace_(imported|exported)_func
in order to pass through the mutable borrow which makes it easier to useFunctionBuilder
s.