Commit Graph

30 Commits

Author SHA1 Message Date
Sam Rawlins 7465b17ad7 front_end: Remove unnecessary imports
Bug: https://github.com/dart-lang/sdk/issues/44569
Change-Id: I0dd5d176a95289333cd42f87f49d7820c54bbe38
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/191470
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2021-03-17 16:48:40 +00:00
Jens Johansen 93f4ac0a83 [cfe] Actually have both ansi and plain text formatted messages (2nd try)
The CFEs FormattedMessage always had two getters to get the text inside
one that would supposedly give an ansi formated version of the message
and one that would supposedly give a plaintext formated version of the
message. They both returned the same string, though, which would either
be with ansi escape codes or plain text depending on the environment at
compile time.

This CL fixes that by having both messages, and letting the reporting
(i.e. whenever the message is read) decide which to use. That way we
can - for instance - report errors with color if the terminal supports
it correctly when reusing a dill (and reissuing problems, but where the
terminal support changes) and if printing the problem to an html <pre>
field (like observatory does).

It also cleans up two different implementations of whether we think
the terminal supports colors or not, by deleting one of them.

This is the second try. Patchset #1 is the original.
Patchset #2(and possibly beyond) is the changes.

TEST=Existing test suites.

Change-Id: I8e483049ce81ce1bd8e5396b588a31e0ad3a8630
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/187402
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2021-02-26 13:06:17 +00:00
Jens Johansen 3a4a4f53d0 Revert "[cfe] Actually have both ansi and plain text formatted messages"
This reverts commit f63f7736c5.

Reason for revert: This somehow breaks the Windows bots. `python tools/test.py -n dartk-win-release-x64 standalone_2/io/process_shell_test`.

Original change's description:
> [cfe] Actually have both ansi and plain text formatted messages
>
> The CFEs FormattedMessage always had two getters to get the text inside
> one that would supposedly give an ansi formated version of the message
> and one that would supposedly give a plaintext formated version of the
> message. They both returned the same string, though, which would either
> be with ansi escape codes or plain text depending on the environment at
> compile time.
>
> This CL fixes that by having both messages, and letting the reporting
> (i.e. whenever the message is read) decide which to use. That way we
> can - for instance - report errors with color if the terminal supports
> it correctly when reusing a dill (and reissuing problems, but where the
> terminal support changes) and if printing the problem to an html <pre>
> field (like observatory does (1)).
>
> It also cleans up two different implementations of whether we think
> the terminal supports colors or not, by deleting one of them.
>
> (1) At least sometimes. It works - I think - only for 'evaluateInFrame',
>     but that's another story (and will be fixed in a follow-up CL).
>
> TEST=Existing test suites.
>
> Change-Id: Iedaedd9a5c41458d40c23ed4b706324c004ae943
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/186291
> Commit-Queue: Jens Johansen <jensj@google.com>
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Reviewed-by: Alexander Markov <alexmarkov@google.com>

Change-Id: I0b53f943a61f76705badfead30d9e1ee35baff57
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/186941
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2021-02-24 12:30:18 +00:00
Jens Johansen f63f7736c5 [cfe] Actually have both ansi and plain text formatted messages
The CFEs FormattedMessage always had two getters to get the text inside
one that would supposedly give an ansi formated version of the message
and one that would supposedly give a plaintext formated version of the
message. They both returned the same string, though, which would either
be with ansi escape codes or plain text depending on the environment at
compile time.

This CL fixes that by having both messages, and letting the reporting
(i.e. whenever the message is read) decide which to use. That way we
can - for instance - report errors with color if the terminal supports
it correctly when reusing a dill (and reissuing problems, but where the
terminal support changes) and if printing the problem to an html <pre>
field (like observatory does (1)).

It also cleans up two different implementations of whether we think
the terminal supports colors or not, by deleting one of them.

(1) At least sometimes. It works - I think - only for 'evaluateInFrame',
    but that's another story (and will be fixed in a follow-up CL).

TEST=Existing test suites.

Change-Id: Iedaedd9a5c41458d40c23ed4b706324c004ae943
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/186291
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2021-02-24 10:33:45 +00:00
Paul Berry c2eb847697 Add "why not promoted" support for method invocations to CFE.
This required moving the logic for computing the context messages from
the inference visitor to the type inferrer.

This includes support for extension method invocations and invocation
of `.call` on a function type.

Bug: https://github.com/dart-lang/sdk/issues/44898
Change-Id: Icda160f69cc815953c43edc92be910c5f49f9401
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/184842
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2021-02-13 15:39:17 +00:00
Paul Berry a42244f73b 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>
2021-02-02 16:15:34 +00:00
Johnni Winther b38821f39d [kernel] Enforce lints in pkg/kernel
Change-Id: I954f7632f22b552febed2a3140f81245277cb050
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171581
Reviewed-by: Jens Johansen <jensj@google.com>
2020-11-11 12:51:28 +00:00
Johnni Winther 1d6eac5ebf [cfe] Only use experimental release version when flag is not on by default
Change-Id: I06267c6d3f0e5abb289e25fde8098aa0e3bead34
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166844
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2020-10-12 12:57:41 +00:00
Jens Johansen 64714f2596 [CFE] Include _fe_analyzer_shared in tests
Change-Id: I6d2ab3465a0aa2488cbe7b9a2f1909ab6c615d32
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/147082
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2020-05-11 13:13:21 +00:00
Jens Johansen 4084c4cc24 [kernel/CFE] Use kernel 'Version' class for versions
Define a "Version" class in kernel that allows easy comparison between
versions (e.g. a < b, a >= b etc).

Use this Version class in CFE.

Change-Id: I2f382e7bb3c2083258743b9b66a909a88d575dbc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144283
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2020-04-21 09:44:52 +00:00
Jens Johansen 5e3972ffd4 [CFE] Sort status files
Change-Id: Ia7e65057fc15ee36e6e9547906bcc9298fc3df93
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/142141
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2020-04-03 06:24:26 +00:00
Jens Johansen c1d21c368a Move a few methods from ClassBuilderImpl to SourceClassBuilder
Change-Id: I85553b68f497f58d32721a93a718a069c8d783e4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125968
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2019-12-02 09:34:32 +00:00
Jens Johansen 5965789b92 [CFE] Fix bug in lint test
Change-Id: Ia96bb796da4c7f966fe808499388c2058c20b841
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/123726
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2019-11-01 14:13:42 +00:00
Paul Berry 6ea11a8b64 Decouple colors.dart from CompilerContext
We're going to move this file into _fe_analyzer_shared, so we can't
have it importing CompilerContext.  It turns out that we were only
using it to cache the decision of whether to display colors, and to
decide whether to verbosely explain how we made that decision.  Those
can be accomplished in other ways.

Change-Id: If1e3a9fee7c0ca919444d8429936045b8408c246
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/123840
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-11-01 11:24:20 +00:00
Johnni Winther 6b61050d9c [cfe+analyzer] Split generated message files into shared and cfe-only
Change-Id: I71dff57403d236f6186d7e1b5fa01fa7149fd0f8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/123661
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2019-10-31 14:39:04 +00:00
Johnni Winther 0ee78fac98 [cfe] Rename declaration.dart and procedure_builder.dart
to builder.dart and function_builder.dart to reflect their primary content.

Change-Id: Ib0f9c2970b6a88e4381b0cd7532e4410b72c2a2a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/120791
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2019-10-10 08:11:27 +00:00
Jens Johansen f09edd1d32 [CFE] Add incremental serializer
Add an incremental serializer that can be used to avoid re-serializing
the same thing again and again.
It does this by grouping libraries into Components / bundles,
serializing them individually and using the concatenated dill feature to
output the wanted data --- just potentially faster if we had the data
in cache.

Note that the serialized output might contain *more* than the input given
if we cached the wanted data into a bigger bundle.
The output will always be "closed" though, i.e. if the stuff that is
included that is too much added a new dependency, that dependency will be
included as well.
This should generally make it safe, although one can imagine situations
where it could pull in lots of dependencies that it wouldn't otherwise
have.

It is being driven by the incremental compiler which makes sure to
invalidate the cache when the data changes.

Except for situations where the libraries are changed externally after
being serialized, but before being serialized again, where one then wants
the updated library serialized, the feature should be safe.

Change-Id: I2a504abe6dbb68434c3b04abff13480ef72a6a6e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/120786
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2019-10-09 13:28:12 +00:00
Johnni Winther 431509ba8e [cfe] Remove builder/builder.dart
Change-Id: I471e2c9a0875c4ff14169a935758f53a74655f25
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/120642
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2019-10-08 20:24:38 +00:00
Johnni Winther 8413a0db0d [cfe] Add *BuilderImpl
In preparation for creating a clean implementable interface for various
builder classes. This is in turn a precursor for deprecating
Builder.target

Change-Id: I83910e84da149775f46c0be4b10f7694fadd0a7f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/119843
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2019-10-04 12:24:45 +00:00
Johnni Winther 40d75d733b [cfe] Refactor if-null and null-aware property access
Change-Id: I19a50b7d56b63c96f24daf8aaf975e0748e29cf8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/116340
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2019-09-19 17:17:10 +00:00
Johnni Winther e3563528e6 [cfe] Add tear off function for extension instance methods.
Change-Id: Ia92640f5dd99cd3eeb5ba737a646472b5f5260a0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114844
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2019-08-29 09:51:53 +00:00
Jens Johansen 5dcec3c93e [CFE] Disallow exports internally
This CL adds a lint, but doesn't cleanup the failures we have.

Change-Id: I711af6d012e0b1f1b7dfe422dd615f32f0084119
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/113993
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2019-08-22 08:09:21 +00:00
Jens Johansen 40589f80aa [CFE] Fourth batch of fixes for requiring explicit types
Change-Id: I13f62232287b84cc82da2bbb0cee4b4d337de8ad
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/113992
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2019-08-22 07:08:27 +00:00
Jens Johansen f2e04caeaf [CFE] Fix CQ race condition with lint status
TBR

Change-Id: Ie99cd8a0d93c765f1c9bc90b97393359b625abdb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/113995
Reviewed-by: Jens Johansen <jensj@google.com>
2019-08-21 13:39:30 +00:00
Jens Johansen 48edb2362a [CFE] Update lint for explicit types to also look at fields and top level fields
Oversight that it didn't always do that.

Change-Id: Ib515ed0f77efcdfb932d5fad9c5b269eeb45a160
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/113988
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2019-08-21 12:33:45 +00:00
Jens Johansen 698c5b1a36 [CFE] Add 'double import' lint
Add a lint to discourage importing the same file more than once.
The idea being that it was probably done by mistake (e.g. automatically
by an editor).
This is done in a number of places and they are currently added to the
status file.

Change-Id: I16bc9c04c5a607f87ead1fb34922a7edb408c3da
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/113985
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2019-08-21 12:20:22 +00:00
Jens Johansen 363ae34c55 [CFE] Third batch of fixes for requiring explicit types
Change-Id: Ie4c8e66acf942901602c91819640967e49044233
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/113822
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2019-08-20 13:11:12 +00:00
Jens Johansen 0e201edeeb [CFE] Second batch of fixes for requiring explicit types
Change-Id: If4f35550e1df10763b4c13d15eba1d9f53e6095e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/113324
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2019-08-19 07:19:45 +00:00
Jens Johansen 9552646dc4 [CFE] First batch of fixes for requiring explicit types
Change-Id: Ic27f8508bc95409a5ee8f90b72f34a73d0f8e2e7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/113034
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2019-08-15 13:13:20 +00:00
Jens Johansen 93d4d28f6c [CFE] Add lint test: Require explicit types
This CL adds a test (lint_test.dart) that gives errors if using e.g.
"var foo = 42;".
We opted to not use the lint "always_specify_types" as that does
more than what the team voted for.

Change-Id: Ia37066ee04ff676d15f41222751557a9245f953f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/113032
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2019-08-15 10:21:00 +00:00