lann edited PR #8448.
lann updated PR #8448.
lann updated PR #8448.
Tracking for myself: next step is to update the top-level world linking: add a e.g.
add_root_to_linker_get_host
, revert the worldadd_to_linker
impl to call child trait closure-formadd_to_linker
s directly (avoiding the need forWorldGetHost
to somehow impl all imported interface/resourceGetHost
s as well).
@alexcrichton
re: https://github.com/bytecodealliance/wasmtime/issues/8382#issuecomment-2072986390 (?Sized
forimpl <T: Host> Host for &mut T
), this doesn't work for methods that return the type itself:27 | impl<T: FooImports + ?Sized> FooImports for &mut T { | - this type parameter needs to be `Sized` 28 | fn x(&mut self) -> T { | ^ doesn't have a size known at compile-time
I'm just going to drop the
?Sized
unless you think its worth trying to special case somehow.
lann edited a comment on PR #8448:
@alexcrichton
re: https://github.com/bytecodealliance/wasmtime/issues/8382#issuecomment-2072986390 (?Sized
forimpl <T: Host> Host for &mut T
), this doesn't work for resource methods that return the type itself:27 | impl<T: FooImports + ?Sized> FooImports for &mut T { | - this type parameter needs to be `Sized` 28 | fn x(&mut self) -> T { | ^ doesn't have a size known at compile-time
I'm just going to drop the
?Sized
unless you think its worth trying to special case somehow.
lann edited a comment on PR #8448:
@alexcrichton
re: https://github.com/bytecodealliance/wasmtime/issues/8382#issuecomment-2072986390 (?Sized
forimpl <T: Host> Host for &mut T
), this doesn't work for methods that return the type itself:27 | impl<T: FooImports + ?Sized> FooImports for &mut T { | - this type parameter needs to be `Sized` 28 | fn x(&mut self) -> T { | ^ doesn't have a size known at compile-time
I'm just going to drop the
?Sized
unless you think its worth trying to special case somehow.
alexcrichton commented on PR #8448:
Is that actually the type parameter
T
shadowing a WIT typeT
? I don't think that any WIT api should returnSelf
, and that might be fixable by renaming the type parameter to_T
perhaps?
Ah, you are correct. That explains why I couldn't figure out where this would be happening...
lann updated PR #8448.
alexcrichton commented on PR #8448:
This has run into a bit of a snag. https://github.com/rust-lang/rust/issues/124984 shows code this PR was going to generate which compiled with Rust 1.77.0 but does not compile with Rust 1.78.0.
alexcrichton updated PR #8448.
alexcrichton updated PR #8448.
alexcrichton commented on PR #8448:
Ok I think most tests should be passing now. A summary of changes now at its current state:
Previously
bindgen!
would generate:pub fn add_to_linker<T, U>( linker: &mut wasmtime::component::Linker<T>, get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static, ) -> wasmtime::Result<()> where U: Host,
Now it generates:
pub trait GetHost< T, >: Fn(T) -> <Self as GetHost<T>>::Output + Send + Sync + Copy + 'static { type Output: Host; } impl<F, T, O> GetHost<T> for F where F: Fn(T) -> O + Send + Sync + Copy + 'static, O: Host, { type Output = O; } pub fn add_to_linker_get_host<T>( linker: &mut wasmtime::component::Linker<T>, host_getter: impl for<'a> GetHost<&'a mut T>, ) -> wasmtime::Result<()> { // ... } pub fn add_to_linker<T, U>( linker: &mut wasmtime::component::Linker<T>, get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static, ) -> wasmtime::Result<()> where U: Host, { add_to_linker_get_host(linker, get) }
Effectively the old
add_to_linker
is still there but everything is actually built on a more-generalGetHost
trait which enables not being requried to use literally&mut U
but instead you can use something likeMyStruct<'a>
. Usage ofadd_to_linker_get_host
will probably require type-annotating closures. For example wasmtime-wasi contains:fn type_annotate<T, F>(val: F) -> F where F: Fn(&mut T) -> &mut T, { val } let closure = type_annotate::<T, _>(|t| t);
Usage of
add_to_linker
will not require type annotations over what's already required today.I would like to, in a future commit I want to refactor all of wasmtime-wasi{,-http} to remove
imp<T: WasiView> Host for T
and replace that withimpl Host for dyn WasiView
using this support. That'll enable removing the oddskip_mut_forwarding_impls
I've added tobindgen!
here which is just to get WASI bits as-is compiling.
alexcrichton commented on PR #8448:
I should also say there are other minor details here and there but the comment above is the main thrust of the change, everything else is "smith a few things until everything compiles again"
lann submitted PR review:
Approach lgtm
lann submitted PR review:
Approach lgtm
lann created PR review comment:
Side note: we should pick a small subset of these tests with good feature coverage to expand. As-is these are useful for review but its hard to know how many/which files to review before stopping, and having so many changed files screws with Github's UI...
lann created PR review comment:
Slightly confusing in the definition but maybe more obvious for implementers?
type Host: Host;
alexcrichton updated PR #8448.
alexcrichton created PR review comment:
That's a good point yeah I've been a bit sad that the actual changes were all hidden by default as well...
alexcrichton submitted PR review.
alexcrichton updated PR #8448.
alexcrichton has marked PR #8448 as ready for review.
alexcrichton requested alexcrichton for a review on PR #8448.
alexcrichton requested wasmtime-core-reviewers for a review on PR #8448.
alexcrichton submitted PR review.
alexcrichton has enabled auto merge for PR #8448.
alexcrichton updated PR #8448.
alexcrichton has enabled auto merge for PR #8448.
alexcrichton updated PR #8448.
alexcrichton has enabled auto merge for PR #8448.
alexcrichton merged PR #8448.
Last updated: Nov 22 2024 at 16:03 UTC