Commit Graph

77 Commits

Author SHA1 Message Date
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
Mayank Patke 553ac951b3 [dart2js] Add indexable bits to powerset.
Change-Id: I5d4c0b4d15a05cfc30d87003785ca841c46b1a0f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426583
Reviewed-by: Stephen Adams <sra@google.com>
2025-05-07 19:18:38 -07:00
Mayank Patke b941f6f0f4 [dart2js] Add modifiable/growable bits to powerset.
Change-Id: Ic8abbe3729a4c3b41fde0a37d8b6afe84bd9ba48
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/407920
Reviewed-by: Stephen Adams <sra@google.com>
2025-05-07 19:18:38 -07:00
Mayank Patke 7103d43876 [dart2js] Add powerset bits for interceptor domain.
Change-Id: Id9509c6b6eb8143263763e508512c0703d4aa493
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404500
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2025-04-16 18:14:21 -07:00
Mayank Patke d0e09ea091 [dart2js] Print powerset value in typemask toString methods.
We may find it useful later to add a more verbose stringification that
writes out the properties expressed by the powerset. For now, just
printing the int value is sufficient to debug e.g. test failures, and
it's relatively straightforward to manually convert an int to a set of
properties by looking at the definitions of the powerset domains.

Change-Id: I2397ffd83a6e86830f67c7f1ef811e33c0b7ff3c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/405567
Reviewed-by: Nate Biggs <natebiggs@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
Nate Biggs e038d8ac81 [dart2js] Add implicit null to type for optional non-nullable parameters.
This ensures any code downstream of this knows that it can receive a null and null checks are not removed during SSA.

Change-Id: I8c3d706875a9b70ed8407d00053fb381df168a49
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/406480
Reviewed-by: Mayank Patke <fishythefish@google.com>
2025-01-30 15:51:02 -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
Stephen Adams 0c527e1b9f [dart2js] Separate Iterables for Map.{keys,values,entries}
The default `MapBase.entries` and `MapBase.values` maps over the keys and does lookups. It is faster to scan the data like `get keys`.

This is essentially the dart2js version of https://github.com/dart-lang/sdk/commit/23a98d808c0

Change-Id: I03894efda459d9a4f7f07c4c79524ba5e4d925cb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/399027
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-12-10 04:36:59 +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
Nate Biggs a9fc1efe05 [dart2js] Clean up more code associated with Dart2JS static types.
The `ClassRelation` concept is no longer needed as we are only using the CFE static type. All creations of "exact" and "this" types were already removed in an earlier CL so we are already always following the 'subtype' path.

Change-Id: Iccc3d61737c5b64b3b4217f7f20b34b181cc7db2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/348463
Reviewed-by: Mayank Patke <fishythefish@google.com>
2024-02-07 00:19:33 +00:00
Nate Biggs 63f766b64e [dart2js] Narrow type of map entries in global inference based on static type.
This helps avoid some regressions from doing less static inference and depending more on the CFE static types.

Change-Id: Id95596fab87ecc9ea0c2baf3a8c21f9c90b90f94
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/348221
Reviewed-by: Mayank Patke <fishythefish@google.com>
2024-02-07 00:19:33 +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 9eba05482b [dart2js] Fix list tracing treating first/last setters as type preserving.
I suspect that when the list of type preserving selectors was created the first/last setters either didn't exist or were just overlooked. Any dynamic List could have its inferred type changed by these operations.

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

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

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

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

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

Bug: https://github.com/dart-lang/sdk/issues/53944
Change-Id: I4e893903f335fc99b13cf526736c27bb066a4bad
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/334420
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-11-08 03:50:21 +00:00
Mayank Patke ac59672086 Reland "[dart2js] Improve computed type of AwaitTypeInformation."
This is a reland of commit b3e2090a77

Original change's description:
> [dart2js] Improve computed type of AwaitTypeInformation.
>
> Change-Id: I7d57bda09a620d1bd8b9ae89d4efd02575f1a4e7
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/322368
> Reviewed-by: Sigmund Cherem <sigmund@google.com>
> Commit-Queue: Mayank Patke <fishythefish@google.com>

Change-Id: I1fdb22bc435a713f43cc7c891b7908f6ed6e8405
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/323080
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2023-08-29 00:09:29 +00:00
Mayank Patke 7c7cb1cdcd Revert "[dart2js] Improve computed type of AwaitTypeInformation."
This reverts commit b3e2090a77.

Reason for revert: http://b/297494642

Original change's description:
> [dart2js] Improve computed type of AwaitTypeInformation.
>
> Change-Id: I7d57bda09a620d1bd8b9ae89d4efd02575f1a4e7
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/322368
> Reviewed-by: Sigmund Cherem <sigmund@google.com>
> Commit-Queue: Mayank Patke <fishythefish@google.com>

Change-Id: I44940fb255e86154ce688379f6d2e3c7286df78a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/322783
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2023-08-25 19:32:01 +00:00
Mayank Patke b3e2090a77 [dart2js] Improve computed type of AwaitTypeInformation.
Change-Id: I7d57bda09a620d1bd8b9ae89d4efd02575f1a4e7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/322368
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2023-08-24 00:43:38 +00:00
Mayank Patke ed0ac21194 [dart2js] Add inference unit tests for await e without a local.
Change-Id: I2465a0b8f29d2158f684099f8500153515421c8e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/322367
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-08-24 00:43:38 +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 b9c73fdf23 [dart2js] Update switch block local handling to correctly propagate types that fall through the block.
Fixes #52170

Change-Id: I7c473c3101d446eb17433d583bfe266bf6f193d6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/298760
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-04-27 19:35:45 +00:00
Nate Biggs a6f543e50a [dart2js] Repro for issue 52170.
Type inference is not tracking the type of 'local' correctly through the switch statement into the inner return. The same code without the for loop does work correctly though.

Change-Id: I0b1b4741e4ff17c22dec3383defb412f5fff0836
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/298980
Reviewed-by: Stephen Adams <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-04-27 18:15:48 +00:00
Stephen Adams 45efccb5e0 Remove left-over patch declarations for List constructor.
This CL replaces https://dart-review.googlesource.com/c/sdk/+/296900

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

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

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

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

TEST=ci

Change-Id: I4ffaf3ae2c4e75ca06e7ba0bf19187b6376f3888
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/297100
Reviewed-by: Brian Quinlan <bquinlan@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2023-04-22 00:38:28 +00:00
Nate Biggs 7714e67efe [dart2js] Merge experimental inferrer into main inferrer branch.
Inference runtime metrics on a large program:
-----Before-----
Duration - Mean: 182.303 Median: 174.500 Max: 292.0
Memory - Mean: 5857.426 Median: 5752.639 Max: 6167.91

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

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

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

Before: 43258484 bytes JS
After: 43258444 bytes JS
Change-Id: I6512637f16d83f3127fd1c060bb770ae56405b88
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/295460
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-04-18 22:15:49 +00:00
Nate Biggs 8b01742d60 [dart2js] Fix linearization issues.
- For parameters of closurized members make sure to mark the virtual parameter as closurized where appropriate. Closurized parameters are treated as dynamic and this needs to propagate to all the virtual target's overrides. Previously only the concrete target was getting marked as closurized.

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

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

This fixes all failures referenced in b/277876666.

Change-Id: Icaca99cb6902c54f481eebdbb65cbd7cf81aa2c2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294960
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-04-15 02:05:49 +00:00
Emmanuel Pellereau 55ec45493f Revert "[dart2js] Patch experimental inferrer (with linearized algorithm) into main inferrer."
This reverts commit 9aa00f6c75.

Reason for revert: breaks google3 (b/277876666)

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

Change-Id: Ia6e038e8e077813e589a54d2242bd2820bd22036
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294741
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Emmanuel Pellereau <emmanuelp@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2023-04-12 12:41:36 +00:00
Nate Biggs 9aa00f6c75 [dart2js] Patch experimental inferrer (with linearized algorithm) into main inferrer.
After this change for a large program we see:
- 20% reduction in runtime (254s -> 202s)
- 2% decrease in memory usage (7671.029MB -> 7524.901MB)
- Code size decrease of <1% (214,788,150 bytes -> 214,757,445 bytes).
- The k-limit of 6 refines imposed on the global inference algorithm is no longer hit for converging types. All but 15 types converge, down from 777 types that were hitting the k-limit before. This means we are likely generating better types/code for all 762 of those types.
- More resilience to dynamic calls with lots of potential targets.

Change-Id: I53d4ade51559f3366f076b6f2b485c5bdc50c6e8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/271480
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-04-11 16:37:26 +00:00
Nate Biggs 7ceea1ec11 [dart2js] Add tracing of types through records in global inference.
Change-Id: I4abdb76caecc91c89792396ff7d3fe4060cc7bc5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/289904
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2023-04-04 02:11:01 +00:00
Nate Biggs 3bc19d459b [dart2js] Fix unevaluated const evaluations for record literals.
Change-Id: I72430e012b5053e37894ac64e9e1d642c478abdd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/290981
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-03-23 22:56:15 +00:00
Nate Biggs 32c5b81f9c [dart2js] Add unit tests for records.
The expectations set here are updated as fixes/improvements are made in the next 2 CLs.

Change-Id: I0ac251ce09b980cde9e01afc1fa81b987a619747
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/290980
Reviewed-by: Stephen Adams <sra@google.com>
2023-03-23 22:56:15 +00:00
Nate Biggs a2719b5552 [dart2js] Make use of new RecordTypeMask for creation of record literals/constants as well as record field accesses.
All calls on records are no longer treated as essentially dynamic calls.  So a call to `record.foo` will not pull all `foo` members into the program (including unused ones). For example in the below test the getter `any` was causing `JSArray.any` to be included in the program. After this change it is no longer pulled in.
https://github.com/dart-lang/co19/blob/master/LanguageFeatures/Records/members_A04_t02.dart#L39

Change-Id: If1f9eac1abadeeed80dca917a8912129d090643e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/287681
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2023-03-17 22:50:44 +00:00
Nate Biggs 9ba4957a31 [dart2js] Add record getters as reachable targets from dynamic call infrastructure.
Change-Id: I78387dffa4a7a16f20e630300bd90b08591efe6c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/287480
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-03-09 21:26:52 +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 9c49b0d175 Reland "[dart2js] Extend const simplifier to local/static reads and invocations."
This reverts commit 090a1ea4e8.

Reason for revert: Relanding with fixes

Original change's description:
> Revert "[dart2js] Extend const simplifier to local/static reads and invocations."
>
> This reverts commit 826df3415a.
>
> Reason for revert: Causes failures in some Angular Dart applications
>
> Original change's description:
> > [dart2js] Extend const simplifier to local/static reads and invocations.
> >
> > We now attempt to evaluate
> > - final local variables with initializers
> > - final statics with initializers
> > - static or local function invocations if they just return an expression
> > by attempting to const-evaluate the initializer/returned expression.
> >
> > Change-Id: I976863d950ba1609c5d8e6a21884ca56af0d2b4b
> > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/275145
> > Reviewed-by: Sigmund Cherem <sigmund@google.com>
> > Commit-Queue: Mayank Patke <fishythefish@google.com>
>
> TBR=sigmund@google.com,fishythefish@google.com,dart-scoped@luci-project-accounts.iam.gserviceaccount.com
>
> Change-Id: I32900085f52219a2dc5add161376ddbe9e733277
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/281800
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Commit-Queue: William Hesse <whesse@google.com>
> Auto-Submit: William Hesse <whesse@google.com>


Change-Id: I46847d45084718633c332954dc6b39b181869983
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/281861
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2023-02-13 22:16:19 +00:00
William Hesse 090a1ea4e8 Revert "[dart2js] Extend const simplifier to local/static reads and invocations."
This reverts commit 826df3415a.

Reason for revert: Causes failures in some Angular Dart applications

Original change's description:
> [dart2js] Extend const simplifier to local/static reads and invocations.
>
> We now attempt to evaluate
> - final local variables with initializers
> - final statics with initializers
> - static or local function invocations if they just return an expression
> by attempting to const-evaluate the initializer/returned expression.
>
> Change-Id: I976863d950ba1609c5d8e6a21884ca56af0d2b4b
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/275145
> Reviewed-by: Sigmund Cherem <sigmund@google.com>
> Commit-Queue: Mayank Patke <fishythefish@google.com>

TBR=sigmund@google.com,fishythefish@google.com,dart-scoped@luci-project-accounts.iam.gserviceaccount.com

Change-Id: I32900085f52219a2dc5add161376ddbe9e733277
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/281800
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: William Hesse <whesse@google.com>
Auto-Submit: William Hesse <whesse@google.com>
2023-02-08 19:05:18 +00:00
Mayank Patke 826df3415a [dart2js] Extend const simplifier to local/static reads and invocations.
We now attempt to evaluate
- final local variables with initializers
- final statics with initializers
- static or local function invocations if they just return an expression
by attempting to const-evaluate the initializer/returned expression.

Change-Id: I976863d950ba1609c5d8e6a21884ca56af0d2b4b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/275145
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2023-02-07 20:07:57 +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
Lasse R.H. Nielsen bee7ab2b32 Make record positional field getters start at $1.
An update for co19 is available at https://github.com/dart-lang/co19/pull/1759

TEST=Existing tests run after change, two new tests for edge cases.

Change-Id: I408e398d532ba2c2e8e60777bb4f7bd0057e27fe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/278912
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2023-01-30 08:14:28 +00:00
Josh Soref 419df9d3e5 Spelling pkg compiler
Closes https://github.com/dart-lang/sdk/pull/50774

GitOrigin-RevId: 41028b5de4e2e0719e08f180e32ccc1f2bef8dac
Change-Id: I5e6675d490a44feb0ea008582879266e421939f6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/276561
Reviewed-by: Stephen Adams <sra@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
Commit-Queue: Erik Ernst <eernst@google.com>
2022-12-20 13:06:29 +00:00
Stephen Adams d633b0a383 [dart2js] More records implementation
These are scattered changes to get to type inferrence.

- Add some impact tracking for used record types
- Add RecordTypeInformation and FieldInRecordTypeInformation
- Add a simple test to show inference is currently very conservative.

Change-Id: Icb81033b11588c1bddd01c8c5fcf69950fdb77e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/275161
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2022-12-14 02:20:18 +00:00
Nate Biggs 3daee0282b [dart2js] Fix inferrer bug in handling exit conditions in try/catch/finally.
This is showing up in places like here where we are inferring `JSObject.toString` to return `String?`:
https://github.com/dart-lang/sdk/blob/main/sdk/lib/_internal/js_runtime/lib/js_patch.dart#L204

Change-Id: Ie15c6a06cd1e0f9ead87b4a9ceaa949bdcbce989
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/269040
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2022-12-01 22:16:35 +00:00
Lasse R.H. Nielsen 8a883fa54d Change : to = for default values in pkg.
Leaves some in parser test:
 pkg/front_end/parser_testcases/error_recovery/keyword_named_formal_parameter_prime.dart

TEST=Refactoring, covered by existing tests.

Change-Id: I7a83ef95df3cbd283878b3685b5c747bd89a1b16
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/256125
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2022-08-24 15:57:16 +00:00
Nate Biggs 709c4202b5 [dart2js] Global inference should merge breaks after each case statement
The type bounds in each case statement can diverge when a break is hit in a conditional control flow block. Previously the switch statement was just merging the end state after visiting each case block. Instead we need to merge all possible termination states for each case.

This is trivial when the switch only contains breaks. The termination states are just those when we reach each break (or the end of the switch if there's a default).

When there are switch-continue statements we must reconcile the states that flow into each targeted switch before reconciling the types of those targeted switches themselves. We achieve that by making two passes over the cases, the first to gather the continue states and the second to update the switches affected by those states. Similar to before this is done repeatedly until a fixed point is reached.

Fixed: 46770
Change-Id: I5795748a4591e6a1dc283f2a54129e09a20d13d8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/250200
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2022-07-07 15:38:51 +00:00
Stephen Adams 6384eceedc [dart2js] Late instance field optimizations
Late fields start out holding a sentinel value and after they are initialized or assigned, never hold a sentinel value again.
This CL implements some removal of checks and loads based on this monotonic behaviour.

On two large Dart Angular apps, this reduces the number of late-instance-field checks by ~25%.
One app is 0.44% smaller, the other is 0.98% smaller.

The optimization_test.dart no longer forces `--disable-inlining` because that prevents the inlining that exposes the optimization opportunities.
Most tests already use `@pragma('dart2js:noInline')` to prevent inlining where relevant.

Change-Id: I2327a96e69191313ed6c07eabe94aa2962fb2648
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/246881
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2022-06-07 05:57:59 +00:00
Mayank Patke 34ebfc6594 [dart2js] Add regression test for https://dart-review.googlesource.com/c/sdk/+/225320
Change-Id: Iff348b9ce13ea249b8c63f8c0952cd446ad5cb7d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/243528
Commit-Queue: Mayank Patke <fishythefish@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2022-05-10 22:56:23 +00:00
Stephen Adams 5c2ca380a4 [dart2js] Tag all sources with @dart = 2.10
Change-Id: Ie9c7548dc81b58db0c1149124db79e4cf1430cc1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/239723
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2022-04-06 21:31:45 +00:00
Sigmund Cherem 017e0f7224 [dart2js] Fix nested conditions in global inference
A bug in global inference made the analysis accidentally carry over
the state of a nested condition in a subexpression and conclude
that it was part of the state of the outer condition.

This was due to the fact that we didn't clear the state when
popping out of the context and reentering the conition state.

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

Change-Id: I4e8294bb1a05bb3b910b6aec374357d75acb67cb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/240321
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
2022-04-06 16:42:34 +00:00
Sigmund Cherem bbf5dc1c59 [dart2js] add regression test for issue 48571
Global type inference incorrectly handles conditions nested within
subexpressions and accidentally carries information from those
in the context of outer conditions.

Change-Id: I99e0af3da65590acb9429771b318b7da8f3b7f14
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/240320
Reviewed-by: Stephen Adams <sra@google.com>
2022-04-06 16:42:34 +00:00
Johnni Winther 1f848492b7 [dart2js] Compute the correct selector for InstanceGetterInvocation
The Selector computed for InstanceGetterInvocation used the name of
the getter eventhough the invocation is actually a .call invocation.
This lead the computation of whether type arguments need to be parsed
to fail because it queried with the wrong selector.

Closes https://github.com/dart-lang/sdk/issues/48304

Change-Id: Ia08fb91fa24b5b04eba850f75f9b66cb89494dda
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/234288
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-03-01 08:55:17 +00:00
Mayank Patke d539c43372 [dart2js] Create child LocalState for inference of labeled statements.
This is analogous to what we do for other control flow constructs.
Without this, a `break` to the label causes the outer scope to also
appear aborted.

Fixes: #48317
Bug: https://github.com/flutter/flutter/issues/96394
Change-Id: I575a5bf96b25b49df6f15d429881e310b3b34d15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/233446
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2022-02-18 00:58:20 +00:00
Stephen Adams 44ba8ecdb2 [js_runtime] Remove unused ES6 Map _LinkedHashMap implementation
If we were to use ES6 Maps, we should try to use a single one for
all 'identity' keys (numbers, strings, enums etc).

Change-Id: Idc600b7cb48b58a074fd4c9bb6205d544f86dbc1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/226540
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2022-01-06 19:57:31 +00:00