Commit Graph

2860 Commits

Author SHA1 Message Date
Alex Crichton
afbd7d3ff8 Include self-pointer in Function descriptions
Previously a `Function` didn't actually take into account the self
pointer and instead left it as an implicit argument. This instead
ensures that there's a `Descriptor::I32` type inside of a `Function`
description that we have to later skip, and this should not only make
the anyref pass correct for Rust exports but it should also make it more
accurate for future webidl transformations.
2019-06-11 12:51:53 -07:00
Alex Crichton
ce4cc317e8 Correct some intrinsic signatures
While this doesn't currently cause issues in the upcoming webidl
refactor this is actually being asserted and causes verification issues
if the types don't align!

These are basically just mistakes from the original implementation of
this module, but this doesn't actually fix a known bug today.
2019-06-11 11:56:08 -07:00
Alex Crichton
621fc9c440 Remove the Clamped descriptor type
This is just a bit too general to work with and is pretty funky. Instead
just tweak `Clamped<&[u8]>` to naturally generate a descriptor for
`Ref(Slice(ClampedU8))`, requiring fewer gymnastics when interpreting
descriptors.
2019-06-11 11:52:13 -07:00
Alex Crichton
6796bc6895 Communicate exceptions through global memory
Instead of allocating space on the stack and returning a pointer we
should be able to use a single global memory location to communicate
this error payload information. This shouldn't run into any reentrancy
issues since it's only stored just before returning to wasm and it's
always read just after returning from wasm.
2019-06-11 11:41:05 -07:00
Alex Crichton
535aa3193c Attempt to fix compilation issues on CI
Can't reproduce the errors on Azure locally, but hopefully tweaking
generated code can get things to work.
2019-06-10 08:47:19 -07:00
Alex Crichton
c3e0edd956
Merge pull request #1586 from alexcrichton/no-web-sys
Make `env_logger` an optional dependency
2019-06-10 10:47:14 -05:00
Alex Crichton
a7726545ac
Merge pull request #1579 from ibaryshnikov/default-init-module
added default module path inside init function when target is web
2019-06-10 10:40:38 -05:00
Alex Crichton
5cf8224d99 Make env_logger an optional dependency
Only used during development no need to pull in its set of features when
typically compiled as a dependency of other crates!

Closes #1580
2019-06-10 07:12:44 -07:00
Alex Crichton
2e05b62013
Merge pull request #1583 from Pauan/asref
Adding in AsRef impl for all wasm_bindgen types
2019-06-10 09:05:22 -05:00
Pauan
b205045424 Adding in AsRef impl for all wasm_bindgen types 2019-06-10 08:05:59 +02:00
ibaryshnikov
8ace8287ff added default module path inside init function when target is web 2019-06-08 01:27:35 +03:00
Alex Crichton
96d333af84
Merge pull request #1577 from c410-f3r/getters-setters-ts
Fix getter and setter for TS
2019-06-07 10:10:22 -05:00
Caio
e7e8ae1877 Fix getter and setter 2019-06-06 16:11:51 -03:00
Alex Crichton
cf2a42ce7c
Merge pull request #1566 from alexcrichton/webidl-bindings-refactor-1
First refactor for WebIDL bindings
2019-06-05 15:05:40 -05:00
Alex Crichton
e24c03182b Attempt to fix CI 2019-06-05 12:26:10 -07:00
Alex Crichton
59e773f5ec Update walrus 2019-06-05 11:08:04 -07:00
Alex Crichton
bf1a31e139 Don't generate a free function shim for classes
This was once required due to flavorful management of the `WeakRef`
proposal but nowadays it's simple enough that we don't need to refactor
it out here.
2019-06-05 07:52:14 -07:00
Alex Crichton
6e8c3e88f8 Directly import __wrap functions if possible
These can have similar optimizations as importing a value directly.
2019-06-05 07:52:14 -07:00
Alex Crichton
c22b907e7f Touch up some comments 2019-06-05 07:52:14 -07:00
Alex Crichton
ee426c03a9 Ensure that generated JS is deterministic
Iteration order of hash maps is nondeterministic, so add a `sorted_iter`
function and then use that throughout whenever iteration order of a hash
map would affect the generated JS.
2019-06-05 07:52:14 -07:00
Alex Crichton
cfd3e0406f Split symbol intrinsics into two
This allows using WebIDL bindings types to describe both of them instead
of having a custom ABI, allowing for more direct and rich bindings
eventually!
2019-06-05 07:52:14 -07:00
Alex Crichton
6f727d7c13 Refactor the module name slightly in gen_init 2019-06-05 07:52:14 -07:00
Alex Crichton
4eafaeae2d Handle the function table export on-demand
Don't delay processing until `finalize`, but instead process it as soon
as it's requested to avoid doing too much logic in `finalize`.
2019-06-05 07:52:14 -07:00
Alex Crichton
71209686e9 Use unwrap_call instead of an explicit match 2019-06-05 07:52:14 -07:00
Alex Crichton
c7021ba307 Update crates/cli-support/src/js/mod.rs
Co-Authored-By: Nick Fitzgerald <fitzgen@gmail.com>
2019-06-05 07:52:14 -07:00
Alex Crichton
3b5e3edd18 Fix anyref closure transformations
* Catch all closures by walking all `Descriptor` values and looking for
  either `Function` or `Closure`.
* Update the correct arguments for wasm by ensuring that the closure
  modifications skip the first two arguments.
2019-06-05 07:52:14 -07:00
Alex Crichton
b51df39bc9 Reimplement anyref processing and passes
This commit reimplements the `anyref` transformation pass tasked with
taking raw rustc output and enhancing the module to use `anyref`. This
was disabled in the previous commits during refactoring, and now the
pass is re-enabled in the manner originally intended.

Instead of being tangled up in the `js/mod.rs` pass, the anyref
transformation now happens locally within one module,
`cli-support/src/anyref.rs`, which exclusively uses the output of the
`webidl` module which produces a WebIDL bindings section as well as an
auxiliary wasm-bindgen specific section. This makes the anyref transform
much more straightforward and local, ensuring that it doesn't propagate
elsewhere and can be a largely local concern during the transformation.

The main addition needed to support this pass was detailed knowledge of
the ABI of a `Descriptor`. This knowledge is already implicitly
hardcoded in `js2rust.rs` and `rust2js.rs` through the ABI shims
generated. This was previously used for the anyref transformation to
piggy-back what was already there, but as a separate pass we are unable
to reuse the knowledge in the binding generator.

Instead `Descriptor` now has two dedicated methods describing the
various ABI properties of a type. This is then asserted to be correct
(all the time) when processing bindings, ensuring that the two are kept
in sync.
2019-06-05 07:52:14 -07:00
Alex Crichton
55fc5367a5 Fix a typo in the JsvalEq intrinsic
This is supposed to be `===`, not `==`.
2019-06-05 07:52:14 -07:00
Alex Crichton
cbd4b87d08 Fix handling imported memories
Need to make sure we update the import itself and configure the value on
the import object!
2019-06-05 07:52:14 -07:00
Alex Crichton
81fbc642f4 Don't pass strings in raytrace-parallel example
Make sure to explicitly parse strings to numbers
2019-06-05 07:52:14 -07:00
Alex Crichton
b4c395bd6e Fix an inverted condition for catch_and_throw 2019-06-05 07:52:14 -07:00
Alex Crichton
edd1469d21 Include docs in generated JS getters/setters 2019-06-05 07:52:14 -07:00
Alex Crichton
164712c305 Temporarily ignore intentionally failing test 2019-06-05 07:52:14 -07:00
Alex Crichton
cba1e70077 Fix TypeScript output for fields 2019-06-05 07:52:14 -07:00
Alex Crichton
ff0a50e31e Fix failing interpreter tests 2019-06-05 07:52:14 -07:00
Alex Crichton
346868f78b Fix a failing CLI test 2019-06-05 07:52:14 -07:00
Alex Crichton
22b26db911 Use delete_typed to improve some ergonomics 2019-06-05 07:52:14 -07:00
Alex Crichton
e8e84a3f9c Remove __exports map on the web target
This is no longe rneeded now that we precisely track what needs to be
exported for an imported item, so all the imports are hooked up
correctly elsewhere without the need for the `__exports` map.
2019-06-05 07:52:14 -07:00
Alex Crichton
3e28e6ea46 Fix web, no-modules, and bundler output types
Make sure the wasm import definition map is hooked up correctly!
2019-06-05 07:52:14 -07:00
Alex Crichton
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
Alex Crichton
b11b6dfe5d
Merge pull request #1573 from not-an-aardvark/implement-flat-and-flatmap
Add Array#flat and Array#flatMap to js-sys (fixes #1454)
2019-06-04 09:59:40 -05:00
Teddy Katz
5c5c13cf9e
Add Array#flat and Array#flatMap to js-sys (fixes #1454) 2019-06-03 18:32:58 -04:00
Nick Fitzgerald
6ac61b5feb
Merge pull request #1572 from alexcrichton/dictionary-fields
Fix small issues around web-sys dictionaries
2019-06-03 13:49:20 -07:00
Alex Crichton
117928f0c0 Add doc comments to web-sys dictionaries/fields
This commit ensures that web-sys generated dictionaries and fields all
have comments like interfaces do, indicating a bare minimum of what's
happening as well as the required features to enable the API.
2019-06-03 13:18:38 -07:00
Alex Crichton
877c31cdc8 web-sys: Don't remove dictionaries if required fields are removed
This commit updates the conditional binding generation for dictionaries
to ensure that a dictionary is not entirely removed if any of its
required fields are removed. If a required field is removed, however, it
cannot be constructed, so the constructor is removed.
2019-06-03 12:57:21 -07:00
Alex Crichton
618b5d3531
Merge pull request #1571 from alexcrichton/less-warnings
Use `dyn` with all trait objects
2019-06-03 11:54:29 -05:00
Alex Crichton
82467f9793 Use dyn with all trait objects
Fixes new warnings showing up on nightly nowadays.
2019-06-03 08:28:55 -07:00
Alex Crichton
f3adee7056 Squash warnings about unused variables
Make sure when compiling for non-wasm targets we don't issue tons of
warnings about unused variables which can't be squashed.
2019-06-03 08:25:07 -07:00
Alex Crichton
c876bd6268
Merge pull request #1570 from DiamondLovesYou/master
Support 8 argument closures.
2019-06-03 09:36:41 -05:00
Alex Crichton
9884c79bd9
Merge pull request #1546 from ibaryshnikov/websockets-example
added websockets example
2019-06-03 09:33:39 -05:00