Fix CFE legacy type promotion.

The previous implementation of type promotion in the CFE was unsound,
didn't follow the spec, and contained a lot of unnecessary logic
related to experiments that eventually led to flow analysis.  This
change updates type promotion to be nearly spec compliant and removes
most of the unnecessary logic.

The lack of spec compliance went (astonishingly) unnoticed for over
three years, probably mostly due to the fact that for the most part it
promoted more eagerly than it should; as a result, any code that was
erroneously accepted by the CFE was rejected by the analyzer.
Unfortunately, in at least one case the erroneous promotion led to
incorrect VM behavior (issue #43640).

There's one aspect in which the CFE implementation is still not spec
compliant.  The spec says that when analyzing an expression `e1 &&
e2`, if `e2` shows that a variable `v` has type `T`, but `e1` assigns
to `v`, then promotion does not occur.  This turns out to be difficult
to model in the existing architecture, since much of the type
promotion logic happens during parsing, and any assignments that occur
in `e1` are parsed prior to figuring out that a logical and is in
progress.  Fortunately, this is a rare circumstance, and allowing type
promotion in this situation is sound, so it should not lead to
incorrect VM behavior.  Considering how long the other incorrect logic
(which was much more severe) went unnoticed, it seems unlikely that it
will cause problems for users.

Bug: https://github.com/dart-lang/sdk/issues/43640
Change-Id: If97293733e64e286780de5079a703717b8f6f142
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166040
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
12 files changed
tree: 98b73c80ac7011ca25329d67905528bbe6b81f59
  1. .dart_tool/
  2. .github/
  3. benchmarks/
  4. build/
  5. client/
  6. docs/
  7. pkg/
  8. runtime/
  9. samples/
  10. samples-dev/
  11. sdk/
  12. tests/
  13. third_party/
  14. tools/
  15. utils/
  16. .clang-format
  17. .gitattributes
  18. .gitconfig
  19. .gitignore
  20. .gn
  21. .mailmap
  22. .packages
  23. .style.yapf
  24. .vpython
  25. AUTHORS
  26. BUILD.gn
  27. CHANGELOG.md
  28. codereview.settings
  29. CONTRIBUTING.md
  30. DEPS
  31. LICENSE
  32. PATENT_GRANT
  33. PRESUBMIT.py
  34. README.dart-sdk
  35. README.md
  36. sdk_args.gni
  37. WATCHLISTS
README.md

Dart

A client-optimized language for fast apps on any platform

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 platforms illustration

License & patents

Dart is free and open source.

See LICENSE and PATENT_GRANT.

Using Dart

Visit dart.dev to learn more about the language, tools, getting started, and more.

Browse pub.dev for more packages and libraries contributed by the community and the Dart team.

Building Dart

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.

Contributing to Dart

The easiest way to contribute to Dart is to file issues.

You can also contribute patches, as described in Contributing.