-
Notifications
You must be signed in to change notification settings - Fork 267
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
Add API that uses WebAssembly ValueTypes, such as floats or reference types #532
Comments
Agreed. There's a lot to think about on this one because it also affects anything with ValueType support, ex Globals. Generics are a neat idea, and this also applies to a codegen solution. Meanwhile, when people start thinking about this, value binders aren't far off. Currently, we have utilities like https://pkg.go.dev/github.com/tetratelabs/wazero/api#DecodeF64 which are documented here https://pkg.go.dev/github.com/tetratelabs/wazero/api#ValueType These utilities can also work with globals, and buy time for a layer to be added to do things naturally. floatG := api.DecodeF32(global.Get(ctx)) One reason we delayed doing this is seeing the bad effects of the naive approach. Ex other libraries using Notably, there's a long summary about things like Reference Type and v128, etc. and decide to not break the current API meanwhile #484 (comment) After a lot of thinking, we are confident we can do one of the following without breaking the current API:
Let's leave this issue open to track doing one of the above. We need to land the more complex times before solidifying an approach and also need a bit more experience with common bindings and what if anything to do about them (ex wasm-bindgen sortof stuff). It would be awesome for us to have an api that doesn't punt to things like Generics is interesting, we'll have to see about how split builds work in Go, maybe a second go.mod file I guess until our floor version is 1.18. In any case, let's continue the discussion here. Meanwhile, if you want to do a playground in another repo that dispatches to current globals and function.call, that would be cool experience to help shape things. |
For evaluation of whatever next API, clarifying the known consumers of our APIs:
When we do things, we'll remember that ad-hoc use shouldn't require things like codegen or a binder library, though some of those doing ad-hoc high level use may be better off using one of these. I'm not entirely sure which of these would be Generics, so that's where I'd love to get some feedback from some experiments on this. Probably more than one.. If I left out important things, please comment back! |
What do you think about something like:
The function will return That construction can be used in two ways:
In the case of
So, it could be:
The issue if this last method is for "void" functions, since calling |
this is an interesting view. bear in mind, we deferred doing things like this because 128 is two uint64s. that said in the approach you are suggesting above, the caller isn't passing a type like that. It feels like when someone does this, they have a signature in mind (and don't want or don't yet have codegen). this #264 was an attempt to be less squishy, ex defining before a function is called, its parameters, vs possibly failing at runtime. Since the function exposes its param and result types, you can imagine the overhead of scanning is somewhat fixed. OTOH there's some glitches mentioned in the issue, hence it being punted. In any case any of these approaches can be done externally as long as we don't try to change the uint64 to another type of uint64 (I think the above in the example isn't necessary to define a new type as you still need the function sig. It is mainly syntactic sugar right? So, I was hoping someone can try on own vs needing an internal change a while as usually there are glitches that come out when doing that. |
food for thought: while we're discussing is the caller side, we've already implemented the callee side (host functions). This code will change for v128 for example (consuming 2 64bit blocks for a i128). When we end up baking in a callee-side means to get go values, we'd likely only support the exact same type mappings that exist on the host side. That makes docs easier to reason with and intuition possible from knowing one side or the other https://github.com/tetratelabs/wazero/blob/main/internal/wasm/gofunc.go#L76-L133 |
https://github.com/stealthrocket/wazergo is where to go for ergonomics now |
I notice that
Call
only returns[]Uint64
, however other types are supported, such asf32
.In that case I need to use:
Should be possible to return based on Generics or create another
Value
type, which have options to unwrap the value (such as Value.Int(), Value.Int32(), Value.Float32). Behind the scenes it will use unsafe, but the public-API will be easier to use.The text was updated successfully, but these errors were encountered: