-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Change preview2 builder methods to use &mut self
#6770
Conversation
I used the same builder design pattern as the previous generation: wasi-cap-std-sync and wasi-tokio |
@pchickey, do you want to take the review on this PR? |
Ah thanks for checking @pchickey, it looks like the issue is: enum WasiCtxBuilder {
Preview1(wasi_preview1::WasiCtx),
Preview2(wasi_preview2::WasiCtxBuilder),
} where one's using a builder and one isn't. If both used a builder then it'd have the same pattern, which I believe would resolve the original motivation for this PR. That being said though I personally prefer |
Understood. Yes, we got rid of all the public &mut self methods on preview 2 WasiCtx that could substitute for the builder, mostly because of interactions with the table. So, now the WasiCtxBuilder is the only way to set things up. We can switch all the builders to &mut self if you think that is better ergonomics. I dont particularly love that |
Ok let's stick with the move-style builder and see how far it gets us, can always revisit later! |
The annoying part is having to extract the dummy ctx builder instance, and then use one more lambda to use it. It's not the end of the world, but it is somewhat unwieldy. And I think it wouldn't become too much simpler even if preview1 weren't in the mix, either. My main concern isn't so much our use in Spin specifically, but more generally that this seems plausible to be hit by embedders more generally. |
Ok. I'm fine with changing it to a &mut Self style builder. It would be nice to keep preview 1 consistent but also its not that important. |
Ok I'll reopen but will work on getting the preview1 bits updated. |
Ok I've additionally renamed methods on preview2 builders to match preview1 builder (e.g. |
Subscribe to Label Actioncc @peterhuene
This issue or pull request has been labeled: "wasi", "wasmtime:c-api"
Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
This commit changes the `WasiCtxBuilder` for preview2 to use a builder pattern more similar to `std::process::Command` where methods take `&mut self` and return `&mut Self` instead of taking `self` and returning `Self`. This pattern enables more easily building up configuration over time throughout code where ownership transfer might otherwise be awkward. A small caveat to this is that the ergonomics of this pattern only really work out well if the final "build" method takes `&mut self` as well. In this situation it's difficult to try to figure out what's supposed to happen if this method is called twice, so I left it to panic for now so we can more easily update it in the future possibly.
* Move preview1 builders to `&mut`-style * Rename methods on preview2 builder to match names on the preview1 builders
52e3023
to
5163a45
Compare
5163a45
to
16d6743
Compare
… feature/preview2 * 'feature/preview2' of github.com:geekbeast/wasmtime: Change preview2 builder methods to use `&mut self` (bytecodealliance#6770) Add a bindgen test that exercises using error types from a different interface (bytecodealliance#6802) Resolve trappable error types with fully qualified package paths (bytecodealliance#6795) Update the dev-dependency for wit-bindgen to 0.9.0 (bytecodealliance#6800) Fix incorrect sample code in documentation (bytecodealliance#6796) (bytecodealliance#6797) Update preview1 to trap on misaligned pointers (bytecodealliance#6776) Fix posix-signals-on-macos on aarch64-apple-darwin (bytecodealliance#6793) consistient WASI preview1 rights reporting (bytecodealliance#6784) Wasmtime: Introduce `{Module,Component}::resources_required` (bytecodealliance#6789)
…6770) * Change preview2 builder methods to use `&mut self` This commit changes the `WasiCtxBuilder` for preview2 to use a builder pattern more similar to `std::process::Command` where methods take `&mut self` and return `&mut Self` instead of taking `self` and returning `Self`. This pattern enables more easily building up configuration over time throughout code where ownership transfer might otherwise be awkward. A small caveat to this is that the ergonomics of this pattern only really work out well if the final "build" method takes `&mut self` as well. In this situation it's difficult to try to figure out what's supposed to happen if this method is called twice, so I left it to panic for now so we can more easily update it in the future possibly. * Synchronize preview1/preview2 builders * Move preview1 builders to `&mut`-style * Rename methods on preview2 builder to match names on the preview1 builders * Fix C API * Fix more tests * Fix benchmark build * Fix unused variable
* Updates to `wasmtime` 13.0.0 * Update the usage of the `WasiCtxBuilder` which as of this update its methods return `&mut Self` bytecodealliance/wasmtime#6770
This commit changes the
WasiCtxBuilder
for preview2 to use a builder pattern more similar tostd::process::Command
where methods take&mut self
and return&mut Self
instead of takingself
and returningSelf
. This pattern enables more easily building up configuration over time throughout code where ownership transfer might otherwise be awkward.A small caveat to this is that the ergonomics of this pattern only really work out well if the final "build" method takes
&mut self
as well. In this situation it's difficult to try to figure out what's supposed to happen if this method is called twice, so I left it to panic for now so we can more easily update it in the future possibly.I'll also note that the original motivations for this come from the upgrade at fermyon/spin#1678