[dartdevc] Retry ddc incremental compile on crash

Change-Id: I00c2eb1b3bc6d9153fd2e88a8074e5670a0e082e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/99442
Reviewed-by: Jake Macdonald <jakemac@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Jenny Messerly <jmesserly@google.com>
Commit-Queue: Vijay Menon <vsm@google.com>
diff --git a/pkg/dev_compiler/bin/dartdevc.dart b/pkg/dev_compiler/bin/dartdevc.dart
index fbe7114..1075043 100755
--- a/pkg/dev_compiler/bin/dartdevc.dart
+++ b/pkg/dev_compiler/bin/dartdevc.dart
@@ -56,6 +56,18 @@
             ZoneSpecification(print: (self, parent, zone, message) {
       output.writeln(message.toString());
     }));
+
+    if (lastResult.crashed && context != null) {
+      // TODO(vsm): See https://github.com/dart-lang/sdk/issues/36644.
+      // If the CFE is crashing with previous state, then clear compilation
+      // state and try again.
+      output.clear();
+      lastResult = await runZoned(() => compile(args, previousResult: null),
+          zoneSpecification:
+              ZoneSpecification(print: (self, parent, zone, message) {
+        output.writeln(message.toString());
+      }));
+    }
     return WorkResponse()
       ..exitCode = lastResult.success ? 0 : 1
       ..output = output.toString();