Commit graph

6148 commits

Author SHA1 Message Date
Stephen Adams 0db3b1215c [dart2js] Use patterns for HIndex simplifications
Change-Id: I8a1e888da1d976ae80effc220a41243ff85ee4f6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372001
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2024-06-18 23:19:28 +00:00
Mayank Patke d430e7ab55 [dart2js] Remove memberContext from getConstantValue.
Change-Id: I3ed4343c7cd2880414a8e99361d8017ca9f756a8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372160
Commit-Queue: Mayank Patke <fishythefish@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2024-06-18 18:31:58 +00:00
Stephen Adams 3a91bcb39e [dart2js] SSA - pre-assign variable to reduce phi assignments
Introducing a partial redundancy with a variable with a longer
live-range can reduce the size of the emitted code.

Flute.complex (-O4): -0.377%
cm_shell (-O4): -0.029%

Change-Id: I0d03119b17f4b58d61f277bf8bb0e57d8e7c47c5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/360360
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-06-17 22:47:57 +00:00
Stephen Adams 77496338dc [dart2js] Constant-fold const record accesses
I noticed that dart2js generated poor code for `(a, b) = (1, 2)`.
This is due to an oversight in not constant-folding record field loads.

Change-Id: Iac110d8c3373d7673c21494fc467f7fcb400de1d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371505
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2024-06-17 19:47:34 +00:00
Nate Biggs b9b4d616a4 [dart2js] Fix record field get receiver type serialization.
Internal users reported a compiler crash when using sequential compilation. Their change involved adding a class hierarchy in which the constructor of a superclass included a RecordIndexGet. When analyzing the constructor of the subclass we also analyze the body of the super constructors.

In this rare case the member being analyzed does not match the member containing the receiver node. Usually calls act as a layer of indirection that we do not analyze across.

When we then save the type of the receiver, we do so in the context of the wrong member (the subclass constructor rather than the superclass constructor). We just have to be more careful to use the correct context member.

The added test fails prior to this change.

Change-Id: I8b9a3b8a7692b8604d5c37c59b94bb8d46afff75
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371580
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2024-06-14 19:17:14 +00:00
Mayank Patke bf83cc30ed [dart2js] Convert VariableUse to a sealed class hierarchy.
Change-Id: I28d71d81031e3e6eefc2b4f6decfe375099a1c32
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371185
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2024-06-13 23:01:34 +00:00
Mayank Patke 0ddba91190 [dart2js] Convert SubclassResult to a sealed class hierarchy.
Change-Id: I151c2f6f72dcecaff6a6976f058940b9ddf97f47
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371461
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2024-06-13 19:25:28 +00:00
Mayank Patke ad3a1a72fd [dart2js] Convert IsTestSpecialization to sealed class hierarchy.
Change-Id: I08552d4dda928259be56e0b99f9f002baeb4d6b2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371240
Commit-Queue: Mayank Patke <fishythefish@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2024-06-13 18:21:59 +00:00
Mayank Patke ca3e67a3b6 [dart2js] Add --interop-null-assertions.
This CL adds a new --interop-null-assertions flag (cf.
--native-null-assertions) with the goal of validating that JS interop
APIs with non-nullable static return types do not return null values.
This flag is currently disabled by default but is intended to assist in
sound null safety migrations.

In general, we don't guarantee type soundness of package:js interop
since users can write incorrect static types which are not backed by
any runtime checks. However, it is likely that during the null safety
migration, some interop APIs which should have been made nullable
weren't. Therefore, we want to offer some additional (but limited)
checking for this case.

For static invocations of functions with non-nullable return types, we
can simply perform a null check on the result of the call.
For instance methods (which could be invoked virtually/dynamically), we
want to perform a null check on the return value in the callee (the
interceptor method) itself when possible.

It's possible for multiple interop bindings to share the same
interceptor method. We produce a null check in the interceptor method
body if all the methods have non-nullable return types. Otherwise, we
insert checks at callsites when appropriate.

Change-Id: Ifd155d7f8326152b6d57d61199e0b7973c4a1211
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369784
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2024-06-12 21:28:23 +00:00
Johnni Winther ce12e3c8ac [cfe] Remove isNonNullableByDefault from class hierarchy
Change-Id: Ib5942357578a6481e8038dd090e4a9d9ff49f831
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369022
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2024-06-03 06:42:54 +00:00
Stephen Adams 20316bcc5b Reapply "[js_runtime, js_dev_runtime] Implement microsecond field of DataTime"
Original change: https://dart-review.googlesource.com/c/sdk/+/366963

This reverts commit 72b2883c6f.


[js_runtime, js_dev_runtime] Implement `microsecond` field of `DataTime`

- Move DateTime implementation for dart2js and DDC into a shared place to reduce duplication.

- Add a _microsecond field to the web DateTime to track microseconds outside of the JavaScript Date.

- The cute dart2js optimization whereby `DateTime.now().millisecondsSinceEpoch` is compiled to `Date.now()` still works.

- Both implementations report better errors.

- Fixed VM bug with in-range sentinel.


Issue: https://github.com/dart-lang/sdk/issues/44876
Issue: https://github.com/firebase/flutterfire/issues/12102
Issue: b/342552853
CoreLibraryReviewExempt: Reapply of unchanged code
Change-Id: I7f14b69e412a052ef3fe6b43cc9cf9d96319adb8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368380
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
2024-05-31 15:42:14 +00:00
Johnni Winther 1315b3ab72 [kernel] Remove isNonNullableByDefault from checkBounds and instantiateToBounds
Change-Id: Ie1faa72cd1d9eaae65e1fb2fd44bf7a70b94a025
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368641
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2024-05-30 13:51:46 +00:00
Jelle van der Waa 18b40a3b27 replace logging.warn with logging.warning
Closes https://github.com/dart-lang/sdk/pull/55843

GitOrigin-RevId: e0a5f9c2cc42bb7d977bb2e41f8e872c44ef6990
Change-Id: Ie7ecc2a86ea1ac9fa57ff2c50c50363c577e819e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368203
Commit-Queue: Kevin Moore <kevmoo@google.com>
Reviewed-by: Kevin Moore <kevmoo@google.com>
2024-05-29 19:07:56 +00:00
Ivan Inozemtsev 72b2883c6f Revert "[js_runtime, js_dev_runtime] Implement microsecond field of DataTime"
This reverts commit fb057ea4e0.

Reason for revert: b/342552853

Original change's description:
> [js_runtime, js_dev_runtime] Implement `microsecond` field of `DataTime`
>
> - Move DateTime implementation for dart2js and DDC into a shared place to reduce duplication.
>
> - Add a _microsecond field to the web DateTime to track microseconds outside of the JavaScript Date.
>
> - The cute dart2js optimization whereby `DateTime.now().millisecondsSinceEpoch` is compiled to `Date.now()` still works.
>
> - Both implementations report better errors.
>
> - Fixed VM bug with in-range sentinel.
>
>
> Change-Id: I9156255bdb6ecc195500ae9bc88f91fb315b6297
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366963
> Reviewed-by: Alexander Aprelev <aam@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>
> Reviewed-by: Lasse Nielsen <lrn@google.com>
> Commit-Queue: Stephen Adams <sra@google.com>

Change-Id: I58572256a7710df4589bb5e41c7afee295c2388b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368103
Reviewed-by: Alexander Thomas <athom@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Auto-Submit: Ivan Inozemtsev <iinozemtsev@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2024-05-27 07:54:14 +00:00
Nate Biggs a52acf1ff2 [dart2js] Fix memory regression in closed world due to member/call pattern on wide type hierarchy.
If the enclosing class is a leaf node search for live matches in "canHit". Do this by iterating the class hierarchy starting at the enclosing class of the element and checking the supertype to see if they're included in the constraint set.

Change-Id: If859bbca1d2744303c03ac91d1601a05c61dfc2d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367220
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2024-05-23 21:02:51 +00:00
Stephen Adams cdf35f8782 [dart2js] Simplify access of multiple type variables from same environment
The change adds a new reduction that recognizes the construction of a type environment from components

    HTypeBind(HTypeEval(env, e1), HTypeEval(env, e2))

and replace with an equivalent expression that constructs the same derived type environment directly

    HTypeEval(env, ...e1...e2...)

This change speeds up the benchmarks that iterate `Map.entries` by roughly 10-25%.

---

Type arguments are passed as separate values [1]. This means that the generative constructor factory `MapEntry<K,V>(this.key, this.value)` has four parameters - `MapEntry$(key, value, $K, $V)`. The passed arguments usually come from the same place, perhaps extracted from the type of the current object, `this.$ti._eval("1")` and `this.$ti._eval("2")`.

Inside `MapEntry$`, the type parameters are re-assembled into a type environment:

    $K._eval("@<0>")._bind($V)

which is used to construct the object type

    $K._eval("@<0>")._bind($V)._eval("MapEntry<1,2>")

After inlining:

    $K = this.$ti._eval("1");
    $V = this.$ti._eval("2");
    $K._eval("@<0>")._bind($V)._eval("MapEntry<1,2>")

After GVN, and reducing the adjacent `._eval("1")._eval("@<0>")` to `._eval("@<1>")`:

    t1 = this.$ti
    t1._eval("@<1>")._bind(t1._eval("2"))._eval("MapEntry<1,2>")

The new reduction gives us:

    this.$ti._eval("@<1,2>")._eval("MapEntry<1,2>")

which can be reduced further by combining adjacent HTypeEvals:

    this.$ti._eval("MapEntry<1,2>")


[1]: It would be better to pass the type arguments as a single Rti object to avoid the extract-recombine pattern, but changing the calling convention is a more extensive change. In the meantime, this reduction cleans up the extract-recombine pattern when inlining brings the parts together.

Change-Id: I28801ce5d952d0f4e5ac1d55c252766159dcceef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367240
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-05-23 16:45:00 +00:00
Stephen Adams fb057ea4e0 [js_runtime, js_dev_runtime] Implement microsecond field of DataTime
- Move DateTime implementation for dart2js and DDC into a shared place to reduce duplication.

- Add a _microsecond field to the web DateTime to track microseconds outside of the JavaScript Date.

- The cute dart2js optimization whereby `DateTime.now().millisecondsSinceEpoch` is compiled to `Date.now()` still works.

- Both implementations report better errors.

- Fixed VM bug with in-range sentinel.


Change-Id: I9156255bdb6ecc195500ae9bc88f91fb315b6297
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366963
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-05-22 05:18:52 +00:00
Sam Rawlins 2e53eada36 compiler: replace unsupported [this] comment references with this.
Work towards https://github.com/dart-lang/dartdoc/issues/3761

Sibling CL to https://dart-review.googlesource.com/c/sdk/+/365204

The analyzer has never recognized `[this]` as a valid doc comment
reference (and the `comment_references` lint rule has similarly
reported such reference attempts). dartdoc has its own algorithms
for resolving comment references, which we are dismantling in favor
of a single resolution, provided by the analyzer.

We've also decided against adding support in the analyzer (see
https://github.com/dart-lang/linter/issues/2079), so these
reference attempts should be re-written.

Change-Id: I0a30a34c9f58bd6c98c6b83e607a973c9ba51ed7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366900
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2024-05-16 20:20:34 +00:00
Johnni Winther ae03b57cbb [cfe] Remove .isNonNullableByDefault from package:kernel
This removes the .isNonNullableByDefault properties and similar from
the AST nodes in package:kernel. NNBD is now always enabled so these
properties are trivial.

TEST=existing

Change-Id: I75ca0551ac4b5910ea63530dd0c9c2e68bd01aff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366320
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-05-15 08:31:38 +00:00
Lasse R.H. Nielsen b464fc9037 Reland "Tweak expect.dart library."
This reverts commit cd2c566bcf.

Reason for revert: Updating to not remove field used by Flutter engine.

Original change's description:
> Revert "Tweak `expect.dart` library."
>
> This reverts commit ff5f391c0a.
>
> Reason for revert: The expect library is used by Flutter engine, and some of its tests use assertStatementsEnabled. There should be a migration path that doesn't require an atomic change, like adding the replacement api before removing the old one.
>
> Original change's description:
> > Tweak `expect.dart` library.
> >
> > Make API more consistent for a few methods.
> > Reduce the number of language features used in tests:
> > * Never iterating an iterable, always converting it
> >   using `.toList()` first and iterating using indices
> >   (fx `setEquals`).
> >   Also require a `List` in places where an `Iterable`
> >   wasn't necessary.
> > * Avoid doing complicated computations that are also
> >   used for the error message. Do simple check first,
> >   then recompute to get better error messages
> >   (fx `allDistinct`).
> >
> > Renamed some rarely used members for consistency
> > (`stringContainsInOrder`->`containsInOrder`,
> > where other string-contains functions just start
> > with `contains`, and `containsOneOf` -> `containsAny`
> > to match `Iterable.any` phrasing, and also it accepts
> > if containing at least one, not precisely one.)
> >
> > Removed a function that wasn't used anywhere.
> >
> > Moved `assertStatementsEnabled` to `variations.dart` as `asserts`.
> > Removed `typeAssertionsEnabled` and `checkedModeEnabled`. The former used in one place, where it was replaced with `checkedImplicitDowncasts` from `variations.dart`, the latter wasn't used anywhere.
> >
> > Deprecates `package:expect/minitest.dart`. It was never intended
> > to be used for new tests, only as a help to convert existing tests
> > written against `package:unit_test`.
> > All existing imports marked as `// ignore: deprecated_member_use`.
> >
> > Change-Id: I07e21d4c0f3ccf11b82ee34af2668fdbb22264d2
> > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352360
> > Reviewed-by: Slava Egorov <vegorov@google.com>
> > Reviewed-by: Ömer Ağacan <omersa@google.com>
> > Reviewed-by: Nate Bosch <nbosch@google.com>
> > Reviewed-by: Stephen Adams <sra@google.com>
> > Commit-Queue: Lasse Nielsen <lrn@google.com>
>
> Change-Id: I360b4347470a0bb2b63c3108e2b83ee2a771bf3f
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362020
> Reviewed-by: Nate Bosch <nbosch@google.com>
> Reviewed-by: Ömer Ağacan <omersa@google.com>
> Reviewed-by: Stephen Adams <sra@google.com>
> Reviewed-by: Leaf Petersen <leafp@google.com>
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Commit-Queue: William Hesse <whesse@google.com>

CoreLibraryReviewExempt: Reland
Change-Id: I53db40edc0733842a008839c3913d51c885e39ab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362502
Reviewed-by: Alexander Thomas <athom@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: William Hesse <whesse@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2024-04-26 15:28:26 +00:00
Nate Biggs 6118b2f590 [dart2js] Fix missing offset logic from indexed sink source.
See https://dart-review.googlesource.com/c/sdk/+/363541 for more context.

Change-Id: Iaf681101410a2505376e0522bf1228035c088028
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364080
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-04-24 17:46:39 +00:00
Nate Biggs 8f6dd1ad3a [dart2js] Handle serialization offset address spaces larger than 2^29.
The dart2js binary serialization infrastructure only supports 30 bit integers with the "writeInt" method. The indexing infrastructure uses 1 of the bits to store locality information leaving 29 bits to encode the address space.

The recent dump info changes expanded the address space of some large programs beyond this 2^29 and is causing some serialization issues when trying to generate dump info.

The solution here is to check when an address is above 2^29 and instead encode the offset as a uint32. This will use 5 bytes for these large values (1 for the large offset indicator and 4 for the offset itself). By doing this we expand the address space to 2^32 which is more than enough to support larger programs.

An alternative would be to use some bits from the indicator and encode the rest in a separate 30-bit int. This would allow us to represent an address space closer to 2^60. But we would need to use an extra bit to differentiate the indicator and an actual offset. Which would reduce the base address space to 2^28 causing us to hit the more expensive 5-byte case earlier and increasing total write size. No known program is anywhere near the 2^32 address space size so the larger address space is not necessary.

Change-Id: Icbed2961099842ebf286b36314e8d6fab7389db4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363541
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2024-04-19 06:03:01 +00:00
Nate Biggs 43fa24f839 [dart2js] Use deferred reads for standalone dump info.
Change-Id: I43492255a1d9db67a95a1c3ed347640d5e66bbc3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363542
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2024-04-19 01:02:38 +00:00
Nate Biggs 226f862be1 [dart2js] Fix broken dart2js_batch_test.
Fixes: https://github.com/dart-lang/sdk/issues/55391
Change-Id: If4fdfb45348811d0f563baa30b68173b8ce0e444
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363460
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2024-04-17 18:29:43 +00:00
Mayank Patke 159906059d [dart2js] Preserve is/as in ConstantTransformer with SNS checks enabled
Also amend SSA type builder to only optimize away casts to *sound* top
types when SNS checks are enabled.

Fixes: b/330884266
Change-Id: Ic619877b7f1e01e1065f4767549880aab2f81106
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363162
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2024-04-16 23:30:10 +00:00
Nate Biggs 9a10125199 [dart2js] Modify error parsing to support new d8 error/stacktrace formatting.
d8 used to include the error message between the stack trace and the error location indicator ("^").

With the newest version being updated to in https://dart-review.googlesource.com/c/sdk/+/362386 the error is no longer located there. It is instead found toward the beginning of the error message.

Both the new and old version of d8 have the error in that location (the old version just duplicated it into the spot the test currently reads it from).

Change-Id: I15143510cd9ed6b8434a5531a08011854ce2da9c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362580
Auto-Submit: Nate Biggs <natebiggs@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2024-04-15 18:26:25 +00:00
Nate Biggs 8e275a4c6d [dart2js] Split deferred_load_id_map tests into 3 shards to avoid timeouts.
Change-Id: I9cf3665be8df64ee80a9890747398faa49cfa79f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362680
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2024-04-12 21:50:39 +00:00
Mayank Patke 841a649632 [dart2js] Ensure --stage is passed in deferred_load_id_map_helper.
Change-Id: I93fe251c334320c1b41fc7077c6da84d6436557c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362640
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2024-04-12 20:41:22 +00:00
Nate Biggs 1b2aebc41b [dart2js] Modify implicit checks analysis to avoid stack overflow on wide class hierarchies.
By having _addImplicitChecks add all the checks to implicitIsChecks before recursing into them, we avoid exploring each new check via recursion.

For a wide enough class hierarchy where one check implies many other checks, the recursive visiting pattern could lead to stack overflows.

Change-Id: I7f50af4e8c0859ac77da143ade68cc3d9e2cc503
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362403
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2024-04-12 19:51:40 +00:00
Chloe Stefantsova 8aa400bf5f [analyzer][cfe] Share the implementation of the Variance class
Part of https://github.com/dart-lang/sdk/issues/54902

Change-Id: Ie406b59baf3efdeaac577f5181320b28c5076068
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/361781
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-04-10 13:08:55 +00:00
William Hesse cd2c566bcf Revert "Tweak expect.dart library."
This reverts commit ff5f391c0a.

Reason for revert: The expect library is used by Flutter engine, and some of its tests use assertStatementsEnabled. There should be a migration path that doesn't require an atomic change, like adding the replacement api before removing the old one.

Original change's description:
> Tweak `expect.dart` library.
>
> Make API more consistent for a few methods.
> Reduce the number of language features used in tests:
> * Never iterating an iterable, always converting it
>   using `.toList()` first and iterating using indices
>   (fx `setEquals`).
>   Also require a `List` in places where an `Iterable`
>   wasn't necessary.
> * Avoid doing complicated computations that are also
>   used for the error message. Do simple check first,
>   then recompute to get better error messages
>   (fx `allDistinct`).
>
> Renamed some rarely used members for consistency
> (`stringContainsInOrder`->`containsInOrder`,
> where other string-contains functions just start
> with `contains`, and `containsOneOf` -> `containsAny`
> to match `Iterable.any` phrasing, and also it accepts
> if containing at least one, not precisely one.)
>
> Removed a function that wasn't used anywhere.
>
> Moved `assertStatementsEnabled` to `variations.dart` as `asserts`.
> Removed `typeAssertionsEnabled` and `checkedModeEnabled`. The former used in one place, where it was replaced with `checkedImplicitDowncasts` from `variations.dart`, the latter wasn't used anywhere.
>
> Deprecates `package:expect/minitest.dart`. It was never intended
> to be used for new tests, only as a help to convert existing tests
> written against `package:unit_test`.
> All existing imports marked as `// ignore: deprecated_member_use`.
>
> Change-Id: I07e21d4c0f3ccf11b82ee34af2668fdbb22264d2
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352360
> Reviewed-by: Slava Egorov <vegorov@google.com>
> Reviewed-by: Ömer Ağacan <omersa@google.com>
> Reviewed-by: Nate Bosch <nbosch@google.com>
> Reviewed-by: Stephen Adams <sra@google.com>
> Commit-Queue: Lasse Nielsen <lrn@google.com>

Change-Id: I360b4347470a0bb2b63c3108e2b83ee2a771bf3f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362020
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: William Hesse <whesse@google.com>
2024-04-09 18:10:57 +00:00
Lasse R.H. Nielsen ff5f391c0a Tweak expect.dart library.
Make API more consistent for a few methods.
Reduce the number of language features used in tests:
* Never iterating an iterable, always converting it
  using `.toList()` first and iterating using indices
  (fx `setEquals`).
  Also require a `List` in places where an `Iterable`
  wasn't necessary.
* Avoid doing complicated computations that are also
  used for the error message. Do simple check first,
  then recompute to get better error messages
  (fx `allDistinct`).

Renamed some rarely used members for consistency
(`stringContainsInOrder`->`containsInOrder`,
where other string-contains functions just start
with `contains`, and `containsOneOf` -> `containsAny`
to match `Iterable.any` phrasing, and also it accepts
if containing at least one, not precisely one.)

Removed a function that wasn't used anywhere.

Moved `assertStatementsEnabled` to `variations.dart` as `asserts`.
Removed `typeAssertionsEnabled` and `checkedModeEnabled`. The former used in one place, where it was replaced with `checkedImplicitDowncasts` from `variations.dart`, the latter wasn't used anywhere.

Deprecates `package:expect/minitest.dart`. It was never intended
to be used for new tests, only as a help to convert existing tests
written against `package:unit_test`.
All existing imports marked as `// ignore: deprecated_member_use`.

Change-Id: I07e21d4c0f3ccf11b82ee34af2668fdbb22264d2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352360
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2024-04-09 14:49:17 +00:00
Jake Macdonald f48b8c6908 Support prebuilt macros in the incremental compiler mode for DDC
Also adds support for modular tests with precompiled macros, and one test exercising that.

Change-Id: Ie372ea7fcb270ecd55baa54c4ed1c4ae5a527df4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/361261
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Auto-Submit: Jake Macdonald <jakemac@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2024-04-09 07:37:26 +00:00
Johnni Winther 63d2008355 [cfe] Make kernel AST and CompilerOptions use strong mode by default
TEST=existing

Change-Id: I8d8bc59dc742a7499338ea2d23a611696492603c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/359222
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2024-04-05 07:45:08 +00:00
Nate Biggs 1e8ea8a7da Wrap field initializers copied by TFA in a FileUriExpression.
Before TFA runs, MixinFullResolution will clone a mixin's fields into the application classes for that mixin. The cloned Field on the application class will have a fileUri that refers to the original mixin file.

However, TFA then copies those fields into FieldInitializers which don't have a fileUri context and so the fileUri for the surrounding Constructor is used. This leaves expressions in the initializer with offsets relative to the mixin's file but in the context of the mixin application's file.

To fix this, we can wrap the initializer in a FileUriExpression referring to the original mixin class. We only do this if the field the initializer is copied from refers to a different file than the target constructor.

Also add handlers for FileUriExpressions to several visitors that don't already support this new AST node.

Change-Id: I47b0d48dfe87303949130a40216b199949cfa1d9
Tested: Existing test suite.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/360420
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2024-04-02 19:55:19 +00:00
Nate Biggs f54eb08177 [dart2js] Update Dart2jsStage definitions and CLI surface area.
Today to invoke Dart2js with sequential actions there are 2 ways to specify the stage from the command line. By specifying a `write-<stage-data>=<some-uri>` or by using `stage=<some-stage>`. Internally we use the former via a similar (but separate) concept to Dart2jsStage. The goal here is to consolidate all these different entry points.

The new CLI works as follows:
- To run the compiler in full you can:
  - Pass no additional flags as before
  - Specify 'stage=all'
  - 'dump-info-all' runs the full compilation from scratch but includes
    dump info.
- To run the compiler in sequential mode you specify a stage:
  - Each stage has its own name passed to the '--stage' flag.
  - All the intermediate data URIs can be passed to every stage and only
    the relevant ones are used for any given stage. If no URI is passed
    then a default URI is used.
  - 'dump-info' is now its own stage. Partial dump info data is
    always included in the emit-js and codegen-emit-js steps.
  - 'cfe-only' flag is maintained for compatibility with Flutter CLI.


Change-Id: I67965d7708688a85c866d8abef3716bee23a083f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358740
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2024-04-02 19:46:11 +00:00
Stephen Adams cc3b3f4976 [dart2js] Reduce x - 0.
25 hits in FluteComplex.
Many come from APIs with `[start, end)` range arguments that are unused so `length = end - start` is now optimized to `end`.

Change-Id: I59527f85323bed717d62249f0c1d69b477645ec2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/360444
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2024-04-01 09:23:19 +00:00
Nate Biggs 6bc1b01241 [dart2js] Eagerly serialize generated impacts so that they can be GCed immediately.
When dump info data is being serialized as part of the codegen + emitter joint phase, all the impacts are considered "generated" and so they must all be serialized with the dump info data. If we wait to serialize them until the end of the phase as we usually do, these impacts cannot be GCed right away. This leads to a much higher memory footprint. By serializing them eagerly we can GC the object and just maintain the much leaner serialized data.

Change-Id: I11606f7291fe8d86af1f72724bd8c68e9666a00a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/359300
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2024-03-23 03:58:52 +00:00
Jake Macdonald 25071fc448 revert dart:_macros, going with SDK vendored package
Change-Id: Iaaf80a44cdbd073b01132d04c0426e8acc28341f
Tested: Revert only
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358501
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Jacob Richman <jacobr@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
Auto-Submit: Jake Macdonald <jakemac@google.com>
2024-03-21 02:40:58 +00:00
Nate Biggs 52f996b5bc [dart2js] Use impacts from codegen results for dump info.
Currently, serialized dump info metadata (output of emitter phase) contains all the impacts created during codegen in a Map<MemberEntity, WorldImpact>. These impacts are already serialized in the output of the codegen phase. This is bad for two reasons: 1) The serialized bytes are duplicated. 2) The impacts cannot be GCed right after the emitter uses them, the dump info registry maintains a reference to them.

To mitigate this I've updated the registry to only store impacts for entities where the impacts are generated during the emitter phase (today only parameter stubs). Rather than try to re-generate those impacts during the dump info phase, we serialize them with the dump info metadata. However, most impacts are generated during the codegen phase and for these we deserialize them from the codegen results at the beginning of the dump info phase.

Change-Id: I1302b4ab759bca3d492bc6b40194d7a7720ed6f8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354580
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-03-07 19:25:15 +00:00
Dmitry Zhifarsky 741ddda4c5 Fix typo and a broken link in dart2js pragma annotations docs
Closes https://github.com/dart-lang/sdk/pull/55064

GitOrigin-RevId: a2076ea4f58b8b63e42b7f8cb45e8f9d54c8cdea
Change-Id: I0ab8a19c0ee1865a2bcf2a467fe649db4951cf0d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355061
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-02-29 15:41:32 +00:00
Stephen Adams 5bcb545696 [dart2js] Clean up HInstruction.inputs ownership
Ensuring HInstruction.inputs is always a growable list allows ~650
calls to be devirtualized* and makes the output of `dart compile
aot-snapshot dart2js.dart` about 0.1% smaller. I was not able to detect a significant performance difference in the SSA phase time.

* Estimated from indirect indexed addressing mode calls in the disassembly.

Change-Id: I330cd42299d994669bf7a1e2303497b4bbdb827c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354160
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-02-28 03:13:29 +00:00
Mayank Patke b0556ba6cb [dart2js] Enable always_declare_return_types in pkg/compiler
Change-Id: Ia61e5d221ed74474b81e8f7188f4b947d17d9050
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354421
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2024-02-26 23:37:28 +00:00
Mayank Patke 37345b9f7e [dart2js] Enable strict-inference and strict-raw-types in pkg/compiler.
Change-Id: I4712d32dc37a8cbfa0e1e5bd61659df651c77471
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354140
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2024-02-26 22:41:58 +00:00
Nate Biggs c0304fa0c6 [dart2js] Add replacementImpact to conditional impacts.
Adds a conditional impact that represents that impact if the replacement node is added to the kernel AST. This is a soundness fix for conditional impacts as the replacement node might have a different set of impacts than the "source".

It's worth noting that the only way this could lead to an incorrect compilation for protobufs is if *every* metadata field was erased. The impact of each "source" is a superset of the impact for every "replacement" node.

This code is new and behind a flag so this bug certainly won't have been visible to anyone.

Change-Id: Ifa3cb7d6b9aa46221c736a1566aa79d73f99917c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353940
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2024-02-24 06:36:42 +00:00
Mayank Patke 9fa1c16029 [dart2js] Convert some collections of const ints to enums
Change-Id: Ib1f5c686c97f8f097fa21a435e684af86f2b569c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352975
Commit-Queue: Mayank Patke <fishythefish@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2024-02-23 19:52:50 +00:00
Mayank Patke 62e5a482e4 [dart2js] Convert some classes to enhanced enums
Change-Id: Ic1cb02d587e100cefb5e6ee409693cfea1b0cfed
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352969
Reviewed-by: Nate Biggs <natebiggs@google.com>
2024-02-23 19:52:50 +00:00
Mayank Patke fcbf5eb56d [dart2js] Convert PragmaAnnotation to enum
Change-Id: I31a9cf2ab9874aef2ccfb329327c49302ab79f66
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353503
Reviewed-by: Stephen Adams <sra@google.com>
2024-02-23 19:52:50 +00:00
Nate Biggs 5f02eda731 [dart2js] Clean up modular impacts serialization.
Impact analysis is no longer supported as a standalone phase. All this serialization logic for impacts is therefore no longer needed and is fact unreachable code.

Change-Id: Ifca8b907c5b8b6ad65cdc35b809aef0a8d4975e2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353560
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2024-02-21 22:47:17 +00:00
Mayank Patke 69df740ea9 [dart2js] Assorted TODO cleanup, bump pubspecs to 3.3.0
Change-Id: I621ac252c5d6f3b157a2f194b7f0b7ad85874e4c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352990
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2024-02-21 00:02:13 +00:00