This changes the way the CFE perform top level inference. Previously
the inference would try to visit only the nodes needed to compute the
resulting type. In particular, statements (for instance inside function
expressions) would never be visited during top level inference.
This approach didn't match the analyzer approach which always visits
the whole field initializer, including any function expressions.
This has lead to various issues in the wild:
https://github.com/dart-lang/sdk/issues/49528https://github.com/dart-lang/sdk/issues/50351
And triggered the language issue:
https://github.com/dart-lang/language/issues/1650
While the old CFE approach allowed for more complex field initializers,
without reporting a cyclic dependency, for instance
var f = () { f(); };
it didn't fit well with the horizontal inference introduced in
the 'inference-update-1' feature, since this relies on full inference of
function expressions. For instance for
T method<T>(T Function(String?) f) { ... }
var a = method((o) => o?.length ?? 0);
var b = method((o) => o != null ? o.length : 0);
var c = method((o) { return o?.length ?? 0; };
the CFE wouldn't infer same type for `a`, `b` and `c`. Furthermore
it would skip the condition `o != null` in `b` because it "didn't need
the type" (it is known to be `bool`), missing that the condition
promotes `o` to non-nullable in the true branch, leading to reporting
an error on `o.length` for being a potentially nullable access.
For these reasons, the CFE is now changed to _always_ visit the whole
field initializer, during top-level inference, making it align itself
with the analyzer implementation.
Closes#49528
Change-Id: Ic409b42699bb0e986f9d041ccb894863c952edf7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/267061
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Not sure if this is has much value in comparison to the existed
implementation in the analyzer.
We also have private implementations for extractor and record
patterns in the analyzer. I don't know yet for sure how (if) we will
share these, but if we do, it might be something like this one.
Change-Id: I86070bcf922a58fbf1087c7ab42c6eb5695c1475
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/266861
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
This reverts commit 700b94eb04.
Reason for revert: Revert due to internal failures: b/256219908
Original change's description:
> [dart2js] Change default for canPerformGlobalTransforms to false
>
> Fixes the staticInterop type erasure issue in dart2js when compiling the
> sdk separately from the code being compiled. With this change, the
> Angular hello_world app runs successfully with the dart:html prototype.
>
> Change-Id: Iaf5071f0f05d4fe1d17349adce4f1ce494154b9c
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262842
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Reviewed-by: Sigmund Cherem <sigmund@google.com>
> Commit-Queue: Riley Porter <rileyporter@google.com>
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I42c5c1ff5eddb675354dbe0e719390df1656e281
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/266306
Commit-Queue: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Riley Porter <rileyporter@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
We delay the execution of the second leak test ("leak test alternative
invalidation") to ensure the first one has fetched pub packages and
avoid both of them trying to do the same thing at the same time, or one
thinking it has been done when it's not actually done yet etc). If this
is slow or there's a crash it waits for at most 10 minutes before
launching the second iteration.
In those 10 minutes, though, it can have started waiting for all other
tests to finish and once they have, if any failed, print the
"Found failures!" (and what has failed of those) mixed in with all the
output from the leak test.
Technically, if the other tests finished within the 10 minutes (they
won't) it might even make it look like there are no failures even if the
second leak tests fails.
This CL fixes the issue by first awaiting the start of the second leak
test before awaiting the finishing of all started processes.
Change-Id: Iaace924346aa2bb4b8c6e025bd53e95e6a414a34
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/266021
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
The initializer was built in an 'inferred' rather than a 'required'
constant context, meaning that it would be encoded as a declaratively
constant literal instead of a structurally constant literal.
Closes#50132
Change-Id: I58b995d879efd2ec374b711718b63ac8f122bcfc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262349
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Fixes the staticInterop type erasure issue in dart2js when compiling the
sdk separately from the code being compiled. With this change, the
Angular hello_world app runs successfully with the dart:html prototype.
Change-Id: Iaf5071f0f05d4fe1d17349adce4f1ce494154b9c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262842
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Riley Porter <rileyporter@google.com>
This revisits the validation after the redesign. The changes from
before the redesign include:
- Accounting for multiple extensions on @staticInterop classes
- Users can implement any of the extension members for a given
export name, with the exception that if there is a getter/setter
pair, both should be implemented if any one of them are
- Since this validation goes on top of exports, the Dart class
needs not be processed, and we use the same export creation process
to create the mock
Change-Id: I05a7cff765d6d37d3955dd93676e2d55d2b201b3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262862
Reviewed-by: Riley Porter <rileyporter@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Creates an external createDartExport function in js_util.
Adds a number of checks for the annotation:
- Classes with the annotation should not have value in the annotation
- Classes with the annotation should have at least one instance member
somewhere in the hierarchy
- There are no export name collisions that are unresolvable accounting
for overrides
- Members with this annotation are instance members with a body only
Also adds checks to createDartExport:
- Checks that the type is a Dart class
- Checks that the type is marked as exportable
Change-Id: I52f27275966e9603e88921ce7897b7615178c4d2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/259511
Reviewed-by: Riley Porter <rileyporter@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
This add the Expression-, Binary-, Cast-, NullAssert-, NullCheck-, List-
and RelationalMatcher and creates these during body building. The
IfCaseStatement is added to support propagation of these to the
inference visitor.
Change-Id: Ia9add15e504cb06af711efc1697a00b8e235e1a4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/263128
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
This change replaces the InferenceVisitorImpl.visitSwitchStatement
with a call to the new shared type analyzer, and implements the
necessary callbacks to allow analysis to work end-to-end.
Change-Id: I73a9514428b4ce092762d3ea450545986d0e1ea9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/257491
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
There was no need for both of these listener callbacks, because they
were always called together. Since `beginCaseExpression` is actually
used, it makes sense to keep `endCaseExpression` and get rid of
`handleCaseMatch`.
Change-Id: I544096b2c2b2814e8cc0c8606455855cb77c9e60
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/264102
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>