commit | a42244f73b27256eca44def4daa552e91c2dbc55 | [log] [tgz] |
---|---|---|
author | Paul Berry <paulberry@google.com> | Tue Feb 02 16:15:34 2021 +0000 |
committer | commit-bot@chromium.org <commit-bot@chromium.org> | Tue Feb 02 16:15:34 2021 +0000 |
tree | d7c8ae6455299daf0ff95fb8e3639b29a7f54d8d | |
parent | 91be638a56a811b46da88093b16408cea045bbe8 [diff] |
Flow analysis: begin tracking non-promotion reasons. This CL implements the core flow analysis infrastructure for tracking reasons why an expression was not promoted. It supports the following reasons: - Expression was a property access - Expression has been written to since it was promoted I expect to add support for other non-promotion reasons in the future, for example: - `this` cannot be promoted - Expression has been write captured - Expression was a reference to a static field or top level variable These non-promotion reasons are plumbed through to the CFE and analyzer for the purpose of making errors easier for the user to understand. For example, given the following code: class C { int? i; f() { if (i == null) return; print(i.isEven); } } The front end now prints: ../../tmp/test.dart:5:13: Error: Property 'isEven' cannot be accessed on 'int?' because it is potentially null. Try accessing using ?. instead. print(i.isEven); ^^^^^^ Context: 'i' refers to a property so it could not be promoted. Much work still needs to be done to round out this feature, for example: - Currently the analyzer only shows the new "why not promoted" messages when the "--verbose" flag is specified; this means the feature is unlikely to be noticed by users. - Currently the analyzer doesn't show a "why not promoted" message when the non-promotion reason is that the expression is a property access. - We need one or more web pages explaining non-promotion reasons in more detail so that the error messages can contain pointers to them. - The analyzer and front end currently only show non-promotion reasons for expressions of the form `x.y` where `x` fails to be promoted to non-nullable. There are many other scenarios that should be handled. Change-Id: I0a12df74d0fc6274dfb3cb555abea81a75884231 Bug: https://github.com/dart-lang/sdk/issues/38773 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/181741 Commit-Queue: Paul Berry <paulberry@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Dart is:
Optimized for UI: Develop with a programming language specialized around the needs of user interface creation.
Productive: Make changes iteratively: use hot reload to see the result instantly in your running app.
Fast on all platforms: Compile to ARM & x64 machine code for mobile, desktop, and backend. Or compile to JavaScript for the web.
Dart's flexible compiler technology lets you run Dart code in different ways, depending on your target platform and goals:
Dart Native: For programs targeting devices (mobile, desktop, server, and more), Dart Native includes both a Dart VM with JIT (just-in-time) compilation and an AOT (ahead-of-time) compiler for producing machine code.
Dart Web: For programs targeting the web, Dart Web includes both a development time compiler (dartdevc) and a production time compiler (dart2js).
Dart is free and open source.
See LICENSE and PATENT_GRANT.
Visit dart.dev to learn more about the language, tools, and to find codelabs.
Browse pub.dev for more packages and libraries contributed by the community and the Dart team.
Our API reference documentation is published at api.dart.dev, based on the stable release. (We also publish docs from our beta and dev channels, as well as from the primary development branch).
If you want to build Dart yourself, here is a guide to getting the source, preparing your machine to build the SDK, and building.
There are more documents on our wiki.
The easiest way to contribute to Dart is to file issues.
You can also contribute patches, as described in Contributing.