Commit Graph

23 Commits

Author SHA1 Message Date
Paul Berry 1f794f000e Migration: do not propagate exact nullability in violation of a /*!*/ hint.
Fixes #41228.

Bug: https://github.com/dart-lang/sdk/issues/41228
Change-Id: I9c7e7554cee08d9f8f2241ff627bab7cbb16f4da
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/141801
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-03-31 22:04:46 +00:00
Paul Berry 244b4247e9 Migration: better description text for edges.
Change-Id: I58651c927a741721283c3c4c951673a86aa7a1b3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140883
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-03-25 19:38:34 +00:00
Paul Berry fcefb8258e Migration: switch graph propagation to breadth first rather than depth first.
Breadth first is theoretically slightly slower due to less locality of
reference, however it has the benefit of ensuring that the user sees
the shortest possible trace when investigating the cause of a change.
Without this change, it's possible to get some really confusing
traces, e.g. a trace suggesting that a type in some
previously-migrated library is nullable due to a cause within the
library currently being migrated.

This CL also adds tracking of why a node was determined to have
non-null intent, which I plan to expose to the user in follow-up CLs.

Change-Id: I43025ca0ab825d178a28555f85ad9eea43eadfe9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/139140
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-03-12 19:32:36 +00:00
Paul Berry 2ec127a305 Migration: give nullability nodes human-readable names.
Change-Id: I86b510c6cc9afacb7d720af214c8f4e5a311c9ff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138885
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-03-11 15:20:59 +00:00
Paul Berry a74253987b Migration: add trace functionality to the preview tool.
This establishes the base functionality.  A lot of follow-up work is
needed from here:

- Each trace should have an entry at the top of it pointing to the
  thing that was made nullable.

- The source code links in traces don't include lengths, so we can't
  highlight whole identifiers when the user clicks on a link.

- Description strings are currently generated by running toString() on
  the individual nullability nodes and edges, resulting in long-winded
  and useless descriptions.

Change-Id: Ibb370bae6bedc7a8c86092462785023002a48ac3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138481
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-03-05 17:21:54 +00:00
Paul Berry eec7876eb2 Migration: prototype a "stacktrace-like" display of the principal cause of a nullability decision.
The principal cause may be displayed by invoking the "postmortem" tool
using the "trace" subcommand, followed by the id of the node for which
a trace is desired.

Change-Id: I5868b4bc979320bb46698b02c7b43b317205c487
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/137429
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-03-03 01:24:17 +00:00
Paul Berry 2fa27b5d57 Introduce a "postmortem output" for nullability migration.
The postmortem output is currently only generated if the static
constant NullabilityMigrationImpl._postmortemPath is non-null.  The
generated file can be analyzed using
pkg/nnbd_migration/tool/postmortem.dart.

Change-Id: Ic5bf7aecc4176306839c00237eed668c2cd42571
Bug: https://github.com/dart-lang/sdk/issues/40624
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136003
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-02-19 16:44:40 +00:00
Paul Berry d5e6ab4195 Migration: propagate non-null intent through compound nodes.
A compound node represents a logical OR ("this node is nullable if and
only if one or more of its components is nullable").  Therefore, if
*all* of the components of a compound node have non-null intent, we
should consider the compound node itself to have non-null intent.
This fixes a problem that was preventing the migration tool from
respecting a "/*!*/" hint applied to the type parameter of a typedef.

Change-Id: Iec2f9d6968378707ba692be7b97f750cf53a8b85
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135786
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-02-14 21:25:01 +00:00
Mike Fairhurst 89db9ec241 [nnbd_migration] Only propagate exact nullability over uncheckable edges
Bug: 40551, 40552
Change-Id: Ib62dd2d9d1685956e3bf6f63a318888f3cd43904
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135762
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Mike Fairhurst <mfairhurst@google.com>
2020-02-14 18:57:47 +00:00
Paul Berry da5ab8ce00 Separate graph propagation state and results out to their own class.
This serves two purposes:

1. It makes it easier to be confident that we're resetting the
   necessary state when re-running graph computation in
   `NullabilityGraph.update`.

2. I'm planning some changes to the graph propagation algorithm (in an
   upcoming CL).  Having the propagation state separate from the rest
   of the graph state will make it easier to reason about these
   changes.

Change-Id: I5e101bbce6e5ad382dd754bfbb9b72e20df23fd1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/133337
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-01-28 13:26:47 +00:00
Paul Berry f525ddeaf3 Add/fix return types to NNBD migration tests.
This will be necessary in order to pass pedantic lints.  See
discussion in https://dart-review.googlesource.com/c/sdk/+/129325.

Change-Id: I61011a082a5401401fa1b7bb0d0bd7aed87a9d10
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129800
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-12-27 18:13:15 +00:00
Mike Fairhurst e34e734b56 [nnbd_migration] track causations for substitution nodes
Change-Id: I7da4f2923d9b99b0bd6c16644a7adeaeda437340
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125463
Reviewed-by: Paul Berry <paulberry@google.com>
2019-11-18 18:49:39 +00:00
Paul Berry 233189e598 Migration: clean up EdgeOrigin class hierarchy.
This CL combines the EdgeOrigin and EdgeOriginWithLocation classes, so
that all EdgeOrigin objects are associated with source locations.  And
it separates the EdgeOrigin and PotentialModification roles of the
ExpressionChecks class into two separate classes.

This will enable a follow-up CL that switches the EdgeOrigin class
over to track source locations via AST nodes rather than offsets,
which will in turn allow rich information to be delivered to the
client about how the nullability graph relates to source code.

Change-Id: I736f60f93681fbbfbd5f9ee9a5589f99f819b9aa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/117282
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-09-16 18:31:08 +00:00
Paul Berry 32e27f68dc Migration: Add the ability to use null for nullability nodes in substitutions.
A nullability node of `null` will be discarded during a substitution.
For instance, attempting to substitute `T=int?null` into `T?1` will
produce `int?1`, rather than `int?2` where `2` is a substitution node.
We will need this functionality in order to compare function types for
equality, which is in turn needed to integrate with flow analysis.

Change-Id: Ife5e3761b083d4584b2aff760dcb104529e7f9d4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112745
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-08-12 19:05:00 +00:00
Paul Berry 621b96f97b Migration: begin adding infrastructure for reporting unsatisfiable substitutions.
Change-Id: I290da86cfdae3d6cfa83032999eaba17a65acd14
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112044
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-08-09 14:07:42 +00:00
Paul Berry 776f2d34e9 Migration: implement "exact nullability" propagation.
This allows us to properly handle contraviariant uses of generics,
where the nullability of a generic parameter needs to be propagated in
the reverse of the usual dependency direction.

Change-Id: Id31f906bb7e3fbbf0846144a4715b9a6591aceda
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/111303
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-07-31 03:56:28 +00:00
Paul Berry 8c699b96e5 Migration: fix some erroneous comments in nullability node test.
These comments were copy/pasted from other tests and weren't properly
updated.

Change-Id: Ib1a0279184bb8dbaeb3601676d24301728a812a8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/111302
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-07-30 18:13:30 +00:00
Paul Berry ea4eaaa145 Migration: Allow edges to be queried to see if they're satisfied.
Change-Id: I9da0233dfbac0c7aee168622c554d003c2c5e16c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106382
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-06-17 21:06:21 +00:00
Paul Berry 5167499427 Migration: record the "origin" of each edge in the NullabilityEdge object.
This paves the way for being able to explain to the user exactly why
the migration tool made any given nullability decision.

Change-Id: I553e4881fdb37b238a066fcfba7c21ae919d7d6e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106381
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-06-17 21:06:21 +00:00
Paul Berry 58664602a5 Change NullabilityGraph.propagate to return a list of unsatisfied edges.
In follow-up CLs this should allow us to simplify the generation of
fixes (since each fix is associated with one or more unsatisfied
edges) and to streamline tests.

Change-Id: I997f704aac41f270756adcdf8d382fb2263273eb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106180
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-06-15 12:55:00 +00:00
Paul Berry 3f83aeb493 Migration: add the ability to "union" nullability nodes.
This will simplify some situations where nullability migration would
otherwise have to visit the source code in a very careful order.  For
example, when analyzing top level fields undergoing type inference, we
can simply create a node for the nullability of each top level field,
and then later use the "union" operation to hook up those nodes to the
nodes resulting from analyzing their initializers.  Without the union
operation, we would have to be careful to visit the top level fields
in dependency order.

Change-Id: I3b07e1abccc5b1c9f1c7c9fa7b13fb6af60c07d6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/105800
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-06-12 20:10:24 +00:00
Paul Berry 0b5e37a429 Migration: Make always/never instance fields of the nullability graph.
Previously, they were static, which made them easier to access, but
made it difficult to track their edges (because we couldn't safely
mutate them, so we had to store their edges in special fields of
NullabilityGraph).  Now that we're passing NullabilityGraph all over
the place anyhow, there's no benefit to making them static anymore.

Change-Id: Ia3e7d32ae479f40f505621e5d6df04060e39b1c7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/105723
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-06-12 20:10:24 +00:00
Paul Berry b385528fee Migration: Write unit tests for NullabilityGraph.
Change-Id: I7d3ab1bde98ff28203dc73d61ecdc77e8fed25f3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/105682
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-06-12 13:34:57 +00:00