Commit Graph

2955 Commits

Author SHA1 Message Date
8e56cdacc5 Rewrite wasm-bindgen with updated interface types proposal (#1882)
This commit is a pretty large scale rewrite of the internals of wasm-bindgen. No user-facing changes are expected as a result of this PR, but due to the scale of changes here it's likely inevitable that at least something will break. I'm hoping to get more testing in though before landing!

The purpose of this PR is to update wasm-bindgen to the current state of the interface types proposal. The wasm-bindgen tool was last updated when it was still called "WebIDL bindings" so it's been awhile! All support is now based on https://github.com/bytecodealliance/wasm-interface-types which defines parsers/binary format/writers/etc for wasm-interface types.

This is a pretty massive PR and unfortunately can't really be split up any more afaik. I don't really expect realistic review of all the code here (or commits), but some high-level changes are:

* Interface types now consists of a set of "adapter functions". The IR in wasm-bindgen is modeled the same way not.
* Each adapter function has a list of instructions, and these instructions work at a higher level than wasm itself, for example with strings.
* The wasm-bindgen tool has a suite of instructions which are specific to it and not present in the standard. (like before with webidl bindings)
* The anyref/multi-value transformations are now greatly simplified. They're simply "optimization passes" over adapter functions, removing instructions that are otherwise present. This way we don't have to juggle so much all over the place, and instructions always have the same meaning.
2019-12-03 11:16:44 -06:00
df34cf843e Allow for js property inspection (#1876)
* Add support for #[wasm_bindgen(inspectable)]

This annotation generates a `toJSON` and `toString` implementation for
generated JavaScript classes which display all readable properties
available via the class or its getters

This is useful because wasm-bindgen classes currently serialize to
display one value named `ptr`, which does not model the properties of
the struct in Rust

This annotation addresses rustwasm/wasm-bindgen#1857

* Support console.log for inspectable attr in Nodejs

`#[wasm_bindgen(inspectable)]` now generates an implementation of
`[util.inspect.custom]` for the Node.js target only. This implementation
causes `console.log` and friends to yield the same class-style output,
but with all readable fields of the Rust struct displayed

* Reduce duplication in generated methods

Generated `toString` and `[util.inspect.custom]` methods now call
`toJSON` to reduce duplication

* Store module name in variable
2019-11-26 12:39:57 -06:00
181b10be3f Update extends.md (#1874)
typo: Bar reference gives Foo.
2019-11-25 08:33:03 -06:00
0acece0c95 'function' typo (#1875) 2019-11-25 08:32:51 -06:00
394be5ec21 Update alert message regarding Firefox version (#1870) 2019-11-22 10:01:15 -06:00
9768ec9cab Remove extraneous -Ztimings flag 2019-11-22 07:59:46 -08:00
aa461c363b Add one more webkit-specific whitelist in web-sys (#1865)
* Add one more webkit-specific whitelist in web-sys

* Run rustfmt
2019-11-21 09:30:08 -06:00
db9d603c8f Bump to 0.2.55 (#1864) 0.2.55 2019-11-19 11:04:37 -06:00
e934a0f3d3 Support multi-value JS engines (#1863)
This commit adds support to wasm-bindgen to run over interface
types-enabled modules that use multi-value returns and returns are
loaded from the returned array rather than from memory.
2019-11-19 10:44:56 -06:00
851390089b Add a mutable accessor for the walrus wasm module 2019-11-19 07:48:34 -08:00
aca49e1a6e Fix the anyref xform working on empty modules (#1861)
If there's no need for a transformation then there's no need to inject
anything, so make sure that wasm-bindgen with anyref passes enabled
works on non-wasm-bindgen blobs as well.

Closes bytecodealliance/cargo-wasi#16
2019-11-18 10:12:41 -06:00
a8882dc3a6 Point master branch documention link to web_sys instead of js_sys (#1859) 2019-11-11 08:46:28 -06:00
ada615f3dd simplify macro for arrays (#1856) 2019-11-08 16:12:22 -06:00
3573164b52 Bump to 0.2.54 (#1854) 0.2.54 2019-11-07 12:59:01 -06:00
d51f539d1a Add an unsafe method view_mut_raw (#1850)
* adding .vscode folder to .gitignore

* Adding view_mut_raw to generated arrays

* test populating rust vector from JS  function

* Uint32Array test, need to make it generic

* Add doc + more test cases

* replacing macro-generated tests with generic test function

it is cleaner, safer and better that way

* improving rustdoc
2019-11-06 12:37:26 -06:00
e7bfa161e0 Fix UI tests for updated beta 2019-11-06 09:15:51 -08:00
2a12ca2a4f Update mod.rs (#1852)
Using Typescript I have this warning:
`./pkg/index.js
  Line 52:22:  Expected '!==' and instead saw '!='  eqeqeq

Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.
`

I guess this should solve the warning.

Thank you for all the work.
2019-11-06 11:12:47 -06:00
79cf4f6198 Add first-class support for binary crates (#1843)
* autodiscover an exported `main` if possible

this allows for first-class support of binary crates

* wrap `main` to zero out arguments and suppress return value

* add test for bin crate support

* process only the export of the generated main wrapper

* skip most of `export` since only one line of that is needed
2019-11-04 13:34:42 -06:00
b29c110d01 Remove dependencies on git versions of crates 2019-11-04 10:37:50 -08:00
935f71afec Switch from failure to anyhow (#1851)
This commit switches all of `wasm-bindgen` from the `failure` crate to
`anyhow`. The `anyhow` crate should serve all the purposes that we
previously used `failure` for but has a few advantages:

* It's based on the standard `Error` trait rather than a custom `Fail`
  trait, improving ecosystem compatibility.
* We don't need a `#[derive(Fail)]`, which means that's less code to
  compile for `wasm-bindgen`. This notably helps the compile time of
  `web-sys` itself.
* Using `Result<()>` in `fn main` with `anyhow::Error` produces
  human-readable output, so we can use that natively.
2019-11-04 11:35:28 -06:00
913fdbc3da Update HTMLImageElement IDL to latest version from gecko (#1842)
* Update HTMLImageElement IDL to latest version from gecko

* Remove Mozilla-specific extensions to HTMLImageElement IDL
2019-10-29 18:11:19 -05:00
1f51831c3d Adding in to_vec method for typed arrays (#1844)
* Adding in to_vec method for typed arrays

* Fixing type error
2019-10-29 18:10:18 -05:00
6159d50eb6 Fix expired Discord link in README.md (#1845) 2019-10-29 17:56:07 -05:00
c7c169ae72 Bump to 0.2.53 (#1840) 0.2.53 2019-10-29 09:37:37 -05:00
9b8711a5b7 Update webidl_ty field in multi-value transform (#1839)
* Reduce indentation in interface types processing

Just a small stylistic change

* Update `webidl_ty` field in multi-value transform

When we're emitting a bindings section we need to be sure to update the
listed type of the binding in addition to the actual binding
expressions. This should help remove the stray return pointer being
listed there by accident!
2019-10-29 08:55:01 -05:00
0397e529e0 Add debugging names for multivalue shims 2019-10-28 20:15:46 -07:00
513285f73d Run rustfmt 2019-10-28 20:15:05 -07:00
a20dd26dde Bump to 0.2.52 (#1833) 0.2.52 2019-10-24 16:08:45 -05:00
e880baf11d Working around bug in Safari (#1829) 2019-10-22 17:26:28 -05:00
c1b4f67444 Adding in unintern function (#1828)
* Adding in unintern function

* Adding in some basic unit tests for interning and uninterning
2019-10-22 17:23:30 -05:00
777a12dc70 Fix TypeScript capitalization in internals guide (#1826) 2019-10-21 09:27:48 -05:00
fe4dd0b301 Merge pull request #1805 from fitzgen/wasm-interface-types-and-multi-value
Wasm interface types and multi-value
2019-10-18 10:03:37 -07:00
46cbd19e60 Improve worker.js reliability (#1820)
While it doesn't happen right now in this particular example, `lastPtr` can be potentially overridden several times before the module is fully initialised.

Rather than having a boolean and a storage for one last argument, `await` a promise returned from `wasm_bindgen` itself in the new `onmessage` handler before executing actual command.

This way all the potential tasks will queue up naturally, wait for the initialisation, and then execute in a correct order.
2019-10-17 17:29:37 -05:00
a31b81307c Update Worklet IDL to latest version from gecko (#1817) 2019-10-16 09:41:25 -05:00
c7514b7ee8 Enable selectionStart and selectionEnd for HTMLInputElement (#1811) 2019-10-08 09:58:59 -07:00
ebef7a7aa7 Update toolchain for raytrace example (#1806)
Pulls in an LLVM tweak which emits far fewer `memory.copy`, drastrically
improving performance on Firefox!
2019-10-04 10:54:15 -05:00
0e3b696fb7 Fix return type of WebIDL indexing getters (#1789)
* Wrap the return type of indexing getters as Option<T> if necessary.

* Update tests for indexing getters

* Fix typo

* Add comments describing what the code segment is doing

* Update indexing getter usage

* Revert "Add comments describing what the code segment is doing"

This reverts commit 624a14c0fffb78e8eaed21658ddddbad70b2462d.

* Revert "Fix typo"

This reverts commit 487fc307bc08c2a7778b2117fb03f0f5eb5a3c18.

* Revert "Wrap the return type of indexing getters as Option<T> if necessary."

This reverts commit 547f3dd36c1182928ff728a8452591a492b65e21.

* Update the return signatures of WebIDL indexing getters
2019-10-03 19:48:37 -05:00
25dd84c503 Get rid of the wasm interface types return pointer hacks
Now that using standard Wasm interface types implies multi-value support, we
don't need these return pointer hacks anymore.
2019-10-03 13:24:50 -07:00
311ae1941f Wasm interface types should imply multi-value 2019-10-03 12:57:26 -07:00
085924567f Fix guide for tests in the remote browser (#1804) 2019-10-03 09:27:07 -05:00
ffa6eabffe fixed broken link (#1803) 2019-10-03 09:26:54 -05:00
74812bd236 Merge pull request #1802 from alexcrichton/switch-cores
Don't offset the number of rayon workers by 1
2019-10-02 11:25:05 -07:00
53c0dcf17a Don't offset the number of rayon workers by 1
If we pass rayon 0 workers it still spawns 1, so both 1 and 2 threads
were actually spawning one thread each. Let's remove the off-by-one so
1 and 2 cores should show a significant difference.
2019-10-01 18:10:18 -07:00
6d1dc813c4 Bump to 0.2.51 (#1797)
This notably brings in async/await support for current beta/nightly
users. Yay!
0.2.51
2019-09-26 14:07:28 -05:00
599ec8b9f4 Use official node releases for anyref test suite (#1798)
Looks like 12.11.0 has all the support we need!
2019-09-26 14:07:21 -05:00
bdcf27c7cb Major improvements to wasm-bindgen-futures (#1760)
This PR contains a few major improvements:

* Code duplication has been removed.

* Everything has been refactored so that the implementation is much easier to understand.

* `future_to_promise` is now implemented with `spawn_local` rather than the other way around (this means `spawn_local` is faster since it doesn't need to create an unneeded `Promise`).

* Both the single threaded and multi threaded executors have been rewritten from scratch:

   * They only create 1-2 allocations in Rust per Task, and all of the allocations happen when the Task is created.

   * The singlethreaded executor creates 1 Promise per tick, rather than 1 Promise per tick per Task.

   * Both executors do *not* create `Closure`s during polling, instead all needed `Closure`s are created ahead of time.

   * Both executors now have correct behavior with regard to spurious wakeups and waking up during the call to `poll`.

   * Both executors cache the `Waker` so it doesn't need to be recreated all the time.

I believe both executors are now optimal in terms of both Rust and JS performance.
2019-09-26 13:33:12 -05:00
0b1a764f8a Guarantee static_method_of uses the right this (#1795)
This came up during #1760 where `Promise.resolve` must be invoked with
`this` as the `Promise` object, but we were erroneously importing it in
such a way that it didn't have a shim and `this` was `undefined`.
2019-09-26 12:33:04 -05:00
025b1d8bca Switch to Cargo's -Zbuild-std for building libstd (#1796)
This commit switches away from `xargo` to using `-Zbuild-std` to
building the standard library for the raytrace-parallel example (which
needs to rebuild std with new target features).
2019-09-26 12:32:50 -05:00
6b31777794 Fix local webdriver discovery via PATH (#1794) 2019-09-26 09:49:43 -05:00
0607a75b78 Switch CI to testing beta toolchains (#1792)
Don't accidentally leak in nightly features and bring a modicum of
stability to the UI tests
2019-09-25 12:45:49 -05:00