[ddc] Delete old const canonicalization logic

There are only two consts in the SDK that triggered this code
path and they work fine with the standard const table canonicalization.

Change-Id: Ic3eb8f9c906869a6868eccccb455a46b7a873436
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/376021
Reviewed-by: Mark Zhou <markzipan@google.com>
Auto-Submit: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
diff --git a/pkg/dev_compiler/lib/src/compiler/shared_compiler.dart b/pkg/dev_compiler/lib/src/compiler/shared_compiler.dart
index ba51d59..6a93055 100644
--- a/pkg/dev_compiler/lib/src/compiler/shared_compiler.dart
+++ b/pkg/dev_compiler/lib/src/compiler/shared_compiler.dart
@@ -374,40 +374,6 @@
     return js.call('#.# = #', args);
   }
 
-  /// Caches a constant (list/set/map or class instance) in a variable, so it's
-  /// only canonicalized once at this location in the code, which improves
-  /// performance.
-  ///
-  /// This method ensures the constant is not initialized until use.
-  ///
-  /// The expression [jsExpr] should contain the already-canonicalized constant.
-  /// If the constant is not canonicalized yet, it should be wrapped in the
-  /// appropriate call, such as:
-  ///
-  /// - dart.constList (for Lists),
-  /// - dart.constMap (for Maps),
-  /// - dart.constSet (for Sets),
-  /// - dart.const (for other instances of classes)
-  ///
-  /// [canonicalizeConstObject] can be used for class instances; it will wrap
-  /// the expression in `dart.const` and then call this method.
-  ///
-  /// If the same constant is used elsewhere (in this module, or another
-  /// module), that will require a second canonicalization. In general it is
-  /// uncommon to define the same large constant (such as lists, maps) in
-  /// different locations, because that requires copy+paste, so in practice this
-  /// optimization is rather effective (we should consider caching once
-  /// per-module, though, as that would be relatively easy for the compiler to
-  /// implement once we have a single Kernel backend).
-  @protected
-  js_ast.Expression cacheConst(js_ast.Expression jsExpr) {
-    if (currentFunction == null) return jsExpr;
-
-    var temp = js_ast.TemporaryId('const');
-    moduleItems.add(js.statement('let #;', [temp]));
-    return js.call('# || (# = #)', [temp, temp, jsExpr]);
-  }
-
   /// Emits a Dart Symbol with the given member [symbolName].
   ///
   /// If the symbol refers to a private name, its library will be set to the
@@ -437,7 +403,7 @@
   /// constant instance of a user-defined class stored in [expr].
   @protected
   js_ast.Expression canonicalizeConstObject(js_ast.Expression expr) =>
-      cacheConst(runtimeCall('const(#)', [expr]));
+      runtimeCall('const(#)', [expr]);
 
   /// Emits preamble for the module containing [libraries], and returns the
   /// list of module items for further items to be added.
diff --git a/pkg/dev_compiler/lib/src/kernel/compiler.dart b/pkg/dev_compiler/lib/src/kernel/compiler.dart
index 8ccb39a..62f1529 100644
--- a/pkg/dev_compiler/lib/src/kernel/compiler.dart
+++ b/pkg/dev_compiler/lib/src/kernel/compiler.dart
@@ -4775,14 +4775,6 @@
       visitConstant(node.constant);
 
   @override
-  js_ast.Expression canonicalizeConstObject(js_ast.Expression expr) {
-    if (isSdkInternalRuntime(_currentLibrary!)) {
-      return super.canonicalizeConstObject(expr);
-    }
-    return runtimeCall('const(#)', [expr]);
-  }
-
-  @override
   js_ast.Expression visitVariableGet(VariableGet node) {
     var v = node.variable;
     var id = _emitVariableRef(v);
@@ -6924,8 +6916,7 @@
       DartType elementType, List<js_ast.Expression> elements) {
     // dart.constList helper internally depends on _interceptors.JSArray.
     _declareBeforeUse(_jsArrayClass);
-    return cacheConst(
-        runtimeCall('constList([#], #)', [elements, _emitType(elementType)]));
+    return runtimeCall('constList([#], #)', [elements, _emitType(elementType)]);
   }
 
   @override
@@ -6946,8 +6937,7 @@
 
   js_ast.Expression _emitConstSet(
       DartType elementType, List<js_ast.Expression> elements) {
-    return cacheConst(
-        runtimeCall('constSet(#, [#])', [_emitType(elementType), elements]));
+    return runtimeCall('constSet(#, [#])', [_emitType(elementType), elements]);
   }
 
   @override
@@ -6973,8 +6963,8 @@
 
   js_ast.Expression _emitConstMap(
       DartType keyType, DartType valueType, List<js_ast.Expression> entries) {
-    return cacheConst(runtimeCall('constMap(#, #, [#])',
-        [_emitType(keyType), _emitType(valueType), entries]));
+    return runtimeCall('constMap(#, #, [#])',
+        [_emitType(keyType), _emitType(valueType), entries]);
   }
 
   /// Returns the key used for shape lookup at runtime.
@@ -7197,14 +7187,6 @@
   }
 
   @override
-  js_ast.Expression cacheConst(js_ast.Expression jsExpr) {
-    if (isSdkInternalRuntime(_currentLibrary!)) {
-      return super.cacheConst(jsExpr);
-    }
-    return jsExpr;
-  }
-
-  @override
   js_ast.Expression visitConstant(Constant node) {
     if (node is StaticTearOffConstant) {
       // JS() or external JS consts should not be lazily loaded.
@@ -7247,7 +7229,7 @@
           type == const VoidType());
       return _emitTypeLiteral(type);
     }
-    if (isSdkInternalRuntime(_currentLibrary!) || node is PrimitiveConstant) {
+    if (node is PrimitiveConstant) {
       return super.visitConstant(node);
     }