Commit Graph

58 Commits

Author SHA1 Message Date
Simon Binder b4cfeb1093 dart2wasm: Prepare standalone target
When compiled to WebAssembly, the Dart SDK needs access to external
host functions to implement regular expressions, stack traces, timers
and more. Currently, `dart2wasm` relies on `js_interop` definition to
implement these functions in JavaScript.

As discussed in https://github.com/dart-lang/sdk/issues/53884, an
alternative is to use `wasm:import` annotations to let an arbitrary
embedder that doesn't necessarily run in a JavaScript context inject
implementations for these host functions.

This would allow running `dart2wasm` apps by e.g.

  - using a runtime like wasmtime and defining host functions in Rust.
  - defining a wrapper module implementing required functions by
    delegating to WASI definitions, and then using say `wasm-merge` to
    run the app in any WASI-compatible runtime.

This prepares the `--standalone` flag on `dart2wasm` to do just that.
When enabled, the compiler uses a different SDK platform to use imports
instead of JS interop. For now, these platforms are almost identical:
I've ported the timer logic to use wasm imports as a demo, but the rest
is still based on existing patch files. We can revisit in subsequent
CLs to incrementally reduce `js_interop` dependencies before removing
that library from the `dart2wasm_standalone` target entirely.

Change-Id: I3f406afbf2dab65506094de5c3f4067f4db66f3e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/486380
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2026-03-19 01:25:57 -07:00
Ömer Ağacan 590b656877 [dart2wasm] Update JS exception catching
This updates JS exception catching as discussed in #55481:

- Only catch JS exceptions when the exception type is `dynamic`,
  `Object`, or an extension of `JSValue`. (nullable or not)

  (Previously we also caught JS exceptions when the type is `Error`.)

- When the JS value caught in Wasm is `null` or `undefined`, box it as a
  non-interop class. For compatibility with dart2js, this class is
  copied from dart2js and has the same `toString` as the dart2js class.

- In other cases: box the JS values as `JSValue`. This means the value
  can be passed as any of the interop types, and can be passed back to
  JS without manual jsification.

Fixes #55481.

Issue: https://github.com/dart-lang/sdk/issues/55481
Change-Id: I23e73074729f740b90df2ca8b3c713fb39966556
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/479640
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2026-02-24 01:43:10 -08:00
Kevin Moore 26fa4add14 dart2wasm: tool cleanup
DRY'd up some helpers and logic
Deleted validate_wasm_test.sh
Added `--run` and `--write-temp` flags to compile_benchmark

Change-Id: I666b25d13d0837a2b9f9fc40488882f1cfc6aff5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/478703
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Kevin Moore <kevmoo@google.com>
2026-02-18 19:16:22 -08:00
Kevin Moore 0f230f3262 [dart2wasm] test all new simd instructions
With one fix
Also added a test script to make future hacking easier

Change-Id: I05c75dd4c458f7c3404ed7dba25484296764a549
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/477941
Commit-Queue: Kevin Moore <kevmoo@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2026-02-03 11:07:42 -08:00
Martin Kustermann ea6fb0a16f [dart2wasm] Allow using table slots for storing values of dart globals
This seems to result in -0.6% compressed main module and a bit less
in uncompressed mode.

Sometimes we have many fields with lazy initializers of the same type.
That led us to emit 1 nullable wasm global for each such field. For
example all proto classes have a `static BuilderInfo i_` field. This has
led to thousands of `(mut (ref null $BuilderInfo))` wasm globals.

Now we use a wasm table for this, which is a O(1) in the binary as they
all get `null` by default, saving us all these globals. The downside is
that accesses have an extra instruction now, but overall this is a win.

The CL also cleans up `globals.dart` by separating the concept of a wasm
global and reading/writing to it from the concept of a Dart global - as
Dart globals can now be backed by wasm globals or table slots.

This CL uses the new capability made possible by the refactoring
in [0] - namely to emit element sections which initialize wasm table
slots with non-function expressions.

[0] https://dart-review.googlesource.com/c/sdk/+/459440

Change-Id: Ie57206dff8c0a57a1df5e48c0808167f822bc4a2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/475800
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2026-01-30 03:34:42 -08:00
Ömer Ağacan 9fcb6cb53a [dart2wasm] compile_benchmark: always run wasm-opt when optimizations are enabled
Currently if I pass `compile_benchmark ... -O0 ... -O4 ...`, the first
`-O` disables wasm-opt, but the second `-O` doesn't enable it again.

With this CL the last `-O` decides whether to run wasm-opt.

Change-Id: I0f41a833f45a25a00c59da0e7e2a3c087b8dd666
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/469460
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2025-12-23 08:32:32 -08:00
Ömer Ağacan f380cba980 [dart2wasm] Remove unused bash function find_flags
Change-Id: Id3faf8784f4fbc2c940ec4811966a8c9d54f873f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/469160
Auto-Submit: Ömer Ağacan <omersa@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2025-12-19 09:10:24 -08:00
Nate Biggs e8b8ecfd52 [dart2wasm] Fix signature selection for direct closure invocation.
Direct closure invocation on tearoffs was using the signature of the raw
member reference rather than the checked entry function. These don't
always have the same signature and therefore it was possible to generate
an invalid code by putting the incorrect # of parameters on the stack.

The added test fails prior to this fix when assertions are enabled.

Also include some small changes that helped with debugging this.

Change-Id: I8c50dca3999781213ea251c6ab97eb1eaf7d0c8b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/467500
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2025-12-11 00:32:20 -08:00
Nate Biggs fdeb9dc575 [dart2wasm] Introduce an opt phase to dart2wasm.
To help facilitate this we move all IO into a separate helper
library/class. This makes it easier to have symmetric read/write
functions and to do IO within compile.dart where necessary.

Adding the new `opt` phase allows us to remove the duplicated code
between dartdev and compile_benchmark simplifying those two files a lot.
It will also allow us to more easily invoke wasm-opt within our internal
build pipeline.

For compile_benchmark we still run the opt phase independently (but
through dart2wasm) to keep the benchmark data as consistent as possible.

Change-Id: Iaa855dbc3a05abfedbc3eea4af32e3ba27e84600
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464640
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2025-12-01 21:50:29 -08:00
Martin Kustermann c942b23b07 [dart2wasm] Fix access of constants under deferred load guard
When accessing a constant under a load guard we can push the constant to
the deferred module (as we only access it under the guard that the
module has been loaded). The access has to therefore also use the
constant initializer function from the deferred module.

We also remove `--extra-compiler-option` prefix for
`--enable-deferred-loading` as the prefix isn't recognized by
dartdev.

Change-Id: I58489303dc10bb265ef730c05a4fc78a8f598edb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464980
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2025-11-28 03:23:01 -08:00
Martin Kustermann ba35b8c59c [dart2wasm] Fix pkg/dart2wasm/tool/compile_benchmark script
The script was incorrectly handling source maps when deferred
loading is enabled and we emit & optimize multiple wasm modules
(the source maps very completely bogus)

Change-Id: Ib65b72a4d2a3c8958bbe80e94c76145b6e1a0e5b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464480
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2025-11-26 01:49:53 -08:00
Nate Biggs 79fa199a2b [dart2wasm] Introduce phases to dart2wasm.
To support internal compilations, dart2wasm must be able to run in
phases. There are a few reasons for this:

1) Kernel transforms are run on the program after the CFE has run. We
must emit a dill that frameworks can transform and then pass the
transformed dill back to dart2wasm.

2) This allows us to avoid forge limits by running each phase of the
compiler in separate blaze actions. TFA has the chance of running long
on large programs and so it might be beneficial to run it as its own
action.

This implementation currently supports 3 phases: "cfe", "tfa", "codegen"
They can be run collectively or in any consecutive combination. Phases
are specified via a '--phases' multi-option. Any data that needs to be
passed between the phases is encoded directly into the serialized dill.

This also opens up the opportunity to make "opt" its own phase that
runs wasm-opt on the wasm emitted from the codegen phase.

Change-Id: Ide830763f7063c7ab880e8e54dc47bd32fd4e7cd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/455280
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2025-10-17 09:38:40 -07:00
Nate Biggs a20f1bcb40 [dart2wasm] Introduce "load ids" to dart2wasm deferred loading.
Load ids provide a way to reduce the overhead of deferred loading. By
default deferred loading requires mapping `loadLibrary` calls to a list
of modules. This requires including (1) library uris, (2) prefix names
and (3) module names directly in the main module. With this loading
modules is easier as the loading function gets the exact filename.

Load ids provide an alternative approach where the compiler emits a
separate file mapping a load ID to the module set required for that ID.
An app could store this mapping on the server allowing the frontend to
include only the load ID in its request and have the server figure out
which modules to send back.

Internal serving infra uses module sets like this so this change allows
easier integration into that tooling. Dart2js already supports emitting
this deferred mapping JSON and internal infra is using that today.

Other changes include:
- Run the deferred loading transformer after TFA. This will exclude unused libraries in the resulting deferred loading map. Mark deferred helpers as entry points so that they don't get tree-shaken.
- Some changes to naming conventions of JS helpers.
- Use filename as module name to simplify JS helpers

Change-Id: I5e2f5e374de77c87095d08bfff6534506cb10652
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/454240
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2025-10-13 13:42:47 -07:00
Nate Biggs f75b0bbb61 [dart2wasm] Fix compile_benchmark script with stress test mode.
Fixes 'web/wasm/flute_stress_test' failure seen at https://dart-ci.firebaseapp.com/#10be4da5dc9dadb22b9c25a6174fff436e8b63e2

Change-Id: I64b2097f9059b80ec72c268e2105a88f0f4e40bd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453620
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2025-10-06 15:47:01 -07:00
Nate Biggs 10be4da5dc [dart2wasm] Run wasm-opt local optimizations on deferred loading modules.
Output for ACX gallery (monolith):
```
acx_gallery.Time.Total(CompileTime): 216.80 s
acx_gallery.Time.Dart2Wasm(CompileTime): 88.37 s
acx_gallery.Time.Wasm2WasmOpt(CompileTime): 128.43 s
acx_gallery.Size.mjs(CodeSize): 421228 bytes
acx_gallery.Size.mjs.gz(CodeSize): 29255 bytes
acx_gallery.Size.wasm(CodeSize): 38083554 bytes
acx_gallery.Size.wasm.gz(CodeSize): 9040482 bytes
acx_gallery.Size.wasm.opt(CodeSize): 13147207 bytes
acx_gallery.Size.wasm.opt.gz(CodeSize): 3288834 bytes
acx_gallery.MemoryUse.Max(MemoryUse): 2398687232 bytes
acx_gallery.MemoryUse.Dart2Wasm(MemoryUse): 2359529472 bytes
acx_gallery.MemoryUse.Wasm2WasmOpt(MemoryUse): 2398687232 bytes
```

Output for ACX gallery (monolith -O0):
```
acx_gallery.Time.Dart2Wasm(CompileTime): 87.49 s
acx_gallery.Size.mjs(CodeSize): 421228 bytes
acx_gallery.Size.mjs.gz(CodeSize): 29255 bytes
acx_gallery.Size.wasm(CodeSize): 38466066 bytes
acx_gallery.Size.wasm.gz(CodeSize): 8509479 bytes
acx_gallery.MemoryUse.Dart2Wasm(MemoryUse): 2261155840 bytes
```

Output for ACX gallery (deferred):
```
acx_gallery.Time.Total(CompileTime): 138.03 s
acx_gallery.Time.Dart2Wasm(CompileTime): 92.67 s
acx_gallery.Time.Wasm2WasmOpt(CompileTime): 45.36 s
acx_gallery.Size.mjs(CodeSize): 422584 bytes
acx_gallery.Size.mjs.gz(CodeSize): 29610 bytes
acx_gallery.Size.wasm(CodeSize): 50639314 bytes
acx_gallery.Size.wasm.gz(CodeSize): 13063929 bytes
acx_gallery.Size.wasm.opt(CodeSize): 20308884 bytes
acx_gallery.Size.wasm.opt.gz(CodeSize): 5569508 bytes
acx_gallery.MemoryUse.Max(MemoryUse): 2165276672 bytes
acx_gallery.MemoryUse.Dart2Wasm(MemoryUse): 2165276672 bytes
acx_gallery.MemoryUse.Wasm2WasmOpt(MemoryUse): 454402048 bytes
```

Change-Id: Ia6627b94ff80019b3c180850a3940d7e714c068b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453240
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2025-10-06 10:28:40 -07:00
Martin Kustermann db36ab27f6 [dart2wasm] Make pkg/dart2wasm/tool/run_benchmark work on MacOS
It seems `realpath` isn't available on stock MacOS always (and
may require `homebrew install coreutils`). So we switch to using
a custom version.

Closes https://github.com/dart-lang/sdk/issues/61226

Change-Id: I8f9fe990346a0d8b93903b02688b704273212ee9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/443260
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2025-08-01 02:01:14 -07:00
Martin Kustermann 4cd2c1da95 [dart2wasm] Make pkg/dart2wasm/tool/compile_benchmark auto-detect correct architecture on Mac
Running `pkg/dart2wasm/tool/compile_benchmark` on

  * MacOS on X64 should use xcodebuild/ReleaseX64
  * MacOS on ARM64 should use xcodebuild/ReleaseARM64

Change-Id: Id4cceb70eea1a3d0723e277325b21eff0fa36ef8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428780
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2025-05-15 04:51:03 -07:00
Ömer Ağacan f4b41f0902 [dart2wasm] Fix handling of --define/-D
When parsing `--define` or `-D` arguments don't split the the value by
commas.

This is consistent with how dart2js handles `-D`, but inconsistent with
how VM handles it.

Example:

    void main() {
      print(const String.fromEnvironment("FOO"));
    }

When compiled with `dart compile js -DFOO="a, b"` and run, dart2js
prints

    a, b

VM prints (when compiled to exe)

    a

Between these two, I think dart2js' behavior is more common, so we
follow dart2js.

Also update compile_benchmark to avoid splitting a single argument "a b"
into "a" and "b" when parsing the arguments and then splicing them back
before calling `dart2wasm`.

Also update the test runner and ddc batch mode argument parser to handle
splitting quoted arguments in `// dart2jsOption = ...` and the same
options for ddc and dart2wasm, by moving dart2js's `splitLine` to a new
library and reusing it in the test runner and ddc.

Fixes https://github.com/flutter/flutter/issues/164873.

See also https://github.com/dart-lang/sdk/issues/60341 for relevant
future work.

Change-Id: Idbdf69072fa212c8e4a390990577eb5a57b49e8a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415280
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2025-03-18 04:11:41 -07:00
Martin Kustermann 20fc102287 [dart2wasm] Switch to only using JS strings
Currently we have 3 different string types (JS Strings, OneByteString
and TwoByteString)s. There's some advantages to this, mainly that
if strings are used purely inside Dart we have more control over
optimizing them. But it does come with some issues

* Operations on mixture of strings are slow
* We get JS strings from outside (in DevTools e.g. websocket messages)
* Any kind of DOM interaction requires copying strings
* Regular expression matches can result in O(N*N) instead of O(N)
* Encoding of string literals/constants is terrible, high size overhead
* ...

Now that there's a standardized way to access JS strings (via
the `js-string` builtin spec) and this standard is finalized and
enabled in Chrome & Firefox it makes sense for us to switch to it.

It reduces app size:

* Smaller size: hello world -25%, flute -5.5%
* Faster startup

The performance changes are nuanced, some workloads will improve
significantly, some workloads will regress.

Improvements will come especially in cases where
strings are concatenated (due to JS not actually allocating new
strings in this case). That impacts e.g. string interpolations,
string buffer, json-to-string encoding, ...

Regressions will come especially for cases where we have to
construct strings from bytes (e.g. in utf8 decoder, utf8+json
decoder) - mainly due to having to go through an intermediary
`WasmArray<WasmI16>` to allocate strings. Also in cases where we
access individual char codes from the strings.

There's some follow-up improvements we can do, but it's better to
not iterate on this CL even longer but get it landed.

This CL will make the benchmarking system use
`--require-js-string-builtin` as well as most of test CI
(in `pkg/dart2wasm/tool/compile_benchmark`)

Though we run some configurations via overriding with
`--no-require-js-string-builtin`
(in `tools/bots/test_matrix.json`)

Issue https://github.com/flutter/flutter/issues/159400#issuecomment-2538593980
Issue https://github.com/dart-lang/sdk/issues/59699

TEST=ci

Change-Id: I238ac65efe092de569da870f23134f889ac929f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392903
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2025-02-27 00:33:34 -08:00
Vyacheslav Egorov 9475d56e17 [infra] Support Mac in pkg/dart2wasm/tool/run_benchmark
R=kustermann@google.com

Change-Id: I4f0604468402437a3361269a244f9b32dd8969f2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/411302
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2025-02-24 02:12:01 -08:00
Siva Annamalai d87b6d5f36 Reland "[SDK] Second step in removing references to dart_precompiled_runtime"
This reverts commit 630e262833.

Reason for revert: Failing golem benchmarks were already failing from before this CL

TEST=ci

Original change's description:
> Revert "[SDK] Second step in removing references to dart_precompiled_runtime"
>
> This reverts commit 85765475d3.
>
> Reason for revert: breaks dart2wasm golem benchmarks
>
> Original change's description:
> > [SDK] Second step in removing references to dart_precompiled_runtime
> >
> > TEST=ci
> >
> > Change-Id: I7b625de2090aa31fd649f0f67055c032f5878772
> > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395065
> > Reviewed-by: Alexander Aprelev <aam@google.com>
> > Commit-Queue: Siva Annamalai <asiva@google.com>
>
> Change-Id: I524191ca9e26bb1d298eb56543bc0f419bfab4d3
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395462
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Reviewed-by: Brian Quinlan <bquinlan@google.com>
> Commit-Queue: Siva Annamalai <asiva@google.com>

Change-Id: I2ec45bb7cad086ed66a9a41df2d19b4c1fdcb131
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395640
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2024-11-15 18:27:36 +00:00
Siva Annamalai 630e262833 Revert "[SDK] Second step in removing references to dart_precompiled_runtime"
This reverts commit 85765475d3.

Reason for revert: breaks dart2wasm golem benchmarks

Original change's description:
> [SDK] Second step in removing references to dart_precompiled_runtime
>
> TEST=ci
>
> Change-Id: I7b625de2090aa31fd649f0f67055c032f5878772
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395065
> Reviewed-by: Alexander Aprelev <aam@google.com>
> Commit-Queue: Siva Annamalai <asiva@google.com>

Change-Id: I524191ca9e26bb1d298eb56543bc0f419bfab4d3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395462
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Brian Quinlan <bquinlan@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
2024-11-15 00:36:18 +00:00
asiva 85765475d3 [SDK] Second step in removing references to dart_precompiled_runtime
TEST=ci

Change-Id: I7b625de2090aa31fd649f0f67055c032f5878772
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395065
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
2024-11-14 23:22:37 +00:00
Siva Annamalai 74c5aa3a7a Revert ""[SDK/VM] - Rename dart_precompiled_runtime to dartaotruntime, ensures we have a uniform name for the executable between the build directories and the SDK directory""
This reverts commit f81a402aa1.

Reason for revert: golem benchmarks are failing to run

TEST=ci

Original change's description:
> "[SDK/VM] - Rename dart_precompiled_runtime to dartaotruntime, ensures we have a uniform name for the executable between the build directories and the SDK directory"
>
> Fixed golem breakage by temporarily copying dartaotruntime to dart_precompiled_runtime
>
> This reverts commit 75e6a748f7.
>
> TEST=ci
>
> Original change's description:
> > Revert "[SDK/VM] - Rename dart_precompiled_runtime to dartaotruntime, ensures we have a uniform name for the executable between the build directories and the SDK directory"
> >
> > This reverts commit 1b331d05c2.
> >
> > Reason for revert: golem builds are failing
> >
> > Original change's description:
> > > [SDK/VM] - Rename dart_precompiled_runtime to dartaotruntime, ensures we have a uniform name for the executable between the build directories and the SDK directory
> > >
> > > TEST=ci
> > >
>
> Change-Id: Id0f383eabb496c06c0acebc639c8e3b056ba82d0
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393781
> Commit-Queue: Siva Annamalai <asiva@google.com>
> Reviewed-by: Ryan Macnak <rmacnak@google.com>

Change-Id: Iec494940412aa31dbefdc5280e35ae99e8cecb26
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393764
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
2024-11-06 05:37:46 +00:00
asiva f81a402aa1 "[SDK/VM] - Rename dart_precompiled_runtime to dartaotruntime, ensures we have a uniform name for the executable between the build directories and the SDK directory"
Fixed golem breakage by temporarily copying dartaotruntime to dart_precompiled_runtime

This reverts commit 75e6a748f7.

TEST=ci

Original change's description:
> Revert "[SDK/VM] - Rename dart_precompiled_runtime to dartaotruntime, ensures we have a uniform name for the executable between the build directories and the SDK directory"
>
> This reverts commit 1b331d05c2.
>
> Reason for revert: golem builds are failing
>
> Original change's description:
> > [SDK/VM] - Rename dart_precompiled_runtime to dartaotruntime, ensures we have a uniform name for the executable between the build directories and the SDK directory
> >
> > TEST=ci
> >

Change-Id: Id0f383eabb496c06c0acebc639c8e3b056ba82d0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393781
Commit-Queue: Siva Annamalai <asiva@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2024-11-06 03:10:31 +00:00
Siva Annamalai 75e6a748f7 Revert "[SDK/VM] - Rename dart_precompiled_runtime to dartaotruntime, ensures we have a uniform name for the executable between the build directories and the SDK directory"
This reverts commit 1b331d05c2.

Reason for revert: golem builds are failing

Original change's description:
> [SDK/VM] - Rename dart_precompiled_runtime to dartaotruntime, ensures we have a uniform name for the executable between the build directories and the SDK directory
>
> TEST=ci
>
> Change-Id: I96ed52994e0d955300c18026032e68003504666d
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389760
> Reviewed-by: Ryan Macnak <rmacnak@google.com>
> Commit-Queue: Siva Annamalai <asiva@google.com>
> Reviewed-by: Alexander Thomas <athom@google.com>

Change-Id: I5dc14973f4ee4e577b2c996839d5e497c97fb440
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393761
Commit-Queue: Siva Annamalai <asiva@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2024-11-05 21:58:09 +00:00
asiva 1b331d05c2 [SDK/VM] - Rename dart_precompiled_runtime to dartaotruntime, ensures we have a uniform name for the executable between the build directories and the SDK directory
TEST=ci

Change-Id: I96ed52994e0d955300c18026032e68003504666d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389760
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
2024-11-05 20:39:15 +00:00
Nate Biggs 963c28a114 [dart2wasm] Allow tests to override jscm mode.
This allows tests that would fail in JS compatibility mode (e.g. tests that do a lot of string manipulation) to disable the mode for their own execution.

Also ensure dart2wasm-*-jscm-* builds do a "create_sdk" so that the dart2js platform dill is available for the test.

The alternative I considered was skipping the test but "--js-compatibility" is a dart2wasm-specific flag and the test infra is unaware of it so we can't skip the test via a status file.

Bug: https://github.com/dart-lang/sdk/issues/56858
Change-Id: I60179eaab2e4522acf1fe0b47c7c02ccb1ca957b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388644
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2024-10-08 13:16:19 +00:00
Martin Kustermann 702176cbd4 [dart2wasm] Remove traces of JSC_useWebAssembly* in test runner & run_wasm.js
Those environment variables are no longer needed for newer versions of
JSC.

Change-Id: I416535ce116e2d0f1911131d52789362ce951fef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/383863
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2024-09-05 12:23:28 +00:00
Ömer Sinan Ağacan 1b1740e941 [dart2wasm] Pass source maps to wasm-opt when optimizing
To be able to know when we are generating a source map, make `dart
compile wasm` aware of the `--no-source-maps` flag.

The "name" segments of source mappings are also made `null` with this
patch. Browsers don't use that segment and binaryen doesn't support it.

Change-Id: I7b52c8fb7cef92ed60547e97ad137e0cd3967f26
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378421
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-08-09 14:23:29 +00:00
Martin Kustermann f3e1b210de [dart2wasm] Make --shell-option work in pkg/dart2wasm/tool/run_benchmark script
Change-Id: Ib7de19a936c211fd593fa81d37764e734193eac8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373260
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2024-06-26 12:08:19 +00:00
Martin Kustermann 18ffc284c3 [dart2wasm] Remove deprecated --name-section flag from dart compile wasm
Change-Id: I1e1746c408a704d23db1dbf05b554afda667a0ce
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371540
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2024-06-14 06:50:18 +00:00
Martin Kustermann 6d185d2003 [dart2wasm] Make pkg/dart2wasm/tool/compile_benchmark more similar to dart compile wasm
This allows copy&past'ing commands from `flutter build web --wasm
--verbose` and replacing `dart compile wasm` with
`pkg/dart2wasm/tool/compile_benchmark`.

* We make the shell script recognize `-o` flag.
* We make the shell script recognize different platform being passed.

Change-Id: Iabecc7c87b35d35f073ced5e111a9ca5ea0d9298
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371341
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-06-13 13:18:19 +00:00
Martin Kustermann a98ce03e13 [dart2wasm] Add --(no-)strip-wasm flag and deprecate --(no-)name-section
`flutter build web --wasm`
  * uses the `--(no-)strip-wasm` flag for stripping
  * by default it strips the wasm file in `--release` mode

=> We align `dart compile wasm` to use the same flag and have the same
   default.

After this CL rolled into flutter, we can make flutter pass the new flag
down and remove the old `--name-section` flag.

Change-Id: I6dc6be86a3a90f14617bc795843b0e54f54fa761
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369062
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-05-31 13:17:38 +00:00
Martin Kustermann 8fa0675a6d [dart2wasm] Make optimized builders run with --use-sdk (and therefore dart compile wasm)
This gives some more coverage for `dart compile wasm`

Change-Id: I62e7f9c6ecbdf80a1445c35d1733a7f89e6bcf54
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366623
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-05-17 13:08:31 +00:00
Martin Kustermann 328ae02be1 [dart2wasm] Remove --dart-sdk option from various places
The CFE's [CompilerOptions] object currently has 3 properties

* `CompilerOptions.sdkDir`: The sdk directory
   => Will use `<sdkDir>/lib/libraries.json` to compile corelibs

* `CompilerOptions.librariesSpecPath`: The libraries.json file
   => Will compile corelibs using this libraries.json

* `CompilerOptions.sdkSummary`: The platform.dill file
   => No need to compile corelibs as platform file is given.

=> Passing any of these is sufficient for the CFE to run.

This CL therefore mandates that either one passes the platform file or
the libraries.json file to dart2wasm. There's no need to also accept the
sdk dir.

As flutter still passes `--dart-sdk` (as well as platform file) - we
simply ignore that flag for the moment, until flutter's usage was
removed.

Change-Id: I4c3b1a7bf87f98e51ceb2e6adfaec4f4a6ce2202
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366821
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-05-17 11:31:58 +00:00
Martin Kustermann 10429f4e89 [dart2wasm] Add a bit more documentation to pkg/dart2wasm/doc/*
Adds some more documentation about

* using `wami` to dump section stats / wasm code
* building & testing dart2wasm

...

Change-Id: I439daf04d8f4599e817577c3b4cb58053a836b47
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365806
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2024-05-15 11:11:27 +00:00
Martin Kustermann 09361f0f16 [dart2wasm] Make test runner use pkg/dart2wasm/tool/run_benchmark (just as golem does)
* We make the test runner use the same runner script as golem uses
* We make the runner script work for different JS shells

=> The runner script encapsulates how to invoke different JS shells, the
   commandline format, environment variables, ...

=> Golem can then continue to use same runner script, but also with new
   shells

Change-Id: Iad63fe6c0563cfeac28cbfb25eb41ee1b7c13f3a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365740
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-05-08 11:00:33 +00:00
Martin Kustermann a46d59fe3b [dart2wasm] Allow --minify/--no-minify to override defaults from -O<level>
* Allow --minify/--no-minify to override defaults from -O<level>

* Remove the unused(!) --name-section option from pkg/dart2wasm/*
  => Stripping it only makes sense at the binaryen step

* Make pkg/dart2wasm/tool/compile_benchmark support -g/--no-minify
  => Only useful for dart2wasm developers

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

Change-Id: I695e985897b212fc345dcfd776553a009723d3b6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/351121
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-02-08 16:46:19 +00:00
Martin Kustermann b562998c14 [dart2wasm] Align semantics of -O3 with dart2js semantics
* Golem is now using -O3
   => remove `--omit-checks` from pkg/dart2wasm/tool/compile_benchmark.

* Dart CI is using -O1/-O2
  => remove `--optimize`/`--no-optimize` from
     pkg/dart2wasm/tool/compile_benchmark and `dart compile wasm`

* Align semantics of -3 with dartjs (enable `--minify`, enable
  `--omit-implicit-checks` disable  `--omit-explicit-checks`).
  => This will make us see changes in benchmarks.

What remains is

* Expose remaining flags in `dart compile wasm` that are needed for
  flutter (or add a generic `--extra-compiler-args` that forwards flags)

* Migrate flutter to use `dart compile wasm`.

* Remove `--omit-type-checks` from pkg/dart2wasm/lib/dart2wasm.dart

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

Change-Id: I80654a3ae81bdc5f4c57e3fadccdf5612236102a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/348500
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-01-26 13:26:40 +00:00
Martin Kustermann 8b823dc300 [dart2wasm] Allow pkg/dart2wasm/tool/compile_benchmark to run from source via --src
Normally it uses the AOT runtime & dart2wasm AOT snapshot, which takes
long to build. (similar reason why one doesn't want to use `dart compile
wasm` in dev cycle)

Fixes also bug in script that used $BINARYEN_FLAGS instead of
"${BINARYEN_FLAGS[@]}" - which caused wasm-opt to run without
any flags.

Change-Id: Id6e03dbc01f7dba22de380453260278858dc0aa9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/348480
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-01-26 08:46:42 +00:00
Martin Kustermann 92d53c426f [dart2wasm] Add -O/--optimization-level flag to dart compile wasm
We make the meaning of -O{0,1,2,3,4} to be similar to what dart2js has.
We also make the pkg/dart2wasm/tool/compile_benchmark accept the same flags.

Follow-up CLs will migrate Dart CI / Golem / flutter to use -O flags.

Change-Id: Id37476c596ec7483e633c7db9eec96438315e919
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/348165
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-01-25 09:53:04 +00:00
Martin Kustermann 1fc755eb54 [dart2wasm] Remove sdk/bin/dart2wasm{,_developer} scripts
We already have a shell script that compiles dart code to wasm and
optimizes it. I think it's rather confusing to have multiple, they
contain somewhat duplicated code as well.

We therefore remove `sdk/bin/dart2wasm{,_developer}` (which is
not used by any CI but purely for developers) in favor of
`pkg/dart2wasm/tool/compile_benchmark`.

=> It support with/without binaryen
=> It support measuring size/time/memory of dart2was & binaryen
=> It supports running compiler with assertions

Some flags/vars are not supported anymore:

* `DART_VM_OPTIONS`: Has no effect (as there's no need to support this)
* `sdk/bin/dart2wasm_developer`: Pass `--compiler-asserts` to `compile_benchmark`.
* `-O`: Optimizes now by-default, pass `--no-binaryen` to `compile_benchmark` to disable
* `-O`: Doesn't implicitly pass `--inlining-limit=10`

Change-Id: Ice656d1bfc216a536522b254e2d52bd4cad73e8e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/347040
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-01-19 16:05:27 +00:00
Martin Kustermann 1d92908169 [dart2wasm] Have binaryen/wasm-opt flags in one place (dart compile exe), make all other places take it from there
Golem build configuration is setup in a way that includes the `pkg/`
folder entirely, so the shell scripts should have access to the
`dart compile exe` sources.

Change-Id: I5395413ce85f11098d14eacbd6ce392f665ddce5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/347021
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-01-19 07:47:52 +00:00
Martin Kustermann 83cf40afef [dart2wasm] Add support for compile-time/code-size/memory-use benchmarks of dart2wasm compiler
```
% DART_CONFIGURATION=ReleaseX64 pkg/dart2wasm/tool/compile_benchmark --
CompileFluteComplex.CompileTime.Total(CompileTime): 34.48 s
CompileFluteComplex.CompileTime.Dart2Wasm(CompileTime): 12.74 s
CompileFluteComplex.CompileTime.Wasm2WasmOpt(CompileTime): 21.74 s
CompileFluteComplex.CodeSize.mjs(CodeSize): 11333 bytes
CompileFluteComplex.CodeSize.mjs.gz(CodeSize): 3144 bytes
CompileFluteComplex.CodeSize.wasm(CodeSize): 3462517 bytes
CompileFluteComplex.CodeSize.wasm.gz(CodeSize): 1019112 bytes
CompileFluteComplex.CodeSize.wasm.opt(CodeSize): 1500111 bytes
CompileFluteComplex.CodeSize.wasm.opt.gz(CodeSize): 477204 bytes
CompileFluteComplexMemoryUse.Max(MemoryUse): 574341120 bytes
CompileFluteComplexMemoryUse.Dart2Wasm(MemoryUse): 574341120 bytes
CompileFluteComplexMemoryUse.Wasm2WasmOpt(MemoryUse): 487387136 bytes
```

We measure all metrics (compile-time, code size, memory use) separately
for dart2wasm and wasm-opt/binaryen. We also report total compilation
time as well as maximum memory usage across the tools.

Change-Id: I94c190475443b52d437a21ba85d5c5433f03dc50
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341486
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2023-12-14 14:59:33 +00:00
Ömer Sinan Ağacan 0d50d07a08 [dart2wasm] Update d8 flags
Change-Id: Ibe1e6c32d1a46055d35dab32878ac958801c550b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335800
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2023-11-14 09:19:08 +00:00
Aske Simon Christensen a2c47adfba Update Binaryen to a51bd6df919a5b79574f0996a760cc20cb05697e
This version fixes an issue with optimizing tuple-valued blocks, which
would arise when inlining functions with multiple return values.

Use the newly added `--type-unfinalizing` and `--type-finalizing`
options to improve the effectiveness of the TypeSSA and TypeMerging
passes.

https://github.com/WebAssembly/binaryen/issues/5923
https://github.com/WebAssembly/binaryen/issues/5933

Change-Id: I1d5bc1052a355bf404f81a420a2352270030fd4c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/327000
Reviewed-by: William Hesse <whesse@google.com>
Auto-Submit: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2023-09-21 11:47:59 +00:00
Ömer Sinan Ağacan 3ee5bdfcf3 [dart2wasm] Add test configuration to test with wasm-opt
- Update dart2wasm script to accept a `-O` argument. When passed it also
  passed `--inlining-limit 10` to dart2wasm (unless it's already passed
  by the caller) and runs wasm-opt on the output, with the same
  arguments as `compile_benchmark`.

- Add new test configurations to run tests with optimized binaries.
  Example configuration: `dart2wasm-linux-optimized-d8`.

Change-Id: Ia7bd8d9c99d3a4baecb72b92b2ba38c0e92807c6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/326620
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2023-09-19 10:29:43 +00:00
Ömer Sinan Ağacan fc9a0549ac [dart2wasm] Simplify compile_benchmark script
wasm-opt can update a file in-place when input and output arguments are
the same. Do it and remove temp file and dirs.

Also remove `--enable-experiment` flags as they're no longer needed.

Change-Id: Ifd07e88b55a98ca9953aad1de8622249513f2f79
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/326302
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-09-19 09:50:48 +00:00
Aske Simon Christensen 590c9cc08f [dart2wasm] Don't emit name section for benchmarks
Since the `compile_benchmark` script is used for compiling benchmarks
which will eventually be used for binary size tracking, the generated
Wasm file should have its names stripped.

Change-Id: I5db06537e29c0316eb5c15420448c64529bc763d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/324520
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Jess Lally <jessicalally@google.com>
2023-09-06 14:58:11 +00:00