Commit Graph

37 Commits

Author SHA1 Message Date
Johnni Winther 47acb386d7 [cfe] Add id testing for inferred variable types
* including inferred parameter/return types for local functions
* added testing for inferred type arguments on literals and bounded variables

Change-Id: I02bceef3f5a41af7794cc63769cf4959321700d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195260
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2021-04-15 05:06:56 +00:00
Johnni Winther 9dff91e2a5 [cfe] Add id testing for inferred type arguments
Change-Id: If932af54e184fcd7bb19a6889edf459c660f0cdb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195020
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2021-04-13 09:10:38 +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
Paul Berry 4ee861b7d0 Flow analysis: Track additional assigned variables information.
We now track the following additional information:

- All local variable reads and read captures (previously we only
  tracked writes)

- For any conditional expression (`?:`) or if-test, the variables
  written in the "then" branch

- For any logical and expression (`&&`), the variables written in the
  right hand side of the expression

Tracking this information will allow us to implement legacy type
promotion as part of _fe_analyzer_shared, using the same API as flow
anaylsis, which will in turn allow a lot of front end and analyzer
code to be removed and simplified.

Change-Id: I01aaf64cefb989a4450c8e6d3a8373c1ca2b6dec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/179980
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2021-01-21 19:48:22 +00:00
Johnni Winther 34fb48bb8a [kernel,front_end] Migrate first wave of pkg/kernel and pkg/front_end
Migrates libraries dependent only on already migrated libraries.

Change-Id: I0e85ee8dbc2afce031b92e0009e71c206a55af28
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/179502
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2021-01-18 15:40:21 +00:00
Dmitry Stefantsov d54e2bb568 [cfe,ddc,dart2js,vm] Add NullType
This CL is the sum of the following 5 CLs:
* https://dart-review.googlesource.com/c/sdk/+/170342/
* https://dart-review.googlesource.com/c/sdk/+/170344/
* https://dart-review.googlesource.com/c/sdk/+/170345/
* https://dart-review.googlesource.com/c/sdk/+/170346/
* https://dart-review.googlesource.com/c/sdk/+/170347/

The reason for landing the 5 CLs as one CL is to prevent potential
troubles with bisecting over the branch because the change is fully
functional only with all 5 CLs.

Closes #40122.

TEST=Verified by changes in .expect files in pkg/vm/.
Bug: https://github.com/dart-lang/sdk/issues/40122
Change-Id: Ib8197802fdc69694387ae47ac990c58b3aaab7a5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170689
Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2020-11-06 12:43:52 +00:00
Johnni Winther b42f954364 [cfe] Use experiment release version when non-nullable is enabled explicitly
Even when non-nullable is enabled by default, enabling the experiment
explicitly should result in the experiment release version (and not
the experiment enabled version) to be used for opting in.

For this change, the semantics of parseExperimentalFlags was change
to _not_ normalize the flags to a full mapping including default values.
For this reason all uses of such maps are renamed to
'explicitExperimentalFlags'.

Closes #43879

Change-Id: I0d0262e68ec1403549abcfd305ae3a4404fe93e3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168654
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2020-10-22 06:17:39 +00:00
Johnni Winther f4501b6e83 Reland "[kernel] Rename Name.name to Name.text"
Including a deprecated getter to avoid breaking dependent code outside
the Dart repo.

Change-Id: I365957b7c2da6e0cb5c71eb8d2906b0dc6ff18ec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163062
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2020-09-17 06:10:49 +00:00
Johnni Winther 644df9b9fb Revert "Reland: [kernel] Rename Name.name to Name.text"
This reverts commit c430a0ac0b.

Reason for revert: Will break flutter_frontend_server when rolled into google3

Original change's description:
> Reland: [kernel] Rename Name.name to Name.text
> 
> Change-Id: I5240b0ff09faf35184998920202d7600dc97766d
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162746
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Commit-Queue: Johnni Winther <johnniwinther@google.com>

TBR=jensj@google.com,johnniwinther@google.com

Change-Id: Ib6961f49dd416171c5d5935c490d79d6f7be779e
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162748
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2020-09-16 08:22:55 +00:00
Johnni Winther c430a0ac0b Reland: [kernel] Rename Name.name to Name.text
Change-Id: I5240b0ff09faf35184998920202d7600dc97766d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162746
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2020-09-16 07:42:42 +00:00
Daco Harkes 7302e01a79 Revert "[kernel] Rename Name.name to Name.text"
This reverts commit 3ff8dd2f51.

Reason for revert: Fails all CI builders. Possibly something landed
in the mean time.

Original change's description:
> [kernel] Rename Name.name to Name.text
> 
> Change-Id: I93162fb387ba123b949e19a7829bd5614845b15d
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162722
> Reviewed-by: Jens Johansen <jensj@google.com>
> Commit-Queue: Johnni Winther <johnniwinther@google.com>

TBR=jensj@google.com,johnniwinther@google.com

Change-Id: I2ffe526dabf37ae09d5e4ab1fbe514925f6e8768
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162744
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2020-09-15 15:21:35 +00:00
Johnni Winther 3ff8dd2f51 [kernel] Rename Name.name to Name.text
Change-Id: I93162fb387ba123b949e19a7829bd5614845b15d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162722
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2020-09-15 14:27:22 +00:00
Johnni Winther dc97454b63 [analyzer,cfe,dart2js] Add pretty printing to id testing
Adds support for pretty printing verbose annotations.
Adds support for force updating annotation texts useful for applying
the pretty printing to valid annotations.

Change-Id: I8fe9b6d2f8198bd5e160854053c8d964ef832a8d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129710
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2020-04-14 13:24:09 +00:00
Johnni Winther 46bb15edf3 [cfe] Fix inheritance test data discrepancies.
Change-Id: I367aace60324a7755f795d2f24aaf0d138bc8d59
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/141602
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2020-04-02 13:14:39 +00:00
Johnni Winther d68f552e70 [analyzer,cfe] Handle (un)assigned state in try-statement
This handles (un)assigned state in try-statement that do not
complete normally. In this case we could create a variable model
for an unreachable state that would be both assigned and unassigned
leading to an assertion failure.

Closes #41284

Change-Id: Id4c7689bc7c614338af3542eb342c964696fca1e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/141981
Auto-Submit: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2020-04-01 15:46:15 +00:00
Johnni Winther 62f84880ef [cfe] Report error on missing return from non-nullable function
Closes #40520
Closes #40948
Closes #40425

Change-Id: I0aa3cfa51b410c90dd0bea963846eeb6b2e73efb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140540
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2020-03-24 08:21:36 +00:00
Johnni Winther d2e96aa6d3 [cfe] Report error on (un)assigned late variables
Closes #40601
Closes #41103
Closes #40946

Change-Id: I1a28f497ffe0be3d1f9e673f1e8be7a518bbfc7e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140403
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2020-03-23 14:48:53 +00:00
Konstantin Shcheglov 9a0c09ecb2 Track definitely unassigned variables.
Change-Id: Id610a133912605f9af63222f25408942420cbf1f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138881
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-03-10 18:35:40 +00:00
Dmitry Stefantsov 029c8f1cee [cfe] Use Supertype instead of InterfaceType in ClassHierarchyBuilder
Change-Id: I1a11ce32237480c0eddf50a7a86cd56b89116e77
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138801
Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2020-03-09 12:57:17 +00:00
Devon Carew 9eeecae3e4 address a few static analysis nits
Change-Id: I461c71550e320ed9f520169bcdbd4083f58b3db3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/137323
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Janice Collins <jcollins@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2020-02-26 20:04:51 +00:00
Johnni Winther a9162bd599 [analyzer,cfe] Implement mixed inheritance id test for analyzer
Change-Id: Ie4ce09b83c2a96a5ad16c60d2924f18cd90a4089
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136633
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-02-24 13:28:26 +00:00
Johnni Winther 5829fc7829 [analyzer,cfe,dart2js] Add marker.options files to automate running id tests on all configurations
Change-Id: Ib5eb7f3967634721047f8dcc57b9e6c350b91a41
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136226
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2020-02-21 08:34:26 +00:00
Dmitry Stefantsov fd992e423e [cfe] Normalize supertypes before nnbd-top-merging them
Closes #40454.

Bug: http://dartbug.com/40454
Change-Id: Ia255c99c937a04876e04a0f0f5935147e55fbd35
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134842
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2020-02-07 18:14:40 +00:00
Johnni Winther 5b47e0fbb7 [cfe] Special case inference of Object.== parameter in legacy mode
Closes #40334

Change-Id: I526ff75a2f135d911f8d555804d03cddc98c3bc0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/133234
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2020-01-28 13:17:37 +00:00
Johnni Winther 5e389080a4 [cfe] Test supertypes computed from ClassHierarchyBuilder
Change-Id: Ia079754bd8272d7b5689a3bdab1e69d5188082be
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132342
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2020-01-22 07:08:36 +00:00
Johnni Winther d302d7f10a [cfe] Insert member signatures for nnbd aware inheritance
Change-Id: I86dbbd586434af81b6dc4f4ae748cbd8177d06e0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129080
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2020-01-15 07:36:28 +00:00
Johnni Winther e3a20bf361 [analyzer,cfe,dart2js] Support annotated code generation
Add support for generating annotations from actual data using
option -g

Change-Id: I88d9cdb62a38d579234b15097c9e9bb3d81ebe8c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129708
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2020-01-03 13:57:39 +00:00
Johnni Winther 904a822432 [cfe+analyzer] Use TryStatement for try/catch and try/finally in CFE
This includes an alignment of assigned variables info collection between
analyzer and cfe by always collecting assigned variables info for both
the try statement and the try block.

Change-Id: I789527adc24da025a85e73cdd98392efe7fc97bd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/128407
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2019-12-16 13:55:50 +00:00
Johnni Winther eda5188a0e [cfe] Implement flow analysis on if elements
Change-Id: I5d8afac580c0bd038e3287bea6dd74cb51f3f2f2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/128541
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2019-12-16 11:48:07 +00:00
Johnni Winther 818ec6db92 [cfe] Implement nnbd-top-merge
+ and use nnbd-top-merge and legacy erasure in hierarchy computation

Change-Id: I4bf06ce8d3c68a9926865ebf84b24b4029828d73
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/128065
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2019-12-13 17:19:59 +00:00
Johnni Winther 72eb475f6c [cfe] Refactor for-in loops to handle flow analysis
Change-Id: Iddbf84e9d878fc828280c76cdaa22f3082b6b842
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/128067
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2019-12-12 13:53:59 +00:00
Konstantin Shcheglov 52dc7690ef Issue 39667. Use flow analysis in IfElement.
Bug: https://github.com/dart-lang/sdk/issues/39667
Change-Id: I4528869a8d39d1b27c0cdf21ab20173bdb0efbc4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127482
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2019-12-07 03:32:14 +00:00
Johnni Winther 441a17d1f9 [cfe] Fix flow analysis for type parameter promotion, initializers, switch continue and for loops
Change-Id: Ia0bbbeb7f968961846a30a31471399bef9065842
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127003
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2019-12-03 14:28:48 +00:00
Johnni Winther f7941eb850 [cfe] Handle break/continue in flow analysis
Change-Id: Ic02e60237b8eda3c98c0715e3fcc668d21e1bf62
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/126728
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2019-12-03 11:25:51 +00:00
Johnni Winther 659b32ffc8 [cfe] Handle chained null shorting and null aware if-null set
Change-Id: I39d2448a957ca7f4f3d1f027e543f773b300ce9b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/126645
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2019-11-28 12:44:55 +00:00
Johnni Winther 3855eeaae7 [cfe] Move shared id-tests into id_tests folder
Change-Id: I5e6efe43c7b0f0b65028cda0a192497e3a378aad
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/124994
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2019-11-14 10:16:16 +00:00
Johnni Winther f443bc918e [cfe] Add tests for inheritance from opt-out libraries
Change-Id: If139945dfdd808da0c24ac550ecfa235b41d3c23
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/123737
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2019-11-13 10:08:08 +00:00