Commit graph

30 commits

Author SHA1 Message Date
Ömer Sinan Ağacan 1d8dde36e1 [dart2wasm] Add array.copy instruction and intrinsics
`array.copy` is used in [1] in `setRange` when source and destinations
are both typed arrays with the same Wasm array type.

[1]: https://dart-review.googlesource.com/c/sdk/+/312907

Change-Id: Iaeecea43c22805eca64b7d98751a52e607210a70
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/314080
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-07-17 16:51:25 +00:00
Ömer Sinan Ağacan ef01fbf60a [dart2wasm] Close parens in compile-time error messages
Change-Id: I1f4582317f1df26624978f91ad2d52f39001cb7a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293542
Reviewed-by: Joshua Litt <joshualitt@google.com>
Auto-Submit: Ömer Ağacan <omersa@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
2023-04-05 16:36:27 +00:00
Devon Carew 1dcb466924 [pkg/wasm_builder] use package:lints/recommended.yaml
Change-Id: Id5bda808afbc2404e7fdd2586c64dfe9521f5be3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/282382
Commit-Queue: Devon Carew <devoncarew@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2023-02-13 17:57:24 +00:00
Joshua Litt 130903685d [dart2wasm] Avoid implicitly internalizing WasmExternRef.
CoreLibraryReviewExempt: Wasm only changes.
Change-Id: I0e0a6cddffa1c7f2d7c74779f480dd10bf509c1c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279268
Commit-Queue: Joshua Litt <joshualitt@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2023-02-10 16:22:47 +00:00
Ömer Sinan Ağacan 4c89d9f6e2 [dart2wasm] Improve Wasm stack error messages
Currently if I generate a `call` with incorrect number of values on
stack, I get an error like:

    Unhandled exception:
       local.get 0                i64
       i64.const 1073741823       i64, i64
       i64.gt_u                   i32
       L1: if () -> ()
         local.get 0              i64
         i64.const 0              i64, i64
         i64.const 1073741823     i64, i64, i64
         ref.null Object          i64, i64, i64, ref null Object

    Underflowing base stack of innermost block

After this I usually need to check the type of the function being called
to see how many arguments it's expecting, with their types.

With this change we now report:

    Unhandled exception:
       local.get 0                i64
       i64.const 1073741823       i64, i64
       i64.gt_u                   i32
       L1: if () -> ()
         local.get 0              i64
         i64.const 0              i64, i64
         i64.const 1073741823     i64, i64, i64
         ref.null Object          i64, i64, i64, ref null Object

    Underflowing base stack of innermost block: expected [i64, i64, i64, ref null Object, ref null Object], but stack contained [i64, i64, i64, ref null Object]

Change-Id: I3191ebf6112e90d341cd121a2afd2fc858282c68
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279089
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-01-18 10:13:19 +00:00
Aske Simon Christensen b8f0fda3dd [dart2wasm] Switch to the new WasmGC test/cast instructions
Also implements various related changes to the WasmGC spec:
- Remove `dataref` and add `structref` and `arrayref`.
- Use new encoding for `array.len` without immediate.

Change-Id: Ic1ba67fad694c453fbdae277f5a7e4c94695977f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/266200
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2023-01-12 14:08:56 +00:00
Jackson Gardner 94475e05f3 [dart2wasm] Emit a generic error for non-dart exceptions coming from JS.
Change-Id: I1a3cb5f5c264c6a8ea1d68da480f7672cf399251
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/278371
Commit-Queue: Jackson Gardner <jacksongardner@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2023-01-10 20:36:28 +00:00
Aske Simon Christensen f053d2170d [dart2wasm] Put function types of imports in singleton rec groups
Starting from ba6be821c99db09b0ef2689dea8f0cb863c47ff5 (11.0.194), V8
enforces type equivalence according to the canonical iso-recursive
types for functions imported from other modules or constructed using
`WebAssembly.Function`, which means that to match such a type, a
function type declared in a Wasm module must be declared in a
singleton rec group.

To be compatible with this new canonicalization scheme, we define the
function types for all imported functions each in their own rec group
separately from other types.

Change-Id: I166b4b7d1c8fa48638f816f874f737536a61f15d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274388
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
2022-12-13 20:43:22 +00:00
Aske Simon Christensen 2846cb8da6 [dart2wasm] Add Wasm bottom heap types
- Add getters for the top and bottom types of the WasmGC hierarchy
  that a type belongs to.
- Rename the internal common supertype from `top` to `common` to avoid
  confusion with the top type of each hierarchy.
- Always use a bottom type when emitting a `ref.null` instruction.
- Translate the `Null` and `Never` Dart types to WasmGC `nullref`.

Change-Id: I43ba5da222a848214647980f7b4876940546242a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/268463
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2022-11-18 11:43:52 +00:00
Aske Simon Christensen eaa2ea9aab [dart2wasm] Switch back opcode for call_ref
V8 and Binaryen now both accept a function type immediate for the
version of call_ref using the proper opcode value of 0x14.

Change-Id: I1010de82d97df0ff80ff1365e2f827d7fd78eb81
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/266162
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2022-11-17 12:59:48 +00:00
Ömer Sinan Ağacan d01dd13a17 [dart2wasm] Minor refactoring in ClassInfoCollector
The interaction between `Translator` and other types like
`ClassInfoCollector` is quite complicated. This patch refactors a few
things to make it slightly simpler.

Changes:

- Add documentation to a few fields, minor rewording in a few other
  field documentation.

- Make `ClassInfoCollector`'s `nextClassId`, `computeRepresentation`,
  `addTypedDataFields` private.

- Initialize of `ClassInfo`'s `nullableType`, `nonNullableType` in
  constructor.

Change-Id: I48e55029844ff41d9f043aac004a1abad8df83dd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/265281
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2022-10-28 17:43:08 +00:00
Aske Simon Christensen c975c5c713 [dart2wasm] Add function type immediate to call_ref
The encoding uses the 0x17 opcode temporarily assigned to `call_ref`
with immediate in V8 and Binaryen for transitioning from `call_ref`
without immediate. After V8 and Binaryen change the proper 0x14
encoding to accepting an immediate, we can switch back to 0x14.

Change-Id: Ib84c62068e73a101d23a1bbd7eb3b893ef7a1493
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/258802
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2022-10-28 16:25:58 +00:00
Joshua Litt f0ab6fb6ef [dart2wasm] Fix memory definition.
Size is number of 64kb pages.

Change-Id: I4c2876ebee553d0dc219e8dd8bb6b1169799a465
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/257260
Commit-Queue: Joshua Litt <joshualitt@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2022-09-06 18:25:36 +00:00
Aske Simon Christensen a85157e233 [dart2wasm] Convert to/from externref via Wasm instructions
This adds support for the newly added `extern.externalize` and
`extern.internalize` instructions and uses these for converting to/from
`externref` instead of a JS round-trip.

Change-Id: If18d8f44ddf013d4c26bf1597be91bcd0db41c5a
Cq-Include-Trybots: luci.dart.try:dart2wasm-linux-x64-d8-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/255462
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
2022-08-19 07:11:18 +00:00
Aske Simon Christensen b1c0992199 [dart2wasm] Implement the three-pronged WasmGC type hierarchy.
This splits the type hierarchy into three separate hierarchies with
the top types `any`, `func` and `extern`.

Update d8 to 10.6.91, which switches to the new type hierarchy.

Also, all ref shorthands for abstract heap types are now nullable, so
the type emitter in the `wasm_builder` is updated to follow that scheme.

To reduce confusion about the nullability of abstract reference types,
these now all require the nullability to be specified explicitly.

Change-Id: I4774d08cbed18307e481c466b2e3402a8d8fb6bd
Cq-Include-Trybots: luci.dart.try:dart2wasm-linux-x64-d8-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/255060
Reviewed-by: Joshua Litt <joshualitt@google.com>
2022-08-19 07:11:18 +00:00
Aske Simon Christensen 5ea5e3f0b2 [dart2wasm] Remove RTT support and emit isorecursive types
Relatedly, remove the --nominal-types and --runtime-types options and
eliminate the instruction and type wrappers that abstracted over these
options.

Rename instructions to the names in the latest WasmGC working draft.

Change-Id: Icd0e4bbcf444d5a3cea1f88f4e3bf8dd2926f70f
Cq-Include-Trybots: luci.dart.try:dart2wasm-linux-x64-d8-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/254902
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
2022-08-16 08:31:57 +00:00
Aske Simon Christensen 9814b569ba [dart2wasm] Remove support for not using non-nullable locals.
With the decision to support non-nullable locals in WasmGC as per
https://github.com/WebAssembly/function-references/issues/44 the
support in dart2wasm for forcing all locals to be nullable is no
longer needed.

This CL removes that support and cleans up some related nullability
issues. Specifically:

- Remove the `--local-nullability` and `--parameter-nullability`
  commandline options. These are now always enabled.
- Clean out special cases around forced nullable locals throughout the
  compiler.
- Make `thisLocal` and `preciseThisLocal` always non-nullable.
- Make `returnValueLocal` (for storing the return value of `return`
  statements inside `try` blocks with `finally`) always defaultable,
  since its initialization flow crosses control constructs.
- Make type argument parameters non-nullable.
- Make non-nullable `FutureOr` translate to a non-nullable Wasm type.
- Implement the "initialized until end of block" validation scheme
  in the Wasm instruction validator.
- Run tests with the `--experimental-wasm-nn-locals` option. This
  is likely going away soon, but for now we need it.

Change-Id: I05873dd70510af5944d86d37cb5765c7bdef73a9
Cq-Include-Trybots: luci.dart.try:dart2wasm-linux-x64-d8-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/252600
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Reviewed-by: William Hesse <whesse@google.com>
2022-07-27 22:47:30 +00:00
Aske Simon Christensen d8d9e06804 [dart2wasm] Support defining, exporting and accessing Wasm tables
Tested: Added tests/web/wasm/table_test.dart
Change-Id: I3971f4432a7a59bd6bc9874fc96202a7a9f2283d
Cq-Include-Trybots: luci.dart.try:dart2wasm-linux-x64-d8-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/248586
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
2022-07-19 13:06:54 +00:00
Devon Carew bc0bb9e257 [pkg/wasm_builder] analyze with package:lints
Change-Id: Ie067adab896b9b73a7eb76a04d813b8acd7ac478
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/250763
Reviewed-by: Jackson Gardner <jacksongardner@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2022-07-07 21:31:28 +00:00
Aske Simon Christensen 90a45668d5 [dart2wasm] Support all import and export kinds in wasm_builder
Also makes table type explicit and fixes a bug in element serialization
for tables beyond index 0.

Change-Id: I7c27071e00331c41010da771ae0075e798e457a9
Cq-Include-Trybots: luci.dart.try:dart2wasm-linux-x64-d8-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/247545
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2022-06-10 12:41:45 +00:00
Aske Simon Christensen b6e912d9f0 [dart2wasm] Use super parameters in wasm_builder
Change-Id: Idfcec5f78aaba230758e06682326af0755dfaa87
Cq-Include-Trybots: luci.dart.try:dart2wasm-linux-x64-d8-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/247388
Reviewed-by: Joshua Litt <joshualitt@google.com>
2022-06-10 12:41:45 +00:00
Devon Carew f7c46f145c [pkg] prefer 'any' deps for package dev dependencies
Tested: CI validation
Change-Id: If65cc156130a65ffe00c6f1660ac320e2921afae
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/246053
Commit-Queue: Devon Carew <devoncarew@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
2022-05-27 01:34:59 +00:00
Aske Simon Christensen 34bfee7ada [dart2wasm] Remove externref and use the new value for anyref.
This matches the spec after anyref and externref were merged, and it's
necessary in order to use the latest Binaryen, which has removed support
for the old value.

Change-Id: I7f1bb5cb08637dd79fe975603d8e236d73ca4fdc
Cq-Include-Trybots: luci.dart.try:dart2wasm-linux-x64-d8-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/245375
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2022-05-23 10:08:00 +00:00
Aske Simon Christensen 7b1675f1a5 [dart2wasm] Abbreviate high stacks in textual instruction trace.
This avoids a pathological case in some tests.

Change-Id: Ib713ad08eb613a709949bee07fa1e583e15cad9c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/245163
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2022-05-20 12:15:32 +00:00
Jackson Gardner 6466bac7cd Add support for importing shared memory as per wasm threading proposal.
Change-Id: I077b8d3a60f543c3e54cd3e6d024260adcb8ed83
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241420
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Jackson Gardner <jacksongardner@google.com>
2022-04-22 22:40:29 +00:00
Aske Simon Christensen fec466e3fe [dart2wasm] Add Wasm function references and more Wasm ref conversions
Having first-class Wasm function references makes it possible to call
JS function objects directly from Dart, and to call some Dart functions
(static functions with no optional parameters and no type parameters)
from JS as function objects.

Change-Id: I1c788338d418c8857493ec76560d74fdd17d5dd2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241001
Reviewed-by: Joshua Litt <joshualitt@google.com>
Reviewed-by: Jackson Gardner <jacksongardner@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2022-04-19 09:40:17 +00:00
Aske Simon Christensen c2339ee782 [dart2wasm] Basic FFI support
Implements memory access through the `Pointer`, `Struct` and `Union` FFI
types. `Pointer` supports `fromAddress`, `address`, `elementAt`, `cast`,
`value`, `ref` (only getter), `[]`, `[]=` (not for structs and unions),
`==` and `hashCode`. Structs and unions support getters and setters for
their members.

`Pointer`, `Struct` and `Union` are all represented as `i32`, both
internally and in imports and exports. They currently don't have any
boxed representation, which means they can't be nullable (a `Pointer`
can still contain `nullptr` - the C null) and can't be assigned to
supertypes (i.e. `Object`, `dynamic`, type variables), stored in
containers nor passed as arguments or return values of local functions
or function expressions. To pass an FFI value in these situations, box
it manually by storing it in a field.

For the FFI integer types, only the explicitly sized versions (e.g.
`Int8`, `Uint32`) are supported.

Whenever the feature is used, the module will import a memory by the
name "ffi.memory", which will be accessed by the operations.

This also adds an optional commandline argument to `run_wasm.js` to
specify the module containing the FFI code. When such a module is
specified, it will be instantiated first, and its exports will appear as
imports to the Dart module under the "ffi" module name.

Change-Id: Ie55b072056f972b42db6b75e0c676944bbe88c1a
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/237686
Reviewed-by: Joshua Litt <joshualitt@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2022-03-22 14:05:28 +00:00
Joshua Litt 1b8eb6b213 [dart2wasm] Add basic support for exceptions.
This CL adds support for try, catch, throw, and rethrow. In addition, it
adds stack trace support. If functions have names then these will print
in the stack trace.

This CL flips an additional 53 tests to passing(5241 -> 5294). 1 test
which was passing on TOT now crashes at compile time due to
a missing language feature which is now reachable through compilation of
a catch block. A number of other tests flip from runtime errors to
compile time crashes due to similar issues.

Note: TryFinally is implemented in the follow on.

Change-Id: I740dd25c4e062e1be2f50bbd18d1302575dff6f1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/226808
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
2022-02-25 19:16:32 +00:00
Aske Simon Christensen 34c0296f6d OWNERS files for dart2wasm
Change-Id: I7d74013b27625d0a5d3e4d3d8f83aa4859fb4892
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/233303
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2022-02-17 09:26:23 +00:00
Aske Simon Christensen 6faa5f3bd0 [dart2wasm] Initial commit for the Dart-to-WasmGC compiler.
This is work in progress. Several language features are still
unimplemented or only partially implemented.

Instructions for running the compiler and its output can be found in
pkg/dart2wasm/dart2wasm.md. These procedures are preliminary and
expected to change.

The best version of d8 to use for this version of dart2wasm is 10.0.40,
as explained here: https://dart-review.googlesource.com/c/sdk/+/232097

This commit also adds a dart2wasm-hostasserts-linux-x64-d8 testing
configuration to run the compiler over the test suite.

The history of the prototype that this is based on can be seen here:

https://github.com/askeksa-google/sdk/tree/wasm_prototype

Issue: https://github.com/dart-lang/sdk/issues/32894

Change-Id: I910b6ff239ef9c5f66863e4ca97b39b8202cce85
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175728
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2022-02-16 11:11:14 +00:00