Stream: git-wasmtime

Topic: wasmtime / Issue #2380 Implement IntoFunc for Func


view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2020 at 14:48):

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 of linker.func that delegate to methods

from

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 realized Func doesn't implement InfoFunc

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 like

impl 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.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2020 at 15:37):

alexcrichton commented on Issue #2380:

Would Linker::define work for you in this case?

Otherwise we could probably add something like IntoFunc<(), ()> for Func perhaps?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2020 at 16:21):

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.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2020 at 16:21):

softprops commented on Issue #2380:

also thanks for the extremely fast feedback

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2020 at 18:42):

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

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2020 at 18:42):

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 of linker.func that delegate to methods

from

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 realized Func doesn't implement InfoFunc

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 like

impl 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