-
Notifications
You must be signed in to change notification settings - Fork 55
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
loader: add support for components #224
loader: add support for components #224
Conversation
c55adb5
to
766811d
Compare
This PR now includes an example of using autogenerated bindings for components. |
That's a lot of mypy failures. I'm unconvinced mypy is actually useful given the sheer amount of |
b742c30
to
317ff2f
Compare
That was a hour of my life I'll never get back but at least mypy is happy now. (Having to spend this much effort on busywork actually kind of turns me off contributing nontrivial code to wasmtime-py so I think next time I'll just go with Aside from that, I think this is ready to merge now, with two caveats:
Ultimately I feel like maybe we should break the interface and surface the |
2f4f4e3
to
de5d50b
Compare
de5d50b
to
eba0eca
Compare
Rebased. |
Note that I've added an example but I'm not totally sure if the .wat file I committed follows the best practices for that kind of thing. I did a In any case I hope the example provides a reasonable amount of testing for this functionality and also shows how to use it. I basically don't show how to handle imports at all (which is unlike the core module handling code) and this is mainly because I don't expect to need more than WASI imports in close future at least, possibly ever; I think maybe another contributor is better positioned to address that, though if it's not a high-effort change I could do something as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me, thank you for this!
Having to spend this much effort on busywork actually kind of turns me off contributing nontrivial code to wasmtime-py
Sorry about that! I originally thought this would be a good place to have type annotations but I'm not sure if I'm swimming upstream here. I don't want to make this library hard to use or contribute to at all, but I figured that if folks had their own type annotations they'd want the usage here checked as well. I do agree though that the more "dynamic" parts like the loader I think can probably skip type-checks entirely.
This is still not thread-safe
I agree this is pretty thorny, and I agree it's best to defer to later. I think your idea is the right way to go here of surface a different API for core-wasm-modules and always require a Store
is passed in. There's basically no way to share an instance across threads, and if a normal Python module can be shared across threads then representing a wasm instance as a Python module isn't the right way to go.
I'm not totally sure if the .wat file I committed follows the best practices for that kind of thing
Looks good to me!
I basically don't show how to handle imports at all
I think deferring this to later is fine yeah. The loader-based pieces were more demo-quality when I first added them anyway so I think it's fine to figure out how to best manage this later.
Thanks! In general I do my best to accommodate whatever the upstream likes even if it's weird or not what I'd do but sometimes things get a little out of hand.
I actually quite like Python type annotations; the issue I have is with mypy. To elaborate: you and I both work in Rust a lot, where type inference is function-local. This is practically a hard necessity in statically typed languages like Rust, because while HM-style inference works just fine globally it quickly becomes unmaintainable if you don't require annotations on at least some boundary, with spooky action at a distance, impossible to understand type errors, etc. (OCaml does it on module boundaries but the basic logic is the same.) However in Python you can't really think of annotations the same way because typing is fundamentally non-local, and any typechecker that attempts to treat it as a local phenomenon is going to create this kind of busywork. I like and use Pyright/Pylance, and I add type annotations in my code where needed to give it the context clues it needs to infer the rest of the types. But it doesn't have the same issue as mypy (perhaps, mypy in the default configuration?) has: if e.g. it knows that
To reiterate perhaps, I think there's definitely value in ensuring downstream users of the library have types available by one means or the others (and I wouldn't mind at all even annotating every public signature to that end, though I'm not sure it's strictly required) but I don't think that in this particular context mypy brings more value than it creates obstructions. |
Do you have a sense for if there's a more conventional type-checker to use? I picked mypy as it seemed like a reasonable default at the time, but I could very well have been wrong and/or times may have changed in the meantime. I've got no love of mypy myself as I've run into lots of issues historically related to I definitely agree that mypy has felt like a lot of busywork, especially in all the |
So, full disclosure, I'm mostly using Pylance from within VS Code, so my user experience will not quite match that of contributors using command-line Pyright analysis. However, I just ran Pyright on the
Not only are these messages much more readable, but some of them are actionable, too! Let's do the breakdown of these 8 messages:
So, out of the 6 errors reported as 8 diagnostics, only 2 are false positives due to runtime invariants outside of the typechecker's ability to reason, 2 are definitely bugs that could be reasonably triggered through normal use, and 2 are bugs that could only be triggered through the use of the module linking proposal extensions. There aren't any false positives due to insufficiently powerful analyses or the like. Mypy, of course, found none of the 6. To handle the false positives due to runtime invariants all I had to do was to add
and now they're gone. The check doesn't hurt readability either. |
3cc473e
to
ac48863
Compare
@alexcrichton OK, it should be calling |
ac48863
to
30230ff
Compare
Nice! I'll try to look into switching to pylance/pyright in the future |
Fixes #220.
Closes #219.
Depends on #221.
Depends on #222.
Works like this: