Stream: wasmtime

Topic: reference types in embeddings


view this post on Zulip Alex Crichton (Jul 13 2020 at 18:01):

@fitzgen (he/him) one step we'll need to take at some point is to implement reference types in the embeddings of wasmtime (Go/Python/.NET/...), and I was curious if you're interested in doing that in one of them? No worries if not, just curious if you were interested in doing so

view this post on Zulip fitzgen (he/him) (Jul 13 2020 at 18:04):

I hadn't thought too much about them, but I've added check boxes to the tracking issue: https://github.com/bytecodealliance/wasmtime/issues/929

This is a tracking issue for the reference types proposal. TODO Depends on bulk memory: #928 Enable the reference types proposal's test suite binary.wast br_table.wast exports.wast globals.wast...

view this post on Zulip fitzgen (he/him) (Jul 13 2020 at 18:04):

I'm happy to do it, but maybe with some guidance around how we test these APIs, since I haven't touched them at all

view this post on Zulip Alex Crichton (Jul 13 2020 at 18:11):

ok cool, if you're curious to give it a shot I'd probably recomend doing the Python one

view this post on Zulip Alex Crichton (Jul 13 2020 at 18:11):

that should be easy enough to get up and running

view this post on Zulip Alex Crichton (Jul 13 2020 at 18:11):

that has some basic docs of how to get started but they may need some tewaking too

Python WebAssembly runtime powered by Wasmtime. Contribute to bytecodealliance/wasmtime-py development by creating an account on GitHub.

view this post on Zulip Alex Crichton (Jul 13 2020 at 18:12):

but I also don't mind doing this to be clear

view this post on Zulip fitzgen (he/him) (Jul 13 2020 at 18:21):

fitzgen@erdos :: (main) :: ~/wasmtime-py
    $ pytest
ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --flake8 --mypy
  inifile: /home/fitzgen/wasmtime-py/pytest.ini
  rootdir: /home/fitzgen/wasmtime-py

do I need to pip install flake8 and mpy too?

view this post on Zulip fitzgen (he/him) (Jul 13 2020 at 18:21):

also, I'm assuming this is all python3?

view this post on Zulip Alex Crichton (Jul 13 2020 at 18:23):

it's all python3 yeah

view this post on Zulip Alex Crichton (Jul 13 2020 at 18:23):

pip3 install -e ".[testing]"

view this post on Zulip Alex Crichton (Jul 13 2020 at 18:23):

run that and that'll install all the dev-deps effectively

view this post on Zulip Alex Crichton (Jul 13 2020 at 18:23):

or so I'm led to believe

view this post on Zulip fitzgen (he/him) (Jul 13 2020 at 18:46):

https://github.com/bytecodealliance/wasmtime-py/pull/38

Also update the set up and testing instructions.

view this post on Zulip fitzgen (he/him) (Jul 13 2020 at 18:58):

@Alex Crichton is there a reason why Val's raw repr is __raw__ and not _raw? I thought that double under was stylistically reserved for python builtins

view this post on Zulip Alex Crichton (Jul 13 2020 at 18:58):

that's b/c I don't know python idioms

view this post on Zulip Alex Crichton (Jul 13 2020 at 18:58):

no reason other than that

view this post on Zulip fitzgen (he/him) (Jul 13 2020 at 18:58):

oh I htink this is a python builtin thing

view this post on Zulip Alex Crichton (Jul 13 2020 at 18:59):

it may be but not intentionally

view this post on Zulip fitzgen (he/him) (Jul 13 2020 at 20:03):

@Alex Crichton thoughts on the representation for externref and funcref in the python API should be? it is tempting to use None for null refs, but then that doesn't discriminate between the type of ref. but maybe this is fine? worked ok for wasm_ref_t in C...

view this post on Zulip Alex Crichton (Jul 13 2020 at 20:04):

yeah I think we should prolly use None

view this post on Zulip Alex Crichton (Jul 13 2020 at 20:04):

and do w/e is necessary to get it work on the python side

view this post on Zulip Alex Crichton (Jul 13 2020 at 20:04):

python's in general "this feels very nice" rather than "this is the fastest it can be"

view this post on Zulip fitzgen (he/him) (Jul 13 2020 at 20:04):

/me nods

view this post on Zulip fitzgen (he/him) (Jul 13 2020 at 22:41):

@Alex Crichton do you know how to handle circular module imports with mypy types? trying to add def funcref(self, f: Optional[Func]) method to Val, but I can't import Func because Func's module imports Val and so I get None when I try to import Func from Val's module, etc

view this post on Zulip Alex Crichton (Jul 13 2020 at 22:43):

@fitzgen (he/him) 'Optional[Func]'

view this post on Zulip Alex Crichton (Jul 13 2020 at 22:43):

if you make it a string it can help with forward references

view this post on Zulip Alex Crichton (Jul 13 2020 at 22:43):

although it doesn't fix everything, you'll still have to import it

view this post on Zulip Alex Crichton (Jul 13 2020 at 22:43):

we may need to rejigger things

view this post on Zulip Alex Crichton (Jul 13 2020 at 22:44):

I'm not too well versted in mypy and forward references, if it's too onerous feel free to disable mypy and I can help figure it out before landing

view this post on Zulip fitzgen (he/him) (Jul 13 2020 at 22:44):

ah, I was trying Optional["Func"] and it wasn't working; will try this

view this post on Zulip Alex Crichton (Jul 13 2020 at 22:44):

oh that may or may not be supposed to work

view this post on Zulip fitzgen (he/him) (Jul 13 2020 at 22:45):

hm, nope I'm getting this error:

ImportError: cannot import name 'Func' from 'wasmtime' (/home/fitzgen/wasmtime-py/wasmtime/__init__.py)

when I add from wasmtime import Func

view this post on Zulip fitzgen (he/him) (Jul 13 2020 at 22:45):

which is just a straight python error, not even at mypy yet

view this post on Zulip Alex Crichton (Jul 13 2020 at 22:46):

bah

view this post on Zulip Alex Crichton (Jul 13 2020 at 22:46):

I'd just disable it for now and I can try to help poke at it later

view this post on Zulip Alex Crichton (Jul 13 2020 at 22:46):

disable mypy that is (it's a flag in pytest.ini)

view this post on Zulip fitzgen (he/him) (Jul 17 2020 at 21:26):

@Peter Huene would you happen to be interested in implementing support for reference types in the .NET api? I've never written a line of .NET code in my life, so it would probably take me quite a while longer to implement than I suspect it would for you.

view this post on Zulip Peter Huene (Jul 17 2020 at 22:02):

Sure, I'd be happy to. There's some .NET GC interactions we'd need to do to implement ref types, which isn't difficult but not commonly done in .NET so probably not a great place to start if learning about .NET.

view this post on Zulip Peter Huene (Jul 17 2020 at 22:10):

I've opened https://github.com/bytecodealliance/wasmtime-dotnet/issues/27 to track.

Now that the reference types proposal is implemented in Wasmtime, let's implement it for .NET embeddings! This means fully supporting the ref values, ref value types, handling reference types i...

view this post on Zulip Peter Huene (Jul 23 2020 at 21:34):

I've opened https://github.com/bytecodealliance/wasmtime-dotnet/pull/29 to implement extern refs, func refs, and table imports of either reference type in .NET. @Yury Delendik no rush at all, but whenever you get a chance to review, I'd appreciate it!

This PR implements support in the .NET API for WebAssembly reference types (extern ref and func ref). It also implements support for declaring table imports in a Host. A few bug fixes were made, in...

Last updated: Nov 22 2024 at 16:03 UTC