Commit Graph

27 Commits

Author SHA1 Message Date
Paul Berry 7ebb0411f3 Rework DartFix listener interface to separate edits from suggestions.
Change-Id: Ieb10433f13d961ee0cfeac580104aed209ed52ea
Reviewed-on: https://dart-review.googlesource.com/c/93744
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Dan Rubel <danrubel@google.com>
2019-02-20 21:32:39 +00:00
Paul Berry e1d3186ed9 Make declarations in provisional_api_test.dart private.
I'm going to do some refactoring in future CLs that may make some of
these classes and/or methods unnecessary.  Making them private will
help highlight when things become unnecessary (because it will allow
dead code hints to be triggered).

Change-Id: I201bf5be0131e69af00789308e17926d98db6f5b
Reviewed-on: https://dart-review.googlesource.com/c/93369
Auto-Submit: Paul Berry <paulberry@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-02-18 18:20:53 +00:00
Paul Berry bb76970857 Sort provisional_api_test.dart
Change-Id: Iab154cc9288758251c29d8f89bab835769c5ce24
Reviewed-on: https://dart-review.googlesource.com/c/93482
Commit-Queue: Paul Berry <paulberry@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-02-18 18:17:13 +00:00
Paul Berry 26970f370c Move source out of PotentialModification.
Rather than have each PotentialModification keep track of its own
source, it's less wasteful to keep track of a map from each source to
a list of the potential modifications for that source.

Change-Id: Ib579f5159100195496a850fbf795b073fc927110
Reviewed-on: https://dart-review.googlesource.com/c/93466
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-02-18 00:34:40 +00:00
Paul Berry fa8c552fd9 Propagate non-null intent from callee to caller.
Change-Id: If0095584d6d0b88e7c39b9871795c499380b636c
Reviewed-on: https://dart-review.googlesource.com/c/93364
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-02-16 13:35:48 +00:00
Paul Berry ab38cf7897 Allow non-nullable usage to imply non-null intent.
If a method parameter is used in unconditional control flow in a way
that a `null` value would directly lead to an exception (i.e. by
dereferencing it, or by passing it to a method that requires a
non-nullable value), this is treated as implying that the method
parameter is intended to be non-nullable.

Change-Id: I4f55e4c95b3cfaee0a2ba9367b47d51083e0b7b1
Reviewed-on: https://dart-review.googlesource.com/c/93363
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-02-16 13:35:48 +00:00
Paul Berry 936b1c0404 Rename _mockOr to _either.
This makes the migration unit tests a little easier to read.

Change-Id: I2ae53c1d1a6c893888b02fcd0e68053c4d4c6cc3
Reviewed-on: https://dart-review.googlesource.com/c/93362
Auto-Submit: Paul Berry <paulberry@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-02-15 22:21:17 +00:00
Paul Berry 837145a7c7 Properly restore state of _inConditionalControlFlow upon entering new function/method.
Each function and method starts in unconditional control flow.  This
should allow more assertions to be recognized as demonstrating
non-null intent.

Change-Id: I5f6437a3009ebf6c91972e267c8a136a2b2fa77f
Reviewed-on: https://dart-review.googlesource.com/c/93129
Auto-Submit: Paul Berry <paulberry@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>
Reviewed-by: Dan Rubel <danrubel@google.com>
2019-02-14 12:58:09 +00:00
Paul Berry 92460b8923 Migration: use non-null assertions as a hint for parameters that should not be nullable.
Change-Id: I30d98fa28840dacb8df4fb038b49c491b347854f
Reviewed-on: https://dart-review.googlesource.com/c/93063
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Dan Rubel <danrubel@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-02-14 01:08:37 +00:00
Paul Berry d1bf6ae7d2 Track nonNullIntent in unconditional control flow.
In a future CL this will be used to prevent nullability from being
propagated into function parameters where it's clearly not intended.

Change-Id: I34430162db33f99e850ca2c11e5bca8736feb94f
Reviewed-on: https://dart-review.googlesource.com/c/93041
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Dan Rubel <danrubel@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-02-13 15:46:46 +00:00
Paul Berry 13c4b160ba Add migration tool support for bare "return;" statements
Change-Id: I10e2adeaf3c682ccac011b307c43052178b0974a
Reviewed-on: https://dart-review.googlesource.com/c/93040
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Dan Rubel <danrubel@google.com>
2019-02-13 15:46:46 +00:00
Paul Berry ca32bef641 Add migration support for the @required annotation.
If a named parameter is annotated as `@required`, then this overrides
the NamedNoDefaultParameterHeuristic; the parameter is considered
required regardless of what happens at call sites.  A duplicate
`@required` annotation is not inserted.

Change-Id: Ib1385d0a65dd9001bb7abede9de2a319f65a1f86
Reviewed-on: https://dart-review.googlesource.com/c/92844
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Dan Rubel <danrubel@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-02-12 21:47:28 +00:00
Paul Berry 6d2daa692c Set non_nullable experiments flag during migration tests.
Fixes #35909

Change-Id: I2c92af7a3e2d31cb7fe04b3ccd2b117badeedf35
Reviewed-on: https://dart-review.googlesource.com/c/92760
Commit-Queue: Paul Berry <paulberry@google.com>
Auto-Submit: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-02-12 19:04:53 +00:00
Paul Berry ce91bcb442 Add migration support for named parameters.
Currently assuming that the language team chooses option 2 for
https://github.com/dart-lang/language/issues/156#issuecomment-460525075.

To handle the case where the user does not specify a default value,
and all call sites supply the named parameter, there are two possible
heuristics:

- assumeNullable: mark the parameter as nullable, since the implicit
  default is `null`, even though the implicit default is never used.

- assumeRequired: consider the parameter to be `@required`, ensuring
  that the implicit default will never be used.

I've provisionally chosen `assumeRequired` as the default behavior.

Functionality not yet implemented:

- If `@required` is already present in the source code, this should
  override the heuristic; also it should not be added again.

- If the parameter is already marked as nullable in the source code,
  this should override the heuristic.

- Uses of `@required` should be translated to `required`.

- If `@required` is already present in the source code, and a default
  value is supplied, the default value should be removed.

- If the parameter is used in a way that demonstrates it was intended
  to be non-nullable (i.e. it appears in a place in unconditional
  control flow that would cause an exception to be thrown if it was
  null), this should override the heuristic and cause it to be marked
  as `@required`.

Change-Id: I9f2ec63787fdb6215e6075ecfcc830ed9942b8b5
Reviewed-on: https://dart-review.googlesource.com/c/92532
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-02-12 14:49:14 +00:00
Paul Berry 640bfb45f8 Mark test as failing due to #35909
Change-Id: I242d87bc7104d0f01af4be4339be451ca2308736
Reviewed-on: https://dart-review.googlesource.com/c/92621
Commit-Queue: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Auto-Submit: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-02-11 17:57:00 +00:00
Paul Berry 7cec1b03b6 Add missing awaits to migration tests.
Change-Id: Id7f4d5f063ba7253f5e8bd7abcf60a53fe7538af
Reviewed-on: https://dart-review.googlesource.com/c/92529
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-02-10 03:27:49 +00:00
Paul Berry b3ee960092 Stop indirecting through VariableRecorder/VariableRepostitory to create constraint variables.
The indirection wasn't adding any value.

Change-Id: I1c1b41a55b5cee37f75c30c3fa6ebfe56083ed56
Reviewed-on: https://dart-review.googlesource.com/c/92526
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-02-10 01:45:20 +00:00
Paul Berry ad3adb6285 Move nullability migration algorithm into analysis server.
Change-Id: Ie240b42cab37e3f5adce8633d368fcf6667b3a37
Reviewed-on: https://dart-review.googlesource.com/c/92522
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-02-09 19:01:14 +00:00
Paul Berry afe37d7fe0 Add migration support for named parameters (with and without default values).
At this point the migration tool is beginning to make assumptions
about decisions the language team hasn't made yet, so I've created a
class to document those assumptions and allow us to test variants.

Change-Id: I4638d7f534cfa2dbd8460277351045c370377ff8
Reviewed-on: https://dart-review.googlesource.com/c/92394
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-02-08 17:47:55 +00:00
Paul Berry 5b7b34eb3a Add a "permissive mode" to the nullability migration tool.
This allows us to try it out on substantial codebases (e.g. the
analyzer itself) without crashing, even though a lot of the underlying
logic is not yet complete.

Change-Id: I24a45eea1889f7d9afa30c0398f359d32ffb52ad
Reviewed-on: https://dart-review.googlesource.com/c/92404
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Dan Rubel <danrubel@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-02-08 13:23:35 +00:00
danrubel d84ec89f39 add NullabilityMigrationListener for communicating changes to the client
Change-Id: If6c9cefd0f43edab3a6731f606b4be9a0934e540
Reviewed-on: https://dart-review.googlesource.com/c/92242
Reviewed-by: Paul Berry <paulberry@google.com>
2019-02-07 20:47:37 +00:00
Paul Berry c2cdc1c639 Allow migration of multiple files at once.
Change-Id: I1940ab2da69327132eb71fbd839b9ac726dc7529
Reviewed-on: https://dart-review.googlesource.com/c/92240
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-02-07 00:02:04 +00:00
Paul Berry d68d8526f4 Allow nullabilty migration prepareInput/processInput to operate on different ASTs.
This required modifying the implementation of nullability migration so
that it no longer holds onto AST nodes, but instead records sources
and offsets.  This will allow the tool to scale to large projects
since the AST for one file can be garbage collected while the AST for
another file is analyzed.

Additional changes:

- provisional_api_test.dart is updated so that it tests the API in two
  ways: once feeding identical ASTs to prepareInput/processInput, and
  once feeding conceptually equal (but not identical) ASTs.

- The internal analyzer API is changed so that the finish() method
  simply returns a list of modifications, rather than a map from path
  to modification list.

- Files are tracked by Source rather than by path.

- Modification objects remember their Source (this should pave the way
  for allowing multiple files to be migrated in a single run of the
  tool).

- The Variables class is split in two, with the methods needed for
  testing in a private class inside migration_test.dart.  These test
  methods can retain pointers to AST nodes without creating
  scalability problems for the production code.

Change-Id: Idd3f3b6893a25bb4294b4b4c820e20e4bc47ffd8
Reviewed-on: https://dart-review.googlesource.com/c/92220
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Dan Rubel <danrubel@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-02-06 23:58:40 +00:00
Paul Berry ba9fbda83e Rework provisional migration API.
Instead of returning a list of SourceFileEdit objects, we now return a
list of SingleNullabilityFix objects.  Each SingleNullabilityFix can
be queried to determine (a) which source file it applies to, (b) the
exact set of source edits to apply, and (c) the kind of change.
Future CLs will add the ability to query (d) the location of the
change, and (e) the reason for the change.

Change-Id: I5a42958ac70d1e39802efd5915d0856109b4a7db
Reviewed-on: https://dart-review.googlesource.com/c/92151
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Dan Rubel <danrubel@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-02-06 23:20:41 +00:00
Paul Berry efcf8b01b1 Move integration tests of migration API to analysis server.
Change-Id: I7109df482f17be884a31313e18e1b4cf57b1ad4c
Reviewed-on: https://dart-review.googlesource.com/c/92140
Auto-Submit: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-02-06 15:37:18 +00:00
Paul Berry 4fb220707e Hardcode SourceFileEdit.fileStamp to -1 in migration prototype.
SourceFileEdit.fileStamp isn't used anymore, so there's no reason to
have extra plumbing to set it.

Change-Id: I1d1c8e9e74f74d19fd306d44e477573de5a66cd7
Reviewed-on: https://dart-review.googlesource.com/c/92061
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Dan Rubel <danrubel@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-02-06 13:10:48 +00:00
Paul Berry 3395550962 Provisional nullability migration API in analysis_server.
Limitations at this point:

- Only one file can be migrated at a time.  If you try to migrate more
  than one file, you will get an assertion failure.

- The ResolvedUnitResult passed to prepareInput must contain precisely
  the same unit (in terms of `identical`) as the ResoledUnitResult
  passed to processInput.  Otherwise you will get an assertion
  failure.

- There is not yet any way to query diagnostic information about the
  migration (e.g. heuristic decisions that were made).

- Only a very small number of constructs can be successfully migrated
  at this point.

- The implementation is not sensibly organized at this point.  Most of
  it is in the analyzer, and then wrapped in the analysis_server.
  Really it all should go in the analysis_server.

I'll be working to rectify these limitations over the next few days,
which will probably involve a lot of rework under the hood.  But
hopefully the API in provisional_api.dart should remain stable, so
that DartFix code can start being written against it.

Change-Id: Idc3ebab380448a812d5e83338789570e33c55af7
Reviewed-on: https://dart-review.googlesource.com/c/92020
Reviewed-by: Dan Rubel <danrubel@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>
Auto-Submit: Paul Berry <paulberry@google.com>
2019-02-05 16:30:35 +00:00