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>
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>
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>
This reinstate the support for access Record from all libraries, opt-in
_and_ opt-out, when 'records' is enabled by default. This was wrongfully
removed in a previous CL.
Change-Id: Iede9257302754ca862edb5573203a251cb7bac9c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/261647
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
This adds support for the experimental 'records' feature in the sdk
by settings its experimental release version to 2.19 and opting the sdk
into the feature the allowed_experiments.
Change-Id: I7a30212e5724e5d8ae3208f177103764b9aed737
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262760
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
This changes the way the CFE handled private injected members. Previously
these were "hidden" within the patch library in which they were declared.
Now they are, like with members injected in augmentation libraries, fully
integrated and accessible within the origin library and all its patches.
This change revealed that the vm and wasm platforms had some
inconsistently declared classes in which injected private members that
were not implemented by all implementing classes. For these, throwing
stubs have been added.
Cq-Include-Trybots: luci.dart.try:dart2wasm-linux-x64-d8-try
Change-Id: I330eade944964ef43b83aa416baef75e3649d023
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262340
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
The Crash class was used for to conflicting purposes: 1) To encapsulate
a captured crash in the CFE, in which case the trace was printed
directly, and 2) To propagate a crash in the CFE together with the
context in which it crash, in which case the trace was not printed but
just included in the Crash object.
This CL adds a `_hasBeenReported` field to ensure that 1) is rethrown
as intended and 2) is printed and a Crash object of type 1) is returned.
Change-Id: I6efc752414158aad60867b5dbb8d799d5b08036a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262420
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
This changes the VM patch files to use parts explicitly, making
handling of patch libraries similar to regular libraries.
Cq-Include-Trybots: luci.dart.try:dart2wasm-linux-x64-d8-try
Change-Id: I6280d62edba3d12a1f77ae6a7f64e1e9b5d18227
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/224949
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
This CL changes the import uri of a patch library builder to be its
file uri. This makes patch libraries more like regular libraries,
preparing for full support for patch parts.
Change-Id: I1fa4c10998f17945d6607e1307337b5f66992c3a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/224947
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>