Commit Graph

1932 Commits

Author SHA1 Message Date
Alex Crichton
68537b9649 Add an optimization to directly wire up imported functions
This commit adds an optimization to `wasm-bindgen` to directly import
and invoke other modules' functions from the wasm module, rather than
going through a shim in the imported bindings. This will be an important
optimization in the future for the host bindings proposal, but for now
it's largely just a proof-of-concept to show that we can do it and is
unlikely to bring about many performance benefits.

The implementation in this commit is largely refactoring to reorganize a
bit how functions are imported, but the implementation happens in
`generate_import_function`.

With this commit, 71/287 imports in the `tests/wasm/main.rs` suite get
hooked up directly to the ES modules, no shims needed!
2018-11-13 13:16:38 -08:00
Alex Crichton
c85f1b74e8
Merge pull request #1028 from alexcrichton/bump
Bump to 0.2.28
2018-11-12 12:31:26 -06:00
Alex Crichton
22ca15f81e Bump to 0.2.28 2018-11-12 09:28:01 -08:00
Alex Crichton
dc4e78550a
Merge pull request #1019 from alexcrichton/rfc-5
Implement rustwasm/rfcs#5, implement `Deref` for imports and `structural` by default
2018-11-12 10:59:46 -06:00
Alex Crichton
f3b9c69903
Merge pull request #1027 from rustwasm/dependabot/cargo/env_logger-0.6
Update env_logger requirement from 0.5 to 0.6
2018-11-12 09:12:35 -06:00
dependabot[bot]
d673d5cfff
Update env_logger requirement from 0.5 to 0.6
Updates the requirements on [env_logger](https://github.com/sebasmagri/env_logger) to permit the latest version.
- [Release notes](https://github.com/sebasmagri/env_logger/releases)
- [Commits](https://github.com/sebasmagri/env_logger/commits/v0.6.0)

Signed-off-by: dependabot[bot] <support@dependabot.com>
2018-11-12 08:17:10 +00:00
Alex Crichton
406581da7e
Merge pull request #1024 from alexcrichton/remove-names
Add a flag to remove the wasm name section
2018-11-09 16:15:14 -06:00
Alex Crichton
02cd0c5837
Merge pull request #1026 from alexcrichton/less-throw
Don't worry about descriptive strings for malloc errors
2018-11-09 16:14:22 -06:00
Nick Fitzgerald
d37052f8b4
Merge pull request #1025 from alexcrichton/fix-create
Fix `--no-modules` passing in `WebAssembly.Module`
2018-11-09 12:49:10 -08:00
Alex Crichton
2e82fdbe16 Don't worry about descriptive strings for malloc errors
This commit updates the `__wbindgen_malloc` shim to avoid throwing a
descriptive error in release mode. This is primarily done for two
reasons:

* If the function is gc'd out in release mode the `"invalid malloc
  request"` string is part of data and can't be gc'd automatically.

* In some esoteric JS environments `TextDecoder` isn't always available,
  and this relatively core function is very quick to bring in that
  requirement early on. For example some recent experimentation with
  WebAudio worklets shows that they currently don't have the
  `TextDecoder` type available!
2018-11-09 12:19:48 -08:00
Alex Crichton
37889d9fcd Fix --no-modules passing in WebAssembly.Module
This fixes a mistake in allowing a `WebAssembly.Module` to be passed to
the initialization function in `--no-modules` mode by ensuring that it
resolves to a map of an instance/module instead of just resolving to an
instance.
2018-11-09 12:15:36 -08:00
Alex Crichton
cb246e38fb Rename host_binding to final 2018-11-09 08:00:41 -08:00
Alex Crichton
2c9084d0e2 Update web-sys test to only test compilation 2018-11-09 07:56:48 -08:00
Alex Crichton
12fc09a124 Add a flag to remove the wasm name section
This commit adds a `--remove-name-section` flag to the `wasm-bindgen`
command which will remove the `name` section of the wasm file, used to
indicate the names of functions typically used in debugging. This flag
is off-by-default and will primarily be controlled by wasm-pack,
typically being passed by default with `wasm-pack build --release`.

Closes #1021
2018-11-09 07:45:19 -08:00
Alex Crichton
4c4f8f16bd
Merge pull request #1023 from jrvidal/master
Fix reference to unexisting method
2018-11-09 09:24:14 -06:00
Roberto Vidal
2faf44250d Fix reference to unexisting method 2018-11-09 13:14:16 +01:00
Alex Crichton
8ba467e905 Disallow both structural and host_binding 2018-11-08 16:47:46 -08:00
Nick Fitzgerald
227e836e04
Merge pull request #1020 from fitzgen/move-by-value-debug-asserts
Only emit JS glue assertions for move arguments in debug mode
2018-11-08 15:37:41 -08:00
Nick Fitzgerald
75c18f0916 Only emit JS glue assertions for move arguments in debug mode 2018-11-08 15:08:46 -08:00
Alex Crichton
4c42aba007 Switch all imports to structural by default
This commit switches all imports of JS methods to `structural` by
default. Proposed in [RFC 5] this should increase the performance of
bindings today while also providing future-proofing for possible
confusion with the recent addition of the `Deref` trait for all imported
types by default as well.

A new attribute, `host_binding`, is introduced in this PR as well to
recover the old behavior of binding directly to an imported function
which will one day be the precise function on the prototype. Eventually
`web-sys` will switcsh over entirely to being driven via `host_binding`
methods, but for now it's been measured to be not quite as fast so we're
not making that switch yet.

Note that `host_binding` differs from the proposed name of `final` due
to the controversy, and its hoped that `host_binding` is a good
middle-ground!

[RFC 5]: https://rustwasm.github.io/rfcs/005-structural-and-deref.html
2018-11-08 13:52:18 -08:00
Alex Crichton
6093fd29d1 Don't convert boolean arguments going to wasm
The wasm spec defines boolean conversion when crossing to the wasm type
i32 as 1 for `true` and 0 for `false`, so no need for us to do it
ourselves!
2018-11-08 13:06:03 -08:00
Alex Crichton
a16b4dd9a4 Optimize shim generation for structural items
This commit removes shims, where possible, for `structural` items.
Instead of generating code that looks like:

    const target = function() { this.foo(); };
    exports.__wbg_thing = function(a) { target.call(getObject(a)); };

we now instead generate:

    exports.__wbg_thing = function(a) { getObject(a).foo(); };

Note that this only applies to `structural` bindings, all default
bindings (as of this commit) are still using imported targets to ensure
that their binding can't change after instantiation.

This change was [detailed in RFC #5][link] as an important optimization
for `structural` bindings to ensure they've got performance parity with
today's non-`structural` default bindings.

[link]: https://rustwasm.github.io/rfcs/005-structural-and-deref.html#why-is-it-ok-to-make-structural-the-default
2018-11-08 13:04:38 -08:00
Alex Crichton
58c3a99f94 Fix a test to actually test the right property
This was a copy/paste typo!
2018-11-08 12:30:40 -08:00
Alex Crichton
64a6241960 Fix tagging static methods as structural 2018-11-08 11:50:34 -08:00
Alex Crichton
b013ec6288 Use splat instead of arguments in tests
Previously `arguments` was used to pass around an array of arguments,
but this wasn't actually a `js_sys::Array` but rather a somewhat
esoteric internal object. When switching over `Array` methods to be
`structural` this caused issues because the inherent methods on an
`arguments` object were different than that of `js_sys::Array`.
2018-11-08 11:46:52 -08:00
Alex Crichton
5b76a6291e Implement Deref for all imported JS types
This commit implements the first half of [RFC #5] where the `Deref`
trait is implemented for all imported types. The target of `Deref` is
either the first entry of the list of `extends` attribute or `JsValue`.

All examples using `.as_ref()` with various `web-sys` types have been
updated to the more ergonomic deref casts now. Additionally the
`web-sys` generation of the `extends` array has been fixed slightly to
explicitly list implementatoins in the hierarchy order to ensure the
correct target for `Deref` is chosen.

[RFC #5]: https://github.com/rustwasm/rfcs/blob/master/text/005-structural-and-deref.md
2018-11-08 11:01:34 -08:00
Alex Crichton
d646b29bb7
Merge pull request #1014 from alexcrichton/more-types
Make `to_idl_type` infallible
2018-11-07 15:32:45 -06:00
Nick Fitzgerald
5baa6ed3b2
Merge pull request #1015 from alexcrichton/example-changes
Don't use path dependencies in examples
2018-11-07 13:31:23 -08:00
Alex Crichton
56400c3738 Don't use path dependencies in examples
This commit updates all examples to not use `path` dependencies but
rather use versioned dependencies like would typically be found in the
wild. This should hopefully make the examples more copy-pastable and
less alien to onlookers!

The development of the examples remains the same where they continue to
use the `wasm-bindgen`, `js-sys`, `web-sys`, etc from in-tree. The
workspace-level `[patch]` section ensures that they use the in-tree
versions instead of the crates.io versions.
2018-11-07 11:27:43 -08:00
Jake Riesterer
3d1f4263ad Change UnionType to IdlType::Union function to include any supported types instead of returning None when there is at least one unsupported type
For example, the constructor in Response.webidl accepts multiple types. However, one of those types is `ReadableStream` which isn't defined yet, and that causes all constructors for Response to be skipped even though the other argument types could be supported.
2018-11-07 10:39:22 -08:00
Alex Crichton
176eedc63b Make to_idl_type infallible
This commit makes the `to_idl_type` infallible, returning a new enum
variant, `UnknownInterface`, in the one location that we still return
`None`. By making this infallible we can ensure that expansion of unions
which have unknown types still generate methods for all the variants
which we actually have all the methods for!
2018-11-07 10:38:35 -08:00
Alex Crichton
ac6a230d83
Merge pull request #1012 from alexcrichton/rename-exported-type
Implement support for `js_class` on exported types
2018-11-05 17:44:21 -06:00
Alex Crichton
16d5243362 Implement support for js_class on exported types
Allow defining types which have different names in Rust than they have
in JS! (just like can be done with imported types)

Closes #1010
2018-11-05 12:29:14 -08:00
Nick Fitzgerald
7a528d4b6b
Merge pull request #1011 from alexcrichton/import-doc
Add a note about renaming types and `js_class`
2018-11-05 12:18:12 -08:00
Alex Crichton
9478a65e3c Add a note about renaming types and js_class
When a type is renamed in Rust via `js_name` then all method imports
will also need a `js_class` annotation to hook them up correctly.
2018-11-05 11:10:09 -08:00
Sendil Kumar N
3c31a32d51
Merge pull request #1008 from henriiik/optional-typescript-return-values
update typescript generation to reflect that Option<T> can be undefined
2018-11-05 01:35:25 +01:00
Henrik Sjööh
d331b706c3 update typescript generation to reflect that Option<T> can be undefined 2018-11-04 10:26:20 +01:00
Alex Crichton
0d5f514709
Merge pull request #996 from alexcrichton/gc-tests
Add tests for the wasm-gc crate
2018-10-31 10:03:35 -05:00
Alex Crichton
40b68c66d9 Fix a bug in coalescing types with GC
When a duplicate type is found is should no longer be considered used!
2018-10-30 15:45:21 -07:00
Alex Crichton
31c11f0781 GC passive segments
We statically know which passive segments are actually used, so let's be
sure to gc them!
2018-10-29 16:49:02 -07:00
Alex Crichton
91d68a0012 Add tests for the wasm-gc crate
This commit adds a test harness and the beginnings of a test suite for
the crate that performs GC over a wasm module. This crate historically
has had zero tests because it was thought that it would no longer be
used once LLD landed with `--gc-sections`, but `wasm-bindgen` has come
to rely more and more on `wasm-gc` for various purposes.

The last release of `wasm-bindgen` was also released with a bug in the
recently refactored support in the `wasm-gc` crate, providing a perfect
time and motivation to start writing some tests!

All tests added here are `*.wat` files which contain the expected output
after the gc pass is executed. Tests are automatically updated with
`BLESS_TESTS=1` in the environment, which is the expected way to
generate the output for each test.
2018-10-29 15:49:35 -07:00
Alex Crichton
6dfbb4be89 Bump to 0.2.27 2018-10-29 14:30:33 -07:00
Alex Crichton
b1d92aecac
Merge pull request #995 from alexcrichton/gc-too-aggressive
Assume all data/element/table/memory segments needed
2018-10-29 14:16:59 -07:00
Alex Crichton
a0a9ed4686
Merge pull request #986 from alexcrichton/gc-types
Eliminate duplicate types in the type section
2018-10-29 14:11:58 -07:00
Alex Crichton
d172c20b76 Assume all data/element/table/memory segments needed
wasm-gc is in dire need of a better test suite, so I'll work on that
before attempting to de-pessimize this.

Closes #994
2018-10-29 14:06:06 -07:00
Alex Crichton
93564f159f Fix build of TODO MVC on stable 2018-10-29 13:47:09 -07:00
Alex Crichton
9a3ef7b747
Merge pull request #961 from jonathanKingston/todo-mvc
Todo mvc
2018-10-29 13:24:59 -07:00
Alex Crichton
bb28f76906 Try to improve the publish script 2018-10-29 13:08:22 -07:00
Alex Crichton
7fad2bf0c8 Bump to 0.2.26 2018-10-29 12:56:37 -07:00
Alex Crichton
27001a226d Eliminate duplicate types in the type section
This commit updates the `wasm-gc` pass of wasm-bindgen to eliminate
duplicate types in the type section, effectively enabling a gc of the
type section itself. The main purpose here is ensure that code generated
by `wasm-bindgen` itself doesn't have to go too far out of its way to
deduplicate at generation time, but rather it can rely on the gc pass to
clean up.

Note that this currently depends on paritytech/parity-wasm#231, but this
can be updated if that ends up not landing.
2018-10-29 12:04:11 -07:00