Commit Graph

5865 Commits

Author SHA1 Message Date
Sigmund Cherem 941b50f3d8 [dart2js]: delete DoesNotCompleteType.
This was added before null safety, and before we had fully
defined the difference between Null, Bottom, and Never types.

I believe now this and Never.nonNullable are equivalent and
the distinction is no longer important to make. Hence, I'm
deleting it to reduce tech debt.

Originally this was added in https://dart-review.googlesource.com/c/sdk/+/88961

Change-Id: I64b3a8b01833bc60305eaecf430bfb249c8d2c98
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/301820
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
2023-05-09 02:56:57 +00:00
Johnni Winther 13c4ad23c5 [kernel] Add SwitchStatement.expressionType
This adds the static type of the switch statement expression to
the AST to better support optimizations based on the possible
runtime values of the switch expression.

TEST=existing

Change-Id: Ief35b687150401100d8c96721a026e9f0911b3b4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/301063
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-05-08 07:39:02 +00:00
Sigmund Cherem 1c59f30d7b [dart2js] fix crash with records and null-assertions.
Our helper function to detect whether a null-assertion was required
didn't include a case to check for record types.

The null-assertion flag is likely to go away soon, since it's
only valuable for mixed applications.

Fixes #52276

Change-Id: Ief4515b8c3eaae5343012da4220e6051bb5a2f19
Fixed: 52276
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/301680
Commit-Queue: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2023-05-05 17:20:13 +00:00
Stephen Adams d3da4311c0 [dart2js] Lower String.codeUnitAt to charCodeAt
Change-Id: Id4408a761304fc2fcb7ce3bd353c626958971ffb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/300500
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2023-05-05 15:27:11 +00:00
Sigmund Cherem 485633b50f Revert "Revert "[dart2js] drop unnecessary modular data(3): exte..."
Revert submission 300902-revert-300800-LYOMDRSVDI

Reason for revert: Fix issue (see patchset 2 in second CL)

Reverted changes: /q/submissionid:300902-revert-300800-LYOMDRSVDI

Change-Id: I4ad50f9a2f493f4cce76aa9155571434bae02d2a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/300922
Commit-Queue: Sigmund Cherem <sigmund@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2023-05-03 00:34:51 +00:00
Sigmund Cherem 618e9ece17 Revert "Revert "[dart2js] drop unnecessary modular data (2): non..."
Revert submission 300902-revert-300800-LYOMDRSVDI

Reason for revert: Fix issue (see patchset 2 in second CL)

Reverted changes: /q/submissionid:300902-revert-300800-LYOMDRSVDI

Change-Id: I74eb4064967ca3604da09bbe7341080360cf1a16
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/300921
Reviewed-by: Nate Biggs <natebiggs@google.com>
2023-05-03 00:34:51 +00:00
Sigmund Cherem ab4fbf128e Revert^2 "[dart2js] drop unnecessary data from modular data."
d57046b535

Change-Id: Ib97b3f9abd3757f6e127c49eba45358f47e44175
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/300920
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2023-05-03 00:34:51 +00:00
Sigmund Cherem d57046b535 Revert "[dart2js] drop unnecessary data from modular data."
Revert submission 300800

Reason for revert: broke bots. CQ didn't retrigger when second change int he chain was updated.

Reverted changes: /q/submissionid:300800

Change-Id: I9b1c2183e6948a88c3c28f806e913ef4f95664cf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/300902
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2023-05-02 23:34:11 +00:00
Sigmund Cherem 03dbb97ca2 Revert "[dart2js] drop unnecessary modular data (2): non foreign..."
Revert submission 300800

Reason for revert: broke bots. CQ didn't retrigger when second change int he chain was updated.

Reverted changes: /q/submissionid:300800

Change-Id: Iee3ef0e1e85a89708337a48c6a5a34a2f5114147
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/300901
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2023-05-02 23:34:11 +00:00
Sigmund Cherem 31d3b8c80d Revert "[dart2js] drop unnecessary modular data(3): external pro..."
Revert submission 300800

Reason for revert: broke bots. CQ didn't retrigger when second change int he chain was updated.

Reverted changes: /q/submissionid:300800

Change-Id: Ib86d944f0881ed8b5b3efea5c343b120d7e9a370
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/300900
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2023-05-02 23:34:11 +00:00
Sigmund Cherem 0e9c4080d4 [dart2js] drop unnecessary modular data(3): external procedures.
Like previous changes, removes unnecessary data from the modular serialization.

Change-Id: Ief8fbbc23f88379688850baa0ee1f6482c2549d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/300800
Commit-Queue: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2023-05-02 23:17:17 +00:00
Sigmund Cherem 0e1c35ced3 [dart2js] drop unnecessary modular data (2): non foreign nodes
The modular data saved references to every static invocation node, but only
needed this data for nodes representing one of the `JS*` foreign helpers.

This together with the previous change collectively reduce the total size of
the modular data by an average 8% on a small sample (which includes the entire
SDK).

Change-Id: I3080a1d7ba03643667cb50d7eadcc9fa0a065e6a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/299921
Reviewed-by: Nate Biggs <natebiggs@google.com>
2023-05-02 23:17:17 +00:00
Sigmund Cherem 2ec5565b88 [dart2js] drop unnecessary data from modular data.
We seem to unnecessarily store all literals when all we need is to know
whether a literal of each kind is in use in the program.

I expect similar changes could help make the modular data more compact and
potentially make enough of a difference where a modular analysis may make
sense.

Change-Id: I045401d742b0467435da179af51c39c3ea08401f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/299960
Reviewed-by: Nate Biggs <natebiggs@google.com>
2023-05-02 23:17:17 +00:00
Srujan Gaddam c4d354dc2a Reland "[pkg:js/dart:js_interop] Move annotations to dart:_js_annotations"
This reverts commit 4919729f00.

This CL also adds back in logic to handle older package:js versions to avoid
failures in our static checking. It also supports dart:js_interop's @JS
annotation since it can now be used for @staticInterop classes.

CoreLibraryReviewExempt: Reland of backend-specific library changes.
Change-Id: I104653a9a6b2593f6bab658808287e2074c18550
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294130
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-05-02 15:24:18 +00:00
Nate Biggs b9c73fdf23 [dart2js] Update switch block local handling to correctly propagate types that fall through the block.
Fixes #52170

Change-Id: I7c473c3101d446eb17433d583bfe266bf6f193d6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/298760
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-04-27 19:35:45 +00:00
Joshua Litt 47b7c1f31d [js] Add js_interop_unsafe library.
CoreLibraryReviewExempt: Web only library.
Change-Id: I4d6007e0731ecae81fcc614168baee7d5e662fd8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293743
Commit-Queue: Joshua Litt <joshualitt@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2023-04-27 18:51:49 +00:00
Nate Biggs a6f543e50a [dart2js] Repro for issue 52170.
Type inference is not tracking the type of 'local' correctly through the switch statement into the inner return. The same code without the for loop does work correctly though.

Change-Id: I0b1b4741e4ff17c22dec3383defb412f5fff0836
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/298980
Reviewed-by: Stephen Adams <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-04-27 18:15:48 +00:00
Nate Biggs 4bbdc97d1c [dart2js] Ensure Dart2JS only reports relevant metrics.
Prior to this change the metrics modified here are all printed during every run of the compiler, even when the compiler is running in phase mode on a phase that cannot modify these metrics.

This will make collection of these metrics easier and ensure the collected data is cleaner.

Change-Id: I62a081d9dbae71256882f24156faf246f4076e61
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/297440
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-04-26 17:36:51 +00:00
Srujan Gaddam 1d28f8e821 [dart:js_interop/ddc/dart2js] Implement JS types using @staticInterop
Currently, dart:_js_types types are all typedefs in the web backends.
This leads to inconsistent semantics, since you can statically pass
Strings to JSString, for example. You cannot do this in dart2wasm.
In order to ensure consistent semantics, we reify these types using
a custom @staticInterop lowering. They all get erased to their
respective Dart type. When we have inline classes, these types
should be implemented using inline classes.

Note that Interceptor will not work for this use case. The reified
type of JS primitives are Dart types e.g. String, bool, and therefore
can not be casted to Interceptor.

In order to do this, the eraser is refactored and the JS backends use
shared erasure code to either erase/emit types.

Tests are added to make sure you need to go through a conversion or
cast to pass Dart objects to JS types.

CoreLibraryReviewExempt: Backend-specific internal library changes.
Change-Id: I5942be628102919ec167f094cfe10fced606363c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/295105
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2023-04-26 15:55:54 +00:00
Stephen Adams 8ee2b8b36b [dart2js] Convert recordTypes after closureData
Fixed #51899
Change-Id: Id9108e6cf13aee409b127fe6cd007bef8f0fe609
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/298460
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2023-04-26 03:57:07 +00:00
Nate Biggs 0028815f16 [dart2js] Remove experimental inferrer.
We have merged the experimental inferrer back into the main inferrer branch and therefore can clean this up.

Change-Id: I66481c51276b0ffbf79b4b41b21a3ee5c2ca9cf2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/298360
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-04-25 21:50:02 +00:00
Stephen Adams e8832a643e [dart2js] Fix value_range_test
The fix is to enable type inference.

The old `List(n)` constructor was replaced by `List.filled`. `List(n)`
could be recognized as fixed-length purely by syntax. The test failed
after the replacement because `List.filled` is not recognized to be
fixed-length purely syntactically in the SSA builder, but rather by
type inference.

With type inference enabled, `List.filled` is recognized, but other
parts of the test need to be more realistic, as type inference also
detects the element type and length.

Bug: #52139
Change-Id: Icfaeb3e341b448bbc263efe43f48a2b76d05bf5b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/298020
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2023-04-25 17:58:29 +00:00
Nate Biggs b508533666 [dart2js] Add 'CONTEXT' diagnostic level option.
Metrics are using 'INFO' level diagnostics but these do not match the stated usage for INFO. This level was originally supposed to be used for contextual info about a previous warning/hint:
https://github.com/dart-lang/sdk/blob/main/pkg/compiler/lib/compiler_api.dart#L44

These is logic that is preventing these metrics from being printed when they are logged following a hint and hints are turned off:
https://github.com/dart-lang/sdk/blob/main/pkg/compiler/lib/src/source_file_provider.dart#L259.

Instead we introduce a 'CONTEXT' for those contextual info messages and use 'INFO' as its own level of logging.

Change-Id: Ie845f30dfd7d04fa9fe1d0a866e07c834dc64b32
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/297280
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-04-24 23:17:09 +00:00
Sigmund Cherem 8026975546 [dart2js] better help message.
Makes more prominent that you can use '-v' to show
extra details about all options.

The message after this change will look as follows:
```
Compile Dart to JavaScript.

Usage: dart compile js [arguments] <dart entry point>
(use -h -v for detailed information about all options)
  -h, --help      Print this usage information
  -o, --output    Write the output to <file name>.
  -O<0,1,2,3,4>   Set the compiler optimization level (defaults to -O1).
```

Fixes https://github.com/dart-lang/sdk/issues/51982

Change-Id: I76fe5478b4a1d4b2ae2170eca72d764bc4d120b4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294164
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
2023-04-24 20:48:14 +00:00
Nate Biggs 339399a593 [dart2js] Resolve failing web unit tests.
- variance_subtype_cast_test.dart: Pass soundNullSafety flag so @dart=2.7 flag doesn't get added to test.
- logical_expression_test.dart: Remove test as this is now covered by test added in https://dart-review.googlesource.com/c/sdk/+/297360.

Change-Id: I02d0fb816c5b41dad31014152ff3a796a528904c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/297860
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-04-24 20:38:27 +00:00
Nate Biggs 9a7f60b438 [dart2js] Add Dart2JS input bytes as an internal metric.
Change-Id: Ib036b0511af2a54aa049f3638d9680fca3b77385
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/297701
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-04-24 19:43:04 +00:00
Stephen Adams 073def1334 [dart2js] Add codegen test for logical operator generation
Change-Id: I5f86fdf4e58122a234dc2c7b16e1e16ec44d0d83
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/297360
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2023-04-24 18:47:14 +00:00
Stephen Adams 45efccb5e0 Remove left-over patch declarations for List constructor.
This CL replaces https://dart-review.googlesource.com/c/sdk/+/296900

The `List` constructor is removed in Dart 3.0.
Some of the `@patch` implementations were not removed.

This is *high priority*. It seems the left-over `@patch factory List` constructor did not cause any errors, instead it *added* a constructor  to `List` that can be used in web compiled code. Even if `List` doesn't have such a constructor in the SDK code proper.
The VM and analyzer will say the invocation is an error, but dart2js happily compiles it and runs.

(It used to be that patches couldn't add public members, that security seems to have been removed.)

Also removes code which tries to detect "the unnamed List constructor",
which is no longer a thing, and a number of invocations of the constructor, where it's not clear that the test is aware that the constructor no longer exists, and is not marked as `@dart=2.x` with x < 12.

TEST=ci

Change-Id: I4ffaf3ae2c4e75ca06e7ba0bf19187b6376f3888
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/297100
Reviewed-by: Brian Quinlan <bquinlan@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2023-04-22 00:38:28 +00:00
Nate Biggs 13849a9dd9 [dart2js] Add Dart input chars to compiler output when reading from dill.
What was being logged as "kernel bytes" or "Dart characters" included the size of the platform dill as well. Changed the text for that to the more general "input bytes". The new source bytes number is the number of bytes registered to Dart2JS by the CFE. This registration is done when the CFE is being run modularly or directly from sources.

When being run modularly the input to phase 0 (CFE-only) is slightly larger (includes extra files) but the input to phase 1 (closed world) ends up matching the non-modular value.

Example output:
Compiled 14,927,936 input bytes (8,010,096 characters source) to 11,647,944 kernel bytes in 0.48 seconds using 114.082 MB of memory

Change-Id: Idaaaf6f9c906659434a9af50882b7ed3343e601a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/297020
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-04-21 22:49:11 +00:00
Stephen Adams 2a66f966f3 [dart2js] Rename dart:_async_await_error_codes -> dart:_async_status_codes
Change-Id: I6b47f08791544eabc09bb05a81bbd0154bc39cb2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296704
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-04-21 00:01:51 +00:00
Sigmund Cherem eda54b0e93 [dart2js] update documentation on source-map extensions to mention VLQ encoding.
Change-Id: Ic564a992310591ee25a9aba1e1dc391160c47df2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296680
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
2023-04-20 20:02:33 +00:00
Stephen Adams b3fbb59d60 [dart2js] Construct _SyncStarIterator outside of transformed code
In the old scheme, sync* generators would have an entry and a
body. The entry contained typed checks and the body had injected code
to call a 'factory' helper method to construct the _SyncStarIterable.
It was necessary to pass the element type to the body to be passed to
the factory.

    int foo(T a, T b) sync* {yield f(a); yield f(b);}

is compiled to something like

    foo(a, b) {
      T._as(a); T._as(b);
      return foo$body(a, b, type$.int);
    }
    foo$body(a, b, R) {
      return _syncStarFactory(function(){BODY}, R);
    }

When type checks were disabled (`-O3`), it was often possible to
generate a single function by merging these as there were no checks.

The new scheme keeps the entry and body separate, and constructs the
_SyncStarIterable in the entry:

    foo(a, b) {
      T._as(a); T._as(b);
      return _syncStarFactory(foo$body(a, b), type$.int);
    }
    foo$body(a, b) {
      return function(){BODY};
    }

This keeps the typed Dart 'level' distinct from the untyped JavaScript
level.

The new scheme is a bit more verbose but has the advantage that the
call to `_syncStarFactory` can be inlined and optimized.

Change-Id: I13802d9c9eefd9323841670d059b75a81569d6cb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296140
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2023-04-20 00:38:10 +00:00
Stephen Adams 0698c194ae [dart2js] Fix impact test by adding @dart=2.19
Rerun with `-g` to update stale impacts.

Change-Id: I6aa8140c41d4478fa12c006e94f6a3618bfb3d17
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296404
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2023-04-19 21:09:57 +00:00
Stephen Adams a6162d1ff0 [dart2js] Fix missing source location on null-check in async method
Change-Id: Idd2530b3cae582819a823132c9777086035e386a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296027
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2023-04-19 16:31:22 +00:00
Nate Biggs 21de916eb8 [dart2js] Add back kernel source file caching guarded by a flag.
Removing this cache means that errors from dill-loaded sources only display an offset rather than an exact file location. This makes debugging externally reported issues more difficult.

See here for more background: https://github.com/dart-lang/sdk/issues/52020#issuecomment-1513533855

Change-Id: I243d0bd340708ddbf979d77b5e9559751ee1b79e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296040
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-04-19 00:34:03 +00:00
Stephen Adams 4c0de8ed89 [dart2js] sync* fixes
Change the calling convention of the sync* body to fix bugs and avoid allocations.

- Body takes the controlling _SyncStarIterator as a parameter.

- `yield` assigns directly to the `_current` field and returns.

- `yield*` calls a method on the controlling iterator (rather than returning the iterable). This avoids an allocation to wrap the iterable, a type test to distinguish `yield` from `yield*`, and allows the `get:iterator` call to happen in the dynamic scope of try-catch surrounding the `yield*` to that it will catch any exceptions.

- Avoid using IIFE to bind constants just to call the body.

- Use a dummy body to avoid the need to testing termination of the body.


Tests now passing:

co19_2/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_sync_t05
language_2/sync_star/move_past_end_test
language_2/sync_star/sync_star_exception_current_test
language_2/sync_star/sync_star_exception_iterator_test
language_2/sync_star/sync_star_exception_nested_test
language_2/sync_star/sync_star_exception_test


Bug: #51992


Change-Id: I397b470e121b8d71242ac28b3130637b78a1d0dc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294685
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2023-04-18 22:24:24 +00:00
Nate Biggs 7714e67efe [dart2js] Merge experimental inferrer into main inferrer branch.
Inference runtime metrics on a large program:
-----Before-----
Duration - Mean: 182.303 Median: 174.500 Max: 292.0
Memory - Mean: 5857.426 Median: 5752.639 Max: 6167.91

-----After-----
Duration - Mean: 144.525 Median: 133.500 Max: 242.0
Memory - Mean: 5867.756 Median: 5727.506 Max: 6262.414

This shows ~20% improvement in runtime and virtually no change in memory usage. Previously we saw a memory regression due to this change. But thanks to improvements in the representation of TypeInformation nodes that memory regression no longer exists.

Code size for this program is also very similar before and after this change.

Before: 43258484 bytes JS
After: 43258444 bytes JS
Change-Id: I6512637f16d83f3127fd1c060bb770ae56405b88
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/295460
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-04-18 22:15:49 +00:00
Stephen Adams 62a67ba5bc [dart2js][js_runtime] Use Array.isArray more consistently
The main reason is to do this change is to avoid inconsistencies in what is considered to be a `JSArray`. Using `Array.isArray` allows js-interop where the JavaScript code subclasses `Array`.

dart2js-production results:

ArrayLoop.pseudopoly.hoisted1-indexing  -50.20%
ArrayLoop.pseudopoly.indexing           -35.18%
Iteration.concat.manual                  11.69%
ListCopy.List.int.unmodifiable.2         12.03%
ListCopy.for.int.2                       12.58%
ListCopy.spread.int.2                    13.57%
ListCopy.toList.fixed.100                16.06%
ListCopy.List.of.fixed.100               16.96%
ListCopy.toList.100                      17.28%
ListCopy.spread.int.cast.2               18.45%
ObjectHash.hash.5                        19.62%
TypedDataPoly.A_UVx5.view.2              21.12%
ObjectHash.manual.5                      21.70%
ListCopy.spread.int.map.2                21.96%
ListCopy.spread.int.cast.100             22.12%
TypedDataPoly.A_UVx5.view.100            23.04%
ListCopy.spread.int.map.100              25.26%
ListCopy.List.of.100                     27.88%
ImagingGaussianBlurOnce                  29.67%
MegaEquality                             37.90%

An investigation of the two regressions shows that they benefit from a micro-benchmarking effect. The previous code was monomorphic at the property access in `receiver.constructor == Array`. If this is forced to be polymorphic, the baseline is quite a bit worse, leading to an improvement in line with some of the other benchmarks.


Change-Id: I5c265b1d7408fbd41da9c6fa17472bf648000c8d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/287140
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2023-04-18 20:39:39 +00:00
Nate Biggs 9834f87c54 [dart2js] Fix noSuchMethod override handling.
This bug manifested as change in 'language/no_such_method/mock_test' from RuntimeError to Passing in 'dart2js-production-linux-d8'.

Change-Id: Ieedb544c3d684437f7c79dfa62b4e30e1970637c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/295480
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-04-17 18:48:11 +00:00
Nate Biggs 90d84c8494 [dart2js] Parameterize calls to get (non-)virtual type information.
Change-Id: Icd3aafc7290cd7dcdd74b6f50095ad5b096422e5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/295260
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-04-15 03:10:53 +00:00
Nate Biggs 8b01742d60 [dart2js] Fix linearization issues.
- For parameters of closurized members make sure to mark the virtual parameter as closurized where appropriate. Closurized parameters are treated as dynamic and this needs to propagate to all the virtual target's overrides. Previously only the concrete target was getting marked as closurized.

- For mixins defining an abstract member, foo, implementations of foo (either directly on the mixin target or superclasses of it) should propagate their types to the abstract foo as they are effectively overriding it. Calls to foo within the body of the mixin can only target the abstract foo with a virtual call. So that virtual target needs to reflect the types of all its overrides.

Tests have been added that capture both of these cases. The values here reflect the non-linearized algorithm but prior to these fixes the linearized algorithms showed a diff for both tests. After these changes there is no diff.

This fixes all failures referenced in b/277876666.

Change-Id: Icaca99cb6902c54f481eebdbb65cbd7cf81aa2c2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294960
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-04-15 02:05:49 +00:00
Nate Biggs c618771744 [dart2js] Improve StaticUse memory utilization
Create a compact version of StaticUse without fields that are often not provided. And intern instances of StaticUse as there are a lot of duplicates.

This should save >150MB in the emitter phase of Dart2JS.

Change-Id: I8d0d0c64bd9e8e3ffc7a86c413cc875be568c5a4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/291620
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-04-13 22:16:04 +00:00
Nate Biggs 5b50a0f021 [dart2js] Fix file read logic for diagnostic reporting.
- Rather than gating reads on URIs we've seen, gate logic on file scheme. Any URI with a 'file' scheme should be readable.
- Use unmapped URI when creating SourceFile. For providers that expand their URIS (e.g. BazelRootProvider) this will make sure we're using the more readable form rather than the prefix substituted version.

Change-Id: I89a00e48a6ed4fc83d403b34c42092fcc42a8b56
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294961
Commit-Queue: Stephen Adams <sra@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2023-04-13 20:38:50 +00:00
Nate Biggs c6986b4e7e [dart2js] Improve namer runtime (the map lookup is a bit slow) and memory utilization by removing library key cache and using library index to disambiguate libraries.
Change-Id: I23ce733398d3c9a780a72eefd858c17a43b8be6f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/291642
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2023-04-13 19:30:32 +00:00
Nate Biggs 89472a00e4 [dart2js] Fix crashes caused by trying to read file from internal library URI.
Fixes https://github.com/dart-lang/sdk/issues/52020
Change-Id: I0a319d340a4aaf8735b40513237cfc089c435d92
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294720
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-04-12 18:49:23 +00:00
Srujan Gaddam 568469b896 Reland "[dart:js_interop] Export some package:js annotations and check them"
This reverts commit df761ba9e7.

This also rebases the original CL onto HEAD so it can be landed first.

CoreLibraryReviewExempt: Reland of backend-specific library changes.
Change-Id: I4f9a017be3ec1924c021f941291d79d7aee06663
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294131
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
2023-04-12 18:15:00 +00:00
Emmanuel Pellereau 55ec45493f Revert "[dart2js] Patch experimental inferrer (with linearized algorithm) into main inferrer."
This reverts commit 9aa00f6c75.

Reason for revert: breaks google3 (b/277876666)

Original change's description:
> [dart2js] Patch experimental inferrer (with linearized algorithm) into main inferrer.
>
> After this change for a large program we see:
> - 20% reduction in runtime (254s -> 202s)
> - 2% decrease in memory usage (7671.029MB -> 7524.901MB)
> - Code size decrease of <1% (214,788,150 bytes -> 214,757,445 bytes).
> - The k-limit of 6 refines imposed on the global inference algorithm is no longer hit for converging types. All but 15 types converge, down from 777 types that were hitting the k-limit before. This means we are likely generating better types/code for all 762 of those types.
> - More resilience to dynamic calls with lots of potential targets.
>
> Change-Id: I53d4ade51559f3366f076b6f2b485c5bdc50c6e8
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/271480
> Reviewed-by: Sigmund Cherem <sigmund@google.com>
> Commit-Queue: Nate Biggs <natebiggs@google.com>

Change-Id: Ia6e038e8e077813e589a54d2242bd2820bd22036
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294741
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Emmanuel Pellereau <emmanuelp@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2023-04-12 12:41:36 +00:00
Stephen Adams 90bba41618 [dart2js] Compile more is tests to instanceof
`o is T` where `T` is an interface implemented by a class hierarchy
can be implemented as `o instanceof R` where `R` is the root of the
hierarchy. The common case is that `R` is a single implementation
class.

`is Record` and `is Type` now generally use `instanceof`.

Fixes: #51366
Change-Id: I1943533bc53024f3199f71910034d49cf6661b22
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294320
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-04-11 21:06:00 +00:00
Nate Biggs 9aa00f6c75 [dart2js] Patch experimental inferrer (with linearized algorithm) into main inferrer.
After this change for a large program we see:
- 20% reduction in runtime (254s -> 202s)
- 2% decrease in memory usage (7671.029MB -> 7524.901MB)
- Code size decrease of <1% (214,788,150 bytes -> 214,757,445 bytes).
- The k-limit of 6 refines imposed on the global inference algorithm is no longer hit for converging types. All but 15 types converge, down from 777 types that were hitting the k-limit before. This means we are likely generating better types/code for all 762 of those types.
- More resilience to dynamic calls with lots of potential targets.

Change-Id: I53d4ade51559f3366f076b6f2b485c5bdc50c6e8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/271480
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-04-11 16:37:26 +00:00
Nate Biggs b3ec488499 [dart2js] Pass option to exclude source code from closed world phase output dill.
Dart2JS uses the source bytes to generate error messages for the CFE and during closed world construction (for const evaluation). But the actual source code is never used beyond that.

For large applications not including the source code can reduce the size of the dill by close to 50%.

Change-Id: I99d2cb5d1cea843bc12a5e90df3ed651ed8a1ff1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293762
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-04-11 15:20:43 +00:00