Commit Graph

6036 Commits

Author SHA1 Message Date
Sam Rawlins aad9e57674 Revert "Revert "[analyzer] new warning for nullable '==' parameter type""
This reverts commit 885457e1d3.

[analyzer] new warning for nullable '==' parameter type

This rule checks that a parameter to an `operator ==` implementation has
a non-nullable type.

I intentionally did not enforce, in this rule, that the parameter is
exactly `Object`. It is legal to narrow the parameter type to a
different non-nullable type, like `int`. I can't imagine doing it, but
it seems to be unrelated to whether the type should be nullable or not.

Fixes https://github.com/dart-lang/linter/issues/3441

Replaces https://github.com/dart-lang/linter/pull/3923

Change-Id: Ic0be2bfebaf59b0336e9a3a58e5b7f5359eb8646
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/291042
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-12-14 23:58:12 +00:00
Mayank Patke b10728fbac [dart2js] Use correct element type for generators.
dart2js previously syntactically matched on `Iterable<T>` and
`Stream<T>` exactly and did not compute the union-free type. The new
computation is a direct translation of the specified semantics.

Change-Id: Iaf916c6ba65e626181663ca554c38c90cdd88899
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341337
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2023-12-14 00:12:50 +00:00
Nate Biggs 66445534ea [dart2js] Fix implicitly used free type variable not being registered in closure scope.
Fixes: https://github.com/dart-lang/sdk/issues/54209
Change-Id: Ia042ac4444ebe134107ab5d626a3328d49b38241
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339381
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-12-13 22:42:57 +00:00
Mayank Patke 4387b5d69c [dart2js] Use futureValueType in impact computation.
Change-Id: Ic6f54cf14098c9cc1cfe01ee01a09e7be5ce419a
Bug: #54317
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341600
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2023-12-13 18:46:45 +00:00
Mayank Patke 0b0a972526 [dart2js] Use correct futureValueType.
Fixes: #54317
Change-Id: Id94b486df6a66ef6c77f2c578ab8d11a73189ff9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341328
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2023-12-13 17:50:00 +00:00
Ahmed Ashour d9962e5053 [analyzer] UNNECESSARY_SET_LITERAL to handle multiple expressions
Bug: https://github.com/dart-lang/sdk/issues/50900
Change-Id: Id09e102c2cc12c9043d3f6c22b3af3babf18920e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/284021
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Oleh Prypin <oprypin@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Oleh Prypin <oprypin@google.com>
2023-12-11 21:24:59 +00:00
Nate Biggs f057c39255 [dart2js] Add dartDeferredLibraryMultiLoader API to js_helper.
This will allow users who are implementing their own deferred loading mechanism
to batch all the loads for a specific library. Today in order to do batching users have to gather the URIs passed to the `dartDeferedLibraryLoader` hook in a list and schedule (e.g. via setTimeout) a load for some future task.

The need to schedule a task has been shown to cause delays in IPL. But loading each part file individually can also be very expensive. So this allows for a compromise where bundling can be done synchronously per loaded library.

Adds ~8kB to unminified main files and ~2.5kB to minified main files.

Bug: https://github.com/dart-lang/sdk/issues/54202
Change-Id: I623643b03920988cda8b0f8b297944be35ffa606
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340480
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-12-08 21:10:48 +00:00
Nate Biggs c447f0007e [dart2js] Add shadow tree based tracer that uses JS Printer hooks to generate source map metadata.
The current tracer does a separate visit of the entire JS AST using metadata from the JS printer in order to generate source maps. This new strategy uses a shadow tree tracking position info to generate source map metadata while the JS AST is bring printed. This saves us an entire tree walk and the memory overhead of storing metadata to pass to the separate source map tracer.

In local invocations of Dart2JS I see a memory improvement of >100MB in the emitter phase and a small time improvement of ~4%.

Change-Id: I622e7015e2eddc7835551f970386e13019394a79
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336760
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2023-12-07 17:35:59 +00:00
Srujan Gaddam b1a7ca77e0 [dart:js_interop] Move JS types to extension types
- Removes @staticInterop JS types declarations in favor of
typedefs (the function types' reified types and the typed data's
reified types have changed to make the type hierarchy work in the
JS backends).
- Adds extension types to dart:js_interop
- Adds a fromInteropObject helper to JSObject to avoid casting to
an extension type
- Deletes now stale tests
- Refactors some dart2wasm @staticInterop declarations since they
can no longer implement JS types
- Updates extension types tests to use the prefix extension_type
instead of inline_class
- Updates comments

CoreLibraryReviewExempt: Backend-specific library.
Change-Id: Ibe04afac9585ddb99fcf6dbaa7f12050d8b876dc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332860
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-12-06 21:59:58 +00:00
Stephen Adams 9864cb2231 [dart2js] Recognize larger no-op regions
Recognize larger regions of no-op control flow. Ideally we would be able to remove these regions from the CFG. Until then, pattern matching larger regions leaves fewer ghost conditions in the generated code.

With pattern matching, we are seeing more examples where this is necessary.

Bug: #29475
Change-Id: Ib0981400883631f56940288f8a32fbc5f3985dfb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340067
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2023-12-06 19:05:19 +00:00
Mayank Patke 4e3cc1cb41 [dart2js] Don't minify Invocation.memberName
Fixes: #54201
Change-Id: I3cc66263a86668ee46743e46564b175d60143916
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/338947
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2023-12-06 18:57:15 +00:00
Stephen Adams af20a8ab03 [dart2js] Relax constraints on dummy reiver optimization of getter calls
This recovers 3.3k or about 15% of the size regression reported in b/314275739

Change-Id: I8209643719c962ca9c5c83eef805521c26634411
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339230
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-12-06 00:52:50 +00:00
David Morgan 29268c6c1d [dart2js] Remove trailing whitespace and newline from error message.
Before:

```
dart compile js --wrong-flag
Compile Dart to JavaScript.

Usage: dart compile js [arguments] <dart entry point>
  -h, --help      Print this usage information.
  -h -v           Show detailed information about all options.
  -o, --output    Write the output to <file name>.
  -O<0,1,2,3,4>   Set the compiler optimization level (defaults to -O1).
     -O0          No optimizations (only meant for debugging the compiler).
     -O1          Default (includes whole program analyses and inlining).
     -O2          Safe production-oriented optimizations (like minification).
     -O3          Potentially unsafe optimizations (see -h -v for details).
     -O4          More agressive unsafe optimizations (see -h -v for details).
  <-- TWO SPACES HERE and a newline

Error: Unknown option '--wrong-flag'.
```

After this change:

```
dart compile js --wrong-flag
Compile Dart to JavaScript.

Usage: dart compile js [arguments] <dart entry point>
  -h, --help      Print this usage information.
  -h -v           Show detailed information about all options.
  -o, --output    Write the output to <file name>.
  -O<0,1,2,3,4>   Set the compiler optimization level (defaults to -O1).
     -O0          No optimizations (only meant for debugging the compiler).
     -O1          Default (includes whole program analyses and inlining).
     -O2          Safe production-oriented optimizations (like minification).
     -O3          Potentially unsafe optimizations (see -h -v for details).
     -O4          More agressive unsafe optimizations (see -h -v for details).

Error: Unknown option '--wrong-flag'.
```
R=sra@google.com
Change-Id: Ie0541d830b53e3e81b4b02a20988cbd41db64325
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339300
Auto-Submit: Morgan :) <davidmorgan@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Morgan :) <davidmorgan@google.com>
2023-12-04 09:24:32 +00:00
Srujan Gaddam 4a95930f0d [dart2js] Fix registering of allowInterop impact
This impact was added so the compiler would correctly consider
JavaScriptFunction live when allowInterop was used. At some
point, this behavior regressed but the effect of this was hidden
by the existence of dart:js_interop JS types. Because the JS
types were implemented using package:js classes, the compiler
assumed JavaScriptFunction was always live. As we are migrating
them to extension types, this bug resurfaced.

There are two key details in this CL:
- The allowInterop impact needs to register that JavaScriptFunction
is instantiated. needToInitializeIsolateAffinityTag is not enough.
- Both resolution and codegen need to add the impact. Before this
CL, we checked for use of allowInterop during SSA and registered
that it was being used, and we only processed the impact if it was
being used. However, this check of the registration only occurred
during resolution. Since resolution occurs before codegen, we never
actually processed the impact.

It isn't clear why both details are needed for
tests/web/regress/issue/37576_test to pass.

Change-Id: Ieff8ac5c4d040cc034f58ecb09a4246d2d8f87b7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336626
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-12-01 22:28:05 +00:00
Srujan Gaddam ae082ef407 [pkg:js] Remove referenceFromIndex lookup in static interop eraser
This was only ever used to handle modular compiles and is no longer
needed now that we erase in DDC instead.

Change-Id: I44577464c29526d4b4fabb7c65c9f5f693edb02a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335407
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-11-28 01:11:30 +00:00
Nate Biggs 3d40816fc3 [dart2js] Remove deserializer 'emptyAsNull' pattern.
Change-Id: I5b5e668fa6c1c261503de55f70aab966ca9df66f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/338300
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-11-27 21:16:39 +00:00
Nate Biggs 7b12b2397e [dart2js] Remove serializer allowNull pattern to be more null safe friendly.
With the exception of the one noted case, this change just adds an `OrNull` method variant for any write that was using `allowNull` and changes the call site to use the new `OrNull` method.

There are a few cases where we weren't using the `allowNull` parameter at all. In those cases I've removed the parameter without adding an `OrNull` variant.

Change-Id: Ie5eae4d7f2fb7ccaf9594b9c533afdd93bd99198
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/338280
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-11-27 21:16:39 +00:00
Nate Biggs 3e160c861f [dart2js] Clean up asserts for sound nullsafe Dart2js.
- Remove asserts that were checking for nulls during migration (via dynamic cast).
- Change map key containment asserts from `map[key] == null` to `!map.containsKey(key)` when the map isn't nullable. The null check makes it unclear if the map allows null without looking at the declaration.
- Update 2 constructors to use `super.`. Suggested by analyzer when I removed constructor bodies.

Change-Id: Idd8969dc84f889adeaaf4024ad6129babc76eb10
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/338240
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-11-27 17:27:19 +00:00
Nate Biggs 04923341cf [dart2js] Use indexed (but not cached) reads for source information.
In the emitter phase source informations are attached to nodes but we have made several changes to ensure the majority of nodes are GCed immediately after being printed. This deserializer cache is holding references to the associated source informations so those objects are not being GCed as well.

Locally see a >400MB memory improvement as a result.

Change-Id: I2fb849c7b0a063579f068bea7d22e7533d61ec05
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/337881
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-11-27 17:01:45 +00:00
Nate Biggs 13c30c0290 [dart2js] Add option to perform indexed but not cached reads.
Some indexed objects might benefit from being deduped in the serialized contents (i.e. to reduce serialized data size) but might be short lived otherwise and therefore don't benefit from being cached by the deserializer.

This adds the option to read from the same index but deserialize a fresh object each time.

Change-Id: I405745fb7be28fa4c5b15640f90d83522f268a27
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/337901
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-11-27 17:01:45 +00:00
Nate Biggs e0116d3bca [dart2js] Stop storing entire emitted code buffer on emitter.
We are only using these buffers to get the length of the code buffers later. Instead just get and store the lengths up front.

Change-Id: I208c94267dc6569b094aec4fb170db658dc8887e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/337880
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-11-23 00:12:19 +00:00
Alexander Thomas 12bceeb4fc [cleanup] Remove references to _2 tests from pkg/compiler
Bug: b/310114753
Change-Id: If4743c822a96b8a4194cba54a271cd24055d70ef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336961
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
Auto-Submit: Alexander Thomas <athom@google.com>
2023-11-22 21:22:53 +00:00
Ryan Macnak c1143082fe Include ARM64 when uploading d8.
Change-Id: I613ca948734a849c43f6f6d02cfd678d18fe7e03
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336200
Reviewed-by: Alexander Thomas <athom@google.com>
2023-11-21 17:15:20 +00:00
Nate Biggs 412bb9f359 Reland "[dart2js] Stop emitting a dill with closed world."
This is a reland of commit b9e25afcb4

Original change's description:
> [dart2js] Stop emitting a dill with closed world.
>
> All transformations to the dill are now performed with the CFE linker phase (phase0b). This means we no longer need to emit a dill as part of the closed world computation. This saves both time and memory resources associated with the cost of serialization during that phase.
>
> Change-Id: I28dde8a1eecd71e823880027505f62fc804fcca6
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332821
> Reviewed-by: Sigmund Cherem <sigmund@google.com>
> Reviewed-by: Mayank Patke <fishythefish@google.com>
> Commit-Queue: Nate Biggs <natebiggs@google.com>

Change-Id: Ia693213dcdc949a8ef4b4204cc033130274d2381
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336982
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-11-18 00:32:49 +00:00
Nate Biggs 0774143afd [dart2js] Split timing out deferred_load_id_map_test.dart test into two tests.
Fixes: https://github.com/dart-lang/sdk/issues/54084
Change-Id: Ie618d74188f455bd9a8c904273482bc80bba4c0b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336981
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Auto-Submit: Nate Biggs <natebiggs@google.com>
2023-11-17 22:45:23 +00:00
Nate Biggs 2b4b9cb753 Reland "[dart2js] Move Dart2js const conditional simplifier to phase 0b, the CFE linker."
This is a reland of commit fdfca11d39

Original change's description:
> [dart2js] Move Dart2js const conditional simplifier to phase 0b, the CFE linker.
>
> Change-Id: I9ed7f46c5641c28dc71b7712dbd4e8d2062b1f4d
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332820
> Reviewed-by: Sigmund Cherem <sigmund@google.com>
> Reviewed-by: Mayank Patke <fishythefish@google.com>

Change-Id: I0ddf00c551196085e2a17936d15d6bc46c76efad
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336580
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-11-17 21:46:02 +00:00
Nate Biggs 193db9b70e [dart2js] More lenient source code handling for diagnostic reporting.
Should avoid exceptions as thrown in https://github.com/flutter/flutter/issues/138326

Only register source code if there is content in the byte array so we know when we should try to read from file. And when trying to read contents of a file for diagnostics, if we fail to read the file then fail gracefully by using position information.

Change-Id: Ic7e2bdcba0b093a48735aa26670509354f953861
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336480
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-11-17 21:40:42 +00:00
Robert Nystrom 2ee771a4f6 Remove the legacy "_2" tests. \o/
I also cleaned up a bunch of places that referred to them.

Change-Id: I45f68818c892f8620ea04257885ffa3763374bb5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335863
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
2023-11-17 20:17:23 +00:00
Stephen Adams 87d9b9d946 [js_ast, dart2js] Unwrap trivial blocks in the compiler, not printer
Simplify the js_ast printer - it should not transform the program
while printing.

js_ast:

- Don't skip blocks containing a single statement.

- Don't rewrite arrow functions.


dart2js:

- Fix rewrite_async.dart to avoid a few singleton blocks.

- Static initializer thunks are transformed in arrow functions with expression bodies.

Change-Id: I4ab75c6ca7f580835a6c9d4eb45240d76df9d895
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336820
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2023-11-17 19:23:27 +00:00
Lasse R.H. Nielsen 5543293a16 Reland "Expire 3.0.0 experiment flags."
This is a reland of commit 6f29e7fce4

Original change's description:
> Expire 3.0.0 experiment flags.
>
> TEST=Existing tests covers.
> Change-Id: I161eefdc28c74f63ba1ee926800a01eea03d9930
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331960
> Commit-Queue: Lasse Nielsen <lrn@google.com>
> Reviewed-by: Alexander Thomas <athom@google.com>

TEST=Existing tests covers.
Change-Id: I384e77744c74774a250be413358a7fa176117167
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332684
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2023-11-17 13:10:01 +00:00
Nate Biggs d7fa5f3d89 Reland "[dart2js] Evaluate CFE consts as part of phase 0b (CFE linker)."
This is a reland of commit bebd08746b

Original change's description:
> [dart2js] Evaluate CFE consts as part of phase 0b (CFE linker).
>
> Constants are current evaluated in a few places during closed world generation, primarily as part of the ScopeModelBuilder. The scope visitor was modifying the AST which meant we had to emit a new dill with these evaluated constants along with the closed world results.
>
> This change instead evaluates the constants directly after linking the Kernel as part of the global transformations. This means we can update the ScopeModelBuilder to not mutate the AST at all as all constants are already simplified.
>
> A potential follow up here is to simplify the ScopeModelBuilder since all nodes should already be simplified if they can be, we should be able to avoid visiting some children.
>
> After this change we only directly create a single ConstantEvaluator, the one in `load_kernel`. The const simplifier also creates one and a follow up CL moves this to to run right after this new transformation.
>
> Note: Alternate versions of this CL tried to make the global transformation simpler by either:
> 1) Running the const evaluator indiscriminately on all expressions. This didn't work because it lead to exponential computation on constants set up as a DAG (see tests/language/const/constant_dag_test).
> 2) Only evaluating ConstantExpression nodes to update UnevaluatedConstants. This does not cover all the cases where the ScopeModelBuilder is modifying the tree and lead to a different compiler output.
>
> Change-Id: I746d889b37feddc9ab6c386c6252016dec745e6e
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332601
> Reviewed-by: Mayank Patke <fishythefish@google.com>

Change-Id: I53871a57144a3a1bd363af141d8f31c8ffa5ca6d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336221
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-11-15 19:15:29 +00:00
Nate Biggs 3fe10c470e Revert "[dart2js] Evaluate CFE consts as part of phase 0b (CFE l..."
Revert submission 332821

Reason for revert: Breaking internal build targets.

Reverted changes: /q/submissionid:332821

Change-Id: Ic81f371c83956027f7e710c663a7eeb432c71d7d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336087
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-11-14 19:44:24 +00:00
Nate Biggs 8bf21bf442 Revert "[dart2js] Move Dart2js const conditional simplifier to p..."
Revert submission 332821

Reason for revert: Breaking internal build targets.

Reverted changes: /q/submissionid:332821

Change-Id: I9ccf92eea6752a1f59cbfa4bfe4305344f716da4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336086
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-11-14 19:44:24 +00:00
Sigmund Cherem 802279dc0e Revert "[dart2js] Stop emitting a dill with closed world."
Revert submission 332821

Reason for revert:
Caused breakage in flutter engine, see https://github.com/flutter/flutter/issues/138326 for details.

Reverted changes: /q/submissionid:332821

Change-Id: I179b3596e938c8b2202b200037ba5dcdd01b3384
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335900
Reviewed-by: Stephen Adams <sra@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2023-11-13 18:39:39 +00:00
Nate Biggs b9e25afcb4 [dart2js] Stop emitting a dill with closed world.
All transformations to the dill are now performed with the CFE linker phase (phase0b). This means we no longer need to emit a dill as part of the closed world computation. This saves both time and memory resources associated with the cost of serialization during that phase.

Change-Id: I28dde8a1eecd71e823880027505f62fc804fcca6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332821
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-11-10 20:38:34 +00:00
Nate Biggs fdfca11d39 [dart2js] Move Dart2js const conditional simplifier to phase 0b, the CFE linker.
Change-Id: I9ed7f46c5641c28dc71b7712dbd4e8d2062b1f4d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332820
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-11-10 20:38:34 +00:00
Nate Biggs bebd08746b [dart2js] Evaluate CFE consts as part of phase 0b (CFE linker).
Constants are current evaluated in a few places during closed world generation, primarily as part of the ScopeModelBuilder. The scope visitor was modifying the AST which meant we had to emit a new dill with these evaluated constants along with the closed world results.

This change instead evaluates the constants directly after linking the Kernel as part of the global transformations. This means we can update the ScopeModelBuilder to not mutate the AST at all as all constants are already simplified.

A potential follow up here is to simplify the ScopeModelBuilder since all nodes should already be simplified if they can be, we should be able to avoid visiting some children.

After this change we only directly create a single ConstantEvaluator, the one in `load_kernel`. The const simplifier also creates one and a follow up CL moves this to to run right after this new transformation.

Note: Alternate versions of this CL tried to make the global transformation simpler by either:
1) Running the const evaluator indiscriminately on all expressions. This didn't work because it lead to exponential computation on constants set up as a DAG (see tests/language/const/constant_dag_test).
2) Only evaluating ConstantExpression nodes to update UnevaluatedConstants. This does not cover all the cases where the ScopeModelBuilder is modifying the tree and lead to a different compiler output.

Change-Id: I746d889b37feddc9ab6c386c6252016dec745e6e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332601
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-11-10 20:38:34 +00:00
Nate Biggs a32d78c13d [dart2js] Rename global and modular Kernel transformers.
Change-Id: I1160143f0cc4b71629efd484083fee8ce35b22e3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/334340
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-11-10 20:38:34 +00:00
Stephen Adams 0be8cb24f2 [dart2js] Avoid excessive --lax-runtime-type-to-string diagnostics
The ~200k of diagnostics causes the Flute compile-time benchmarks to
fail.

Bug: 53993
Change-Id: I81d26758f906bc82f1ff7149e7c735967216297c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335028
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2023-11-09 01:15:50 +00:00
Nate Biggs 9eba05482b [dart2js] Fix list tracing treating first/last setters as type preserving.
I suspect that when the list of type preserving selectors was created the first/last setters either didn't exist or were just overlooked. Any dynamic List could have its inferred type changed by these operations.

Due to Dart2js's type representation this bug affects more than just dynamic lists. We track some simple values as part of the type system. So an operation that modifies a value can technically modify the type, as Dart2js represents it, even if the "real" type is preserved.

In the added test we would represent the list literal's type as "List(length: 2, elementType: Bool(true))". Notice the type states the elementType is specifically true, not just bool. Thus the first/last operations are modifying that type. But since we aren't registering this type change, SSA optimizes away the call/index and inlines the element itself.

Interestingly, this primarily manifested for bools due to a check in SSA:
https://github.com/dart-lang/sdk/blob/main/pkg/compiler/lib/src/ssa/optimize.dart#L475

In that code we are inlining constant-like expressions for the arguments of static invocations (such as the argument to a Expect.isTrue call). However, a few lines earlier you will see we only inline bool constants:
https://github.com/dart-lang/sdk/blob/main/pkg/compiler/lib/src/ssa/optimize.dart#L467

So when the list element type is anything other than a bool, this inlining does not trigger thus avoiding the bug.

Bug: https://github.com/dart-lang/sdk/issues/53944
Change-Id: I4e893903f335fc99b13cf526736c27bb066a4bad
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/334420
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-11-08 03:50:21 +00:00
Jacob Richman 933537b66b Trivial cleanup to make VSCode workspace for the SDK
free of diagnostics as long as you filter with "!TODO"

R=athom@google.com, jensj@google.com, natebiggs@google.com

Change-Id: I73cf3c5ef6dab81808330c4eb5f44cb62e753c81
Tested: manually verified that VSCode is warning free. No changes in functionality.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333903
Auto-Submit: Jacob Richman <jacobr@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Jacob Richman <jacobr@google.com>
2023-11-07 17:49:53 +00:00
Nate Biggs ad2708d071 [dart2js] Delete modular compilation step.
The Dart2JS team has agreed that this mode of compilation is no longer worth investing in at this time and its existence adds some overhead to other feature work so it is worth fully removing. In the future we may revisit this mode of compilation. Below is some more context for any future exploration in this space.

What didn't work with modular analysis:
- current modular analysis was computing impacts, which were dense (50% of the size of kernel)
- using it moved work to a modular phase, and cut Phase1 in half however end-to-end time was not better
- data overhead was very high
- it made it much harder to maintain invariants throughout the pipeline: the data is tightly coupled with the kernel AST, making it hard to make late modifications to the AST.

How to potentially make it better:
- make the data much more sparse
- make the data more independent from the kernel AST so that transformations are not breaking
- reduce the critical path in a more substantial way.

Note: We retain and ignore the commandline flags used for modular analysis in order to avoid breaking build pipelines that were passing them. We may remove these at a later date.

Change-Id: If574ce2358280ab5fedd89c62665328601e72e22
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333360
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-11-03 00:11:50 +00:00
Johnni Winther 72f1591f29 [cfe] Use getTypeAsInstanceOf instead of getInterfaceTypeAsInstanceOfClass
The changes calls to getInterfaceTypeAsInstanceOfClass (et al.) to
getTypeAsInstanceOf to ensure that we take extension types into account.

Change-Id: I7d732cdae8494002b44561cb02c49d58dd0ba67b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332920
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2023-10-31 22:30:50 +00:00
Mayank Patke b034a909a6 [dart2js] Avoid discarding type tests during SSA with
--experiment-null-safety-checks

Change-Id: If3e2465103494d4772b1f8b71e7c57ae83b3e036
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332371
Commit-Queue: Mayank Patke <fishythefish@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2023-10-30 22:08:47 +00:00
Nate Biggs 5403dc4927 [dart2js] Remove unused NonConstantValue.
The only constructor invocation of `NonConstantValue` is in the deserializer. Which means we're never creating any of these objects to serialize.

Also remove unused `handleClosureCall` method in `pkg/compiler/lib/src/inferrer/builder.dart`

Change-Id: I04e492bc4824795dd8fc109ee7464be56b27cb93
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332500
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-10-28 04:17:16 +00:00
Alexander Aprelev 6a464c9dee Revert "Expire 3.0.0 experiment flags."
This reverts commit 6f29e7fce4.

Reason for revert: broke g3 bot

Original change's description:
> Expire 3.0.0 experiment flags.
>
> TEST=Existing tests covers.
> Change-Id: I161eefdc28c74f63ba1ee926800a01eea03d9930
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331960
> Commit-Queue: Lasse Nielsen <lrn@google.com>
> Reviewed-by: Alexander Thomas <athom@google.com>

Change-Id: Ied6f612dc922824ffdadc4660898f3b859922ff5
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332582
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
Auto-Submit: Alexander Aprelev <aam@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2023-10-27 16:50:09 +00:00
Lasse R.H. Nielsen 6f29e7fce4 Expire 3.0.0 experiment flags.
TEST=Existing tests covers.
Change-Id: I161eefdc28c74f63ba1ee926800a01eea03d9930
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331960
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
2023-10-27 13:57:00 +00:00
Stephen Adams cb52932c72 [tests, dart2js] Fix test using minified type names
1. Add `Object` and `Map` to the very short list of names that are
unminified in the app.

2. Tweak test to avoid testing minified name.

Change-Id: Ide0cedc2950b5392eb6963403a48c0f89cd1b50a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332368
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-10-27 01:36:28 +00:00
Nate Biggs 23282457ad [dart2js] Small improvements in emitting JS.
- Remove unused Map in source map emitter logic.
- Buffer output writing for both JS and source maps. Previously we were only buffering the source map writes.

During local compilations of a large program combined these amount to a >100MB improvement in memory usage.

Change-Id: I633c2f81aa28744e30c6a706bb3927423b38a6e0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331361
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-10-26 16:00:51 +00:00
Nate Biggs 9542aa442a [dart2js] Add back private indices for entity maps.
After further review the slight increase in memory usage is minimal and worth the improvement in runtime for each phase.

The new indices follow the same format as before, we assign each entity an index when it is registered into the entity map. However these new indices are only used by the entity maps and not as part of the serialization format for those entities. The index only exists to make look ups faster in the "map". As such, I've made the field private to prevent/discourage outside use of it.

Change-Id: I7a7c20a2dd51b01d2390bb4401545821a1014832
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331360
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-10-24 22:49:38 +00:00