Fixed issue where KernelIsolate::AcceptCompilation was being called even when no compilation was done. Fixes #32145.

Change-Id: I043484560b77548cf33847e0d57c6e89a8a178f3
Reviewed-on: https://dart-review.googlesource.com/41025
Reviewed-by: Alexander Markov <alexmarkov@google.com>
diff --git a/runtime/vm/isolate_reload.cc b/runtime/vm/isolate_reload.cc
index 697c75d..6db3341 100644
--- a/runtime/vm/isolate_reload.cc
+++ b/runtime/vm/isolate_reload.cc
@@ -521,6 +521,16 @@
   free(buffer);
 }
 
+static void AcceptCompilation(Thread* thread) {
+  TransitionVMToNative transition(thread);
+  if (KernelIsolate::AcceptCompilation().status !=
+      Dart_KernelCompilationStatus_Ok) {
+    FATAL(
+        "An error occurred in the CFE while accepting the most recent"
+        " compilation results.");
+  }
+}
+
 // NOTE: This function returns *after* FinalizeLoading is called.
 void IsolateReloadContext::Reload(bool force_reload,
                                   const char* root_script_url,
@@ -560,6 +570,7 @@
     packages_url = String::New(packages_url_);
   }
 
+  bool did_kernel_compilation = false;
   if (isolate()->use_dart_frontend()) {
     // Load the kernel program and figure out the modified libraries.
     const GrowableObjectArray& libs =
@@ -593,7 +604,7 @@
         CommonFinalizeTail();
         return;
       }
-
+      did_kernel_compilation = true;
       kernel_program.set(
           ReadPrecompiledKernelFromBuffer(retval.kernel, retval.kernel_size));
     }
@@ -612,14 +623,12 @@
     I->object_store()->set_changed_in_last_reload(
         GrowableObjectArray::Handle(GrowableObjectArray::New()));
     ReportOnJSON(js_);
-    if (isolate()->use_dart_frontend()) {
-      TransitionVMToNative transition(thread);
-      if (KernelIsolate::AcceptCompilation().status !=
-          Dart_KernelCompilationStatus_Ok) {
-        FATAL(
-            "An error occurred in the CFE while accepting the most recent"
-            " compilation results.");
-      }
+
+    // If we use the CFE and performed a compilation, we need to notify that
+    // we have accepted the compilation to clear some state in the incremental
+    // compiler.
+    if (isolate()->use_dart_frontend() && did_kernel_compilation) {
+      AcceptCompilation(thread);
     }
     TIR_Print("---- SKIPPING RELOAD (No libraries were modified)\n");
     return;
@@ -681,12 +690,12 @@
       isolate()->object_store()->set_root_library(lib);
       FinalizeLoading();
       result = Object::null();
-      TransitionVMToNative transition(thread);
-      if (KernelIsolate::AcceptCompilation().status !=
-          Dart_KernelCompilationStatus_Ok) {
-        FATAL(
-            "An error occurred in the CFE while accepting the most recent"
-            " compilation results.");
+
+      // If we use the CFE and performed a compilation, we need to notify that
+      // we have accepted the compilation to clear some state in the incremental
+      // compiler.
+      if (did_kernel_compilation) {
+        AcceptCompilation(thread);
       }
     } else {
       result = tmp.raw();