Commit Graph

2820 Commits

Author SHA1 Message Date
117fce1c82 Merge pull request #1692 from alexcrichton/fix-anyref-bugs
Fix a number of `anyref` related bugs in our passes
2019-08-02 09:47:14 -05:00
adde6c2da7 Correct base calculation in anyref allocator
This `base` value is the raw value coming out of the first call to
`table.grow`. Throwing in the addition of `JSIDX_RESERVED` just wasn't
right!
2019-08-01 12:00:33 -07:00
6cc7e3dadf Ensure the 0th slot of anyref table is undefined
This is currently required by our ABI for wasm-bindgen where `None` js
values going out have an index of 0 and are intended to be `undefined`.
This also refactors initialization a bit to be slightly more generic
over the constants we already have defined in this module.
2019-08-01 11:59:05 -07:00
5aee2f9c6a Fix an off-by-one in anyref stack manipulation
With more than two anyref stack arguments we were accidentally storing
the anyref values one higher in the stack than intended, so fix this
off-by-one by switching up some addition logic.
2019-08-01 11:58:33 -07:00
6e3e9d2dae Correctly hook up the anyref table initialization
This functionality got lost in recent refactorings for WebIDL bindings
unfortunately, so this commit touches things up to ensure that the
anyref table initialization in anyref-mode is hooked up correctly, even
when tests are enabled. This invovled moving injection of the start
function to the webidl processing pass and ensuring its intrinsic is
registered in the internal maps of wasm-bindgen.
2019-08-01 11:56:57 -07:00
36db788829 Merge pull request #1689 from alexcrichton/direct-imports
Support emitting direct imports in wasm files
2019-08-01 10:24:08 -05:00
2aac606d3f Support emitting direct imports in wasm files
Support was previously (re-)added in #1654 for importing direct JS
values into a WebAssembly module by completely skipping JS shim
generation. This commit takes that PR one step further by *also*
embedding a direct import in the wasm file, where supported. The wasm
file currently largely just imports from the JS shim file that we
generate, but this allows it to directly improt from ES modules where
supported and where possible. Note that like #1654 this only happens
when the function signature doesn't actually require any conversions to
happen in JS (such as handling closures).

For imports from ES modules, local snippets, or inline JS they'll all
have their import directives directly embedded into the final
WebAssembly binary without any shims necessary to hook it all up. For
imports from the global namespace or possibly vendor-prefixed items
these still unconditionally require an import shim to be generated
because there's no way to describe that import in an ES-friendly way
(yet).

There's a few consequences of this commit which are also worth noting:

* The logic in `wasm-bindgen` where it gracefully handles (to some
  degree) not-defined items now only is guaranteed to be applied to the
  global namespace. If you import from a module, it'll be an
  instantiation time error rather than today's runtime error when the
  import is called.

* Handling imports in the wasm module not registered with
  `#[wasm_bindgen]` has become more strict. Previously these imports
  were basically ignored, leaving them up for interpretation depending
  on the output format. The changes for each output target are:

  * `bundler` - not much has changed here. Previously these ignored
    imports would have been treated as ES module imports, and after this
    commit there might just be some more of these imports for bundlers
    to resolve.

  * `web` - previously the ignored imports would likely cause
    instantiation failures because the import object never actually
    included a binding for other imports. After this commit though the
    JS glue which instantiates the module now interprets all
    unrecognized wasm module imports as ES module imports, emitting an
    `import` directive. This matches what we want for the direct import
    functionality, and is also largely what we want for modules in
    general.

  * `nodejs` - previously ignored imports were handled in the
    translation shim for Node to generate `require` statements, so they
    were actually "correctly handled" sort of with module imports. The
    handling of this hasn't changed, and reflects what we want for
    direct imports of values where loading a wasm module in Node ends up
    translating the module field of each import to a `require`.

  * `no-modules` - this is very similar to the `web` target where
    previously this didn't really work one way or the other because we'd
    never fill in more fields of the import object when instantiating
    the module. After this PR though this is a hard-error to have
    unrecognized imports from `#[wasm_bindgen]` with the `no-modules`
    output type, because we don't know how to handle the imports.

  Note that this touches on #1584 and will likely break the current use
  case being mentioned there. I think though that this tightening up of
  how we handle imports is what we'll want in the long run where
  everything is interpreted as modules, and we'll need to figure out
  best how wasi fits into this.

This commit is unlikely to have any real major immediate effects. The
goal here is to continue to inch us towards a world where there's less
and less JS glue necessary and `wasm-bindgen` is just a polyfill for web
standards that otherwise all already exist.

Also note that there's no explicitly added tests for this since this is
largely just a refactoring of an internal implementation detail of
`wasm-bindgen`, but the main `wasm` test suite has many instances of
this path being taken, for example having imports like:

    (import "tests/wasm/duplicates_a.js" "foo" (func $__wbg_foo_969c253238f136f0 (type 1)))
    (import "tests/wasm/duplicates_b.js" "foo" (func $__wbg_foo_027958cb2e320a94 (type 0)))
    (import "./snippets/wasm-bindgen-3dff2bc911f0a20c/inline0.js" "trivial" (func $__wbg_trivial_75e27c84882af23b (type 1)))
    (import "./snippets/wasm-bindgen-3dff2bc911f0a20c/inline0.js" "incoming_bool" (func $__wbg_incomingbool_0f2d9f55f73a256f (type 0)))
2019-07-31 12:28:24 -07:00
38b8232f55 Merge pull request #1688 from alexcrichton/llvm-9-threads
Fully update threading support for LLVM 9
2019-07-30 14:01:20 -05:00
8cb792474c Fully update threading support for LLVM 9
Support has landed in rust-lang/rust for full support for LLVM 9's
interpretation of WebAssembly threads. This commit updates our thread
transformation pass to take all this into account, namely:

* The threadign pass now runs by default and is keyed on whether memory
  is shared, not off an env var.
* TLS is initialized in addition to memory on each thread.
* Stack pointer finding is tweaked to account for the TLS base also
  being a mutable global.
* The build of the parallel raytrace example was updated to use today's
  nightly.
2019-07-30 09:17:23 -07:00
849c3453d9 Merge pull request #1687 from alexcrichton/in-memory
Add support to emit output to memory
2019-07-30 10:47:02 -05:00
8b0143669e Merge pull request #1686 from alexcrichton/update-walrus
Update to walrus 0.10.0
2019-07-30 10:46:44 -05:00
10e400bee4 Add support to emit output to memory
Don't necessarily require a filesystem to execute `wasm-bindgen`,
allowing the `wasm-bindgen-cli-support` crate to be compiled to
WebAssembly, for example, and possibly run `wasm-bindgen` in your
browser! For now this is largely just an internal refactoring and won't
result in many use cases, but it felt like a good refactoring to have
regardless.
2019-07-30 08:08:17 -07:00
7158144932 Update to walrus 0.10.0
Ensure that we enable the new `parallel` feature in the CLI so our tools all use
parallelized parsing, but none of our specific crates need it for usage.
2019-07-30 07:56:18 -07:00
8940ba0ab2 Merge pull request #1682 from alexcrichton/update-walrs
Update to walrus 0.9.0
2019-07-30 09:12:51 -05:00
78db35daac Merge pull request #1683 from alexcrichton/no-modules-lenient
Improve leniency of `--no-modules` output
2019-07-30 09:12:39 -05:00
423bebbd14 Improve leniency of --no-modules output
Instead of assuming names like `URL` and `Request` are defined, instead
check to see if they exist first and otherwise skip the checks that
reference them.
2019-07-29 14:49:15 -07:00
0daa290129 Update to walrus 0.9.0
This commit updates the `walrus` dependency with recent upstream API
changes in `walrus` itself, namely updates to passive segements and how
memory data segments are handled
2019-07-29 13:25:32 -07:00
68a1519eaa Merge pull request #1612 from Pauan/cache
Initial interning implementation
2019-07-22 14:02:40 -05:00
029b8ff249 Merge pull request #1675 from alexcrichton/llvm-9-threads
Update 'threads-xform' for LLVM 9
2019-07-22 09:12:57 -05:00
59af3186af Fixing CI build error 2019-07-19 23:32:58 +02:00
7b6ef7087e Adding in note to the intern docs 2019-07-19 23:29:34 +02:00
aef62bd56c Adding in enable-interning to CI test suite 2019-07-19 23:29:27 +02:00
f8da1e672f Fixing unsafe_get_str function 2019-07-19 22:15:07 +02:00
10ab4cbc18 Fixing TypeScript types for cached strings 2019-07-19 22:11:45 +02:00
554ef90035 Fixing issue with wasm-interpreter 2019-07-19 22:03:33 +02:00
b9b8c209d0 Update 'threads-xform' for LLVM 9
In LLVM 9 LLD has been updated to emit shared memory and passive
segments by default for threaded code, and `__wasm_init_memory` is a
function exported used to initialize memory. Update our
transform/runtime here to hook up all those wires correctly.

Closes #1631
2019-07-19 11:10:38 -07:00
efacd8b74d Merge pull request #1514 from ibaryshnikov/threadsafe-futures
Threadsafe futures
2019-07-19 09:38:04 -05:00
55b486ad78 Merge pull request #1673 from Pauan/web-sys-partial-eq
Adding in PartialEq and Eq to web-sys types
2019-07-19 08:49:52 -05:00
c82253ca68 Fixing doc test error 2019-07-18 23:40:16 +02:00
ed778f5eb2 Adding in PartialEq and Eq to web-sys types 2019-07-18 23:12:49 +02:00
b13f757e90 Shared more betwee legacy with/without atomics 2019-07-18 14:11:59 -07:00
be294c8248 Remove a debugging statement 2019-07-18 14:04:45 -07:00
c8451d6f3e Rename some files
* Use "legacy" instead of "stable" since `futures 0.1` is quicly
  becoming "legacy"
* Rename "atomics" to "legacy_atomics" to leave room for the
  libstd-based futures atomics version.
* Rename "polyfill" to "wait_async_polyfill" to specify what it's
  polyfilling.
2019-07-18 14:00:45 -07:00
d590a9e053 Deduplicate JsFuture definitions
Turns out it's the exact same for both before and after atomics, so
let's use the same definition!
2019-07-18 13:59:14 -07:00
cde9684e4b Clean up atomics/futures + polyfill
* Remove now-unneeded `State` enum
* Remove timeout argument from polyfill since we don't need it
* Call `Atomics.waitAsync` if it's available instead of using our polyfill
* Remove some extraneous dead code from the polyfill
* Add a `val: i32` argument to the polyfill
* Simplify the flow of futures with `Package` since `waitAsync` handles
  all the heavy lifting for us.
* Remove `Arc<Package>` and just use `Package`
* Remove `RefCell` from inside of `Package` now that it is no longer
  needed.
2019-07-18 13:55:54 -07:00
366ed2308f Adding in docs for intern 2019-07-18 22:40:56 +02:00
544ec49e02 Shifting the unsafe responsibility a bit 2019-07-18 22:21:48 +02:00
ca15a59ace Changing from uluru to HashMap 2019-07-18 21:51:29 +02:00
3177fa9edc Minor doc fix 2019-07-18 21:51:29 +02:00
2405fad319 Shifting the unsafety guarantees around 2019-07-18 21:51:29 +02:00
c3676bc6f9 Removing unneeded if statement 2019-07-18 21:51:29 +02:00
8572255e73 Making uluru optional 2019-07-18 21:51:29 +02:00
adf21fe6cb Removing unneeded size argument 2019-07-18 21:51:29 +02:00
cc6ec867f7 Fixing compile errors 2019-07-18 21:51:28 +02:00
1723e9d024 More simplifications 2019-07-18 21:51:28 +02:00
1e4cac9c95 Simplifying the output 2019-07-18 21:51:28 +02:00
4e504654d1 Undoing some formatting 2019-07-18 21:51:28 +02:00
fd88626e38 Fixing compile errors 2019-07-18 21:51:28 +02:00
2ee4c54f00 Changing to use WasmSlice for the caching 2019-07-18 21:51:28 +02:00
f7e8e70684 Fixing compile errors 2019-07-18 21:51:28 +02:00