Commit Graph

54 Commits

Author SHA1 Message Date
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
Kevin Moore 07fd58715c pkg-compiler: drop Pair class, use Record
Change-Id: I19b05ffc6bd8e87e58990a62a21b8a2986fe9f54
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382760
Commit-Queue: Nate Biggs <natebiggs@google.com>
Auto-Submit: Kevin Moore <kevmoo@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2024-10-07 17:55:44 +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
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 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 37363c83c9 [dart2js] Fix type of RandomAccessFileOutputProvider.onFailure.
Issue: #48820
Change-Id: I62e182a5fd974a5dc488c3dc1b08ff8c1aaae9d1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352781
Reviewed-by: Nate Biggs <natebiggs@google.com>
2024-02-15 19:44:48 +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 c944fc1db1 [dart2js] Delete standalone JS tracer.
JsTracer has been replaced in non-test code with an online tracer that is faster and more memory efficient. Some test/support code still uses the original tracer. Update this code to use the newer online tracer.

Change-Id: I576ab38801044da8457719070eb5765bfcdc5ff0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331020
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2023-12-28 20:32:47 +00:00
Nate Biggs c447f0007e [dart2js] Add shadow tree based tracer that uses JS Printer hooks to generate source map metadata.
The current tracer does a separate visit of the entire JS AST using metadata from the JS printer in order to generate source maps. This new strategy uses a shadow tree tracking position info to generate source map metadata while the JS AST is bring printed. This saves us an entire tree walk and the memory overhead of storing metadata to pass to the separate source map tracer.

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

Change-Id: I622e7015e2eddc7835551f970386e13019394a79
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336760
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2023-12-07 17:35:59 +00:00
Nate Biggs af7cbd2a04 [cfe] Fix kernel AST nodes serialized format missing file offset.
Dart2JS uses the file offset on these nodes to create JS source maps. We want to maintain these file offsets across the serialization layer when we compile from dill files rather than directly from sources.

Dart2JS tests were serializing via `--test-mode` flag and thus had incorrect source locations for some stack traces.

TEST=Updating tests for all of these in fasta offsets tests.

Change-Id: I33862462fbff84d88f8c51bdeb1efc5771cfb8b2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/327160
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-09-25 21:07:10 +00:00
Stephen Adams a6162d1ff0 [dart2js] Fix missing source location on null-check in async method
Change-Id: Idd2530b3cae582819a823132c9777086035e386a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296027
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2023-04-19 16:31:22 +00:00
Nate Biggs 35492bdf14 [dart2js] Remove bytes cache from SourceFileProvider.
During each phase we are caching the bytes for files we read. We end up holding onto them longer than we would otherwise need to. The only time this cache is actually used is to report messages from the CFE. In those infrequent cases we can easily re-read the necessary file.

In the CFE and closed world phases this saves >300MB because the source file bytes can be released. In codegen and global inference the savings are more modest (<10MB). The emitter phases does not benefit from this because it's holding onto the input file to do deferred reading.

Change-Id: I980c81178ed250646d446521059460d8277fe3f6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292040
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-04-04 02:41:42 +00:00
Nicholas Shahan 7c0e4d67c7 [dart2js] Prevent unsound compiles
- Remove unsound platform .dill files from the packaged SDK.
- Throw and error referencing the sound null safety requirements of
  Dart 3 when compiling with `--no-sound-null-safety` and an unsound
  platform .dill file is not found.

Change-Id: I703a446e3e92c76a6b48168577fc0161eea83854
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/289280
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-03-28 21:31:27 +00:00
Nate Biggs a560f96987 [dart2js] Update pkg/compiler/test with small changes prior to enabling sound null safety.
Change-Id: I3937815c9a3f01c0113e2b6edc93bb3cf8eb85b3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/283000
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-02-15 04:04:48 +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
Devon Carew 21ab29fef6 [deps] rev package:source_maps to the latest
Change-Id: Ic0926143ea98bc3bc1eebfaca0d20c3f5578154a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/282808
Reviewed-by: Kevin Moore <kevmoo@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2023-02-13 21:18:37 +00:00
Nate Biggs 5dc018df0c [dart2js] Migrate sourcemaps/helpers/diff.dart for null safety migration.
Change-Id: I718c831272e369ba9df2b19474f4765ba085b9f0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279840
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-02-02 04:21:58 +00:00
Nate Biggs 9944232752 [dart2js] Migrate test/sourcemaps for null safety migration.
Change-Id: Ieacc99cdb4593bf291a366b3544a8eddabb2e116
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279589
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-01-27 00:24:47 +00:00
Nate Biggs 7b9470edbf [dart2js] Migrate test/sourcemaps/tools for null safety migration.
Change-Id: I6a130dc27f31ac795f276a1b1e4d8699678b8dcb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279588
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-01-27 00:24:47 +00:00
Nate Biggs e6df56399f [dart2js] Migrate test/sourcemaps/helpers for null safety migration.
Change-Id: I4405287e4304b2918fe0d613914d4d63178701e2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279587
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-01-27 00:24:47 +00:00
Sigmund Cherem 5f765bcf8f [dart2js] fix minified_names_test.
This test broke on a d8 roll back in January, since then other changes in the compiler
made the test drift further away from the original issue

Change-Id: I081dd48ae9eea2aec4117a377805c26675d2e557
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/271862
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
2022-12-10 01:24:54 +00:00
Sigmund Cherem e8906e65e7 [3.0 alpha][dart2js] No longer infer the null-safety mode from sources.
This prepares dart2js to default to sound null safety in Dart 3.0.

The compiler no longer infers the default mode based on the input
program, instead uses sound null safety unless
'--no-sound-null-safety' is specified.

On a separate change, we expect to remove the option of disabling
null safety.

Note: this change should also be reflected in the CHANGELOG, but
we've currently not included it to redeuce merge conflicts, as we plan
to land multiple 3.0-alpha changes in a short window of time

Change-Id: Id87498cc5976548ec89d1f36c60674b72406950a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/270860
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2022-12-07 04:02:13 +00:00
Nate Biggs 975cb8a9cb [dart2js] Move memory compiler out of test folder.
Change-Id: I4fd3b1fa91582ce19fb16a61a81013d694e0cd59
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/270540
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2022-11-18 02:59:15 +00:00
Nate Biggs 3ed70b013b [dart2js] Remove JClosedWorld interface and use only implementer, JsClosedWorld, everywhere.
Change-Id: I9641033aa3a93a28ee428ddc63aa7fc337e5468a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/267802
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2022-11-04 15:11:27 +00:00
Sigmund Cherem d9b74dc377 [dart2js] prepare io/kernel_source_information for migration
Change-Id: I800afd2e8091bc2560bb373f3d1535d15b84e82a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262276
Reviewed-by: Mayank Patke <fishythefish@google.com>
2022-10-04 17:08:00 +00:00
Sigmund Cherem 8bff8336a4 [dart2js] migrate source_file_provider
This reapplies f740b500e2

The change is not that different from the original, except that a
few changes have landed in between to address the failure
encountered by the SDK roll last time. Namely, the map lookup on
`resolvedUri` is normalized, so that the lookup will always match
how the store operation is done, and hence will succeed when copying
cache entries between resolvedUri and uri (see also
https://dart-review.googlesource.com/c/sdk/+/250440).


Change-Id: Ic3ad778a3e9ea465b515de9800f296c71683970c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/260081
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
2022-09-23 01:41:18 +00:00
Ahmed Ashour 5fe480b788 Fix typos
Fix #49864

TEST=ci

Change-Id: I9a7e06d604cd0b4f56f2ac229ab3fc9f01cb9d76
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/256824
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2022-09-16 19:35:00 +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
Johnni Winther 50ac2500a1 [dart2js] Handle private names correctly in K/J-model
The library wasn't taken into account when handling computing class
members in the K/J-model and not handled correctly when computing
applicable selectors. This made dart2js unable to handle members with
a name private to a different library than the enclosing library.

Fixes #33732
Fixes #49226

Change-Id: I5ba143d87662bbd42e0ff02355054e4a937be8f8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/252665
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2022-08-11 06:56:32 +00:00
Sigmund Cherem 710c0b3695 [dartj2s] (tech-debt) better error locations for sources from dill files.
This change addresses a technical debt issue in dart2js, where
errors sometimes get reported as a binary offset location, instead
of a line/column position with contextual data from the source file.

The reason for this behavior is that dartj2s reports binary offsets
when it can't recover line/column data and show the contents of the
file. This typically happens if the file cannot be read directly
from disk.

The fix consits of adding an API to record the contents of files
that are not read directly by the compiler. We then use this API to
provide all sources collected by the CFE when parsing components
from .dill files.

Note: this CL also deletes the `autoread` feature in
source-file-provider. That feature was added for the same purpose.
The way it worked was that instead of registering source content, it
tried to read the sources from disk on-demand as errors got
reported. This doesn't always work for three reasons:

* First, we often use custom schemes (like the multi-root scheme) in
  dill files to make the .dill deterministic in distributed build
  systems, the autoload feature had no understanding of how to
  translate those custom URIs to file URIs (that translation is only
  define at the time the .dill is being built).

* Second, sometimes the files are simply not available, for example,
  in hermetic build systems like bazel we have no access to those
  files.

* Third, when files were found, there was no guarantee that the
  contents were consistent. That is, the current version of the file
  on disk could have been modified and have different contents than
  those used when the .dill file was built.

I tested this manually by adding a crash in SSA and observing the
location in multiple scenarios, including running from source,
running from a .dill with file URIs, running from a .dill with
multi-root URIs, crashing in SDK locations in regular files and
patch files.

Change-Id: Ief09be577f4c9c4b345b4e2641918cafbe93c3fc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/251700
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
2022-07-19 17:10:06 +00:00
Stephen Adams f740b500e2 Revert "[dart2js] Migrate source_file_provider.dart"
This reverts commit c9ff7d95fd.

Reason for revert: Test failure in google3

Original change's description:
> [dart2js] Migrate source_file_provider.dart
>
> Change-Id: Iaded7ebfe4415f8108c9364521939b8394ab598a
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/249780
> Reviewed-by: Nate Biggs <natebiggs@google.com>
> Commit-Queue: Stephen Adams <sra@google.com>

TBR=sra@google.com,natebiggs@google.com

Change-Id: I23d7ae645b871ed7cca00e49288eb9e2c3f4fce7
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/250105
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2022-06-28 18:00:53 +00:00
Stephen Adams c9ff7d95fd [dart2js] Migrate source_file_provider.dart
Change-Id: Iaded7ebfe4415f8108c9364521939b8394ab598a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/249780
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2022-06-27 20:38:25 +00:00
Siva Annamalai 5cb3b37c74 Revert "Refactor _Future."
This reverts commit 69f32d6ad7.

Reason for revert: We seem to have a number of tests failing with timeouts in CBUILD after this change, please see logs at
https://dart-in-g3-qa-prod.corp.google.com/dg3/Home#/cbuild/find/69f32d6ad7e724e3148cb2eb6601e63165e76ad3

Original change's description:
> Refactor `_Future`.
>
> This is a major rewrite of the `_Future` class,
> which is the default implementation of the `Future` interface.
>
> The main goal was to reduce the number of expensive type checks
> in the internal passing around of data.
> Expensive type checks are things like
> * `is _Future<T>` (more expensive than just `is _Future`, the latter
>   can be a single class-ID check.
> * Covariant generic parameter checks (using `T` covariantly in a
>   parameter forces a run-time type check).
>
> Also removed some plain unnecessary casts and turned some
> implicit casts from `dynamic` into `unsafeCast`s.
>
> This seems to be an success, at least on very primitive benchmarks, according to Golem:
> FutureCatchErrorTest    41.22% (1.9 noise)
> FutureValueTest         46.51% (2.8 noise)
> EmptyFutureTest         59.15% (3.1 noise)
> FutureWhenCompleteTest  51.10% (3.2 noise)
>
> A secondary goal was to clean up a very old and messy class,
> and make it clearer for other `dart:async` how to interact
> with the future.
>
> The change has a memory cost: The `_FutureListener<S,T>` class,
> which represents a `then`, `catchError` or `whenComplete`
> call on a `_Future`, now contains a reference to its source future,
> the one which provides the inputs to the callbacks,
> as well as the result future returned by the call.
> That's one extra memory slot per listener.
>
> In return, the `_FutureListener` now does not need to
> get its source future as an argument, which needs a covariant
> generic type check, and the methods of `_Future` can be written
> in a way which ignores the type parameters of both `_Future`
> and `_FutureListener`, which reduces complex type checks
> significantly.
>
> In general, typed code is in `_FutureListener`, which knows both
> the source and target types of the listener callbacks, and which
> contains the futures already at that type, so no extra type checking
> is needed.
> The `_Future` class is mostly untyped, except for its "public"
> API, called by other classes, which checks inputs,
> and code interacting with non-native futures.
> Invariants ensure that only correctly typed values
> are stored in the untyped shared `_resultOrListeners` field
> on `_Future`, as determined by its `_state` integer.
> (This was already partially true, and has simply been made
> more consistent.)
>
> Further, we now throw an error in a situation that was previously
> unhandled: When a `_Future` is completed with *itself*.
> That would ensure that the future would never complete
> (it waits for itself to complete before it can complete),
> and may potentially have caused weird loops in the representation.
> In practice, it probably never happens. Now it makes the error
> fail with an error.
> Currently a private `_FutureCyclicDependencyError` which presents
> as an `UnsupportedError`.
> That avoids code like
> ```dart
> import "dart:async";
> void main() {
>   var c = Completer();
>   c.complete(c.future); // bad.
>   print("well!");
>   var d = Completer();
>   d.complete(c.future);
>   print("shucks!");
> }
> ```
> from hanging the runtime by busily searching for the end of a cycle.
>
> See https://github.com/dart-lang/sdk/issues/48225
> Fixes #48225
>
> TEST= refactoring covered by existing tests, few new tests.
>
> Change-Id: Id9fc5af5fe011deb0af3e1e8a4ea3a91799f9da4
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/244241
> Reviewed-by: Martin Kustermann <kustermann@google.com>
> Commit-Queue: Lasse Nielsen <lrn@google.com>

TBR=lrn@google.com,kustermann@google.com,sra@google.com,sigmund@google.com,nshahan@google.com

Change-Id: I455be5a04b4c346df26d4ded0fa7388baccb0f8c
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/247762
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2022-06-09 16:51:55 +00:00
Lasse R.H. Nielsen 69f32d6ad7 Refactor _Future.
This is a major rewrite of the `_Future` class,
which is the default implementation of the `Future` interface.

The main goal was to reduce the number of expensive type checks
in the internal passing around of data.
Expensive type checks are things like
* `is _Future<T>` (more expensive than just `is _Future`, the latter
  can be a single class-ID check.
* Covariant generic parameter checks (using `T` covariantly in a
  parameter forces a run-time type check).

Also removed some plain unnecessary casts and turned some
implicit casts from `dynamic` into `unsafeCast`s.

This seems to be an success, at least on very primitive benchmarks, according to Golem:
FutureCatchErrorTest    41.22% (1.9 noise)
FutureValueTest         46.51% (2.8 noise)
EmptyFutureTest         59.15% (3.1 noise)
FutureWhenCompleteTest  51.10% (3.2 noise)

A secondary goal was to clean up a very old and messy class,
and make it clearer for other `dart:async` how to interact
with the future.

The change has a memory cost: The `_FutureListener<S,T>` class,
which represents a `then`, `catchError` or `whenComplete`
call on a `_Future`, now contains a reference to its source future,
the one which provides the inputs to the callbacks,
as well as the result future returned by the call.
That's one extra memory slot per listener.

In return, the `_FutureListener` now does not need to
get its source future as an argument, which needs a covariant
generic type check, and the methods of `_Future` can be written
in a way which ignores the type parameters of both `_Future`
and `_FutureListener`, which reduces complex type checks
significantly.

In general, typed code is in `_FutureListener`, which knows both
the source and target types of the listener callbacks, and which
contains the futures already at that type, so no extra type checking
is needed.
The `_Future` class is mostly untyped, except for its "public"
API, called by other classes, which checks inputs,
and code interacting with non-native futures.
Invariants ensure that only correctly typed values
are stored in the untyped shared `_resultOrListeners` field
on `_Future`, as determined by its `_state` integer.
(This was already partially true, and has simply been made
more consistent.)

Further, we now throw an error in a situation that was previously
unhandled: When a `_Future` is completed with *itself*.
That would ensure that the future would never complete
(it waits for itself to complete before it can complete),
and may potentially have caused weird loops in the representation.
In practice, it probably never happens. Now it makes the error
fail with an error.
Currently a private `_FutureCyclicDependencyError` which presents
as an `UnsupportedError`.
That avoids code like
```dart
import "dart:async";
void main() {
  var c = Completer();
  c.complete(c.future); // bad.
  print("well!");
  var d = Completer();
  d.complete(c.future);
  print("shucks!");
}
```
from hanging the runtime by busily searching for the end of a cycle.

See https://github.com/dart-lang/sdk/issues/48225
Fixes #48225

TEST= refactoring covered by existing tests, few new tests.

Change-Id: Id9fc5af5fe011deb0af3e1e8a4ea3a91799f9da4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/244241
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2022-06-09 15:32:33 +00:00
Stephen Adams 618db8a41d [dart2js] Rename lib/compiler.dart to lib/compiler_api.dart
Always import 'lib/compiler_api.dart' with prefix 'api'.
Remove import of 'lib/src/compiler.dart' with prefix 'api'.

Some of the test helper files under 'compiler/test' are a little tedious
with lots of 'api.' prefixes and I could be convinced to change them
back but I think we should stick with always using a prefix under
'compiler/lib/'.

Change-Id: I3f82d7d31f1c90a860c9811fce031a64cea04ddb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241867
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2022-04-21 03:42:39 +00:00
Stephen Adams e057dddc73 [dart2js] Add missing Copyright lines
Years are the earliest year that can be reliably tracked using
'blame'.

TBR=sigmund@google.com

Change-Id: I1a7e650469a83d79e6eb65be899a5955dc74e1d4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/239620
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
2022-03-31 16:23:25 +00:00
Joshua Litt 1e799e1580 [dart2js] Merge CompilerImpl into Compiler.
This indirection is no longer needed.

Change-Id: Ic917ec758dc8a8a648fea9f74ddf75f47b6b9d4d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232485
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
2022-02-14 20:42:50 +00:00
Joshua Litt 4ce081c99b [dart2js] Remove old compiler interface.
Change-Id: If4f98f4d32a42ce8c2aabd98116997934b13b557
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232001
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
2022-02-10 16:27:25 +00:00
Nate Bosch 33e174084a Replace Uri.scheme == with Uri.isScheme
Use `hasScheme` in place of comparing against the empty string, and
`isScheme` to compare against all other schemes.

TEST=No behavior changes.

Change-Id: Ifc9fd13c6cf37933ebd4a754c4b500dedbcb291b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231185
Reviewed-by: Kevin Moore <kevmoo@google.com>
Commit-Queue: Nate Bosch <nbosch@google.com>
2022-02-08 21:38:57 +00:00
Joshua Litt 58e577da15 [dart2js] Move common_elements.dart to common/elements.dart.
Change-Id: Idaed02bb747670413f63e7f7b0797eb591e12f57
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231523
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
2022-02-03 21:21:39 +00:00
Stephen Adams 770969e25c [js_ast] Prepare visitors for null-safety
`BaseVisitor<R>` has two methods that return `null`, which will not
match the generic return type with NNBD.

The fix is to make the methods abstract, and provide a convenience
specialization `BaseVisitorVoid` with the default methods.

Change-Id: I62cd69c5ed1c912b2804da5044e2cda93d70b878
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/224460
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2021-12-17 01:16:49 +00:00
Sam Rawlins abb286e012 compiler: Remove unnecessary exclusion in analysis options
Change-Id: Idc8df59d395403183ab5da11bcb1894bcfc0d8bc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/222381
Auto-Submit: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
2021-12-09 17:25:29 +00:00
Lasse R.H. Nielsen 2360783808 Expire experiments released in earlier stable versions.
Remove messages referring to expired `non-nullable` experiment.
Remove occurrences of --enable-experiment with expired experiments.

TEST=Flags were expired. If existing tests still run, it's a success.

Change-Id: Id66d78eb0a3191ec5e31375faf0effd9ea7b768f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/219789
Auto-Submit: Lasse R.H. Nielsen <lrn@google.com>
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
2021-11-11 08:28:31 +00:00
Mark Zhou ff26406d72 [dart2js] Representing late/lazy fields with arrow functions.
Change-Id: Ic47077253eb07f5caa60b9409ccbf9bb87f34d4a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/209856
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
2021-10-14 21:04:15 +00:00
Stephen Adams 09b15a583c [dart2js] Move --csp flag handling to 'features'.
Change-Id: Iae6c01c10121023a02f8c850247f41007727ea75
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/215009
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
2021-10-01 04:23:24 +00:00
Kevin Moore b85488cedd pkg:compiler - enable and fix null operator lints
Change-Id: I5aaef20fdd61fd6ac9dc69978111fb680c7f99e5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211624
Auto-Submit: Kevin Moore <kevmoo@google.com>
Commit-Queue: Kevin Moore <kevmoo@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
2021-09-24 23:07:19 +00:00
Kevin Moore 70533ae7fa pkg:compiler - enable and fix prefer_final_fields lint
Change-Id: I042f6047c2c10490121398027489217c6291425d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211622
Auto-Submit: Kevin Moore <kevmoo@google.com>
Commit-Queue: Kevin Moore <kevmoo@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2021-09-24 21:37:39 +00:00
Johnni Winther 1eda15854d [cfe] Allow experiments only in current sdk version
Experiments that have not be enabled by default should only be allowed
in the current version of the sdk.

Closes #45460

Change-Id: I159f390ac85fe37943920717ce11a4c817d5b4a9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193480
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2021-03-31 15:20:08 +00:00
Sam Rawlins 18bc70b898 Remove unnecessary imports from compiler/test
Bug: https://github.com/dart-lang/sdk/issues/44569
Change-Id: Iacb5553755af38e931431cb5aa4e3495cd34539f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/190602
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2021-03-16 19:44:10 +00:00
Nate Bosch 58e7e7eb26 Prepare for breaking change in package:http
The `url` argument is changing from `Object`, accepting either `String`
or `Uri` at runtime, to `Uri` for better static help.
https://github.com/dart-lang/http/pull/507

- Switch to using `Uri` for requests. Where sensible push this type into
  the signature of the surrounding method.
- Make some updated method private where they were unnecessarily public
  which makes it harder to have confidence when looking for usages.
  Rename a method with an unnecessary `get` name.

Change-Id: Ibf075741d6b9d292349b15f1dc84004981729aca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/179368
Auto-Submit: Nate Bosch <nbosch@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
2021-01-15 16:35:01 +00:00