Commit graph

5614 commits

Author SHA1 Message Date
Oleh Prypin 27ad1a74dd Revert "[dart2js] Add runtime type check for await."
This reverts commit c81711bdda.

Reason for revert: `Internal Error: Runtime type information not available for type_variable_local` - b/295131730

Original change's description:
> [dart2js] Add runtime type check for `await`.
>
> See https://github.com/dart-lang/sdk/issues/49396 for details.
>
> Fixes: #50601
> Change-Id: Ie89130cffe642b3e4935d7d02fe2e34f7fc8b12e
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/316320
> Commit-Queue: Mayank Patke <fishythefish@google.com>
> Reviewed-by: Stephen Adams <sra@google.com>

Change-Id: I481b119b6569d1bc9cf2ab80d997a3eb6d06f674
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/319421
Reviewed-by: Alexander Thomas <athom@google.com>
Auto-Submit: Oleh Prypin <oprypin@google.com>
Commit-Queue: Oleh Prypin <oprypin@google.com>
2023-08-09 11:23:19 +00:00
Mayank Patke c81711bdda [dart2js] Add runtime type check for await.
See https://github.com/dart-lang/sdk/issues/49396 for details.

Fixes: #50601
Change-Id: Ie89130cffe642b3e4935d7d02fe2e34f7fc8b12e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/316320
Commit-Queue: Mayank Patke <fishythefish@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2023-08-08 20:18:04 +00:00
Srujan Gaddam a56642e9a1 [dart:js_util] Handle type parameters in export/mocks.
Several changes are made:

- createDartExport now does not export methods that define type parameters.
- createStaticInteropMock adds conformance checks to make sure implementing
members can handle all possible values of a type parameter in an interop
member. An error is added to reduce confusion around this.
- Export creator now uses dart:js_interop_unsafe for a lot of its lowering
as the dart:js_util equivalents are buggy when it comes to calling exported
functions in JS with JS types.
- Small code changes are added to backends to handle the above changes.

Change-Id: Ie3b6b157930537267f270b60373b2b17e0a14344
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/316141
Reviewed-by: Joshua Litt <joshualitt@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-08-04 21:45:29 +00:00
Nate Biggs 37fba7b9dc [dart2js] Add alias mapping for deferred import IDs.
Today the deferred import mapping is missing a way to match a specific user-defined deferred load alias to a corresponding runtime load ID. This adds a new field, "importPrefixToLoadId", under each library entry, which is keyed by library URI, which maps from the user-defined deferred load ID to the Dart2JS runtime load ID.

Example using https://github.com/dart-lang/sdk/blob/main/tests/language/deferred/split_constants_canonicalization_test.dart:
```
{
  "_comment": "This mapping shows which compiled `.js` files are needed for a given deferred library import.",
  "split_constants_canonicalization_test.dart": {
    "name": "<unnamed>",
    "imports": {
      "1": [
        "out.js_1.part.js"
      ],
      "4": [
        "out.js_2.part.js"
      ]
    },
    "importPrefixToLoadId": {
      "a": "1",
      "b": "4"
    }
  },
  "split_constants_canonicalization_a.dart": {
    "name": "<unnamed>",
    "imports": {
      "2": [
        "out.js_4.part.js",
        "out.js_3.part.js"
      ],
      "3": [
        "out.js_4.part.js",
        "out.js_5.part.js"
      ]
    },
    "importPrefixToLoadId": {
      "a_1": "2",
      "a_2": "3"
    }
  },
  "split_constants_canonicalization_b.dart": {
    "name": "<unnamed>",
    "imports": {
      "5": [
        "out.js_4.part.js",
        "out.js_6.part.js"
      ],
      "6": [
        "out.js_4.part.js",
        "out.js_7.part.js"
      ]
    },
    "importPrefixToLoadId": {
      "b_1": "5",
      "b_2": "6"
    }
  }
}
```

Change-Id: Ia6a6f8e45613c0081485e3fe5ddc84627749ee8e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/317222
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-08-03 22:13:40 +00:00
Nate Biggs 29dcf29314 [dart2js] Easy runtime improvements in SSA.
There are two changes here that account for ~5% of the cycles spent compiling large programs:
1) Calls to 'runtimeType' (specifically _AbstractType.toString) are expensive and CodegenPhase.name calls this 2/3 times per member in the target program.
2) ModularNamer._jsVariableReservedCache is a late final field that gets instantiated for every namer in the program, of which there is one per member in the target program. All the subsets are static and so _jsVariableReservedCache can be static as well. Ideally this would be const but const sets cannot have duplicate strings and the various subsets have some overlaps.

Change-Id: Iefc294145feebe397b2db84a5f49906c6b1372a1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/317981
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-08-03 19:58:07 +00:00
Johnni Winther 9987c437de [dart2js] Enable verification of compilation with errors
Change-Id: I02ea869b1ef07df910820edbf87da6e3b10d02e6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310100
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-08-03 08:14:19 +00:00
Nate Biggs 2ec35b5761 [dart2js] Fix issue with non-async try/catch nested in catch block of async try/catch.
Fixes: 53082
Change-Id: Iadb11da5d6e71109682fc941f10e7373f70a1430
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/317340
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2023-08-01 19:39:32 +00:00
Johnni Winther a76f4d5c34 [cfe] Rename InlineClass to ExtensionTypeDeclaration
This renames InlineClass to ExtensionTypeDeclaration, and InlineType
to ExtensionType. Members of extension type declarations are called
extension type members instead of extension type declaration members
for "brevity".

TEST=existing

Change-Id: I91ed62533ddd345644492f04dc3310d007460288
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/316780
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2023-08-01 09:04:38 +00:00
Johnni Winther bf9ea56ff7 [kernel] Remove nodes used for the old 'extension-types' experiment
This removes ExtensionType, ExtensionTypeShowHideClause and
CallSiteAccessKind from package:kernel which where only used by the now
removed 'extension-types' experiment.

A follow-up CL will rename InlineClass/InlineType to
ExtensionTypeDeclaration/ExtensionType to match the names of the
Extension Type feature currently being implemented.

TEST=existing

Change-Id: I58d2e8b0a92ac61329ee161cc6884a2c0e6f87ae
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/316420
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2023-07-27 10:47:08 +00:00
Nate Biggs 4f03bd0c30 [dart2js] Defer loading of codegen results.
This was landed a while ago as https://dart-review.googlesource.com/c/sdk/+/254600. However, this had to be rolled back because at the time this increased memory usage for the emitter phase. This change prevented GC from cleaning up the byte arrays of the codegen serialized files which resulted in an increased max heap.

However, now that we map (rather than copy) files into memory, there is no overhead to keeping a reference to the codegen serialization files.

Thanks to recent improvements in the efficiency of deferred serialization this change seems to improve max memory usage by up to 1.2GB for the emitter phase. Avoiding caching results also helps in this regard, usage of the results is fairly localized.

Change-Id: I4d401a877cb74cbb36b511eb598a759fe300fd5d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/316180
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-07-26 02:23:40 +00:00
Mayank Patke b336f3900b [dart2js] Bailout tracing of record fields when record is bailed out
Fixes: #52968
Change-Id: Ie59d4c0f903089622bc260d471bc136fa91eacde
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/315020
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2023-07-19 23:34:46 +00:00
Nate Biggs acd2ad41b6 [dart2js] Union old and new type when refining in type inference.
This change doesn't seem to have a significant impact on most compilation results:
- Golem results show no significant difference in microbenchmarks.
- For a medium and large app tested, while we see a small change in the actual inference results, the generated code is identical before/after this change.
- Timing and memory usage on internal compilations seem comparable before/after this change.

Note: This replaces the need for any notion of "invalid" refines so I will clean up that code in a follow up change.

Change-Id: I2a293eacd944fc17ee2dab97d3d947c042b4038f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/313720
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-07-14 20:46:17 +00:00
Nate Biggs 25a1d01084 [dart2js] Remove need for individual closures in Deferrable serialized data.
This new approach uses static tear-offs where possible to avoid allocating a new Closure for each Deferrable.

Note: This doesn't scale to every case but as of today the one case not covered is a singleton and so only 1 closure should be allocated there regardless.

Data from a fairly large app:
Before:
Total => 3.8GB
Closures => 85.6MB
Closure Context => 71.0MB

After:
Total => 3.7GB
Closures => 28.9MB
Closure Context => 49.8MB

Diff:
Closures => 56.7MB
Closure Context => 21.2MB

Change-Id: If233f958df2822708b51c0d14c7439b5d3a5a07b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/313340
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-07-14 01:29:36 +00:00
Sigmund Cherem 72f1c288bc [dart2js] Bailout tracing when hitting return values of async members.
When tracing closures, we accidentally ignored the fact that returning from a non-async
function allows the value to flow in other ways (e.g. through the completion of a future).

This changes the node tracer to always consider the async marker when looking at values
that flow into 'MemberInformation' information nodes, which are the nodes we use
to represent the returned value of a method.

Fixes #52825

Change-Id: I3322e105dc9612f47a516a17f9465bf1002a9f87
Fixed: 52825
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312708
Commit-Queue: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2023-07-14 00:24:07 +00:00
Nate Biggs 64fe77f8db [dart2js] Revert invalid refinement change.
A user found another case where this fails (b/290868787).

In this case a ForwardingTypeMask is delegating the subtyping checks to its `forwardTo` mask which ends up saying the masks are equal even though the wrapper around the forwarded masks means they are not equal.

Change-Id: I015f2faf57557ff4189acb6c7144d09cf1ae6bb6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/313341
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-07-12 15:56:09 +00:00
Nate Biggs 924a33c0f5 [dart2js] Fix valid/invalid refinement logic.
The issue here was that isInMask does not hold inversely. The key is that we want to verify which refinements to skip, therefore we want to calculate *in*valid refinements. We want to skip refines where the new type is a Union AND the old tpye is a supertype of the new type. after.isInMask(before) gives us that but !before.isInMask(after) does not.

I've renamed isValidRefinement to isInvalidRefinement to more accurately capture this distinction.

Change-Id: I0d99479357a140095a5d0dfb7e2f987556097891
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312160
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-07-05 20:56:28 +00:00
Nate Biggs 73160bc40d [dart2js] Temporarily undo valid refines change.
It's still unclear why this is causing an issue but this will unblock b/285636639 until the underlying cause is found and fixed.

Change-Id: I44db6059a13738d5781c0557810ee53556ecb9c0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312100
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-06-30 20:40:45 +00:00
Nate Biggs fe73f0cf5d [dart2js] Reduce size of Dart2JS deferred loading event logs.
- Only include the script tag src if it differs from the previous log entry.
- Use single letters for each event field's key.
- Fix some typos.
- Remove 'uri' from download event as it can be inferred from script tag src and part file name.

Change-Id: Ib7916ea5e92720a10c7e1e1cab2e535fae2bbf49
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311180
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-06-26 20:43:32 +00:00
Nate Biggs 43df18a0d2 [dart2js] Use existing J-model entities where possible when converting from kernel to JS entity maps.
Change-Id: I1bcfecb313fab1e7dc03bf1d8c14b8410226f431
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309140
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-06-23 16:02:50 +00:00
Nate Biggs dbd34a452e [dart2js] Remove nullability on type declaration for IR type variables.
The only nullable call to the JTypeVariable constructor was if the K-model had a Local as the typeDeclaration.

However, the K-model creates LocalTypeVariable entities for these instead of TypeVariable entities. The former is never added to the K- element map so they aren't copied over to the J-model up front:
https://github.com/dart-lang/sdk/blob/main/pkg/compiler/lib/src/kernel/element_map_impl.dart#L1531

Instead the corresponding JTypeVariable entities are added later when the closures are created:
https://github.com/dart-lang/sdk/blob/main/pkg/compiler/lib/src/js_model/element_map_impl.dart#L1871

Change-Id: If018fe8ca666695989b0f2075d837f8e6994f0fb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311060
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-06-23 16:02:50 +00:00
Stephen Adams 5a595124b4 [dart2js] Handle null as a switch statement case value.
Bug: 51527
Change-Id: I6203c9aa668689bb44800082864174b9fb215289
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310500
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2023-06-22 19:55:22 +00:00
Stephen Adams b64fc318e7 [dart2js] Update JavaScript global names list
The following would fail unminified because the variable shadowed the
global JavaScript constructor. The fix is to add more global names to
the avoid-list. This is not a problem for js-interop since those are
accessed via `self` or `globalThis`.

```
import 'dart:typed_data';

foo(int Float32Array) => Float32List(Float32Array);

main() => print((foo)(10));
```

Change-Id: I887ece4a888fdab5df437822f9f1f34b384ec24f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310482
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2023-06-21 01:49:57 +00:00
Stephen Adams 5cbba84b91 [dart2js] Better const Maps and Sets
Constant Sets now have their own classes rather than being constructed as a wrapper over a const Map. The new scheme is similar to Maps - using a ConstantStringSet backed by a JavaScript Object 'dictionary' when the elements are all suitable String values, otherwise using a GeneralConstantSet backed by a list of elements that is converted to a lookup map on demand.

Constant Sets and Maps with suitable String keys are backed by a JavaScript Object literal 'dictionary'. The use of the Object literal has been changed so that the property values are no longer the values of the Dart Map, but the position of the key in the order of the entries. The values are provided as a List (Array), so there is an additional indexing operation to access the value on lookup. This does not seem to affect performance.

The advantage of the two-level lookup using the 'dictionary' is that Maps with the same keys (in the same order) can share a 'dictionary'. In order to achieve the advantage, the JavaScript Object is modeled as a first class ConstantValue - JavaScriptObjectConstantValue.

These changes achieve a code size benefit of -0.90% (~130K) on the main unit of a certain large app, and -0.35% for flute/benchmarks/lib/complex.dart

Change-Id: Icad2e6136218486a439e3c5ed0296462e3c3c4e6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310020
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-06-20 23:44:08 +00:00
Nate Biggs eb7dc8494a [dart2js] Fix event log init logic.
The bug can be occur when 2 Dart2JS apps load on the same page but 1 uses a version of the Dart2JS runtime prior to https://dart-review.googlesource.com/c/sdk/+/309361 and the other uses the runtime from after 309361. If the one from before 309361 loads onto the page first, the `$__dart_deferred_initializers__` will be initialized without `eventLog`. Then the second app will load and see that `$__dart_deferred_initializers__` is present and try to add to `eventLog`, but `eventLog` will not be present.

This would cause an exception in the Dart2JS runtime and probably prevent the page form loading correctly.

Change-Id: I05b17867e24ae80cb4d7cdc615c8b985321912f5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309761
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-06-15 21:58:34 +00:00
Nate Biggs a54d2ec9b8 [dart2js] Use J- instead of K- entities everywhere.
The only entities specific to the K- model are `KLocalFunction` and `KLocalTypeVariable`. I've copied these both (as is) to the J- model.

The only thing we "lose" here is the calls to `checkFamily` in `kernel/element_map_impl.dart`. Given how interchangable the 2 models were, this wasn't adding much value anyway.

Since there is still a distinction between the K- environment and J- environment, we can now think of that conversion as being between a `J` and `J'` environment where the semantics are slightly different (e.g. `J'` has closure conversion applied).

Using the same model also makes it easier to have more intermediate states of the `J` model. For example, we might keep around the `JLocalFunction` nodes until SSA and do closure conversion at that point instead.


Change-Id: If149241725a03b8de6aba6d486506434529b998d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306980
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-06-15 18:12:52 +00:00
Nate Biggs a7d2477af7 [dart2js] Address small comments on compact_flags.
Change-Id: I33d00f58a6d8ef04a1ff48cf7312d99dbefa9f91
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309360
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-06-14 18:32:49 +00:00
Nate Biggs df0382c900 Reland "[dart2js] Simplify event log initialization logic in each part file prologue."
This is a reland of commit 7b2d5baa48

Original change's description:
> [dart2js] Simplify event log initialization logic in each part file prologue.
>
> Change-Id: I0731b78f5b0437f5e5026ee6d9f2511698968804
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308201
> Commit-Queue: Nate Biggs <natebiggs@google.com>
> Reviewed-by: Sigmund Cherem <sigmund@google.com>

Change-Id: I0bc53c9d0745ea01af638f47e503c9570dec266b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309361
Reviewed-by: Stephen Adams <sra@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-06-14 18:26:55 +00:00
Ilya Yanok 042952ef9b Revert "[dart2js] Simplify event log initialization logic in each part file prologue."
This reverts commit 7b2d5baa48.

Reason for revert: breaks ~600 tests in G3 (though it looks to be just one JS file that got broken), b/287219647

Original change's description:
> [dart2js] Simplify event log initialization logic in each part file prologue.
>
> Change-Id: I0731b78f5b0437f5e5026ee6d9f2511698968804
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308201
> Commit-Queue: Nate Biggs <natebiggs@google.com>
> Reviewed-by: Sigmund Cherem <sigmund@google.com>

Change-Id: Iedd1b0a4909f490bc54eebde3462e6bd57c3c1a9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309283
Reviewed-by: Alexander Thomas <athom@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Ilya Yanok <yanok@google.com>
2023-06-14 15:53:07 +00:00
Nate Biggs b8d4b98edd [dart2js] Move compact flag logic to shareable library.
Change-Id: I23fd110c3bed55f968e43eef138a3860d4fdb22e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308724
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-06-14 01:39:10 +00:00
Nate Biggs f60c7b2ad3 [dart2js] Remove unnecessary abstraction from env libraries.
Change-Id: Id9c4cc319a848ed7deebc6065d731886f737e280
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307722
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2023-06-14 00:02:39 +00:00
Johnni Winther 90d5a99c15 [cfe] Remove redirecting factory field
TEST=existing

Change-Id: Ic9f51693d0cc75cbe745dcaa0f4feb26d7005a9e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307941
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-06-13 09:24:28 +00:00
Nate Biggs 7b2d5baa48 [dart2js] Simplify event log initialization logic in each part file prologue.
Change-Id: I0731b78f5b0437f5e5026ee6d9f2511698968804
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308201
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-06-13 00:50:49 +00:00
Johnni Winther 01b725e178 [dart2js] Enable kernel verification
This enables kernel verification of components loaded from source when
asserts are enabled.

Change-Id: Icf5d42e2c978428138733403f9af35824e97821c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/299641
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-06-12 08:43:21 +00:00
Nate Biggs ac6150c4c0 [dart2js] Improve deferred part file logging.
Adds an "eventLog" property to the global "$__dart_deferred_initializers__" object. The event log is just a JS Array that gets initialized alongside $__dart_deferred_initializers__.

Each event entry is a String->String JS object. I unified the format of these event objects for easier parsing.

Each printed event is now valid JSON (passed through JSON.stringify) so we can more easily post-process the logs if necessary.

Fully replacing the existing "_eventLog" field makes the logging logic simpler. Having a single array allows us to not include a timestamp because the array captures the event ordering (actual timing doesn't matter). It also makes it easier to stringify the logs when there's only 1 data source/format.

Sample output:
```

{"hunkName":"out.js_1.part.js","event":"loadHunk"}
{"uri":"path_to/out.js_1.part.js","hunkName":"out.js_1.part.js","event":"downloadHunk"}
{"file":"out.js_1","event":"beginLoadPart"}
{"file":"out.js_1","event":"endPartLoad","hash":"aCscY7yv4EHodRPmCqYn5BqMelA="}
{"uri":"path_to/out.js_1.part.js","hunkName":"out.js_1.part.js","event":"downloadHunkSuccess"}
{"hunkName":"out.js_1.part.js","hash":"aCscY7yv4EHodRPmCqYn5BqMelA=","event":"initialize"}

```

Change-Id: Ifee73be0bf7dc53a0e7710ff033dd2b0fae9fb0e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307240
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2023-06-09 17:05:11 +00:00
Johnni Winther c308c9327d [cfe] Ensure Member.isInlineClassMember is set
TEST=existing

Change-Id: I16fbeb0bbe431e3f85ed11c21e0506e6aa4abf58
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/302206
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2023-06-08 15:02:03 +00:00
Srujan Gaddam 5b3a57908d [dart:js_interop] Remove ObjectLiteral
This annotation is unneeded as named arg external constructors
is enough to determine if an object literal is created. The one
exception is an empty object literal, but our guidance is to use
utility functions to create one instead. This is a better fit for
that purpose too as an interface for an empty object literal is
more uncommon.

CoreLibraryReviewExempt: Backend-specific library.
Change-Id: I10cf891601b28ff7e56129842d099ea28863626d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307506
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-06-06 20:50:36 +00:00
Johnni Winther 5476e3bd6e [kernel] Rename InterfaceType.className to classReference
+ Name.libraryName -> libraryReference

Change-Id: I25b5022ea87f92fb5837f03d29f1671f0e68261b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304740
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-06-01 06:43:46 +00:00
Nate Biggs f5aa52af8d [dart2js] Only read platform binaries when necessary.
Fixes issue with platform binary getting included twice in Flutter builds leading to issues with type erasure and factory constructors.

Tested internally on sequential, non-sequential, modular and Flutter builds. All executed normally.

Change-Id: I359d98f51629364efa5f9e00c748eccc20261ad4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306683
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-05-31 23:04:38 +00:00
Nate Biggs d083c63685 [dart2js] Increase inferrer engine refine limit.
Some large programs are still hitting this limit on type nodes that would otherwise converge.

We can set this limit arbitrarily high to avoid the chance of any node that will converge from hitting it. We are still maintaining the metric and check and continuing to monitor internally. However, confirmed that several large apps that were hitting the 12 limit are now fully refining all nodes.

Change-Id: I17be593a69dac4490cde92506e405d305f3c9b16
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306561
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-05-31 17:49:28 +00:00
Nate Biggs 25f4aa70b8 [dart2js] Ensure that types cannot end up in a diverging inference loop.
The UnionTypeMask k-limit can cause cycles in the type graph to end up in an infinite loop where they continually widen and narrow. The solution is to ensure monotonicity of these union operations, if we are attempting to go from a FlatTypeMask to a UnionTypeMask, the UnionTypeMask should be strictly wider than the FlatTypeMask.

Change-Id: I32ec0927c7c7863a5f093df7c087b19ef3f1bc01
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296480
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-05-24 15:05:59 +00:00
Nate Biggs a4277869d0 [dart2js] Small improvements to record type inference.
Change-Id: Iec3bf6f639e5047327866810e3847ce1925e8d8f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304580
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-05-23 03:53:59 +00:00
Mayank Patke 93614d26c5 [dart2js] Add record literals to deferred loading ConstantCollector.
Change-Id: Id22dca8b50e8f7ac99b9ac8a8ec19bf431db72e2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304782
Commit-Queue: Mayank Patke <fishythefish@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-05-22 19:31:47 +00:00
Nate Biggs 48156719a6 [dart2js] Move parameter narrowing from NarrowTypeInformation into field on ParameterTypeInformation.
Change-Id: I1715e47e73c2d45fbe6e4f8bfc9a336224f53bc3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304161
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-05-22 18:38:23 +00:00
Nate Biggs a8e7db5deb [dart2js] Consolidate type narrowing logic.
Currently _narrowType for TypeInformation nodes has logic to process DartTypes. This logic is a simplified version of the logic in createFromStaticType. We can consolidate the two and just use createFromStaticType directly.

And since the static type is only ever used for this type narrowing (and its immutable) we can create the AbstractValue up front and store that instead of the DartType.

There was no difference in the emitted JS when tested on 2 large programs.

Change-Id: I432279684580edf64ff52254653bd26501d461b7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304160
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-05-22 18:38:23 +00:00
Nate Biggs 327a680c34 [dart2js] Fix type inference for record accessses on invalid indices.
Bug: 52438
Change-Id: Ic180e181142f6a33e9915f13890d9a3825a5ec0c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304380
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-05-18 20:25:27 +00:00
Srujan Gaddam eb8e3d549a [dart:js_interop] Add new diagnostic reporter so we can avoid transforms
Adds a delegating reporter so we can keep track of whether there are
interop errors. If there are, we do not do the transforms on the JS
backends.

Change-Id: Ib0f36b748443cb7fe8f8bb427692d653557d59fa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304261
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-05-18 18:53:03 +00:00
Nate Biggs bb179504c0 [dart2js] Resolve non-converging parameter types in linearized inference algorithm.
Due to the introduction of "virtual parameters" (parameters of virtual functions) there was a new pattern that allowed for non-converging types. If two functions are mutually recursive and one makes a virtual call to the other, then we end up with a cycle in the parameter types.

That part isn't new, that cycle already existed. However, now the cycle can include the virtual parameters for those functions. The way we enqueue the users after resolving a virtual parameter can cause an alternating pattern of refinement that doesn't allow the cycle to fully resolve itself.

We resolve this by manually enqueueing the concrete parameter and its associated NarrowTypeInformation (which enforces the static type). The key is that these are enqueued before other users of the virtual parameter which in the bad case are other members in the cycle that were being processed out of order.

Change-Id: Ic20afcc55ca6e75152d7858eaab1cb24a57ea20e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/303120
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-05-16 17:24:48 +00:00
Nate Biggs 776b614018 [dart2js] Add stage flag to Dart2JS.
Maintains functionality of existing '--write-X-uri' and '--read-X-uri' but also introduces new '--stage' flag that indicates which phases of the compiler should run.

Also expands the behavior of the `--output` flag to support taking a file prefix and/or an output directory that files are written out to.

Valid invocations can look like:
`dart2js main.dart --stage=cfe`
`dart2js main.dart --stage=cfe --output=prefix1-`
`dart2js main.dart --stage=cfe --output=/some/path/`


Change-Id: If90fb16f549d35f16f77d660c51f8d28673e454f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/300520
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-05-10 22:43:37 +00:00
Nate Biggs 9a25f65eb6 [dart2js] Introduce formalized phases to Dart2JS.
This change locks down the Dart2JS command line API to the few invocation flows we use today:
1) Full compile from Dart sources.
2) Full compile from pre-compiled dill sources (modular CFE).
3) Phased compilation from Dart sources.
4) Phased compilation from pre-compiled dill sources (modular CFE).

It also ensures that each phase is run individually (accounting for sharding in codegen/emitter).

There are already places in the code where we assume that Dart2JS will be invoked in one of these ways so this should codify those assumptions.

Change-Id: I4e2a85d123e0c2ad924e2dd1b230548a995af0da
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/299760
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-05-10 22:43:37 +00:00
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