Commit Graph

1866 Commits

Author SHA1 Message Date
Alex Crichton
a0fc095407 Restructure internals of wasm-gc
This commit restructures some of the internals of `wasm-gc` now that
I've actually got a better grasp on the wasm format and what all the
ownership edges look like. This shouldn't actually result in any
user-facing changes, but should make us be a bit more compatible with
operations in the future.

Memories/tables/elements/segments are no longer considered automatic
roots but rather need to be rooted by something else to prevent a gc.
For example an element section is gc'd along with a table if the table
is never referenced, along with data segments as well if the memory
isn't referenced.

Additionally all index sets now don't contained offseted indices, but
rather everything is always stored relative to the "index space" to
ensure consistency.

This should make it a bit easier to add future items to gc!
2018-10-28 10:10:51 -07:00
Alex Crichton
1fa407d2f9
Merge pull request #980 from alexcrichton/tweka-free
Tweak some logic in `JsValue::drop`
2018-10-26 09:53:08 +02:00
Alex Crichton
d70257af6c Tweak some logic in JsValue::drop
While technically correct the current implementation sort of made it
only roundaboutedly so. Tweak the logic a bit and the associated comment
to ensure that stack values are never dropped and the global constants
are all skipped.
2018-10-24 23:33:01 -07:00
Alex Crichton
f016ae5846 Indicate workable browsers 2018-10-23 08:50:58 -07:00
Alex Crichton
c8f2f77480
Merge pull request #954 from alexcrichton/fix-futures
Defer future execution to the next event loop tick
2018-10-23 16:40:31 +02:00
Alex Crichton
a1da85a24b Defer future execution to the next event loop tick
Previously whenever a future readiness notification came in we would
immediately start polling a future. This ends up having two downsides,
however:

* First, the stack depth may run a risk of getting blown. There's no
  recursion limit to defer execution to later, which means that if
  futures are always ready we'll keep making the stack deeper.

* Second, and more worrisome in the near term, apparently future
  adapaters in the `futures` crate (namely the unsync oneshot channel)
  doesn't actually work if you immediately poll on readiness. This may
  or may not be a bug in the `futures` crate but it's good to fix it
  here anyway.

As a result whenever a future is ready to get polled again we defer its
polling to the next turn of the event loop. This should ensure that the
current call stack is always drained and we're effectively enqueueing
the future to be polled in the near future.
2018-10-23 07:12:54 -07:00
Alex Crichton
cb170ef94f
Merge pull request #972 from alexcrichton/bulk-memory
Implement support for WebAssembly threads
2018-10-23 11:30:59 +02:00
Alex Crichton
25b26f41e7 Implement support for WebAssembly threads
... and add a parallel raytracing demo!

This commit adds enough support to `wasm-bindgen` to produce a workable
wasm binary *today* with the experimental WebAssembly threads support
implemented in Firefox Nightly. I've tried to comment what's going on in
the commits and such, but at a high level the changes made here are:

* A new transformation, living in a new `wasm-bindgen-threads-xform`
  crate, prepares a wasm module for parallel execution. This performs a
  number of mundane tasks which I hope to detail in a blog post later on.
* The `--no-modules` output is enhanced with more support for when
  shared memory is enabled, allowing passing in the module/memory to
  initialize the wasm instance on multiple threads (sharing both module
  and memory).
* The `wasm-bindgen` crate now offers the ability, in `--no-modules`
  mode, to get a handle on the `WebAssembly.Module` instance.
* The example itself requires Xargo to recompile the standard library
  with atomics and an experimental feature enabled. Afterwards it
  experimentally also enables threading support in wasm-bindgen.

I've also added hopefully enough CI support to compile this example in a
builder so we can upload it and poke around live online. I hope to
detail more about the technical details here in a blog post soon as
well!
2018-10-23 01:20:18 -07:00
Sendil Kumar N
dd80cf1ab1
Merge pull request #974 from alexcrichton/smaller
Shrink binary size of distributed `wasm-bindgen`
2018-10-18 08:40:12 +02:00
Alex Crichton
cb9c9fb011 Shrink binary size of distributed wasm-bindgen
This shaves a little over 2MB off the download locally for Linux,
removing debuginfo (which no one's probably gonna use anyway) as well as
switching from jemalloc to the system allocator.
2018-10-17 19:15:09 -07:00
Alex Crichton
ab8be88e7b
Merge pull request #970 from alexcrichton/more-new
Bind more Typed Array constructors in `js-sys`
2018-10-17 09:57:47 -05:00
Alex Crichton
58fb907baa
Merge pull request #971 from alexcrichton/update-parity-wasm
Update parity-wasm
2018-10-16 16:20:09 -05:00
Alex Crichton
a4a2ec605d Update parity-wasm
Bring in some support for bulk-memory-operations instructions
2018-10-16 14:04:40 -07:00
Alex Crichton
995aefa87e
Merge pull request #969 from alexcrichton/no-modules-moudle
Allow passing a `WebAssembly.Module` in `--no-modules`
2018-10-16 14:24:25 -05:00
Alex Crichton
9effb7c707 Bind more Typed Array constructors in js-sys
Bind `new Int8Array(length)`, `new Int8Array(buffer, offset)` and `new
Int8Array(buffer, offset, length)`.
2018-10-16 11:16:22 -07:00
Alex Crichton
34b75c35b2 Allow passing a WebAssembly.Module in --no-modules
I've noticed this in a few cases where it's sometimes easy to have a
`WebAssembly.Module` on-hand for the `--no-modules` mode where you don't
want to necessarily `fetch`. This commit changes the exported
initialization function in `--no-modules` mode to support both!
2018-10-16 10:48:07 -07:00
Nick Fitzgerald
0b59657603
Merge pull request #945 from alexcrichton/remove-json
Don't use JSON for custom section format
2018-10-16 05:49:00 -07:00
Alex Crichton
79c050a0e6
Merge pull request #966 from katis/dataview_endian_overloads
Add overloads with endianness parameter to DataView gets and sets
2018-10-15 09:35:22 -05:00
Joni Katajamäki
83f9f54b04 Fix getFloat64 comments 2018-10-15 16:24:49 +03:00
Joni Katajamäki
968b5e0154 Add overloads with endianness parameter to DataView gets and sets 2018-10-15 14:32:17 +03:00
Alex Crichton
2b90532db5
Merge pull request #965 from djozis/master
Removed buffer copy from webgl example
2018-10-14 22:08:38 -05:00
David Jozis
b369932b37 Fixed typo 2018-10-14 17:00:56 -04:00
David Jozis
30bb9b09d3 Switched from raw pointer casts to using as_ptr() 2018-10-14 16:50:35 -04:00
David Jozis
52128e9baa Cleaned up memory buffer access 2018-10-14 13:28:27 -04:00
David Jozis
f408310ab7 Removed buffer copy from webgl example 2018-10-14 13:28:27 -04:00
Alex Crichton
f749c7cf95 Don't use JSON for custom section format
This commit migrates away from using Serde for the custom section in
wasm executables. This is a refactoring of a purely-internal data
structure to `wasm-bindgen` and should have no visible functional change
on users.

The motivation for this commit is two fold:

* First, the compile times using `serde_json` and `serde_derive` for the
  syntax extension isn't the most fun.
* Second, eventually we're going to want to stablize the layout of the
  custom section, and it's highly unlikely to be json!

Primarily, though, the intention of this commit is to improve the
cold-cache compile time of `wasm-bindgen` by ensuring that for new users
this project builds as quickly as possible. By removing some heavyweight
dependencies from the procedural macro, `serde`, `serde_derive`, and
`serde_json`, we're able to get a pretty nice build time improvement for
the `wasm-bindgen` crate itself:

|             | single-core build | parallel build |
|-------------|-------------------|----------------|
| master      |             36.5s |          17.3s |
| this commit |             20.5s |          11.8s |

These are't really end-all-be-all wins but they're much better
especially on the spectrum of weaker CPUs (in theory modeled by the
single-core case showing we have 42% less CPU work in theory).
2018-10-12 11:23:00 -07:00
Nick Fitzgerald
aac8696d05
Merge pull request #959 from alexcrichton/moreundef
Fix generated shims if APIs don't exist
2018-10-12 10:18:44 -07:00
Alex Crichton
13cac2d0c4 Fix generated shims if APIs don't exist
This commit fixes instantiation of the wasm module even if some of the
improted APIs don't exist. This extends the functionality initially
added in #409 to attempt to gracefully allow importing values from the
environment which don't actually exist in all contexts. In addition to
nonexistent methods being handled now entire nonexistent types are now
also handled.

I suspect that eventually we'll add a CLI flag to `wasm-bindgen` to say
"I assert everything exists, don't check it" to trim out the extra JS
glue generated here. In the meantime though this'll pave the way for a
wasm-bindgen shim to be instantiated in both a web worker and the main
thread, while using DOM-like APIs only on the main thread.
2018-10-10 17:46:51 -07:00
Alex Crichton
e03e40451e
Merge pull request #955 from alexcrichton/non-send
Ensure that `JsValue` isn't considered `Send`
2018-10-10 17:41:49 -07:00
Alex Crichton
41d3a08028
Merge pull request #958 from alexcrichton/no-global-cache
js_sys: Use a thread local to cache `global()`
2018-10-10 17:41:41 -07:00
Alex Crichton
e0b73abc7e
Merge pull request #957 from alexcrichton/promise-clone
js_sys: Add `#[derive(Clone, Debug)]` to `Promise`
2018-10-10 16:52:57 -07:00
Alex Crichton
e72ae12e77
Merge pull request #956 from alexcrichton/js-sys-typed-array-slice
js-sys: Add bindings for `TypedArray.slice`
2018-10-10 16:52:39 -07:00
Alex Crichton
4993e45fd9 Squash a few warnings that snuck in by accident 2018-10-10 16:09:24 -07:00
Alex Crichton
105a6bc853 js_sys: Use a thread local to cache global()
When we add threads it's not actually valid to have a global cache as
the index is only valid on one thread! Instead let's use a per-thread
cache using `thread_local!` which compiles to basically the same code as
before for single-threaded wasm.
2018-10-10 16:01:32 -07:00
Alex Crichton
e9fa209dcf js_sys: Add #[derive(Clone, Debug)] to Promise
I think we just forgot this from earlier!
2018-10-10 15:58:47 -07:00
Alex Crichton
f9d2dbd0b6 js-sys: Add bindings for TypedArray.slice
This commit adds support for the `slice` function on all `TypedArray`
instances. The `slice` function is similar to `subarray` except that it
actually copies the data, whereas `subarray` just returns a different
view into data.
2018-10-10 15:57:00 -07:00
Alex Crichton
e46537e6c2 Ensure that JsValue isn't considered Send
The `JsValue` type wraps a slab/heap of js objects which is managed by
the wasm-bindgen shim, and everything here is not actually able to cross
any thread boundaries. When wasm actually has threads, for example, each
thread will have to have its own slab of objects generated by
wasm-bindgen, and indices in one slab aren't valid in any other slabs.

This is technically a breaking change because `JsValue` was previously
`Send` and `Sync`, but I'm hoping that in practice this isn't actually a
breaking change because nothing in wasm can be using threads which in
theory shouldn't activate the `Send` and/or `Sync` bounds.
2018-10-10 15:47:07 -07:00
Nick Fitzgerald
dd82a3e134 Bump to 0.2.25 2018-10-10 13:19:40 -07:00
Alex Crichton
70e13705b4
Merge pull request #952 from alexcrichton/field-export
Fix bindings for classes only referenced through struct fields
2018-10-10 11:55:24 -07:00
Nick Fitzgerald
fe35750448
Merge pull request #953 from alexcrichton/bigint
Add caveat for `BigInt` and `u64` in browser support
2018-10-10 11:44:04 -07:00
Alex Crichton
5957289ef2 Add caveat for BigInt and u64 in browser support
Closes #948
2018-10-10 10:30:32 -07:00
Alex Crichton
f6cb73442a Fix bindings for classes only referenced through struct fields
The bindings generation for a class would accidentally omit the `__wrap`
function if it was only discovered very late in the process that
`__wrap` was needed, after we'd already passed the point where we needed
to have decided that.

This commit moves struct field generation of bindings much earlier in
the binding generation process which should ensure everything is all
hooked up by the time we generate the classes themselves.

Closes #949
2018-10-10 10:21:19 -07:00
Alex Crichton
35eeb711ad
Merge pull request #947 from fitzgen/use-global-allocator-not-system
Use the global allocator, not the system allocator
2018-10-10 08:43:23 -07:00
Nick Fitzgerald
3ceb0441d3 Use the global allocator, not the system allocator
This was previously causing us to accidentally always pull in the system
allocator, even if users were trying to just use a custom global allocator.
2018-10-09 18:08:46 -07:00
Alex Crichton
d70149dd91
Merge pull request #946 from fitzgen/guide-testing-wasm-pack
guide: clarify testing docs; prefer `wasm-pack`-based workflows
2018-10-09 09:38:18 -07:00
Nick Fitzgerald
8d195d07ee guide: clarify testing docs; prefer wasm-pack-based workflows 2018-10-09 09:31:01 -07:00
Alex Crichton
1410b5253d
Merge pull request #944 from alexcrichton/windows-slash
Fix web-sys build on some Windows builds
2018-10-08 12:46:44 -07:00
Alex Crichton
6a9ad2e5d3
Merge pull request #942 from alexcrichton/parity-wasm-public
Update parity-wasm dependency
2018-10-08 12:46:35 -07:00
Alex Crichton
a40b27da60
Merge pull request #941 from alexcrichton/fix-201
Add tests for internal imports now working
2018-10-08 10:20:05 -07:00
Alex Crichton
18deb5e848 Fix web-sys build on some Windows builds
The official pathname separator on Windows is `\` instead of `/`, but
we've been unconditionally using `/`. This typically works on Windows
because Cargo's default `OUT_DIR` listing is a normal `C:\...` path
which works with either `/` or `\`. If, however, a user sets
`CARGO_TARGET_DIR` to a UNC-style path like `\\?\C:\...` then `/` is
*not* the same as `\`, but rather `/` is interpreted as part of the file
name (to allow file names with `/` in the name).

Let's bypass all this and just use a build script output env var.

Closes #943
2018-10-08 10:19:43 -07:00