Elements. Stop using ElementLocation for Element.hashCode, use identityHashCode().
And because we don't use `location` often anymore, stop caching it.
Change-Id: I3470803e09499fc49e57351bfe27a0993b223dae
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401941
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
index 4f79009..ab9a176 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -2528,12 +2528,6 @@
   /// Cached flags denoting presence of specific annotations in [_metadata].
   int _metadataFlags = 0;
 
-  /// A cached copy of the calculated hashCode for this element.
-  int? _cachedHashCode;
-
-  /// A cached copy of the calculated location for this element.
-  ElementLocation? _cachedLocation;
-
   /// The documentation comment for this element.
   String? _docComment;
 
@@ -2667,13 +2661,6 @@
   }
 
   @override
-  int get hashCode {
-    // TODO(scheglov): We might want to re-visit this optimization in the future.
-    // We cache the hash code value as this is a very frequently called method.
-    return _cachedHashCode ??= location.hashCode;
-  }
-
-  @override
   bool get hasImmutable {
     var metadata = this.metadata;
     for (var i = 0; i < metadata.length; i++) {
@@ -2992,7 +2979,7 @@
 
   @override
   ElementLocation get location {
-    return _cachedLocation ??= ElementLocationImpl.con1(this);
+    return ElementLocationImpl.con1(this);
   }
 
   @override
@@ -3311,11 +3298,6 @@
 }
 
 abstract class ElementImpl2 implements Element2 {
-  /// A cached copy of the calculated `hashCode` for this element.
-  int? _cachedHashCode;
-
-  ElementLocation? _cachedLocation;
-
   @override
   final int id = ElementImpl._NEXT_ID++;
 
@@ -3332,13 +3314,6 @@
   // TODO(augmentations): implement enclosingElement2
   Element2? get enclosingElement2 => throw UnimplementedError();
 
-  @override
-  int get hashCode {
-    // TODO(scheglov): We might want to re-visit this optimization in the future.
-    // We cache the hash code as this is a very frequently called method.
-    return _cachedHashCode ??= location.hashCode;
-  }
-
   /// Return an identifier that uniquely identifies this element among the
   /// children of this element's parent.
   String get identifier {
@@ -3364,7 +3339,7 @@
 
   @override
   ElementLocation? get location {
-    return _cachedLocation ??= ElementLocationImpl.fromElement(this);
+    return ElementLocationImpl.fromElement(this);
   }
 
   @override
@@ -6547,9 +6522,6 @@
       super.element as JoinPatternVariableElementImpl2;
 
   @override
-  int get hashCode => identityHashCode(this);
-
-  @override
   bool get isConsistent {
     return inconsistency == shared.JoinedPatternVariableInconsistency.none;
   }
@@ -7274,9 +7246,6 @@
   LibraryElement2? get exportedLibrary2 => exportedLibrary;
 
   @override
-  int get hashCode => identityHashCode(this);
-
-  @override
   String get identifier => 'export@$nameOffset';
 
   @override
@@ -7331,9 +7300,6 @@
   }
 
   @override
-  int get hashCode => identityHashCode(this);
-
-  @override
   String get identifier => 'import@$nameOffset';
 
   @override
diff --git a/pkg/analyzer/lib/src/dart/element/type.dart b/pkg/analyzer/lib/src/dart/element/type.dart
index 99a68c8..90fbcfd 100644
--- a/pkg/analyzer/lib/src/dart/element/type.dart
+++ b/pkg/analyzer/lib/src/dart/element/type.dart
@@ -370,16 +370,15 @@
       for (var namedParameter in sortedNamedParameters) {
         namedParameterInfo.add(namedParameter.isRequired);
         namedParameterInfo.add(namedParameter.name);
-        namedParameterInfo.add(namedParameter.type);
       }
     }
 
     return Object.hash(
-        nullabilitySuffix,
-        returnType,
-        requiredPositionalParameterCount,
-        Object.hashAll(positionalParameterTypes),
-        namedParameterInfo);
+      nullabilitySuffix,
+      returnType,
+      requiredPositionalParameterCount,
+      namedParameterInfo,
+    );
   }
 
   /// Given two functions [f1] and [f2] where f1 and f2 are known to be
diff --git a/pkg/analyzer/test/src/dart/element/element_test.dart b/pkg/analyzer/test/src/dart/element/element_test.dart
index d2eea14..7b60991 100644
--- a/pkg/analyzer/test/src/dart/element/element_test.dart
+++ b/pkg/analyzer/test/src/dart/element/element_test.dart
@@ -104,7 +104,6 @@
     expect(classA.hasNonFinalField, isTrue);
   }
 
-  @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/44522')
   void test_hasNonFinalField_true_inherited() {
     var classA = class_(name: 'A');
     ClassElementImpl classB =
diff --git a/pkg/analyzer/test/src/dart/element/function_type_test.dart b/pkg/analyzer/test/src/dart/element/function_type_test.dart
index 02e2ac0..087a015 100644
--- a/pkg/analyzer/test/src/dart/element/function_type_test.dart
+++ b/pkg/analyzer/test/src/dart/element/function_type_test.dart
@@ -303,7 +303,7 @@
   }
 
   test_hash_optionalPositionalParameterType() {
-    _testHashesSometimesDiffer((i) => FunctionTypeImpl(
+    _testHashesAlwaysEqual((i) => FunctionTypeImpl(
             typeFormals: const [],
             parameters: [
               positionalParameter(name: 'x', type: class_(name: 'C$i').thisType)
@@ -364,7 +364,7 @@
   }
 
   test_hash_requiredPositionalParameterType() {
-    _testHashesSometimesDiffer((i) => FunctionTypeImpl(
+    _testHashesAlwaysEqual((i) => FunctionTypeImpl(
             typeFormals: const [],
             parameters: [
               requiredParameter(name: 'x', type: class_(name: 'C$i').thisType)