Commit Graph

1123 Commits

Author SHA1 Message Date
Paul Berry 2a8ea8900b Migration: as a temporary measure, remove code via commenting it out.
The new FixBuilder infrastructure has the ability to remove dead code
either by commenting it out or by deleting it entirely.  Previous to
FixBuilder all we could do is comment it out.  My intention when
landing FixBuilder was to keep this behavior so that we could make a
deliberate switch at a later time (when everything was well tested).
But I accidentally set the flag wrong for some code paths, and so
currently we delete code.

This has caused some bugs in the preview tool (which I will file in
the issue tracker shortly).  In order to avoid causing problems for
members of the language team who intend to try out the tool this week,
I'm switching back to "comment code out" as a temporary measure.

Change-Id: I0ca8674b6a8d9ab23cf6726a15fa3dc1919085b4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/133081
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-01-23 19:36:19 +00:00
Mike Fairhurst 8e337e34b1 [nnbd_migration] Don't union implicit types to bounds
Fixes https://github.com/dart-lang/sdk/issues/40181

As long as its possible to union a bound to a node involved in a
substitution, its possible to make a bound "exact nullable." This
implies that all instantiations of that type must be with a nullable
version of that parameter, which is not desirable for any program.

This marks new failing tests due to
https://github.com/dart-lang/sdk/issues/39404. However, re-running this
on package:collection resulted in a better migration result (no issues
from the non-nullable inferred types being made explicit or not). So my
personal feeling is this is worth landing now, however, we could land it
later.

Change-Id: I63479c5e4edecf301c27e21b5ba57508d625e8ab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132748
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Mike Fairhurst <mfairhurst@google.com>
2020-01-23 18:49:49 +00:00
Janice Collins 569021a279 Updates to steamroll_ecosystem prior to port.
This should be the last version before a Dart implementation.

Pins package_config to old version per SDK and dart-lang/sdk#40208,
fixes updates of repositories in place, speeds up fetching of
initial repositories, and allows fetching without recursive
dev_dependencies.


Change-Id: Ie00b5dab7fc9b34191c61cd4e2ad3f7540d71b51
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132960
Commit-Queue: Janice Collins <jcollins@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-01-23 18:21:27 +00:00
Paul Berry e0f97cda30 Migration: switch to using the FixBuilder.
Change-Id: I41e978439d36a26e55be71071a931390eb3dbf57
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/133020
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-01-23 16:06:57 +00:00
Mike Fairhurst 835eb766fa [nnbd_migration] Support LUB(T extends num, num)
Change-Id: Ibac663aaafc3ace6acb2522aa609fc3ac2892153
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132980
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Mike Fairhurst <mfairhurst@google.com>
2020-01-22 23:26:19 +00:00
Paul Berry 0673525175 Migration: add permissive mode support to FixBuilder
Change-Id: If9a82fc274ea89089df0c3b17bae02ba564a74ec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132943
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-01-22 22:59:39 +00:00
Brian Wilkerson 500822341e First steps to allow migration to be incrementally rerun
Change-Id: Ib4e682739a732ad9b8863ecb780ad88e5cbd9c6d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132921
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-01-22 20:23:38 +00:00
Paul Berry ce5a0f5e32 Migration: fix instrumentation when dropping the condition and else parts of an "if"
When migrating an unnecessary "if" test like this one:

  if (x != null) {
    Do something;
  } else {
    Do something else;
  }

We make two modifications to the user's file:
- Drop "if (x != null) {"
- Drop "} else { Do something else; }"

With this change, the first modification has a description of
NullabilityFixDescription.discardCondition and the second has a
description of NullabilityFixDescription.discardElse.  Previously,
both modifications had a description of
NullabilityFixDescription.discardElse, which was confusing.

Change-Id: I6407d7616b7a2d2c8af853ab48c3480959c4fdb9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132682
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-01-22 15:29:37 +00:00
Paul Berry 2196965729 Migration: fix unused import
Change-Id: Ifa357fa2b396a483b3193878e70b3a75d2eb5429
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132809
Auto-Submit: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-01-22 15:25:37 +00:00
Paul Berry 47950b5153 Migration: add logic to remove unnecessary "as" expressions.
Only works when the FixBuilder is enabled.

Change-Id: I9f2ee95603f9b6b247eae1ba00e817a71fc299d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132681
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-01-22 00:05:34 +00:00
Paul Berry be46dad0a7 Migration: verify that "as" expressions are allowed to be null
Change-Id: I19a8b3f3f4d9c2597b5dfbe2aaae1823c2c9cde2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132680
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-01-22 00:05:34 +00:00
Paul Berry f679efb946 Migration: make an inverse function for Variables.uniqueIdentifierForSpan.
Change-Id: Id4c9f5683b147f5f47df889b95477f6770e9c57e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132760
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-01-21 22:50:29 +00:00
Mike Fairhurst fd7bcca521 [nnbd_migration] Assign instance creation parameters to bounds
Change-Id: Ifa0d0574978f7e3e5946724f7c34a7dfa35a15b7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132448
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Mike Fairhurst <mfairhurst@google.com>
2020-01-21 18:00:57 +00:00
Mike Fairhurst cafa0dce7d [nnbd_migration] Assign implicit call type parameters to bounds
Change-Id: I777da4b32f6226eb94b96b00167925343bb1d987
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132447
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-01-21 18:00:57 +00:00
Mike Fairhurst 873777245a [nnbd_migration] assign explicit call() type-parameters to their bounds
Change-Id: I399e5d5240808ed8cf9fa0687c32e7b8e121d9bb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132446
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-01-21 18:00:57 +00:00
Paul Berry 850b89ff94 Migration: create wrapper methods for EditPlanner.surround
Addresses a concern from code review
https://dart-review.googlesource.com/c/sdk/+/129302 that
EditPlanner.surround is difficult to use correctly, by adding wrapper
methods for several common use cases that are easier to use correctly.
Also adapts fix_aggregator.dart to make use of the new methods.

EditPlanner.surround remains in the public API for EditPlanner because
there are still use cases for it that aren't supported by the wrapper
methods.  My hope is that the remaining use cases are either rare
enough or trivial enough that we don't need wrappers for them; if that
proves to be incorrect we can always add more wrapper methods.

Change-Id: Ia1d6cc8b10ffaedcf8803ff7c8f9460ada1d7c4e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132462
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-01-21 15:58:02 +00:00
Paul Berry d9dd257265 Make it easier for tests based on AnalysisContextCollectionImpl to enable NNBD.
This CL allows tests based on AnalysisContextCollectionImpl to enable
NNBD by modifying the analysis options and introduce a different
feature set, rather than having to add virtual filesystem files to
convince the analyzer that NNBD is enabled for the package.  This is
more consistent with the way we enable NNBD for other unit tests that
invoke analysis more directly, and is less sensitive to details of how
the analyzer infers the current language version.

Currently used in the migration engine's EditPlanTest, which in a
subsequent CL will need this functionality to test editing source code
that contains null checks.

Change-Id: I352fd2d7f6ee71d42f02a31714e3395567967240
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132461
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-01-21 15:58:02 +00:00
Paul Berry 48aa6470ca Migration: plumb more fix reasons through FixBuilder to instrumentation.
Now there are only two circumstances in which an AtomicEdit won't have
information about the reason for the change:

- The AtomicEdit object was associated with adding or removing parens,
  in which case we don't compute information about the reason for the
  change because it's not straightforward to compute, and it should be
  clear to the user anyway.

- Information about the reason for the change hasn't been plumbed
  through properly (this should be addressed in follow-up CLs).

Since we are rapidly approaching a situation where nearly all
AtomicEdits will have reason information, the separation between
AtomicEdit and AtomicEditWithInfo now seems silly, so I just moved the
`info` object into AtomicEdit and removed AtomicEditWithInfo entirely.

Change-Id: I61afd9cd58b71d4695685e65d0142a2693b8e6b2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132451
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-01-21 15:58:02 +00:00
Paul Berry 236d952dae Migration: fix broken reasons for dead code elimination
Change-Id: I949c41e7ecdad4e332e5a7c28e1419754de89203
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132450
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-01-21 15:58:02 +00:00
Paul Berry 5a7bb50905 Migration: generalize creation of unique IDs for source spans
Previously, we used the offset of an AST node as a unique ID to
represent it, with a special hack to make sure we can distinguish a
generic function type from its return type (which has the same
offset).  But in an upcoming CL, I will need to start associating
unique IDs with expressions, so that will bring up a whole bunch more
ambiguity.

This CL switches to a technique where we combine the offset and the
end of any source span into a single unique identifier.  The algorithm
produces an output that is no larger than the square of either input.
Since we have 64-bit integers in Dart, this should be adequate for any
reasonable input file size.

Change-Id: I68ce27533eb485cc824e1080326d02de98bff1e7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132404
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-01-21 15:58:02 +00:00
Paul Berry 31bfacfda4 Migration: change API to make use of FixBuilder's "changes" data structure.
The new FixBuilder component of the migration engine communicates the
changes it produces using a "changes" data structure of type Map<int,
List<AtomicEdit>>, and is not compatible with the old
SingleNullabilityFix class (which made the incorrect assumption that
each SourceEdit was associated with a single fix).  This CL changes
the migration engine's instrumentation API to use this data structure,
and changes its listener API to avoid reference to the
SingleNullabilityFix class.  This allows SingleNullabilityFix to be
deleted.

This required changing AtomicEditWithReason so that it can hold
multiple fix reasons, and a NullabilityFixDescription.  It does so
using a new object, AtomicEditInfo, and AtomicEditWithReason is
renamed to AtomicEditWithInfo.

In addition, the old FixInfo class is removed, since it carries the
same information as the new AtomicEditWithInfo class.

This required deleting the "incremental workflow" functionality from
UnitRenderer.  This functionality was disabled, and I believe it
wouldn't have worked anyway (since it, too, made the incorrect
assumption that each SourceEdit was associated with a single fix).

Change-Id: Id965cfd803b408c66f15436017b87fc3e46521c6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132306
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-01-19 16:50:01 +00:00
Paul Berry 0b4fda7243 Migration: adapt instrumentation tests to test FixBuilder integration.
Change-Id: Ifaa471d881984c466bb07be17c48baf5be0175e8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132170
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-01-17 20:47:16 +00:00
Paul Berry 5dff804997 Migration: handle code changes within a non-dead branch of an if.
The FixBuilder implemenation is now at feature parity with the
non-FixBuilder implementation when testing with api_test.dart, except
for one test of extension functionality (which doesn't seem worth
fixing right now, since extensions are still so rarely used).

Change-Id: I89df7ec388824fa9f4181706bfadbaeb232d2b5f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132169
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-01-17 20:47:16 +00:00
Paul Berry f656cad5f4 Migration: add support for converting @required to required.
Support only exists in the FixBuilder.

Change-Id: I921bd40058fb3b10321fbccf8eae61e02473ff4e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132220
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-01-17 20:47:16 +00:00
Paul Berry cacfb70f7b Migration: further support for adding ?s to types in FixBuilder.
Previously, we tried to hook in to the resolver so that every time it
tried to check the type of a TypeAnnotation, the FixBuilder would see
if it needed to add a `?` to it before letting the resolver continue.
This was clumsy and didn't catch all the TypeAnnotations.  This CL
changes to a simpler technique where we simply visit all
TypeAnnotations, making note of where we need to add `?`s and updating
types, prior to re-running resolution.

Change-Id: Idf5ba286415fb2b90e2cd1d5ba3635b6b559aef6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132164
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-01-17 20:47:16 +00:00
Janice Collins f96c48307d First version of the ecosystem steamroller.
This creates a editable repository workspace of the transitive dev
dependencies of a given pub package, assuming that package and its
dependencies are either stored at github under dart-lang/[package_name],
or special knowledge has been hardcoded into the script.

Tested on 'collection'.  Packages in its transitive dev dependencies
are likely to work, others probably not.

Bug: https://github.com/dart-lang/sdk/issues/40173
Change-Id: I7c8f0d06a7d8eb1160957c3832f11b37a11ade98
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131947
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Janice Collins <jcollins@google.com>
2020-01-17 18:18:09 +00:00
Paul Berry f1df196ddf Migration: add FixBuilder support for enums
Change-Id: I2ab1fa367d17f827cd229ebfa0f1e7a055134ed7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131944
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-01-16 22:03:48 +00:00
Paul Berry b0786edaba Migration: additional support for collection literals.
In particular, we now properly propagate changes to explicit type
arguments down into the collection elements.

Change-Id: Ia3f5fbc0679b7d5d561c1243d28ff6148b85a941
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131942
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-01-16 22:03:48 +00:00
Paul Berry 37753f016c Add methods to CollectionElementProvider to get type arguments of typed literals.
We will need to hook into this for migration as well, because the type
arguments of typed literals will be changed by migration from star
types to either nullable or non-nullable types.

Change-Id: Ie721390effd9cf733b9f977c1ba729f6fc4b2ebb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131920
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2020-01-16 22:03:48 +00:00
Paul Berry 3af7abc78b Migration: Remove source parameter from MigrationResolutionHooks API.
The source is already known to the FixBuilder, so it is redundant.

Change-Id: Iafafd6514bbe469ebc2136a65984b388f5c64342
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131881
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-01-16 22:03:48 +00:00
Paul Berry fa02e7d8cd Migration: add collection element caching to MigrationResolutionHooksImpl.
This should make the fix builder faster, since TypedLiteralResolver
has to query the elements of various collections multiple times.

Change-Id: If49317b8e095b49b693e8a4885914a631efd6d2e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131844
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-01-16 22:03:48 +00:00
Paul Berry 3f02e7d749 Migration: add FixBuilder support for generic function type annotations.
Change-Id: Ifca6d611da8d95cfc243c32a3af8bd3a1f03bd54
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131880
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-01-16 22:03:48 +00:00
Paul Berry 2b756f6b02 Migration: add FixBuilder support for IfElement.
One minor issue remains: when dead code elimination causes a
collection to become empty, migration should insert explicit type
parameter(s) to ensure that the empty collection will still get
analyzed as having the right type.  This is noted in TODO comments.

Change-Id: Ibed25f6cb8ed9eec3ddccb0444178960c6b35c84
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131843
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-01-16 06:45:35 +00:00
Mike Fairhurst 689e0feab2 [nnbd_migration] Mark implicit dynamic for type params as nullable
Looks like we used to do this, but we stopped when we started changing
this pattern:

```
dynamic x = 1;
int y = x;
```

Our first iteration treated `dynamic` as nullable all the time. This is
not ideal in the example above. So we went back and instead began
treating `dynamic` as nullable only when it was observed to have a null
value.

However, in the case of unbounded type parameters:

```
class C<T> {}
```

We don't want to wait to observe:

```
C<Object> o = C(null);
```

before treating the bound as nullable.

Change-Id: I50b8ca6188d82cd62f795ada99a355afe2eae771
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131714
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Mike Fairhurst <mfairhurst@google.com>
2020-01-15 19:50:16 +00:00
Paul Berry 8ff8fdb1c2 Migration: small simplification to _PassThroughBuilderImpl.
Instead of storing planIndex in the class (which makes it hard to
follow what methods are expected to update it, and consequently hard
to tell that _processPlans will process each plan exactly once), pass
it between _processPlans and _handleRemoveEditPlans so that it's
clearer how it is updated.

Change-Id: I1b03ad2b8bb0ae5e488d02827d2a4a56f37ede21
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131711
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-01-15 13:00:53 +00:00
Paul Berry d1a7c25b38 Migration: test removal of all list elements when there is a trailing separator
Change-Id: I35e98c967b18b9585f0cd0e08af8957120a27320
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131710
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-01-15 13:00:53 +00:00
Paul Berry fc8a02ee3c Pass TypeSystem and TypeProvider into TypedLiteralResolver.
Previously, TypedLiteralResolver obtained them from the library, but
this didn't work when the resolver was invoked by the migration tool,
because the migration tool needed to re-run migration of a non-NNBD
library using the NNBD TypeProvider and TypeResolver.

Change-Id: I73acca120a726c773c2e08b65d1227531a5fd2e1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131704
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-01-14 20:41:23 +00:00
Paul Berry 9786c9c063 Migration: wire up elimination of dead if branches to FixBuilder.
Change-Id: I317c2476aa21e556333729893872b937a46a82e4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131583
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-01-14 20:41:23 +00:00
Paul Berry a57350be7b Migration: Add logic to FixAggregator to eliminate dead "if" branches.
Change-Id: Icfe62535f588c691086835ae22c80b49191be514
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131581
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-01-14 20:41:23 +00:00
Paul Berry 1eb5f10c27 Migration: add the ability to create EditPlans that remove source code.
This will allow for dead code elimination.

Change-Id: I128dddcfe5e83dde351512ebffb14ea7088c8b9e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131540
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-01-14 20:41:23 +00:00
Paul Berry da2a3aee27 Migration: Add tests for the algorithm used by EditPlaner.passThrough.
Change-Id: Ie405bb95d735f96eb4605558a9ed22d4877f150a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131484
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-01-14 20:41:23 +00:00
Paul Berry 6bee2660eb Migration: Remove _incorporateParent method.
We no longer need this--all of its functionality is now implemented in
EditPlanner.passThrough.

Change-Id: I54c1b22fed99443b8ca3844bea1903c48a5f36eb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131460
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-01-14 20:41:23 +00:00
Paul Berry 2c121e4ecd Migration: modify pass through edit plans to integrate up the tree stepwise.
Consider a generic AST structure like this:

   A
  / \
 B   C
    / \
   D   E

Previously, if we wanted to build a "pass through" edit plan for A,
incorporating inner plans representing changes to be made to B, D, and
F, we would do the following: (1) pass each inner plan through the
_incorporateParent function, which might leave it unchanged or might
produce a plan targeted at the parent node, and then (2) ask each
inner plan for its set of changes, and produce a new plan for A
containing those changes.

The purpose of step (1) was to allow an edit plan to describe changes
that might affect the node above it.  For example, changing an
expression might cause the parentheses surrounding it to become
unnecessary, so those parentheses would be removed (that's the case
that's currently implemented).  Or, removing a list element from a
list might necessitate adjusting the comma before or after it, which
belongs to the parent node (this isn't implemented yet).

This had a design flaw: step (1) might produce overlapping changes.
For instance, calling _incorporateParent on the plans for D and E
might conceivably both plans for C, and those plans might try to make
overlapping (and thus incompatible) changes to node C.

It turns out that this isn't a problem for eliminating unnecessary
parens, because it's impossible for two edit plans to target two
different non-overlapping AST nodes whose parents are both the same
ParenthesizedExpression node (because a ParenthesizedExpression has
only one child).  But it will be a problem for removing elements
lists, statements from blocks, declarations from classes, etc.

The new strategy is that we will bubble inner plans up the tree one
level at a time.  In the example above, we would first combine the
inner plans for D and E into a pass through plan for C.  Then we would
combine the plans for B and C into a plan for A.  This is a bit more
work, but I believe it can be made efficient in typical use cases, and
it will avoid the problem described above because at each stage, all
the inner plans we combine will have the same parent, so it will be
tractable to figure out their interactions with each other.

Some vestiges of the old _incorporateParent approach still remain; I
plan to remove them in a follow-up CL.

Change-Id: I9ecbdb1549b949177ffc5d66447d4aede77e2dd9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131400
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-01-13 23:26:33 +00:00
Brian Wilkerson c8f2683ebc Add a reason to the MakeNullable change and plumb it through to the AtomicEdit
Change-Id: I5a0a258b07e12fa9a43efc219c1af0c021380716
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/130939
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-01-13 21:20:58 +00:00
Konstantin Shcheglov 489c0be893 Extract PostfixExpressionResolver.
Change-Id: I915453f32d65f74e2ec12dd65bd17620bbb7d4ce
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131220
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-01-12 17:53:24 +00:00
Konstantin Shcheglov bd018fbd1a Issue 39694. LHS of ?? should be inferred with a nullable context.
Bug: https://github.com/dart-lang/sdk/issues/39694
Change-Id: I481a8792b0c3587a505263f52f65e7cc4fc4f067
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131210
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-01-11 21:14:22 +00:00
Paul Berry 9b0cf08847 Split EditPlan into a base and derived class.
The derived class, NodeProducingEditPlan, represents an edit plan
whose effect will be to transform the source AST node into another AST
node (e.g. replace an expression with one of its subexpressions).  The
base class, EditPlan, will be able to represent more general kinds of
edit plans.

Future CLs will introduce edit plans that don't result in an AST node,
e.g. an edit plan that removes a source statement or a collection
element, or an edit plan that replaces one source statement or
collection element with several.

Change-Id: I01455f643b858c6500d864be679b12768029cffb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/130941
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-01-10 22:10:32 +00:00
Brian Wilkerson c75e2796f1 Make AtomicEdit concrete and remove subclasses
Change-Id: Iff7d591e8278cae074f76ca2e8cf561503bf4149
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131120
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2020-01-10 21:06:41 +00:00
Paul Berry 38453843fb Migration: annotate API tests that assume dead code is commented out.
In later CL's, I will make it possible for dead code to be deleted
instead of commented out.  This change prepares for that, by
explicitly noting which API tests assume that dead code is commented
out.

Change-Id: I4e0ff6f1de4c0ab5fda050956944725b2d23dc5e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/130931
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-01-10 20:42:32 +00:00
Mike Fairhurst 693c3c444d [nnbd_migration] Make list constructor nullable if specified length
Change-Id: Ia65768ddf6c7da11a44b362d3c99cc0372a14e84
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/130891
Commit-Queue: Mike Fairhurst <mfairhurst@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-01-10 20:41:01 +00:00