Migration: Improvements to graph debug output.

Two minor fixes:

- Ensure that the immutable nodes `always` and `never` are always
  drawn with the `shape=none` attribute.  (Previously, the first time
  we encountered an immutable node we would draw it in the style of a
  mutable node, which made things very confusing).

- Add a space before `style=filled` in the graphviz output.
  Previously we would output things like
  `n21 [label="type(13) (ordinary nullable)"style=filled]`,
  which graphviz seems to do ok with but seems inadvisable.

Change-Id: Iefcb4005c9bb2e24ae8d80552e5e4a23ec062c56
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/133868
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
This commit is contained in:
Paul Berry 2020-01-30 21:33:12 +00:00 committed by commit-bot@chromium.org
parent ab6d0ef178
commit aa5a5ff5a8

View file

@ -248,22 +248,24 @@ class NullabilityGraph {
Map<NullabilityNode, String> shortNames = {};
int counter = 0;
String nameNode(NullabilityNode node) {
if (node.isImmutable) {
var name = 'n${counter++}';
print(' $name [label="$node" shape=none]');
return name;
}
var name = shortNames[node];
if (name == null) {
shortNames[node] = name = 'n${counter++}';
String styleSuffix = node.isNullable ? 'style=filled' : '';
String styleSuffix = node.isNullable ? ' style=filled' : '';
String intentSuffix =
node.nonNullIntent.isPresent ? ', non-null intent' : '';
print(
' $name [label="$node (${node._nullability}$intentSuffix)"$styleSuffix]');
String label = '$node (${node._nullability}$intentSuffix)';
print(' $name [label="$label"$styleSuffix]');
if (node is _NullabilityNodeCompound) {
for (var component in node._components) {
print(' ${nameNode(component)} -> $name [style=dashed]');
}
}
} else if (node.isImmutable) {
shortNames[node] = name = 'n${counter++}';
print(' $name [label="$node" shape=none]');
}
return name;
}