[dart2js] Cleanup ImpactCacheDeleter.

This cl mostly just removes indirection around clearing the Impact cache.
However, there is one minor logic change, today we clear the impact cache
before calling DeferredLoadTask._buildResult, but after this cl the
impact cache is cleared by its owner(Compiler) in the compiler pipeline
itself.

Change-Id: I5845b786887f861c61a0ac79a3c8f2de2a3a2a14
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232026
Reviewed-by: Mark Zhou <markzipan@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
diff --git a/pkg/compiler/lib/src/compiler.dart b/pkg/compiler/lib/src/compiler.dart
index 4c636e3..f8d3873 100644
--- a/pkg/compiler/lib/src/compiler.dart
+++ b/pkg/compiler/lib/src/compiler.dart
@@ -73,7 +73,6 @@
   BackendStrategy backendStrategy;
   CompilerDiagnosticReporter _reporter;
   Map<Entity, WorldImpact> _impactCache;
-  ImpactCacheDeleter _impactCacheDeleter;
 
   ImpactStrategy impactStrategy = const ImpactStrategy();
 
@@ -98,7 +97,6 @@
 
   DiagnosticReporter get reporter => _reporter;
   Map<Entity, WorldImpact> get impactCache => _impactCache;
-  ImpactCacheDeleter get impactCacheDeleter => _impactCacheDeleter;
 
   final Environment environment;
 
@@ -170,7 +168,6 @@
         kernelFrontEndTask, options, reporter, environment);
     backendStrategy = createBackendStrategy();
     _impactCache = <Entity, WorldImpact>{};
-    _impactCacheDeleter = _MapImpactCacheDeleter(_impactCache);
 
     if (options.showInternalProgress) {
       progress = InteractiveProgress();
@@ -437,7 +434,7 @@
     // this until after the resolution queue is processed.
     deferredLoadTask.beforeResolution(rootLibraryUri, libraries);
 
-    impactStrategy = JavaScriptImpactStrategy(impactCacheDeleter, dumpInfoTask,
+    impactStrategy = JavaScriptImpactStrategy(dumpInfoTask,
         supportDeferredLoad: deferredLoadTask.isProgramSplit,
         supportDumpInfo: options.dumpInfo);
 
@@ -469,8 +466,7 @@
     _userCodeLocations
         .addAll(result.moduleLibraries.map((module) => CodeLocation(module)));
     selfTask.measureSubtask('runModularAnalysis', () {
-      impactStrategy = JavaScriptImpactStrategy(
-          impactCacheDeleter, dumpInfoTask,
+      impactStrategy = JavaScriptImpactStrategy(dumpInfoTask,
           supportDeferredLoad: true, supportDumpInfo: true);
       var included = result.moduleLibraries.toSet();
       var elementMap = (frontendStrategy as KernelFrontendStrategy).elementMap;
@@ -590,6 +586,11 @@
 
     KClosedWorld kClosedWorld = resolutionWorldBuilder.closeWorld(reporter);
     OutputUnitData result = deferredLoadTask.run(mainFunction, kClosedWorld);
+
+    // Impact data is no longer needed.
+    if (!retainDataForTesting) {
+      _impactCache.clear();
+    }
     JClosedWorld jClosedWorld =
         backendStrategy.createJClosedWorld(kClosedWorld, result);
     return jClosedWorld;
@@ -626,9 +627,6 @@
       emptyQueue(enqueuer, onProgress: onProgress);
       enqueuer.queueIsClosed = true;
       enqueuer.close();
-      // Notify the impact strategy impacts are no longer needed for this
-      // enqueuer.
-      impactStrategy.onImpactUsed(enqueuer.impactUse);
       assert(compilationFailed ||
           enqueuer.checkNoEnqueuedInvokedInstanceMethods(elementEnvironment));
     });
@@ -1066,23 +1064,6 @@
   }
 }
 
-class _MapImpactCacheDeleter implements ImpactCacheDeleter {
-  final Map<Entity, WorldImpact> _impactCache;
-  _MapImpactCacheDeleter(this._impactCache);
-
-  @override
-  void uncacheWorldImpact(Entity element) {
-    if (retainDataForTesting) return;
-    _impactCache.remove(element);
-  }
-
-  @override
-  void emptyCache() {
-    if (retainDataForTesting) return;
-    _impactCache.clear();
-  }
-}
-
 class _EmptyEnvironment implements Environment {
   const _EmptyEnvironment();
 
diff --git a/pkg/compiler/lib/src/deferred_load/deferred_load.dart b/pkg/compiler/lib/src/deferred_load/deferred_load.dart
index 503c1bb..6aeafcd 100644
--- a/pkg/compiler/lib/src/deferred_load/deferred_load.dart
+++ b/pkg/compiler/lib/src/deferred_load/deferred_load.dart
@@ -445,10 +445,6 @@
     }
 
     reporter.withCurrentElement(main.library, () => measure(work));
-
-    // Notify that we no longer need impacts for deferred load, so they can be
-    // discarded at this time.
-    compiler.impactStrategy.onImpactUsed(DeferredLoadTask.IMPACT_USE);
     return _buildResult();
   }
 
diff --git a/pkg/compiler/lib/src/dump_info.dart b/pkg/compiler/lib/src/dump_info.dart
index f7c4faf..38b59d0 100644
--- a/pkg/compiler/lib/src/dump_info.dart
+++ b/pkg/compiler/lib/src/dump_info.dart
@@ -666,9 +666,6 @@
       }
     }
 
-    // Notify the impact strategy impacts are no longer needed for dump info.
-    compiler.impactStrategy.onImpactUsed(IMPACT_USE);
-
     // Track dependencies that come from inlining.
     for (Entity entity in inlineMap.keys) {
       CodeInfo outerInfo = infoCollector._entityToInfo[entity];
diff --git a/pkg/compiler/lib/src/frontend_strategy.dart b/pkg/compiler/lib/src/frontend_strategy.dart
index 1edd506..3fc6ccc 100644
--- a/pkg/compiler/lib/src/frontend_strategy.dart
+++ b/pkg/compiler/lib/src/frontend_strategy.dart
@@ -64,16 +64,3 @@
 
   void extractJsInteropAnnotations(LibraryEntity library);
 }
-
-/// Class that deletes the contents of an [WorldImpact] cache.
-// TODO(redemption): this can be deleted when we sunset the old front end.
-abstract class ImpactCacheDeleter {
-  /// Removes the [WorldImpact] for [element] from the resolution cache. Later
-  /// calls to [getWorldImpact] or [computeWorldImpact] returns an empty impact.
-  void uncacheWorldImpact(Entity element);
-
-  /// Removes the [WorldImpact]s for all [Element]s in the resolution cache. ,
-  /// Later calls to [getWorldImpact] or [computeWorldImpact] returns an empty
-  /// impact.
-  void emptyCache();
-}
diff --git a/pkg/compiler/lib/src/js_backend/backend.dart b/pkg/compiler/lib/src/js_backend/backend.dart
index 164d917..f9e007c 100644
--- a/pkg/compiler/lib/src/js_backend/backend.dart
+++ b/pkg/compiler/lib/src/js_backend/backend.dart
@@ -10,7 +10,6 @@
 import '../dump_info.dart' show DumpInfoTask;
 import '../elements/entities.dart';
 import '../enqueue.dart' show ResolutionEnqueuer;
-import '../frontend_strategy.dart';
 import '../inferrer/types.dart';
 import '../js_model/elements.dart';
 import '../tracer.dart';
@@ -263,12 +262,11 @@
 }
 
 class JavaScriptImpactStrategy extends ImpactStrategy {
-  final ImpactCacheDeleter impactCacheDeleter;
   final DumpInfoTask dumpInfoTask;
   final bool supportDeferredLoad;
   final bool supportDumpInfo;
 
-  JavaScriptImpactStrategy(this.impactCacheDeleter, this.dumpInfoTask,
+  JavaScriptImpactStrategy(this.dumpInfoTask,
       {this.supportDeferredLoad, this.supportDumpInfo});
 
   @override
@@ -291,13 +289,6 @@
       impact.apply(visitor);
     }
   }
-
-  @override
-  void onImpactUsed(ImpactUseCase impactUse) {
-    if (impactUse == DeferredLoadTask.IMPACT_USE) {
-      impactCacheDeleter.emptyCache();
-    }
-  }
 }
 
 /// Interface for resources only used during code generation.
diff --git a/pkg/compiler/lib/src/universe/world_impact.dart b/pkg/compiler/lib/src/universe/world_impact.dart
index 19fe89f..7368e456 100644
--- a/pkg/compiler/lib/src/universe/world_impact.dart
+++ b/pkg/compiler/lib/src/universe/world_impact.dart
@@ -323,12 +323,6 @@
     // Apply unconditionally.
     impact.apply(visitor);
   }
-
-  /// Notifies the strategy that no more impacts of [impactUseCase] will be
-  /// applied.
-  void onImpactUsed(ImpactUseCase impactUseCase) {
-    // Do nothing.
-  }
 }
 
 /// Visitor used to process the uses of a [WorldImpact].