Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upSupport pulling type information directly from `.wasm` modules #39784
Conversation
@typescript-bot pack this |
Heya @weswigham, I've started to run the tarball bundle task on this PR at 0f6b16e. You can monitor the build here. |
Hey @weswigham, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running |
This would be amazing to have, especially for AssemblyScript users, but also anyone importing Wasm with type declarations. This would help reduce the barrier of entry for people wanting to try WebAssembly. What would it do to existing JS projects that rely on |
Related: #31713 |
|
||
|
||
//// [wasmImportsSimple.js] | ||
import * as mod from "test.wasm"; |
ExE-Boss
Aug 5, 2020
Contributor
The emitted module specifier doesn’t look right.
The emitted module specifier doesn’t look right.
weswigham
Aug 5, 2020
•
Author
Member
The test harness strips the leading /.lib/
because it's on the real disk from the host machine (and has the corresponding full, real path) - it only does this in the test harness~
The test harness strips the leading /.lib/
because it's on the real disk from the host machine (and has the corresponding full, real path) - it only does this in the test harness~
@typescript-bot pack this |
Heya @weswigham, I've started to run the tarball bundle task on this PR at 0f6b16e. You can monitor the build here. |
Hey @weswigham, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running |
To better support
wasm
modules under node's--experimental-wasm-modules
flag.In this PR, I add a new
experimentalWasmModules
typescript flag, which allows one to import.wasm
files directly in TS code without us issuing an error (this is only supported at runtime innode
using the node flag mentioned above). When enabled, we parse the contents of referenced.wasm
files for their exported function names and types, and generate a declaration file on-the-fly in memory for it based on those types (and that declaration file is what we then bind/check against).This is still very much a limited experiment, with only a small subset of possible features implemented thus far, but is far enough along to be able to show some new behavior:
In the above, on the left, I'm watch-rebuilding an
assemblyscript
program into awasm
module. On the right, I'm consuming that module in the editor, and getting live updates (with auto imports) as the backing.wasm
module updates. Repo available here.In any case, this should be a complete enough implementation to be able to gauge interest in the feature.
TODO:
readFile
compiler API so it can more easily returnUInt8Array
instances, rather thanstring
s (since wasm file contents are most definitely not strings). (You'll note that right now I have a separate host API call for it, which is very painful). Pretty much our entire file pipeline is geared for strings only (especially in the language service) - this is probably the biggest practical blocker for this..wasm
files (and introduce more early sanity checks on index bounds).wasm
imports when building the program (wasm files may import other wasm (or JS?) files - while this has no bearing on the types of the exports, it may result in the inclusion of more files in the program (which may in turn impact declaration emit))i32
/i64
/f32
/f64
subtypes ofnumber
and strongly check that the inputs/outputs of awasm
module are bounds-checkeddeclaration: true
is set.wasm
parsing/tree reuse in the language service (I had to wholly disable incremental LS operations on wasm files to get the LS to function, since they both need nonstring file reads, and are not updatable with the normal incremental parser)