Commit Graph

52 Commits

Author SHA1 Message Date
ff0a50e31e Fix failing interpreter tests 2019-06-05 07:52:14 -07:00
68c5233f80 First refactor for WebIDL bindings
This commit starts the `wasm-bindgen` CLI tool down the road to being a
true polyfill for WebIDL bindings. This refactor is probably the first
of a few, but is hopefully the largest and most sprawling and everything
will be a bit more targeted from here on out.

The goal of this refactoring is to separate out the massive
`crates/cli-support/src/js/mod.rs` into a number of separate pieces of
functionality. It currently takes care of basically everything
including:

* Binding intrinsics
* Handling anyref transformations
* Generating all JS for imports/exports
* All the logic for how to import and how to name imports
* Execution and management of wasm-bindgen closures

Many of these are separable concerns and most overlap with WebIDL
bindings. The internal refactoring here is intended to make it more
clear who's responsible for what as well as making some existing
operations much more straightforward. At a high-level, the following
changes are done:

1. A `src/webidl.rs` module is introduced. The purpose of this module is
   to take all of the raw wasm-bindgen custom sections from the module
   and transform them into a WebIDL bindings section.

  This module has a placeholder `WebidlCustomSection` which is nowhere
  near the actual custom section but if you squint is in theory very
  similar. It's hoped that this will eventually become the true WebIDL
  custom section, currently being developed in an external crate.

  Currently, however, the WebIDL bindings custom section only covers a
  subset of the functionality we export to wasm-bindgen users. To avoid
  leaving them high and dry this module also contains an auxiliary
  custom section named `WasmBindgenAux`. This custom section isn't
  intended to have a binary format, but is intended to represent a
  theoretical custom section necessary to couple with WebIDL bindings to
  achieve all our desired functionality in `wasm-bindgen`. It'll never
  be standardized, but it'll also never be serialized :)

2. The `src/webidl.rs` module now takes over quite a bit of
   functionality from `src/js/mod.rs`. Namely it handles synthesis of an
   `export_map` and an `import_map` mapping export/import IDs to exactly
   what's expected to be hooked up there. This does not include type
   information (as that's in the bindings section) but rather includes
   things like "this is the method of class A" or "this import is from
   module `foo`" and things like that. These could arguably be subsumed
   by future JS features as well, but that's for another time!

3. All handling of wasm-bindgen "descriptor functions" now happens in a
   dedicated `src/descriptors.rs` module. The output of this module is
   its own custom section (intended to be immediately consumed by the
   WebIDL module) which is in theory what we want to ourselves emit one
   day but rustc isn't capable of doing so right now.

4. Invocations and generations of imports are completely overhauled.
   Using the `import_map` generated in the WebIDL step all imports are
   now handled much more precisely in one location rather than
   haphazardly throughout the module. This means we have precise
   information about each import of the module and we only modify
   exactly what we're looking at. This also vastly simplifies intrinsic
   generation since it's all simply a codegen part of the `rust2js.rs`
   module now.

5. Handling of direct imports which don't have a JS shim generated is
   slightly different from before and is intended to be
   future-compatible with WebIDL bindings in its full glory, but we'll
   need to update it to handle cases for constructors and method calls
   eventually as well.

6. Intrinsic definitions now live in their own file (`src/intrinsic.rs`)
   and have a separated definition for their symbol name and signature.
   The actual implementation of each intrinsic lives in `rust2js.rs`

There's a number of TODO items to finish before this merges. This
includes reimplementing the anyref pass and actually implementing import
maps for other targets. Those will come soon in follow-up commits, but
the entire `tests/wasm/main.rs` suite is currently passing and this
seems like a good checkpoint.
2019-06-05 07:52:14 -07:00
137bbdf2e3 Bump to 0.2.45 2019-05-20 09:44:03 -07:00
d422436487 Update dependencies and use new walrus custom sections APIs 2019-05-17 14:58:50 -07:00
773c6ff430 Bump to 0.2.44 2019-05-16 07:47:23 -07:00
5a017c1e22 Update walrus dependency 2019-05-03 07:12:28 -07:00
f2429be07f Bump to 0.2.43 2019-04-29 08:28:41 -07:00
df6e15e3ab Bump to 0.2.42 2019-04-11 07:39:45 -07:00
02394724ea Bump to 0.2.41 2019-04-10 10:53:32 -07:00
6803c619bb Bump to 0.2.40 2019-03-21 17:08:48 -07:00
228f58dca3 Bump to 0.2.39 2019-03-13 11:02:27 -07:00
795bf7c6b1 Update walrus to 0.5.0 2019-03-06 15:09:20 -08:00
a659f27c07 Bump to 0.2.38 2019-03-04 09:11:23 -08:00
8fb705a1ef Upgrade to walrus 0.4
Also be sure to have an explicit GC pass!
2019-02-19 14:14:01 -08:00
9bab9d4af1 Fix an assert while deleting table elements
LLVM's mergefunc pass may mean that the same descriptor function is used
for different closure invocation sites even when the closure itself is
different. This typically only happens with LTO but in theory could
happen at any time!

The assert was tripping when we tried to delete the same function table
entry twice, so instead of a `Vec<usize>` of entries to delete this
commit switches to a `HashSet<usize>` which should do the deduplication
for us and enusre that we delete each descriptor only once.

Closes #1264
2019-02-19 08:17:14 -08:00
e9f423d57e Bump to 0.2.37 2019-02-15 08:16:24 -08:00
17dc79e4c5 Configure walrus to generate DWARF/names at the right times
Fixes ##1254
2019-02-14 07:20:43 -08:00
802cfedcbd Bump to 0.2.36 2019-02-12 13:19:02 -08:00
6f00d9563f interpreter: handle closure descriptors with less than two parameters
This might happen because of LTO.

Fixes #1244
2019-02-12 12:57:22 -08:00
d9cf9b3735 Bump to version 0.2.35 2019-02-12 11:36:19 -08:00
894b479213 Migrate wasm-bindgen to using walrus
This commit moves `wasm-bindgen` the CLI tool from internally using
`parity-wasm` for wasm parsing/serialization to instead use `walrus`.
The `walrus` crate is something we've been working on recently with an
aim to replace the usage of `parity-wasm` in `wasm-bindgen` to make the
current CLI tool more maintainable as well as more future-proof.

The `walrus` crate provides a much nicer AST to work with as well as a
structured `Module`, whereas `parity-wasm` provides a very raw interface
to the wasm module which isn't really appropriate for our use case. The
many transformations and tweaks that wasm-bindgen does have a huge
amount of ad-hoc index management to carefully craft a final wasm
binary, but this is all entirely taken care for us with the `walrus`
crate.

Additionally, `wasm-bindgen` will ingest and rewrite the wasm file,
often changing the binary offsets of functions. Eventually with DWARF
debug information we'll need to be sure to preserve the debug
information throughout the transformations that `wasm-bindgen` does
today. This is practically impossible to do with the `parity-wasm`
architecture, but `walrus` was designed from the get-go to solve this
problem transparently in the `walrus` crate itself. (it doesn't today,
but this is planned work)

It is the intention that this does not end up regressing any
`wasm-bindgen` use cases, neither in functionality or in speed. As a
large change and refactoring, however, it's likely that at least
something will arise! We'll want to continue to remain vigilant to any
issues that come up with this commit.

Note that the `gc` crate has been deleted as part of this change, as the
`gc` crate is no longer necessary since `walrus` does it automatically.
Additionally the `gc` crate was one of the main problems with preserving
debug information as it often deletes wasm items!

Finally, this also starts moving crates to the 2018 edition where
necessary since `walrus` requires the 2018 edition, and in general it's
more pleasant to work within the 2018 edition!
2019-02-12 07:25:53 -08:00
078257943d Bump to 0.2.34 2019-02-11 18:58:54 -08:00
ef37986541 Update more parity-wasm 2019-02-04 22:06:10 -08:00
78c4075e40 Bump to 0.2.33 2019-01-18 15:32:17 -08:00
31fdede9fc Bump to 0.2.32 2019-01-16 13:11:13 -08:00
61a6fcfced Fix and execute wasm-bindgen-wasm-interpreter tests 2019-01-11 13:20:08 -08:00
b04f60cf2b Bump to 0.2.31 2019-01-09 09:17:50 -08:00
fbf000a508 Bump to 0.2.30 2019-01-07 07:47:07 -08:00
63e3ba722d Bump to 0.2.29 2018-12-04 06:04:47 -08:00
42053ddd4e Move closure shims into the descriptor
Currently closure shims are communicated to JS at runtime, although at
runtime the same constant value is always passed to JS! More pressing,
however, work in #1002 requires knowledge of closure descriptor indices
at `wasm-bindgen` time which is not currently known.

Since the closure descriptor shims and such are already constant values,
this commit moves the descriptor function indices into the *descriptor*
for a closure/function pointer. This way we can learn about these values
at `wasm-bindgen` time instead of only knowing them at runtime.

This should have no semantic change on users of `wasm-bindgen`, although
some closure invocations may be slightly speedier because there's less
arguments being transferred over the boundary. Overall though this will
help #1002 as the closure shims that the Rust compiler generates may not
be the exact ones we hand out to JS, but rather wrappers around them
which do `anyref` business things.
2018-11-29 12:42:44 -08:00
48f4adfa8c Run rustfmt over everything 2018-11-27 12:07:59 -08:00
22ca15f81e Bump to 0.2.28 2018-11-12 09:28:01 -08:00
6dfbb4be89 Bump to 0.2.27 2018-10-29 14:30:33 -07:00
7fad2bf0c8 Bump to 0.2.26 2018-10-29 12:56:37 -07:00
a4a2ec605d Update parity-wasm
Bring in some support for bulk-memory-operations instructions
2018-10-16 14:04:40 -07:00
dd82a3e134 Bump to 0.2.25 2018-10-10 13:19:40 -07:00
79e4324a3b Update parity-wasm dependency
While doing this, make `parity-wasm` a public dependency of all crates
instead of using the `Any` trick as that's not really needed any more.
2018-10-08 10:01:53 -07:00
c210ccd596 Bump to 0.2.24 2018-10-05 09:53:19 -07:00
8ba41cce6e Improve codegen for Closure<T>
This commit improves the codegen for `Closure<T>`, primarily for ZST
where the closure doesn't actually capture anything. Previously
`wasm-bindgen` would unconditionally allocate an `Rc` for a fat pointer,
meaning that it would always hit the allocator even when the `Box<T>`
didn't actually contain an allocation. Now the reference count for the
closure is stored on the JS object rather than in Rust.

Some more advanced tests were added along the way to ensure that
functionality didn't regress, and otherwise the calling convention for
`Closure` changed a good deal but should still be the same user-facing.
The primary change was that the reference count reaching zero may cause
JS to need to run the destructor. It simply returns this information in
`Drop for Closure` and otherwise when calling it now also retains a
function pointer that runs the destructor.

Closes #874
2018-09-29 07:00:53 -07:00
7ecf4aae87 cargo +nightly fmt --all
Rustfmt all the things!
2018-09-26 08:26:00 -07:00
f834a427d7 Bump to version 0.2.23 (and js-sys and wasm-bindgen-futures to 0.3.0) 2018-09-26 07:31:54 -07:00
51ec485c94 Bump to 0.2.22 2018-09-21 13:41:58 -07:00
a117c057fb More conservatively patch closure descriptors
Previously `wasm-bindgen` would take its `breaks_if_inlined` shims and
attempt to remove them entirely, replacing calls to `breaks_if_inlined`
to the imported closure factories. This worked great in that it would
remove the `breaks_if_inlined` funtion entirely, removing the "cost" of
the `#[inline(never)]`.

Unfortunately as #864 discovered this is "too clever by half". LLVM's
aggressive optimizations won't inline `breaks_if_inlined`, but it may
still change the ABI! We can't replace calls to `breaks_if_inlined` if
the signature changes, because the function its calling has a fixed signature.

This commit cops out a bit and instead of replacing calls to
`breaks_if_inlined` to the imported closure factories, we instead
rewrite calls to `__wbindgen_describe_closure` to the closure factories.
This means that the `breaks_if_inlined` shims do not get removed. It
also means that the closure factory shims have a third and final
argument (what would be the function pointer of the descriptor function)
which is dead and unused.

This should be a functional solution for now and let us iterate on a
true fix later on (if needed). For now the cost of this
`#[inline(never)]` and the extra unused argument should be quite small.

Closes #864
2018-09-21 13:34:59 -07:00
f18b10ca52 Bump to 0.2.21 2018-09-06 22:10:11 -07:00
e67397ec27 Merge pull request #793 from alexcrichton/bump
Bump to 0.2.20
2018-09-06 14:49:54 -07:00
9d5898ab48 Bump to 0.2.20 2018-09-06 14:49:43 -07:00
5a3cd893e0 Implement AsRef<JsValue> for Closure<T>
This commit adds an implementation of `AsRef<JsValue>` for the `Closure<T>`
type. Previously this was not possible because the `JsValue` didn't actually
exist until the closure was passed to JS, but the implementation has been
changed to ... something a bit more unconventional. The end result, however, is
that `Closure<T>` now always contains a `JsValue`.

The end result of this work is intended to be a precursor to binding callbacks
in `web-sys` as `JsValue` everywhere but still allowing usage with `Closure<T>`.
2018-09-06 14:46:59 -07:00
f7e6fa2a04 Bump dependency on parity-wasm to 0.32.0
Brings support for atomic instructions!
2018-08-28 10:12:56 -07:00
d9bc0a3176 Bump to 0.2.19 2018-08-27 13:39:23 -07:00
98008b9e77 Bump to 0.2.18
At the same time, also add a `publish.rs` script to ease our publishing woes.
2018-08-27 13:37:55 -07:00