Commit graph

6781 commits

Author SHA1 Message Date
Nate Bosch 3c231e4f57 Read package_config.json in more tests
Towards #48275

R=mit@google.com

Change-Id: I38cc986937543c5e4d1f2a2cd4c7804d180a2741
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/244304
Commit-Queue: Nate Bosch <nbosch@google.com>
Reviewed-by: Michael Thomsen <mit@google.com>
Commit-Queue: Michael Thomsen <mit@google.com>
Auto-Submit: Nate Bosch <nbosch@google.com>
2022-05-11 18:58:44 +00:00
Konstantin Shcheglov f3ac80c753 Add LibraryAugmentationDirective and parsing for it.
Change-Id: I64e19bcd8f1f57c558237562deabc024fad84163
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/244301
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-05-11 16:26:34 +00:00
Chloe Stefantsova aa9b83eefc [cfe] Require a non-null name for mixin supertypes
The function types are given an empty name in that case. Those types
are further discarded and can have any intermediary name.

Part of https://github.com/dart-lang/sdk/issues/48919

Change-Id: I57d223ee7914d0227baa3a4ef5733bb8055fa2c3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/244240
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2022-05-11 09:27:45 +00:00
Paul Berry 0d636e5543 Ensure that partial inference results aren't refined by later partial inference stages.
As part of the implementation of
https://github.com/dart-lang/language/issues/731 (improved inference
for fold etc.), I expanded the front end's type inference logic so
that instead of just having a downward phase and an upward phase, it
could have 3 or more phases.  The function that previously did
downward inference became repurposed to do "partial inference" (which
could either be the first, downward stage, or a later, horizontal
stage).  However, I failed to generalize the logic that prevents types
assigned by one inference stage from being refined by later
stages--previously this logic was only needed for upward inference,
but now it's needed for horizontal inference stages as well.  (This
logic is needed because of Dart's "runtime checked covariance"
behavior--it means that we want to stick with the type from downward
inference, even if a later horizontal inference stage is able to find
a more precise type, because that more precise type may lead to
runtime failures).

As part of this change I've re-architected the inference methods so
that they are responsible for creating and returning the list of
inferred types.  This makes the inference logic more similar between
the front end and analyzer, and is easier to read IMHO.  The total
number of list allocations is the same as before.

Change-Id: I19bfcede9c2968e50f110b571164549f16495217
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/243707
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-05-10 15:10:44 +00:00
Paul Berry 51d578cf91 Fix horizontal inference logic for extension method invocations.
The front end desugars extension methods by inserting a synthetic
`this` argument before all other arguments.  But this synthetic
argument isn't included in the `formalTypes` and `actualTypes` arrays.
So when recording a value into
`_DeferredParamInfo.evaluationOrderIndex` we may need to subtract 1 in
order to ensure that later logic will find the correct argument.

Fixes a corner case of https://github.com/dart-lang/language/issues/731.

Change-Id: Idbf136195e40555199f7c5b61a575a430f6ec6bd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/243854
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2022-05-10 14:54:53 +00:00
Aske Simon Christensen 6c7604291c [dart2wasm] Build platform dill and compile dart2wasm to AOT snapshots
This adds a --platform= option to dart2wasm to read the SDK libraries
from that dill file instead of compiling them from source every time.
If the option is not given, the SDK libraries are compiled, like before.

Also adds a "dart2wasm" build target, which will build the dart2wasm
platform dill and compile dart2wasm to two AOT snapshots (with and
without asserts). The dart2wasm scripts in sdk/bin are updated to run
via these snapshots and use this platform dill.

This speeds up test runs for the dart2wasm-hostasserts-linux-x64-d8
configuration by approximately 45x.

Change-Id: If2c7750a6eb39725310745f887792784d0dfc583
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/243624
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: William Hesse <whesse@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
2022-05-10 10:06:06 +00:00
Joshua Litt d753b61535 [dart2wasm] Implement runtime type test for FutureOr.
Change-Id: I9ad00f5e9b1ca77f52f03e24115f8f4bae5910b2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/243166
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2022-05-09 16:13:22 +00:00
Jens Johansen 3bf3c8b44f [CFE] Add --traceStepTiming to strong and weak suite
This option traces in which steps time is spent when running a suite.

On my machine for instance I get these results on a run ofstrong and
weak suites:

$ out/ReleaseX64/dart --enable-asserts pkg/front_end/test/fasta/strong_suite.dart -DsemiFuzz=true --traceStepTiming
Running suite strong...
[ 02:58 | 100.0% | +  571 | -    0 ]: strong/value_class/value_mixin_error

             check errors: 0:00:00.156828 ms
stress constant evaluator: 0:00:00.269382 ms
                    print: 0:00:00.439196 ms
                typeCheck: 0:00:02.575744 ms
       match expectations: 0:00:04.869435 ms
                   verify: 0:00:04.951524 ms
                  compile: 0:00:18.307246 ms
      transform component: 0:00:22.121665 ms
                 semifuzz: 0:00:59.717862 ms
              write .dill: 0:01:05.066461 ms
                      run: 0:01:15.028423 ms

$ out/ReleaseX64/dart --enable-asserts pkg/front_end/test/fasta/weak_suite.dart -DsemiFuzz=true --traceStepTiming
Running suite weak...
[ 10:11 | 100.0% | + 2225 | -    0 ]: weak/variance/unconstrained_inference

             check errors: 0:00:00.506722 ms
stress constant evaluator: 0:00:00.759073 ms
                    print: 0:00:01.293962 ms
                typeCheck: 0:00:09.974299 ms
       match expectations: 0:00:16.386842 ms
                   verify: 0:00:17.585821 ms
                  compile: 0:01:01.966016 ms
      transform component: 0:01:23.560216 ms
                 semifuzz: 0:02:50.969460 ms
              write .dill: 0:04:08.087519 ms
                      run: 0:05:17.911549 ms

In both cases writing dill and running takes quite a while, and
interesting writing the dill is almost as slow as running it.

Change-Id: Ie528e8f7e8a493e17e40a7235b456cc75381ca61
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242874
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-05-09 14:03:33 +00:00
Paul Berry d5635390aa Remove unnecessary TODO comment.
This comment was meant as a note to myself as part of the
implementation of https://dart-review.googlesource.com/c/sdk/+/243002.
I accidentally forgot to delete it even though I added the necessary
test cases (`testLaterUnnamedParameterDependsOnNamedParameter` and
`testEarlierNamedParameterDependsOnUnnamedParameter` in
`tests/language/inference_update_1/horizontal_inference_enabled_test.dart`).

Change-Id: I80f0c63fa19256a4cd3fa657578124fa9bddf6d4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/243845
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-05-06 14:40:40 +00:00
Nate Biggs c6173d3686 [dart2js] Correctness updates for async lowering.
- Wrap returns in Future.value to ensure the returned Future has the async function's return type.
- Skip any function that has try/catch/finally as these introduce more complex control flow. (Might be able to convert these using an onError callback in the future).
- Don't assume futureValueType since CFE might not populate it in Kernel when syntax is incorrect.

Change-Id: Ice3954da52a10a74f93b0adc6409a2d98e13cb3b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241260
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2022-05-05 21:25:45 +00:00
Paul Berry ce591d17c3 Resolve deferred function literals in stages.
This change allows function literals in invocations to be inferred in
dependency order.  For example, given the following code:

    U f<T, U>(T Function() g, U Function(T) h) => h(g());
    test() {
      var x = f(() => 0, (y) => [y]);
    }

The function literal `() => 0` is inferred first, causing the type
parameter `T` to be assigned the type `int`.  Then, `(y) => [x]` is
inferred with the benefit of this type assignment, so `y` gets the
type `int`, and consequently, `U` gets assigned the type `List<int>`.

This completes the support for
https://github.com/dart-lang/language/issues/731 (improved inference
for fold etc.)

Change-Id: I48c22693720a1cc8bbf435643e863834e07f02b1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/243002
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-05-03 22:04:39 +00:00
Johnni Winther 7ab89309fb [cfe] Handle nullable expressions in implicit tearoff
This might be a compile-time error but it should at least not create
an Instantiation on a potentially nullable expression.

In response to https://github.com/dart-lang/sdk/issues/48323

Change-Id: I6682ddbb8db82623ac7bf4ecf37f8535377f4ca0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242869
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-05-02 11:58:19 +00:00
Chloe Stefantsova 9d0da22184 [cfe] Report types after construtor name in redirecting targets
Closes https://github.com/dart-lang/sdk/issues/41842

Change-Id: I396067e955c9bad610af6c3690cfaa58659824bb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242867
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2022-05-02 09:33:10 +00:00
Paul Berry 40632d7186 Ensure that parenthesized function literals are deferred too.
When a function literal is wrapped in parentheses, it shouldn't affect
how it interacts with type inference.  This change ensures that
parenthesized function literals are treated the same as
unparenthesized ones by the logic that supports
https://github.com/dart-lang/language/issues/731 (improved inference
for fold etc.)

Change-Id: I672787a31addbfe3f3282b6e638e00b693eea46f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/243000
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-04-29 20:35:51 +00:00
Paul Berry 08c60454c1 Defer analysis of closure arguments when inference-update-1 is enabled.
In order to address https://github.com/dart-lang/language/issues/731
(improved type inference for `fold` etc.) we're going to need to
sometimes defer analysis of invocation arguments that are closures, so
that closure parameters can have their types inferred based on other
parameters.  To avoid annoying the user with inconsistent behaviors,
we defer analysis of closures in all circumstances, even if it's not
necessary to do so for type inference purposes.

This has a minor user-visible effect: if an invocation contains some
closures and some non-closures, any demotions that happen due to write
captures in the closures are postponed until the end of the
invocation; this means that the write-captured variables remain
promoted for other invocation arguments, even if those arguments
appear after the closure.  This is safe because there is no way for
the closure to be called until after all of the other invocation
arguments are evaluated.  See the language tests in
tests/language/inference_update_1/write_capture_deferral_enabled_test.dart
for details.

Note that this change only has an effect when the experimental feature
`inference-update-1` is enabled.

Change-Id: If7bb38e361755180c033ecb2108fc4fffa7570b1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241864
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-04-28 17:14:30 +00:00
Ahmed Ashour 1586ac81a0 Fix typos
TEST=comment only change

Fixes #48853

Change-Id: I1fd47b8f186514af95a49ef253170045c584f970
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241963
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2022-04-28 12:53:43 +00:00
Jens Johansen 7ca259a978 [CFE] Skip import_package_by_file_uri when doing leak testing
In 64a169ec7e an incremental test -
import_package_by_file_uri - was added, which imports a file both via
its "file uri" and via its "package uri", resulting in "the same"
library existing twice. This also means that two libraries has the same
"file uri" which is what we search for when leak testing, meaning that
our weekly leak test failed.

This CL skips this test for leak testing as it by design will trigger
the situation the leak test looks for.

Change-Id: I85a9ac4e3f4dc19203955dbb1724402196c78fdf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242840
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-04-28 10:49:31 +00:00
Jens Johansen 48574b06cb [CFE] Do equivalence test when fuzzing
Change-Id: If1afee9723df003f4a2cc39ab9db24e7c0c0cb93
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242546
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2022-04-28 09:03:54 +00:00
Jens Johansen d68c796efd [CFE] Demonstrate changing error upon recompilation
Recompiling changes the given error from

```
Can't create typedef from non-function type.
```

to

```
Couldn't find constructor 'Bar'.
```

which does seem to make more sense when the code is `new Bar<int>()`.

http://dartbug.com/48897

Change-Id: I4d025fc2ec96f530b4d4b00aec18fab6a781710f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242543
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2022-04-28 09:03:54 +00:00
Jens Johansen a4d92fc170 [CFE] Demonstrate changing initializer (and wrong one on initial compile)
Seemingly caused by ordering of things in finishForwarders.

http://dartbug.com/48895

Change-Id: I605502d336f9f40dfc01245af436f09633d200a4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242540
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2022-04-28 09:03:54 +00:00
Jens Johansen b2d509dc82 [CFE] Demonstrate changing nullability (on constant type) on recompile
FunctionNode.namedParameters[0]
      VariableDeclaration.initializer
       ConstantExpression.type
        InterfaceType.declaredNullability

changes from Nullability.legacy to Nullability.nonNullable.

http://dartbug.com/48894

Change-Id: Ic9e0ff3ea6c51d71d6073f8e37e1e96127414cc9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242446
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2022-04-28 09:03:54 +00:00
Jens Johansen da3015a44b [CFE] Demonstrate changing type on recompile #2
http://dartbug.com/48893

Change-Id: I5c8108379fff231d76d7c698a703a9185bc6aae4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242445
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2022-04-28 09:03:54 +00:00
Jens Johansen a7ff623e6e [CFE] Demonstrate changing interfaceTargetReference via noSuchMethod on recompilation
http://dartbug.com/48892

Change-Id: I85dd6afdc2bb0eb0e04602666cbdf7be30b7e6ce
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242444
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2022-04-28 09:03:54 +00:00
Jens Johansen a477591467 [CFE] Demonstrate changing type on recompile
VariableDeclaration.type changes from InterfaceType(String?) to
FutureOrType(FutureOr<String>?) and the async transformation goes
from calling _completeWithNoFutureOnAsyncReturn to calling
_completeOnAsyncReturn upon recompilation with no change.

http://dartbug.com/48891

Change-Id: Ie28bcc37739742ccb33c033d7c7edff3f5b921e3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242443
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2022-04-28 09:03:54 +00:00
Jens Johansen bd95cae6d5 [CFE] Demonstrate bugs wrt types pointing to TreeNodes
This demonstrates two things:
1) fileOffset changes because it goes to point from one file to another
    -- it doesn't specify the file of course --- and Constants shouldn't
   have fileOffsets in them at all.
2) Constant pointing to a type that points to a Typedef (which it
   shouldn't) which then again also changes upon recompilation.

http://dartbug.com/48890

Change-Id: If5f7ce56b3e95d92fc0c060002842325f9136146
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242441
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2022-04-28 09:03:54 +00:00
Jens Johansen ce6d876892 [CFE] Incremental suite outputs expect file sooner
Change-Id: I2e151d356c2aa2d5345ecfcadb2a7105a4d1f9ae
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242451
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2022-04-28 09:03:54 +00:00
Johnni Winther 39333427c0 [cfe] Augment test to use nonfunction type alias
Change-Id: I478d1abf75f8a9a9d162a75f9885545d61c9d5ed
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242541
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-04-27 12:47:18 +00:00
Martin Kustermann efdffab8b7 Reland "[vm] Fix some async* semantics issues: Only run generator if there's active subscription (not paused/cancelled)"
This fixes an issue where VM would run the async* generator after a
`yield` / `yield*` even though the subscription may be paused or
cancelled.

Furthermore this fixes an issue where `StackTrace.current` used
in async* generator crashes VM and/or produces truncated stack
trace.

This fixes the following existing tests that were failing before:

  * co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_t08
  * co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_t09
  * co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_t10
  * language/async_star/async_star_cancel_test
  * language/async_star/pause_test

New in reland: Allow the generator to to cause cancelling it's own consumer.
This addresses the issue of original revert
  -> see https://github.com/flutter/flutter/issues/101514

Issue https://github.com/flutter/flutter/issues/100441
Issue https://github.com/dart-lang/sdk/issues/48695
Issue https://github.com/dart-lang/sdk/issues/34775

TEST=vm/dart{,_2}/causal_stacks/flutter_regress_100441_test

Change-Id: I091b7159d59ea15fc31162b4b6b17260d523d7cb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242400
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2022-04-26 12:01:34 +00:00
Jens Johansen d2356115d0 [CFE] Demonstrate late lowering recompilation bug
Change-Id: I8af2b05294c17b80ff2c3f92e5c4d38e5da7aaa9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242285
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-04-26 06:46:03 +00:00
Johnni Winther 6fdaed9eba [cfe] Handle tear-offs of patched constructors
Previously the tear-offs created for the origin constructors were not
replaced with the tear-offs created for the patch constructors - as is
normally done for the constructors themselves. This lead the tear-offs
to refer to unlowered code, breaking dart2js.

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

Change-Id: I1cb09c07bb2ac7fffb81acd31547ee96e7ecdc64
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242284
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-04-25 15:50:47 +00:00
Jens Johansen 70256e540d [CFE] Explicitly initialize to null in outlines too
Currently initializers (in, say, a Constructor) is included in the
outline if it is not null. Null values are explicitly added only when
building the bodies.
This has the unfortunate effect of initializers copied in the outline
phase (e.g. for mixins) not including the null initializer. If, however,
later recompiling (even without changes, and if the split is correct)
suddenly an initializer changes.

This CL fixes the issue by initializing to null in the outline phase.

Change-Id: I1269da25ab893d4610cf2dbb4fbfdbd5697e5323
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242282
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-04-25 12:54:53 +00:00
Jens Johansen 430abc54e8 [CFE] Add toText to Reference and CanonicalName
Add `toText` to both Reference and CanonicalName.
Change how CanonicalNames are printed through `text_util.dart` to be
more aligned with how the corresponding node would be printed had
it existed (and the CanonicalName thus normally not been used for
printing).
Add a test for (some definition of) common cases where printing should
be the same wherther done though the node, the reference or the
canonical name.
Fix usage of toStringInternal in the constant evaluator (though only
in use through an experiment) and add a test that showed that the
previous output was bad and the new isn't (at least in this case).

Change-Id: I10cbc1a542c7d8b079e0510bbd5eb5173b2e7563
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242102
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-04-25 11:13:44 +00:00
Jens Johansen a5a7b4c801 [CFE] Make strong/weak suite fuzzing work with parts
This CL follows up on
https://dart-review.googlesource.com/c/sdk/+/239668
where parts was left non-working.

Now part files are ignored (i.e. we don't try to split it and add
imports/exports where it isn't supported), and the part declaration(s)
is(/are) kept only in the "main" file.

Change-Id: I63fa8ac8fcf173234a8162297f1c5eb1d94b00da
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241961
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-04-22 05:39:49 +00:00
Jens Johansen 84d75cbd53 [CFE] Fix issues with parts and experimental invalidation
From a high level, the experimental invalidation works by comparing the
before and after version of a changed file, checking if the (textual)
outline has changed. If it hasn't it can go ahead with the experimental
invalidation, only recompiling the changed file/library.

Turns out, though, that if a *part* is changed in a
textual-outline-changing-way it is *not* detected, i.e. one can (in a
part) make a change that isn't compatible with (safe) experimental
invalidation, yet experimental invalidation will still be in effect.
A similar issue exists if a mixin is declared in a part file.

This CL fixes the issue.

Change-Id: I150184885164229e6a9e0a6fa86f7c330b3bc3f3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241969
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-04-22 05:37:39 +00:00
Paul Berry efe0bf3ec5 Push logic for constraining argument types into argument visiting loop.
In order to implement https://github.com/dart-lang/language/issues/731
(improved inference for fold etc.), we'll need to gradually accumulate
type constraints as we evaluate arguments, and periodically re-do
inference; we can't just accumulate all the formal types and actual
types and run them through an inference process at the end.

This change moves us a step toward that eventuality, by accumulating
type constraints after type inference visits each argument, rather
than all at once after all arguments have been visited.  The total
amount of work done is unchanged.

Change-Id: I91ed0529cd3142afe4153cac8c25bce3c20f137d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241800
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-04-21 13:38:16 +00:00
Paul Berry e63cea6634 Unify named and unnamed argument handling logic for invocations.
In order to support https://github.com/dart-lang/language/issues/731
(improved inference for fold etc.) I'm going to need to add logic to
_inferInvocation to postpone type analysis of arguments that are
function expressions.  To avoid having to code up this logic twice, it
will be helpful to have both named and unnamed arguments handled by
the same chunk of code.

In particular, this change unifies the computation of
inferredFormalType, the recursive call to inferExpression, the logic
for hoisting, and the update of the local variables identicalInfo,
formalTypes, and actualTypes.  We pay a small price by having to have
multiple `if (isExpression)` checks, but these should be very fast.

Change-Id: I095a7eac84237eeb878cc3dd86e76a6a871f31d5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241041
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-04-21 12:33:18 +00:00
Johnni Winther b2717a1cd3 [cfe] Support adding default constructors through macros
This adds support for adding a no-name constructor using macros to a
class with no explicit constructor.

Change-Id: I4b614b74fe141ccb4797ace8d73c3ce2869f3826
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241750
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-04-21 10:34:18 +00:00
Chloe Stefantsova 59e6a37962 [cfe] Use NNBD-updated least closure in constraint gathering
Closes https://github.com/dart-lang/sdk/issues/47797

Change-Id: I58544e185fc691630d56960d54f0711f4a91b60a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241746
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2022-04-21 09:28:28 +00:00
Jens Johansen 64a169ec7e [CFE] Avoid crash with experimental invalidation when same file is imported with both package and file uri
If importing the same file both by package-uri and file-uri it becomes
two different libraries in the compiler. They both have the same file
uri though.
When invalidating such a file by file uri they will both be invalidated.
When having experimental invalidation enabled it will - for each of
those invalidated libraries - get the source, compare it to the current
on-disk source, and - if the outline hasn't changed - remove the old
source to avoid having something wrong in memory. When trying to process
the second version of the file the old source has been removed and we
thus will crash if using a bang on the output from the uriToSource
lookup.
This CL avoids the crash by postponing the removal of the old source
until we're sure we'll return successfully. This is also more correct
in general as we might otherwise remove sources where we're (for later
reasons) going to bail out.

Change-Id: If5d767764a958b2dbb09cc011745e13e572038a5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241745
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-04-21 09:12:47 +00:00
Jens Johansen 3aa8f2519b [CFE] Fix using part as entry with experimental invalidation
Change-Id: I813aecd06aa2e7c4cc6b1aadff50a77268096ca6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241743
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-04-21 09:12:29 +00:00
Jake Macdonald 49f10b2ab8 fix a few issues discovered while implementing the observable example
Change-Id: Ic4c88ab446b682170489289799c63a9d57f8b700
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241802
Auto-Submit: Jake Macdonald <jakemac@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-04-20 21:28:58 +00:00
Joshua Litt 84497e41ca [package:js] Add @trustTypes annotation.
Adds an experimental `@trustTypes` annotation which can be used during
migration to static interop to preserve the older semantics for JS interop.

Change-Id: Ic00a6c968b15f8c8f5d0840b82db5a6670eaf0eb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241362
Reviewed-by: Riley Porter <rileyporter@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
2022-04-20 15:24:18 +00:00
Paul Berry 8f8a63fccb Don't hoist function literals when reordering expressions to support "named arguments anywhere".
Hoisting function literals isn't necessary because evaluating a
function literal doesn't have any side effects.

This paves the way for adding support for
https://github.com/dart-lang/language/issues/731 (improved inference
for fold etc.), which will require deferring type analysis of function
literals.  By not hoisting them, we will be able to avoid a lot of
unnecessary complexity in the logic to defer them.

Change-Id: I0a49aa9f769f0506569e6029a3697898308600c2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241007
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-04-20 14:24:28 +00:00
Johnni Winther 6bf48988c8 [cfe] Add test for type arguments on map().toList()
This updates the analysis helpers to add a test for the `map().toList()`
problem addressed in https://dart-review.googlesource.com/c/sdk/+/241605

Included in the CL is the addition of the 'analyze.dart' tools, which
can be used for advanced code searches. This was used to find the
occurences of `map().toList()`.

Change-Id: I6e9da282e37fde4534ed5e308260f092779d0750
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241744
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-04-20 12:28:18 +00:00
Johnni Winther f26c0e2056 [cfe] Add explicit type argument to .map(...).toList()
Expressions like

  List<VariableDeclaration> variables = ...
  List<Expression> reads = variables.map((v) => VariableGet(v)).toList()

don't get the intended type argument `<Expression>` through inference,
but instead the type inferred from the return type of the closure, in
this case `<VariableGet>`.

This causes problems when used with the AST which assumes that
expressions are interchangeable wherever they are used, and is likely
the cause of https://github.com/flutter/flutter/issues/102077 .

This CL adds an explicit type argument in these cases.

TEST=general/infer_map

Change-Id: I0bcae21f06c54f290dc20686b0d84c065d8ea04c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241605
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-04-20 06:56:58 +00:00
Paul Berry 21b3e4f3da Consolidate common code between the two type schema environment tests.
Change-Id: I014f6024372e57577026f0a1f2dda905899c3b00
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241200
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-04-19 22:25:17 +00:00
Paul Berry 0ae5ca163b Rework type inference logic to avoid redundant constraint gathering.
Previously, the front end would perform downwards and upwards
inference using separate TypeConstraintGatherer objects.  This meant
that any constraint gathering work performed during downwards
inference had to be repeated during upwards inference.

This change avoids the extra work by using a single
TypeConstraintGatherer object for both downwards and upwards
inference.

This should help pave the way to implementing support for
https://github.com/dart-lang/language/issues/731 (improved inference
for fold etc.)

Change-Id: Ib4031ab1397d6a8547a705f386632de0e4dd1a2b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241120
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-04-19 18:08:12 +00:00
Johnni Winther bf5aa0603d [cfe] Remove JumpTarget.parent
Only the 'fileUri' property was used, so we pass it directly instead.

Change-Id: I7b47f18f7ebc2c50036c5202e469caad4ba35897
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241009
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-04-19 14:27:37 +00:00
Chloe Stefantsova 6b2ee2d01f [cfe] Apply a recovery step for 'const' for-in variables
Closes https://github.com/dart-lang/sdk/issues/48808

Change-Id: I68177a6eb7f0a5d64dee6eca9befa9957863f26c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241604
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2022-04-19 14:09:27 +00:00
Chloe Stefantsova e307c0b6c4 [cfe] Allow extension members with names as Object static members
Closes https://github.com/dart-lang/sdk/issues/48834

Change-Id: If756cf5b3416b2ed9953fe577b8b2e9490a70dd1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241603
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2022-04-19 13:54:07 +00:00