Change-Id: If63a5b3caa8fe300d97a722c3d42929457bae1e2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/326300
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Jackson Gardner <jacksongardner@google.com>
Commit-Queue: Jackson Gardner <jacksongardner@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Change-Id: I582f956cd4b712203c2f6dd630b4e1384040446d
Tested: analysis clean (this is a lint only related change)
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329400
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
There's no difference between a module watchpoints field being `null` or
`[]`, so the type `List<int>? watchPoints` can be simplified as
`List<int> watchPoints` and by treating empty list the same way as
previous `null`.
Change-Id: I9be8c872c4336b1c0bf5157af5e8587136cf2088
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/325261
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
The `--watch` debug option to print the stack trace leading to a
particular byte in the output Wasm file didn't work for instructions
after the instruction encoder was changed to produce intermediate
instruction objects.
This is fixed by keeping a map from instruction objects to stack
traces in the instructions builder and registering those stack traces
when serializing the instructions.
Change-Id: I90d665753813452d07783c7f47e1e6bf63a3a18e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/324681
Reviewed-by: Jess Lally <jessicalally@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
The Wasm validation rules state that the failure type is sharpened to
non-nullable if the cast target type is nullable.
Change-Id: I77596c31ea7443c5dace543d13024262879a5fb5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/318660
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
This CL mostly just moves code around. There are three broad changes in this CL:
1) Reify the builder / built pattern that exists implicitly in the existing code. Builders now live in `src/builder`, while the built ir lives in `src/ir`.
2) Reify the module subsections.
3) `pkg/dart2wasm` has been updated to use the new API.
There is only one minor logic change in the entire CL, we now defer serialization of a module until the bytes are actually required, as opposed to serializing eagerly.
This change is designed to make the wasm_builder more robust. By clearly delineating which parts of the AST are mutable and which parts are immutable, then it should make it easier for users of the wasm_builder to avoid undefined behavior, i.e. holding on to something that can change.
Change-Id: I676107b867aa74fabf413108673e170126bdb5c1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/316280
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
This CL lays the foundation for allowing us to emit instructions without finalizing imports, which will in turn enable more flexibility in code generation. For example, we will no longer need to do a pre-code generation pass to collect imports. In addition, it will pave the way for other optimizations as suggested in the `TODO` at the top of `instructions.dart`.
Perhaps counter-intuitively, even without any optimizations, this doesn't seem to be a measurable regression:
Before:
Completed compilation of dart2wasm-html-engine in 52652ms.
Completed compilation of dart2wasm-html-html in 51827ms.
Completed compilation of dart2wasm-html-ui in 20399ms.
Completed compilation of dart2wasm-canvaskit-canvaskit in 32899ms.
Completed compilation of dart2wasm-canvaskit-ui in 20695ms.
Completed compilation of dart2wasm-skwasm-ui in 20319ms.
After:
Completed compilation of dart2wasm-html-engine in 51476ms.
Completed compilation of dart2wasm-html-html in 48845ms.
Completed compilation of dart2wasm-html-ui in 19676ms.
Completed compilation of dart2wasm-canvaskit-canvaskit in 31933ms.
Completed compilation of dart2wasm-canvaskit-ui in 19733ms.
Completed compilation of dart2wasm-skwasm-ui in 19962ms.
Change-Id: Ib3740f88db56070fc3ccdde484675267e4bf40c1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/315580
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
This marks all types without subtypes as final and all types with
subtypes as non-final. This makes the emitted types maximally final
and is appropriate for a closed-world module.
V8 currently ignores the finality of types for the temporary WasmGC
encoding, which make our current encoding work even though it
implicitly marks some types as final that shouldn't be. For the final
WasmGC instruction encoding, V8 is likely to reject modules containing
final types with subtypes.
Change-Id: If3030c49e8fe60fec8099b731b6fcf618d6a7e64
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310163
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
- Use `array.copy` and `array.fill` when possible.
- Use the Wasm array directly (instead of `[]` and `[]=`) when possible
to avoid redundant bounds checks.
- `_GrowableList.insert` is rewritten to avoid a redundant write when
the element is not added to the end.
- Remove redundant bounds checks when calling `Lists.copy`.
Change-Id: I08d96b56201cbb4ff24ca969b7fde8bcc1315e4b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/315120
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
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>
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>
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>
- 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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>