softprops opened Issue #2380:
<!-- Please try to describe precisely what you would like to do in
Cranelift/Wasmtime and/or expect from it. You can answer the questions below if
they're relevant and delete this text before submitting. Thanks for opening an
issue! -->Feature
<!-- What is the feature or code improvement you would like to do in
Cranelift/Wasmtime? -->I've been struggling with a way to decompose chains of
linker.func
that delegate to closures into chains oflinker.func
that delegate to methodsfrom
linker.func("module", "foo", closure)? .linker.func("module", "bar", closure)?
into
linker.func("module", "foo", foo(&store))? .linker.func("module", "bar", bar(&store))?
My best guess way to do that would be to decompose into methods that returned
impl IntoFunc
but its type signature proved cumbersome to make that work.My next thought was that I could just return
Func
objects from method but then realizedFunc
doesn't implementInfoFunc
fn foo(store: &Store) -> Func { Func::wrap(...) } fn bar(store: &Store) -> Func { Func::wrap(...) }
This seems trivial to add but I'm not sure what the type arguments for
IntoFunc
would look likeimpl IntoFunc<?,?> for Func { fn into_func(self, store: &Store) -> Func { self } }
Benefit
<!-- What is the value of adding this in Cranelift/Wasmtime? -->
A slightly more flexible linker api.
Implementation
<!-- Do you have an implementation plan, and/or ideas for data structures or
algorithms to use? -->An open question above was what to fill in for type parameters
impl IntoFunc<?,?> for Func { fn into_func(self, store: &Store) -> Func { self } }
Alternatives
<!-- Have you considered alternative implementations? If so, how are they
better or worse than your proposal? -->I could have a muting api which roughly implements what I started out with
fn with_foo(linker: mut Linker, store: &Store) -> Result<Linker, ...> { linker.func("module", "foo", closure) } fn with_bar(linker: mut Linker, store: &Store) -> Result<Linker, ...> { linker.func("module", "foo", closure) } with_foo(linker, store)? .with_bar(linker, store)?
This has the workaround-for-an-api feel to it.
alexcrichton commented on Issue #2380:
Would
Linker::define
work for you in this case?Otherwise we could probably add something like
IntoFunc<(), ()>
forFunc
perhaps?
softprops commented on Issue #2380:
ohhh nice. I could try that. since there's and into impl for Func => Extern that might tick the box for me.
softprops commented on Issue #2380:
also thanks for the extremely fast feedback
softprops commented on Issue #2380:
Linker::define
seems to work so I'm going to close this issue. Thanks again @alexcrichton for such an amazing project
softprops closed Issue #2380:
<!-- Please try to describe precisely what you would like to do in
Cranelift/Wasmtime and/or expect from it. You can answer the questions below if
they're relevant and delete this text before submitting. Thanks for opening an
issue! -->Feature
<!-- What is the feature or code improvement you would like to do in
Cranelift/Wasmtime? -->I've been struggling with a way to decompose chains of
linker.func
that delegate to closures into chains oflinker.func
that delegate to methodsfrom
linker.func("module", "foo", closure)? .linker.func("module", "bar", closure)?
into
linker.func("module", "foo", foo(&store))? .linker.func("module", "bar", bar(&store))?
My best guess way to do that would be to decompose into methods that returned
impl IntoFunc
but its type signature proved cumbersome to make that work.My next thought was that I could just return
Func
objects from method but then realizedFunc
doesn't implementInfoFunc
fn foo(store: &Store) -> Func { Func::wrap(...) } fn bar(store: &Store) -> Func { Func::wrap(...) }
This seems trivial to add but I'm not sure what the type arguments for
IntoFunc
would look likeimpl IntoFunc<?,?> for Func { fn into_func(self, store: &Store) -> Func { self } }
Benefit
<!-- What is the value of adding this in Cranelift/Wasmtime? -->
A slightly more flexible linker api.
Implementation
<!-- Do you have an implementation plan, and/or ideas for data structures or
algorithms to use? -->An open question above was what to fill in for type parameters
impl IntoFunc<?,?> for Func { fn into_func(self, store: &Store) -> Func { self } }
Alternatives
<!-- Have you considered alternative implementations? If so, how are they
better or worse than your proposal? -->I could have a muting api which roughly implements what I started out with
fn with_foo(linker: mut Linker, store: &Store) -> Result<Linker, ...> { linker.func("module", "foo", closure) } fn with_bar(linker: mut Linker, store: &Store) -> Result<Linker, ...> { linker.func("module", "foo", closure) } with_foo(linker, store)? .with_bar(linker, store)?
This has the workaround-for-an-api feel to it.
Last updated: Dec 23 2024 at 12:05 UTC