[analyzer][cfe] Remove unnecessary use of shared views
This CL removes the unnecessary conversion from `TypeStructure` types
to `SharedTypeView` and `SharedTypeSchemaView` and back. By design,
the shared constraint generation method is operating on
`TypeStructure` types and uses the shared procedures named with the
'Internal' suffix to transform those types. In this CL the shared
procedures that are only used in the shared constraint generation
method or in 'Internal' procedures are converted to 'Internal'
themselves, and the corresponding update in the parameters accepted
and returned by those procedures is made.
Part of https://github.com/dart-lang/sdk/issues/54902
Change-Id: Ic8596b342bde7e78093e990fc0f12f705ff6dee1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395962
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
diff --git a/pkg/_fe_analyzer_shared/lib/src/type_inference/type_analyzer_operations.dart b/pkg/_fe_analyzer_shared/lib/src/type_inference/type_analyzer_operations.dart
index 75410e9..855556a 100644
--- a/pkg/_fe_analyzer_shared/lib/src/type_inference/type_analyzer_operations.dart
+++ b/pkg/_fe_analyzer_shared/lib/src/type_inference/type_analyzer_operations.dart
@@ -175,23 +175,23 @@
 
   /// Returns `true` if [type] is `Function` from `dart:core`. The method
   /// returns `false` for `Function?` and `Function*`.
-  bool isDartCoreFunction(SharedTypeView<TypeStructure> type);
+  bool isDartCoreFunctionInternal(TypeStructure type);
 
   /// Returns `true` if [type] is `Record` from `dart:core`. The method
   /// returns `false` for `Record?` and `Record*`.
-  bool isDartCoreRecord(SharedTypeView<TypeStructure> type);
+  bool isDartCoreRecordInternal(TypeStructure type);
 
   /// Returns `true` if [type] is `E<T1, ..., Tn>`, `E<T1, ..., Tn>?`, or
   /// `E<T1, ..., Tn>*` for some extension type declaration E, some
   /// non-negative n, and some types T1, ..., Tn.
-  bool isExtensionType(SharedTypeView<TypeStructure> type);
+  bool isExtensionTypeInternal(TypeStructure type);
 
   /// Returns `true` if [type] is `A<T1, ..., Tn>`, `A<T1, ..., Tn>?`, or
   /// `A<T1, ..., Tn>*` for some class, mixin, or enum A, some non-negative n,
   /// and some types T1, ..., Tn. The method returns `false` if [type] is an
   /// extension type, a type alias, `Null`, `Never`, or `FutureOr<X>` for any
   /// type `X`.
-  bool isInterfaceType(SharedTypeView<TypeStructure> type);
+  bool isInterfaceTypeInternal(TypeStructure type);
 
   @override
   bool isNever(SharedTypeView<TypeStructure> type);
@@ -209,7 +209,7 @@
   bool isNonNullableInternal(TypeStructure type);
 
   /// Returns `true` if [type] is `Null`.
-  bool isNull(SharedTypeView<TypeStructure> type);
+  bool isNullInternal(TypeStructure type);
 
   /// Returns `true` if [type] is `Object` from `dart:core`. The method returns
   /// `false` for `Object?` and `Object*`.
@@ -465,12 +465,11 @@
   ///
   /// In the example below the appearance of `X` in the return type of `foo` is
   /// a parameter type of a kind used in type inference. When passed into
-  /// [matchInferableParameter] it will yield the parameter `X` defined by
-  /// `foo`.
+  /// [matchInferableParameterInternal] it will yield the parameter `X` defined
+  /// by `foo`.
   ///
   ///   X foo<X>(bool c, X x1, X x2) => c ? x1 : x2;
-  TypeParameterStructure? matchInferableParameter(
-      SharedTypeView<TypeStructure> type);
+  TypeParameterStructure? matchInferableParameterInternal(TypeStructure type);
 
   /// If [type] is a subtype of the type `Iterable<T>?` for some `T`, returns
   /// the type `T`.  Otherwise returns `null`.
@@ -541,8 +540,7 @@
   /// If [type] isn't introduced by a class, mixin, enum, or extension type,
   /// returns null.
   TypeDeclarationMatchResult<TypeDeclarationType, TypeDeclaration,
-          TypeStructure>?
-      matchTypeDeclarationType(SharedTypeView<TypeStructure> type);
+      TypeStructure>? matchTypeDeclarationTypeInternal(TypeStructure type);
 
   /// If [typeSchema] takes the form `FutureOr<T>`, `FutureOr<T>?`, or
   /// `FutureOr<T>*` for some `T`, returns the type schema `T`. Otherwise
@@ -711,8 +709,8 @@
       SharedTypeView<TypeStructure> type);
 
   /// Returns [type] suffixed with the [suffix].
-  SharedTypeView<TypeStructure> withNullabilitySuffix(
-      SharedTypeView<TypeStructure> type, NullabilitySuffix suffix);
+  TypeStructure withNullabilitySuffixInternal(
+      TypeStructure type, NullabilitySuffix suffix);
 }
 
 mixin TypeAnalyzerOperationsMixin<
@@ -1399,8 +1397,8 @@
       TypeStructure p, TypeStructure q,
       {required bool leftSchema, required AstNode? astNodeForTesting}) {
     switch ((
-      typeAnalyzerOperations.matchTypeDeclarationType(new SharedTypeView(p)),
-      typeAnalyzerOperations.matchTypeDeclarationType(new SharedTypeView(q))
+      typeAnalyzerOperations.matchTypeDeclarationTypeInternal(p),
+      typeAnalyzerOperations.matchTypeDeclarationTypeInternal(q)
     )) {
       // If `P` is `C<M0, ..., Mk> and `Q` is `C<N0, ..., Nk>`, then the match
       // holds under constraints `C0 + ... + Ck`:
@@ -1455,9 +1453,8 @@
     // If `P` is `P0?` the match holds under constraint set `C1 + C2`:
     NullabilitySuffix pNullability = p.nullabilitySuffix;
     if (pNullability == NullabilitySuffix.question) {
-      TypeStructure p0 = typeAnalyzerOperations
-          .withNullabilitySuffix(new SharedTypeView(p), NullabilitySuffix.none)
-          .unwrapTypeView();
+      TypeStructure p0 = typeAnalyzerOperations.withNullabilitySuffixInternal(
+          p, NullabilitySuffix.none);
       final TypeConstraintGeneratorState state = currentState;
 
       // If `P0` is a subtype match for `Q` under constraint set `C1`.
@@ -1494,19 +1491,16 @@
     // If `Q` is `Q0?` the match holds under constraint set `C`:
     NullabilitySuffix qNullability = q.nullabilitySuffix;
     if (qNullability == NullabilitySuffix.question) {
-      TypeStructure q0 = typeAnalyzerOperations
-          .withNullabilitySuffix(new SharedTypeView(q), NullabilitySuffix.none)
-          .unwrapTypeView();
+      TypeStructure q0 = typeAnalyzerOperations.withNullabilitySuffixInternal(
+          q, NullabilitySuffix.none);
       final TypeConstraintGeneratorState state = currentState;
 
       // If `P` is `P0?` and `P0` is a subtype match for `Q0` under
       // constraint set `C`.
       NullabilitySuffix pNullability = p.nullabilitySuffix;
       if (pNullability == NullabilitySuffix.question) {
-        TypeStructure p0 = typeAnalyzerOperations
-            .withNullabilitySuffix(
-                new SharedTypeView(p), NullabilitySuffix.none)
-            .unwrapTypeView();
+        TypeStructure p0 = typeAnalyzerOperations.withNullabilitySuffixInternal(
+            p, NullabilitySuffix.none);
         if (performSubtypeConstraintGenerationInternal(p0, q0,
             leftSchema: leftSchema, astNodeForTesting: astNodeForTesting)) {
           return true;
@@ -1590,7 +1584,7 @@
     // If `P` is a type variable `X` in `L`, then the match holds:
     //   Under constraint `_ <: X <: Q`.
     NullabilitySuffix pNullability = p.nullabilitySuffix;
-    if (typeAnalyzerOperations.matchInferableParameter(new SharedTypeView(p))
+    if (typeAnalyzerOperations.matchInferableParameterInternal(p)
         case var pParameter?
         when pNullability == NullabilitySuffix.none &&
             typeParametersToConstrain.contains(pParameter)) {
@@ -1602,7 +1596,7 @@
     // If `Q` is a type variable `X` in `L`, then the match holds:
     //   Under constraint `P <: X <: _`.
     NullabilitySuffix qNullability = q.nullabilitySuffix;
-    if (typeAnalyzerOperations.matchInferableParameter(new SharedTypeView(q))
+    if (typeAnalyzerOperations.matchInferableParameterInternal(q)
         case var qParameter?
         when qNullability == NullabilitySuffix.none &&
             typeParametersToConstrain.contains(qParameter) &&
@@ -1672,7 +1666,7 @@
     // If `P` is `Null`, then the match holds under no constraints:
     //  Only if `Q` is nullable.
     if (pNullability == NullabilitySuffix.none &&
-        typeAnalyzerOperations.isNull(new SharedTypeView(p))) {
+        typeAnalyzerOperations.isNullInternal(p)) {
       return typeAnalyzerOperations.isNullableInternal(q);
     }
 
@@ -1697,7 +1691,7 @@
 
     // If `Q` is `Function` then the match holds under no constraints:
     //   If `P` is a function type.
-    if (typeAnalyzerOperations.isDartCoreFunction(new SharedTypeView(q))) {
+    if (typeAnalyzerOperations.isDartCoreFunctionInternal(q)) {
       if (p is SharedFunctionTypeStructure) {
         return true;
       }
@@ -1711,7 +1705,7 @@
     // A type `P` is a subtype match for `Record` with respect to `L` under no
     // constraints:
     //   If `P` is a record type or `Record`.
-    if (typeAnalyzerOperations.isDartCoreRecord(new SharedTypeView(q))) {
+    if (typeAnalyzerOperations.isDartCoreRecordInternal(q)) {
       if (p is SharedRecordTypeStructure<TypeStructure>) {
         return true;
       }
@@ -1825,8 +1819,8 @@
     //   respect to `L` under constraints `C`.
 
     if ((
-      typeAnalyzerOperations.matchTypeDeclarationType(new SharedTypeView(p)),
-      typeAnalyzerOperations.matchTypeDeclarationType(new SharedTypeView(q))
+      typeAnalyzerOperations.matchTypeDeclarationTypeInternal(p),
+      typeAnalyzerOperations.matchTypeDeclarationTypeInternal(q)
     )
         case (
           TypeDeclarationMatchResult(
diff --git a/pkg/_fe_analyzer_shared/test/mini_ast.dart b/pkg/_fe_analyzer_shared/test/mini_ast.dart
index 98c400b..1ac22f8 100644
--- a/pkg/_fe_analyzer_shared/test/mini_ast.dart
+++ b/pkg/_fe_analyzer_shared/test/mini_ast.dart
@@ -2897,9 +2897,9 @@
 
   @override
   TypeDeclarationKind? getTypeDeclarationKindInternal(Type type) {
-    if (isInterfaceType(SharedTypeView(type))) {
+    if (isInterfaceTypeInternal(type)) {
       return TypeDeclarationKind.interfaceDeclaration;
-    } else if (isExtensionType(SharedTypeView(type))) {
+    } else if (isExtensionTypeInternal(type)) {
       return TypeDeclarationKind.extensionTypeDeclaration;
     } else {
       return null;
@@ -2951,25 +2951,23 @@
   }
 
   @override
-  bool isDartCoreFunction(SharedTypeView<Type> type) {
-    Type unwrappedType = type.unwrapTypeView();
-    return unwrappedType is PrimaryType &&
-        unwrappedType.nullabilitySuffix == NullabilitySuffix.none &&
-        unwrappedType.name == 'Function' &&
-        unwrappedType.args.isEmpty;
+  bool isDartCoreFunctionInternal(Type type) {
+    return type is PrimaryType &&
+        type.nullabilitySuffix == NullabilitySuffix.none &&
+        type.name == 'Function' &&
+        type.args.isEmpty;
   }
 
   @override
-  bool isDartCoreRecord(SharedTypeView<Type> type) {
-    Type unwrappedType = type.unwrapTypeView();
-    return unwrappedType is PrimaryType &&
-        unwrappedType.nullabilitySuffix == NullabilitySuffix.none &&
-        unwrappedType.name == 'Record' &&
-        unwrappedType.args.isEmpty;
+  bool isDartCoreRecordInternal(Type type) {
+    return type is PrimaryType &&
+        type.nullabilitySuffix == NullabilitySuffix.none &&
+        type.name == 'Record' &&
+        type.args.isEmpty;
   }
 
   @override
-  bool isExtensionType(SharedTypeView<Type> type) {
+  bool isExtensionTypeInternal(Type type) {
     // TODO(cstefantsova): Add the support for extension types in the mini ast
     // testing framework.
     return false;
@@ -2981,9 +2979,8 @@
   }
 
   @override
-  bool isInterfaceType(SharedTypeView<Type> type) {
-    Type unwrappedType = type.unwrapTypeView();
-    return unwrappedType is PrimaryType && unwrappedType.isInterfaceType;
+  bool isInterfaceTypeInternal(Type type) {
+    return type is PrimaryType && type.isInterfaceType;
   }
 
   @override
@@ -2994,9 +2991,7 @@
   }
 
   @override
-  bool isNull(SharedTypeView<Type> type) {
-    return type.unwrapTypeView() is NullType;
-  }
+  bool isNullInternal(Type type) => type is NullType;
 
   @override
   bool isObject(SharedTypeView<Type> type) {
@@ -3100,8 +3095,8 @@
   }
 
   @override
-  TypeParameter? matchInferableParameter(SharedTypeView<Type> type) {
-    if (type.unwrapTypeView()
+  TypeParameter? matchInferableParameterInternal(Type type) {
+    if (type
         case TypeParameterType(
           :var typeParameter,
           nullabilitySuffix: NullabilitySuffix.none
@@ -3166,23 +3161,22 @@
   }
 
   @override
-  TypeDeclarationMatchResult<Type, String, Type>? matchTypeDeclarationType(
-      SharedTypeView<Type> type) {
-    Type unwrappedType = type.unwrapTypeView();
-    if (unwrappedType is! PrimaryType) return null;
+  TypeDeclarationMatchResult<Type, String, Type>?
+      matchTypeDeclarationTypeInternal(Type type) {
+    if (type is! PrimaryType) return null;
     TypeDeclarationKind typeDeclarationKind;
-    if (unwrappedType.isInterfaceType) {
+    if (type.isInterfaceType) {
       typeDeclarationKind = TypeDeclarationKind.interfaceDeclaration;
-    } else if (isExtensionType(type)) {
+    } else if (isExtensionTypeInternal(type)) {
       typeDeclarationKind = TypeDeclarationKind.extensionTypeDeclaration;
     } else {
       return null;
     }
     return new TypeDeclarationMatchResult(
         typeDeclarationKind: typeDeclarationKind,
-        typeDeclaration: unwrappedType.name,
-        typeDeclarationType: unwrappedType,
-        typeArguments: unwrappedType.args);
+        typeDeclaration: type.name,
+        typeDeclarationType: type,
+        typeArguments: type.args);
   }
 
   @override
@@ -3253,9 +3247,8 @@
       property.whyNotPromotable;
 
   @override
-  SharedTypeView<Type> withNullabilitySuffix(
-      SharedTypeView<Type> type, NullabilitySuffix modifier) {
-    return SharedTypeView(type.unwrapTypeView().withNullability(modifier));
+  Type withNullabilitySuffixInternal(Type type, NullabilitySuffix modifier) {
+    return type.withNullability(modifier);
   }
 
   @override
diff --git a/pkg/analyzer/lib/src/dart/resolver/flow_analysis_visitor.dart b/pkg/analyzer/lib/src/dart/resolver/flow_analysis_visitor.dart
index d9d547f..cb68fbb 100644
--- a/pkg/analyzer/lib/src/dart/resolver/flow_analysis_visitor.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/flow_analysis_visitor.dart
@@ -491,9 +491,9 @@
 
   @override
   TypeDeclarationKind? getTypeDeclarationKindInternal(DartType type) {
-    if (isInterfaceType(SharedTypeView(type))) {
+    if (isInterfaceTypeInternal(type)) {
       return TypeDeclarationKind.interfaceDeclaration;
-    } else if (isExtensionType(SharedTypeView(type))) {
+    } else if (isExtensionTypeInternal(type)) {
       return TypeDeclarationKind.extensionTypeDeclaration;
     } else {
       return null;
@@ -541,22 +541,20 @@
   }
 
   @override
-  bool isDartCoreFunction(SharedTypeView<DartType> type) {
+  bool isDartCoreFunctionInternal(DartType type) {
     return type.nullabilitySuffix == NullabilitySuffix.none &&
-        type.unwrapTypeView().isDartCoreFunction;
+        type.isDartCoreFunction;
   }
 
   @override
-  bool isDartCoreRecord(SharedTypeView<DartType> type) {
+  bool isDartCoreRecordInternal(DartType type) {
     return type.nullabilitySuffix == NullabilitySuffix.none &&
-        type.unwrapTypeView().isDartCoreRecord;
+        type.isDartCoreRecord;
   }
 
   @override
-  bool isExtensionType(SharedTypeView<DartType> type) {
-    DartType unwrappedType = type.unwrapTypeView();
-    return unwrappedType is InterfaceType &&
-        unwrappedType.element is ExtensionTypeElement;
+  bool isExtensionTypeInternal(DartType type) {
+    return type is InterfaceType && type.element is ExtensionTypeElement;
   }
 
   @override
@@ -565,12 +563,11 @@
   }
 
   @override
-  bool isInterfaceType(SharedTypeView<DartType> type) {
-    DartType unwrappedType = type.unwrapTypeView();
-    return unwrappedType is InterfaceType &&
-        !unwrappedType.isDartCoreNull &&
-        !unwrappedType.isDartAsyncFutureOr &&
-        unwrappedType.element is! ExtensionTypeElement;
+  bool isInterfaceTypeInternal(DartType type) {
+    return type is InterfaceType &&
+        !type.isDartCoreNull &&
+        !type.isDartAsyncFutureOr &&
+        type.element is! ExtensionTypeElement;
   }
 
   @override
@@ -584,16 +581,14 @@
   }
 
   @override
-  bool isNull(SharedTypeView<DartType> type) {
-    return type.unwrapTypeView().isDartCoreNull;
-  }
-
-  @override
   bool isNullableInternal(DartType type) {
     return typeSystem.isNullable(type);
   }
 
   @override
+  bool isNullInternal(DartType type) => type.isDartCoreNull;
+
+  @override
   bool isObject(SharedTypeView<DartType> type) {
     return type.unwrapTypeView().isDartCoreObject &&
         type.nullabilitySuffix == NullabilitySuffix.none;
@@ -677,10 +672,9 @@
   }
 
   @override
-  TypeParameterElement? matchInferableParameter(SharedTypeView<DartType> type) {
-    DartType unwrappedType = type.unwrapTypeView();
-    if (unwrappedType is TypeParameterType) {
-      return unwrappedType.element;
+  TypeParameterElement? matchInferableParameterInternal(DartType type) {
+    if (type is TypeParameterType) {
+      return type.element;
     } else {
       return null;
     }
@@ -723,17 +717,16 @@
 
   @override
   TypeDeclarationMatchResult<InterfaceType, InterfaceElement, DartType>?
-      matchTypeDeclarationType(SharedTypeView<DartType> type) {
-    DartType unwrappedType = type.unwrapTypeView();
-    if (isInterfaceType(type)) {
-      InterfaceType interfaceType = unwrappedType as InterfaceType;
+      matchTypeDeclarationTypeInternal(DartType type) {
+    if (isInterfaceTypeInternal(type)) {
+      InterfaceType interfaceType = type as InterfaceType;
       return TypeDeclarationMatchResult(
           typeDeclarationKind: TypeDeclarationKind.interfaceDeclaration,
           typeDeclarationType: interfaceType,
           typeDeclaration: interfaceType.element,
           typeArguments: interfaceType.typeArguments);
-    } else if (isExtensionType(type)) {
-      InterfaceType interfaceType = unwrappedType as InterfaceType;
+    } else if (isExtensionTypeInternal(type)) {
+      InterfaceType interfaceType = type as InterfaceType;
       return TypeDeclarationMatchResult(
           typeDeclarationKind: TypeDeclarationKind.extensionTypeDeclaration,
           typeDeclarationType: interfaceType,
@@ -830,10 +823,9 @@
   }
 
   @override
-  SharedTypeView<DartType> withNullabilitySuffix(
-      SharedTypeView<DartType> type, NullabilitySuffix suffix) {
-    return SharedTypeView(
-        (type.unwrapTypeView() as TypeImpl).withNullability(suffix));
+  DartType withNullabilitySuffixInternal(
+      DartType type, NullabilitySuffix suffix) {
+    return (type as TypeImpl).withNullability(suffix);
   }
 }
 
diff --git a/pkg/front_end/lib/src/type_inference/type_inference_engine.dart b/pkg/front_end/lib/src/type_inference/type_inference_engine.dart
index adab1f4..7ef8deb 100644
--- a/pkg/front_end/lib/src/type_inference/type_inference_engine.dart
+++ b/pkg/front_end/lib/src/type_inference/type_inference_engine.dart
@@ -552,9 +552,7 @@
 
   @override
   // Coverage-ignore(suite): Not run.
-  bool isExtensionType(SharedTypeView<DartType> type) {
-    return type.unwrapTypeView() is ExtensionType;
-  }
+  bool isExtensionTypeInternal(DartType type) => type is ExtensionType;
 
   @override
   bool isFinal(VariableDeclaration variable) {
@@ -563,8 +561,8 @@
 
   @override
   // Coverage-ignore(suite): Not run.
-  bool isInterfaceType(SharedTypeView<DartType> type) {
-    return type.unwrapTypeView() is InterfaceType;
+  bool isInterfaceTypeInternal(DartType type) {
+    return type is InterfaceType;
   }
 
   @override
@@ -573,9 +571,7 @@
   }
 
   @override
-  bool isNull(SharedTypeView<DartType> type) {
-    return type.unwrapTypeView() is NullType;
-  }
+  bool isNullInternal(DartType type) => type is NullType;
 
   @override
   // Coverage-ignore(suite): Not run.
@@ -892,21 +888,17 @@
   }
 
   @override
-  SharedTypeView<DartType> withNullabilitySuffix(
-      SharedTypeView<DartType> type, NullabilitySuffix modifier) {
+  DartType withNullabilitySuffixInternal(
+      DartType type, NullabilitySuffix modifier) {
     switch (modifier) {
       case NullabilitySuffix.none:
-        return new SharedTypeView(
-            computeTypeWithoutNullabilityMarker(type.unwrapTypeView()));
+        return computeTypeWithoutNullabilityMarker(type);
       // Coverage-ignore(suite): Not run.
       case NullabilitySuffix.question:
-        return new SharedTypeView(type
-            .unwrapTypeView()
-            .withDeclaredNullability(Nullability.nullable));
+        return type.withDeclaredNullability(Nullability.nullable);
       // Coverage-ignore(suite): Not run.
       case NullabilitySuffix.star:
-        return new SharedTypeView(
-            type.unwrapTypeView().withDeclaredNullability(Nullability.legacy));
+        return type.withDeclaredNullability(Nullability.legacy);
     }
   }
 
@@ -926,10 +918,9 @@
   }
 
   @override
-  StructuralParameter? matchInferableParameter(SharedTypeView<DartType> type) {
-    DartType unwrappedType = type.unwrapTypeView();
-    if (unwrappedType is StructuralParameterType) {
-      return unwrappedType.parameter;
+  StructuralParameter? matchInferableParameterInternal(DartType type) {
+    if (type is StructuralParameterType) {
+      return type.parameter;
     } else {
       return null;
     }
@@ -943,15 +934,14 @@
 
   @override
   TypeDeclarationMatchResult<TypeDeclarationType, TypeDeclaration, DartType>?
-      matchTypeDeclarationType(SharedTypeView<DartType> type) {
-    DartType unwrappedType = type.unwrapTypeView();
-    if (unwrappedType is TypeDeclarationType) {
-      switch (unwrappedType) {
+      matchTypeDeclarationTypeInternal(DartType type) {
+    if (type is TypeDeclarationType) {
+      switch (type) {
         case InterfaceType(:List<DartType> typeArguments, :Class classNode):
           return new TypeDeclarationMatchResult(
               typeDeclarationKind: TypeDeclarationKind.interfaceDeclaration,
               typeDeclaration: classNode,
-              typeDeclarationType: unwrappedType,
+              typeDeclarationType: type,
               typeArguments: typeArguments);
         case ExtensionType(
             :List<DartType> typeArguments,
@@ -960,7 +950,7 @@
           return new TypeDeclarationMatchResult(
               typeDeclarationKind: TypeDeclarationKind.extensionTypeDeclaration,
               typeDeclaration: extensionTypeDeclaration,
-              typeDeclarationType: unwrappedType,
+              typeDeclarationType: type,
               typeArguments: typeArguments);
       }
     } else {
@@ -975,15 +965,13 @@
   }
 
   @override
-  bool isDartCoreFunction(SharedTypeView<DartType> type) {
-    return type.unwrapTypeView() ==
-        typeEnvironment.coreTypes.functionNonNullableRawType;
+  bool isDartCoreFunctionInternal(DartType type) {
+    return type == typeEnvironment.coreTypes.functionNonNullableRawType;
   }
 
   @override
-  bool isDartCoreRecord(SharedTypeView<DartType> type) {
-    return type.unwrapTypeView() ==
-        typeEnvironment.coreTypes.recordNonNullableRawType;
+  bool isDartCoreRecordInternal(DartType type) {
+    return type == typeEnvironment.coreTypes.recordNonNullableRawType;
   }
 
   @override