Commit Graph

112 Commits

Author SHA1 Message Date
Lasse R.H. Nielsen f1fcecc81d Improve optimization of int & 0xFFFFFFFF.
Recognize a second operand if its `ToUint32` is `0xFFFFFFFF`,
not just the exact value. This includes fx `& -1`, which is output
by `toUnsigned(32)`.

Change-Id: Ieccb42591efd72b4aae62a7c6e678f05510abdc6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/510960
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2026-06-11 06:09:58 -07:00
Kallen Tu 8bfb683892 Enable 'primary-constructors' feature flag.
This CL enables the primary constructors feature by default in Dart 3.13.

The primary constructors feature is a brevity feature. There are no new semantics, but it allows us to express declarations in a less verbose way.

This feature allows one constructor and a set of instance variables to be specified in the header of a declaration.

Currently a declaration with a constructor and some fields is written as:

```dart
// Current syntax.
class Point {
  int x;
  int y;
  Point(this.x, this.y);
}
```

With a primary constructor, we would write the above as:

```
class Point(var int x, var int y);
```

If a primary constructor needs an initializer list or a body, they can be
specified inside the class using the `this` body syntax:

```dart
class Point(var int x, var int y) {
  this : assert(x >= 0) {
    print('Point created at $x, $y');
  }
}
```

As part of this feature, you can also use the `new` and `factory` keywords to
declare constructors in the class body without repeating the class name:
```dart
class Point {
  int x, y;

  // Equivalent to Point(this.x, this.y)
  new(this.x, this.y);

  // Equivalent to Point.origin()
  new origin() : x = 0, y = 0;

  // Equivalent to factory Point.clone(Point other)
  factory clone(Point other) => Point(other.x, other.y);
}
```

To learn more about the feature, check out the feature specification located here: https://github.com/dart-lang/language/blob/main/accepted/future-releases/primary-constructors/feature-specification.md

Tested: Has existing language, CFE, analyzer, analysis server tests.
Bug: https://github.com/dart-lang/sdk/issues/61524
Change-Id: I296f2fcd918b87bf2a1dd00256340759866c2423
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/489241
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Michael Thomsen <mit@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2026-05-04 15:09:49 -07:00
Nate Biggs 3d2d6492c1 Add 'external-effect' pragma support to all the backends.
Call sites targeting a procedure annotated with `external-effect` will
not produce any code, including the argument which will not be
evaluated.

However, the single parameter will be treated as 'live' for the purposes
of any global analysis the backends do. This is useful for things like
protobuf shaking where a user may want to retain certain protobuf
messages without actually emitting the code that retains those messages.

Today this functionality is available internally in the vm and wasm SDK
libraries. dart2js has similar functionality represented via the
opaqueTrue and opaqueFalse booleans (which will cause conditional
branches to get shaken after analysis). This will replace dart2js's
opaque(True/False).

This also adds validation to the frontend to ensure a method annotated
with 'external-effect' is well-formed.

Change-Id: If1c4096673e655c58fe7638840a16125003e7809
Tested: Backend tests for codegen were added. A frontend test was added for the validation. A language test was added to confirm the behavior.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/476020
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2026-04-27 09:42:38 -07:00
Stephen Adams cf01e0743c [dart2js] Choose between while- and for- loops
Change-Id: I6b564775e42649a974b72331528e02803a41616e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/447880
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2025-09-14 18:30:04 -07:00
Stephen Adams 063b3c12a5 [dart2js] Add missing case of updating call attributes
When an indirect call is replaced by a direct call, the direct call
(HInvokeStatic) should have the correct attributes for the target.

Change-Id: I950b6ed4f1537e2420905ac45d89a2bd6f2fa2c8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448442
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2025-09-05 11:56:32 -07:00
Stephen Adams 5492cfd1bc [dart2js] Never elide _Enum.index
This ensures that `_Enum.index` is always available for switch strength
reduction optimizations. Most real programs use the index of at least one `enum`, so the field is not usually elided. This change makes small tests and benchmarks behave more like real programs where these optimizations happen.

Bug: #51657
CoreLibraryReviewExempt: dart2js specific annotation
Change-Id: If98e483d7cce265e823fd574565089e328215cca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/446481
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2025-08-27 11:44:04 -07:00
Stephen Adams 3f2a6963fb [dart2js] Improve algorithm for condition targets
1. Use a work queue to avoid recursion on deep trees.

2. Use a visited set to avoid cycles and repeated work on conditions like `b && b`.

Bug: #60801
Change-Id: If20de27b1ddd157feee2391289ec781c03f741ae
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/431704
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2025-05-30 18:05:54 -07:00
Stephen Adams b00c777f79 [dart2js] allow-cse and allow-dce annotations
Add `@pragma('dart2js:allow-cse')` and `@pragma('dart2js:allow-dce')`.

These annotations allow the compiler to do common subexpression
elimination and dead code elimination on calls to getters and methods.

Change-Id: Ie4091466e4782a4d28a7f9bfbfdb60a5de45a384
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426360
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2025-05-21 23:02:06 -07:00
Mayank Patke 2bb32ec55a [dart2js] Update pubspec to 3.8 and reformat.
Change-Id: Ib1afd38a7d3694c2e5ed591132f41b147f76d75a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427560
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2025-05-09 10:34:12 -07:00
Tim Maffett 4a821b4046 simple typo fix
Closes https://github.com/dart-lang/sdk/pull/60485

GitOrigin-RevId: efef9e67c7e2bb2ab8146f852bed98eb3590f360
Change-Id: I062510b397e368da9de195b50e332b25f52196c1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420620
Reviewed-by: Kevin Moore <kevmoo@google.com>
Commit-Queue: Kevin Moore <kevmoo@google.com>
2025-04-06 20:27:31 -07:00
Mayank Patke 76d660a3e1 [dart2js] Remove bool conversions
The CFE will now add an `as bool` when a `dynamic` value is used as a
condition, giving the condition the right static type. Without
`--omit-implicit-checks` we faithfully emit a cast, so no bool
conversion is needed. With `--omit-implicit-checks`, we trust that the
condition is a boolean and emit no check of any kind - but you get what
you asked for.

Change-Id: I5c9f6b6516386fab5b863f256f9676fc7abe19b2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417323
Reviewed-by: Stephen Adams <sra@google.com>
2025-03-27 13:46:20 -07:00
Stephen Adams 9505e957e1 [dart2js] Add more refinements for null-test and type-tests.
Bug: #26835 #28330
Change-Id: I2ea5d3022901a67b10fdb7ca0a6233a22ca233bf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417328
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2025-03-25 17:30:21 -07:00
Stephen Adams 57f177210a [dart2js] Test for complex condition strengthening
Bug: #26835 #28330
Change-Id: Ic3bc05f1b5525e58173c335c5f3f4f91dd09e2f3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417329
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2025-03-24 15:29:23 -07:00
Mayank Patke 1bbbf26434 [dart2js] Refactor FlatTypeMask cache.
As the powerset grows, the cache needs to be keyed on both the base and
the full flags. While we're at it, we ensure that all FlatTypeMask
allocations go via the cache.

Change-Id: Ifdd400bf4ea23a936c4d37be91a5d527102aa3b4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/413700
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2025-03-07 04:20:04 -08:00
Mayank Patke f00dbb5856 [dart2js] Reformat pkg/compiler.
Change-Id: I9e379d1f0673b589139a2389c6d3602c36995cd2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/413720
Reviewed-by: Nate Biggs <natebiggs@google.com>
2025-03-07 04:20:04 -08:00
Mayank Patke 6acaf9b8f4 [dart2js] Account for late sentinels in trivial inference results.
Fixes: #49599
Fixes: #55058
Fixes: #60115
Change-Id: I66673b6e467b54428e8d5ba317eec8aa3248645f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/258961
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2025-02-18 16:50:18 -08:00
Mayank Patke 66fa0e2a49 [dart2js] Clean up nullability adjustments in interface sufficiency test
Now that https://github.com/dart-lang/sdk/issues/60076 has been
addressed, we no longer need to widen the nullability ourselves.

Change-Id: I4bc5a1767d9e2d98bcf0ca4c24171482e0f600ac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/409162
Commit-Queue: Mayank Patke <fishythefish@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2025-02-13 01:49:09 -08:00
Stephen Adams e962350dd6 [dart2js] Simply is-test when type parameters not needed
Sometimes the type expression of a is-test can be widened to one that
does not use type variables:

```dart
void addAll(Iterable<E> items) {
  if (items is List<E>) {
    ... items[i] ...  // code specialized to lists
  }
  ...
}
```

Changing `is List<E>` to `is List` is more efficient, but not possible
at the source level since the explicit type parameter is needed for
type promotion.

This change uses a predicate provided by the Kernel package to widen
an interface type when generating the CFG instructions for the
is-test. This can lead to knock-on optimizations like compiling `is X`
to `instanceof`.



Bug: #54998
Change-Id: I956b9d9b8a31ae40aee86e31def475baa9ab5cfe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/408124
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2025-02-06 16:54:50 -08:00
Stephen Adams a1c54855a6 [dart2js] Detect larger no-op regions
Change-Id: Id4ced6f3a54d40a3775b77fde8453e45a6383ee2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404800
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2025-01-24 14:35:55 -08:00
Stephen Adams b3502f17cb [dart2js] Reduce redundant phis with refinements
Redundant phi elimination removes phis that join the same value.
However, this does not work when one or more of the inputs has a refinement (HTypeKnown). This change adds redundant phi elimination when the phi inputs have refinements.

The need for this optimization shows up when static js_interop needs a dispatch on type for conversion:

```
final JSAny? jsValue;
if (value is String) {
  jsValue = value.toJS;
} else if (value is bool) {
  jsValue = value.toJS;
...
```

(The `.toJS` calls become no-ops since, for dart2js, we are already in JavaScript, and so leave an otherwise pointless if-then-else chain).

Change-Id: If1a94856592163a81ac36c686cee04232c16d197
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403950
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2025-01-16 11:16:31 -08:00
Mayank Patke c878108cc8 [dart2js] Update pubspec to Dart 3.7 and reformat.
All non-pubspec changes generated by `dart format pkg/compiler`.

Change-Id: Iadaa70974816d96ccb47813fe72d5a2bb83d6bda
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/400181
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2024-12-13 11:24:50 -08:00
Lasse R.H. Nielsen f8086c81ae Collect all test-related files in package:expect.
Collects files from `package:async_helper` and `tests/language`
that are generally useful, so that all test-related helpers are
in `package:expect`.

Moves the two libraries from `package:async_helper` into `package:expect`,
and the `tests/language/static_type_helper.dart` file too.

Deprecates `async_minitest.dart`, to follow `minitest.dart`,
expecting the Flutter use of it to have been fixed to not break
on deprecation (I believe Flutter no longer breaks builds on deprecations at all).

Patch 1 is the actual change.
Patch 2+4+8 is changing all existing references to the files.
Patch 6 ignores deprecation in files still using `async_minitest.dart`.

3+5+7+9 are updating this text to make the numbers match.
Then it's just test-expectations and small tweaks from there.

Change-Id: I1b665135b5fef9b9a0c3b340ffe9daf874d0174c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373120
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2024-10-11 16:53:52 +00:00
Stephen Adams 9162f0f9c9 Reapply "[dart2js] Make more use of kernel's static type"
This reverts commit f9aec1c997.

Change-Id: I731b29714797fbea38da09ed48a0dd4852af986b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379669
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-08-15 18:58:55 +00:00
Stephen Adams f9aec1c997 Revert "[dart2js] Make more use of kernel's static type"
This reverts commit 1057e5575f.

Reason for revert: Breakage in product test

Original change's description:
> [dart2js] Make more use of kernel's static type
>
> This change helps with one hang-over from Dart 1.
>
> In code like `a[i] == 1`, the type of the indexed element was inferred
> as the element type of `a`. This was great if `a` was a traced List,
> but too general if the provenance of `a` is unknown, since the general
> element type over all lists is 'top'.
>
> Dart 3 gives much better guarantees than Dart 1. We can now rely on
> the front-end inferred type for `a[i]`. To do so, we track the
> abstract value contraint for the type through SSA so that SSA-level
> type propagation can re-apply the constraint.
>
> This removes about 100 interceptor calls from the main unit of some
> large ACX apps.
>
> Change-Id: I6839a6045d9341633c08678affb35fdb2998a96d
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379145
> Reviewed-by: Mayank Patke <fishythefish@google.com>
> Commit-Queue: Stephen Adams <sra@google.com>

Change-Id: I5e2b9fde9ffd7d79332fd493649e8f342219c8ea
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379667
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-08-08 22:14:38 +00:00
Stephen Adams 1057e5575f [dart2js] Make more use of kernel's static type
This change helps with one hang-over from Dart 1.

In code like `a[i] == 1`, the type of the indexed element was inferred
as the element type of `a`. This was great if `a` was a traced List,
but too general if the provenance of `a` is unknown, since the general
element type over all lists is 'top'.

Dart 3 gives much better guarantees than Dart 1. We can now rely on
the front-end inferred type for `a[i]`. To do so, we track the
abstract value contraint for the type through SSA so that SSA-level
type propagation can re-apply the constraint.

This removes about 100 interceptor calls from the main unit of some
large ACX apps.

Change-Id: I6839a6045d9341633c08678affb35fdb2998a96d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379145
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-08-08 00:30:48 +00:00
Stephen Adams 15792df87e [dart2js] Use indexes for operation names and verbs
Change-Id: Ic954a7e20062aa8bf1c0f622ee9b0656bc563ba5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/375024
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2024-07-15 02:18:52 +00:00
Stephen Adams e66a0cbde8 [dart2js] Unmodifiable Array and typed data using flags
- Add SSA HArrayFlags{Check,Get,Set} instructions to check for
  fixed-length and unmodifiable JSArray and JavaScript typed data
  instances.

- Add optimizations to remove redundant checks.

- Added HOutputConstrained interface for instructions that must have
  the input and output in the same JavaScript variable. This
  generalizes some code generation logic already applied to HCheck.

Bug: #53785
Change-Id: I61750dd03aa3a964eed3bc76e1656c5f60f77109
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372002
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2024-07-10 01:39: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
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
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
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 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
Stephen Adams 4df361c3c3 Reapply "[dart2js] Replace phi with controlling condition"
This reverts commit aec3ec0244.

- Corrected 'controlling condition' detection.
- Added test that is incorrectly compiled to infinite loop with incorrect controlling condition detection.

See https://github.com/dart-lang/sdk/issues/54115#issuecomment-1944285230 for an image of part of the CFG for `doWhileLoop` where the condition in B4 was previously mis-identified as controlling `phi(true,false)` at B12.

Issue: #54115
Change-Id: I0d2c2ff83b202071f6d7050d34de8ff25d05cb22
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352443
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-02-15 01:02:39 +00:00
Mayank Patke aec3ec0244 Revert "[dart2js] Replace phi with controlling condition"
This reverts commit 75b1973041.

Reason for revert: Breaks g3 tests

Original change's description:
> [dart2js] Replace phi with controlling condition
>
> Rewrite `phi(true, false)` to the controlling condition.
>
> This patchset comparison shows the general effect: https://dart-review.googlesource.com/c/sdk/+/340065/2..3/pkg/compiler/test/codegen/data/phi_to_condition_test.dart
>
> This change is a partial remedy for http://dartbug.com/54115
>
> Issue: #54115
> Change-Id: Ibcc5d17f6c4c8ad9600840ec106f84edcd008e4a
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340065
> Reviewed-by: Nate Biggs <natebiggs@google.com>
> Commit-Queue: Stephen Adams <sra@google.com>

Issue: #54115
Change-Id: Id717ef469b09a5b07e43b3ffafc54bc6b409f0df
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350006
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2024-02-03 00:56:15 +00:00
Stephen Adams 75b1973041 [dart2js] Replace phi with controlling condition
Rewrite `phi(true, false)` to the controlling condition.

This patchset comparison shows the general effect: https://dart-review.googlesource.com/c/sdk/+/340065/2..3/pkg/compiler/test/codegen/data/phi_to_condition_test.dart

This change is a partial remedy for http://dartbug.com/54115

Issue: #54115
Change-Id: Ibcc5d17f6c4c8ad9600840ec106f84edcd008e4a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340065
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-01-25 01:11:03 +00:00
Mayank Patke f79ed9301b [dart2js] Remove remaining language version overrides
Now that dart2js only takes migrated files as input, all tests should
use the current language version.

Change-Id: I6c84850f5786aeac04154b67bd7a3c19083c8bba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/345344
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2024-01-23 01:26:09 +00:00
Nate Biggs ef75007c2f [dart2js] Fix as-check type registration.
We would expect failing as checks to throw in all modes (unless --omit-as-casts is provided). However, the new test program fails in production mode. This is because we are not registering the type usage of the function's type parameter. This leads us to drop the as check completely later on.

We should be doing subtype checks with nullability if we want to consider an as test omitted.

Golem patch results: https://golem.corp.goog/Comparison?repository=dart#targetA%3Ddart2js%3BmachineTypeA%3Dlinux-x64%3BrevisionA%3D107840%3BpatchA%3Dnatebiggs--dart2js--Fix-as-check-type-registration.-7%3BtargetB%3Ddart2js%3BmachineTypeB%3Dlinux-x64%3BrevisionB%3D107839%3BpatchB%3DNone

Fixed: https://github.com/dart-lang/sdk/issues/54419
Change-Id: If93f78a939a690f05f5398c1a5ca971df1fc9243
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343821
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2024-01-09 00:04:50 +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
Stephen Adams 404edd9435 [dart2js] Fix SSA value range analysis bugs
Treat the loop update marker more like an ordinary symbolic value. The old symbolic marker attempted to do widening 'on the fly', which could lead to incorrect results when the update could reset the value to a constant lower than the starting value. The new version moves the widening to a single place, at the loop update.

Fix #53355 by caching intermediate results so that long chains of diamond control flow are not explored exponentially.

There are very few changes in apps. There is one change in a Flutter app that is like the changed codegen/value_range_test where the bounds check can be eliminated because the loop index may be decremented, but not more than the increment, so is still weakly monotonic. There is one change in a large ACX app where a lower bounds check is no longer removed but I *think* it was previously removed incorrectly, though it is hard to tell since it is in a huge function.

Issue: #48465
Issue: #53078
Issue: #53355
Change-Id: Ib125cd6bb30cef52f8dfcd53eaa13e439f26316c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/322594
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2023-08-29 00:52:58 +00:00
Stephen Adams d3da4311c0 [dart2js] Lower String.codeUnitAt to charCodeAt
Change-Id: Id4408a761304fc2fcb7ce3bd353c626958971ffb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/300500
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2023-05-05 15:27:11 +00:00
Stephen Adams e8832a643e [dart2js] Fix value_range_test
The fix is to enable type inference.

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

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

Bug: #52139
Change-Id: Icfaeb3e341b448bbc263efe43f48a2b76d05bf5b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/298020
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2023-04-25 17:58:29 +00:00
Nate Biggs 339399a593 [dart2js] Resolve failing web unit tests.
- variance_subtype_cast_test.dart: Pass soundNullSafety flag so @dart=2.7 flag doesn't get added to test.
- logical_expression_test.dart: Remove test as this is now covered by test added in https://dart-review.googlesource.com/c/sdk/+/297360.

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

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

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

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

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

TEST=ci

Change-Id: I4ffaf3ae2c4e75ca06e7ba0bf19187b6376f3888
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/297100
Reviewed-by: Brian Quinlan <bquinlan@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2023-04-22 00:38:28 +00:00
Stephen Adams 90bba41618 [dart2js] Compile more is tests to instanceof
`o is T` where `T` is an interface implemented by a class hierarchy
can be implemented as `o instanceof R` where `R` is the root of the
hierarchy. The common case is that `R` is a single implementation
class.

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

Fixes: #51366
Change-Id: I1943533bc53024f3199f71910034d49cf6661b22
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294320
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-04-11 21:06:00 +00:00
Nate Biggs 545ee13cd4 [dart2js] Clean up usages of 'new' keyword.
Change-Id: I193e19581d29a9c4b343ae0a681d1ff530cfce1d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/281309
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-02-14 02:36:38 +00:00
Mayank Patke 397ed8673c [dart2js] Add phase 1 kernel transformer to simplify const conditionals.
Suppose we have code like

if (isDevMode) {
  // do foo
} else {
  // do bar
}

where isDevMode is const (or can be evaluated as const). In particular,
isDevMode can be controlled by compile-time options, like
bool.fromEnvironment.

We currently eliminate the dead branch during SSA, but that means we do
the work of compiling dead code in the previous phases. Instead, we can
recognize that the condition is const (or effectively const) and
eliminate the dead AST subtree directly.

Change-Id: Ia91da5ebc7fa496a1b963308c6e02d572cab936e
Bug: b/254543452
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/270281
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-02-07 20:07:57 +00:00
Nate Biggs 1add1a8522 [dart2js] Migrate test/codegen for null safety migration.
This change seems fairly large but most of the files only contain a change to remove the language comment.

Change-Id: I36d7fcc327172101a61ff97b7d49b168911b6e01
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279820
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-02-02 04:21:58 +00:00
Nate Biggs f8c6fe1446 [dart2js] Fix some more sound null safety issues.
Change-Id: Idca708abb1defca7ce1db8c6923c6f31f8ab3438
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/278840
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-01-11 17:35:29 +00:00