Skip to content

Commit 73eaef2

Browse files
stereotype441Commit Queue
authored and
Commit Queue
committed
[analyzer] Use InterfaceElementImpl2 when interfacing with shared code.
Change the analyzer's use of the following shared generic types so that it supplies the type parameter `InterfaceElementImpl2` instead of `InterfaceElement` as the type it uses to represent interfaces: - `MergedTypeConstraint` - `TypeAnalyzer` - `TypeAnalyzerOperations` - `TypeAnalyzerOperationsMixin` - `TypeConstraintFromArgument` - `TypeConstraintFromExtendsClause` - `TypeConstraintFromFunctionContext` - `TypeConstraintFromReturnType` - `TypeConstraintGenerator` - `TypeConstraintGeneratorMixin` - `TypeConstraintOrigin` - `TypeDeclarationMatchResult` - `UnknownTypeConstraintOrigin` To avoid type casts, I tightened up the return type of `InterfaceTypeImpl.element3` so that it returns `InterfaceElementImpl2` instead of `InterfaceElement2`. The analyzer public API is unchanged, though--`InterfaceType.element3` still has a return type of `InterfaceElement2`--so clients should be unaffected. This is part of a larger arc of work to change the analyzer's use of the shared code so that the type parameters it supplies are not part of the analyzer public API. See #59763. Change-Id: Ie13fcb31d8dfe0a2a256eda177a8c4a1a022008d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402428 Commit-Queue: Paul Berry <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent 3e1e0bb commit 73eaef2

File tree

5 files changed

+24
-27
lines changed

5 files changed

+24
-27
lines changed

pkg/analyzer/analyzer_use_new_elements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ lib/src/dart/resolver/this_lookup.dart
8585
lib/src/dart/resolver/type_property_resolver.dart
8686
lib/src/dart/resolver/typed_literal_resolver.dart
8787
lib/src/dart/resolver/variable_declaration_resolver.dart
88-
lib/src/dart/resolver/yield_statement_resolver.dart
8988
lib/src/diagnostic/diagnostic_factory.dart
9089
lib/src/error/best_practices_verifier.dart
9190
lib/src/error/correct_override.dart

pkg/analyzer/lib/src/dart/element/type.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,8 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
683683
.toList();
684684

685685
@override
686-
InterfaceElement2 get element3 => (element as InterfaceFragment).element;
686+
InterfaceElementImpl2 get element3 =>
687+
(element as InterfaceElementImpl).element;
687688

688689
@override
689690
List<GetterElement> get getters => accessors

pkg/analyzer/lib/src/dart/element/type_constraint_gatherer.dart

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import 'package:_fe_analyzer_shared/src/type_inference/type_constraint.dart'
2020
TypeConstraintOrigin,
2121
UnknownTypeConstraintOrigin;
2222
import 'package:_fe_analyzer_shared/src/types/shared_type.dart';
23-
import 'package:analyzer/dart/element/element.dart';
2423
import 'package:analyzer/dart/element/type.dart';
2524
import 'package:analyzer/src/dart/ast/ast.dart';
2625
import 'package:analyzer/src/dart/element/element.dart';
@@ -39,20 +38,20 @@ typedef MergedTypeConstraint = shared.MergedTypeConstraint<
3938
TypeParameterElementImpl2,
4039
PromotableElementImpl2,
4140
InterfaceType,
42-
InterfaceElement>;
41+
InterfaceElementImpl2>;
4342

4443
/// Instance of [shared.TypeConstraintFromArgument] specific to the Analyzer.
4544
typedef TypeConstraintFromArgument = shared.TypeConstraintFromArgument<
4645
DartType,
4746
PromotableElementImpl2,
4847
TypeParameterElementImpl2,
4948
InterfaceType,
50-
InterfaceElement>;
49+
InterfaceElementImpl2>;
5150

5251
/// Instance of [shared.TypeConstraintFromExtendsClause] specific to the Analyzer.
5352
typedef TypeConstraintFromExtendsClause
5453
= shared.TypeConstraintFromExtendsClause<DartType, PromotableElementImpl2,
55-
TypeParameterElementImpl2, InterfaceType, InterfaceElement>;
54+
TypeParameterElementImpl2, InterfaceType, InterfaceElementImpl2>;
5655

5756
/// Instance of [shared.TypeConstraintFromFunctionContext] specific to the Analyzer.
5857
typedef TypeConstraintFromFunctionContext
@@ -63,7 +62,7 @@ typedef TypeConstraintFromFunctionContext
6362
PromotableElementImpl2,
6463
TypeParameterElementImpl2,
6564
InterfaceType,
66-
InterfaceElement>;
65+
InterfaceElementImpl2>;
6766

6867
/// Instance of [shared.TypeConstraintFromReturnType] specific to the Analyzer.
6968
typedef TypeConstraintFromReturnType = shared.TypeConstraintFromReturnType<
@@ -73,23 +72,23 @@ typedef TypeConstraintFromReturnType = shared.TypeConstraintFromReturnType<
7372
PromotableElementImpl2,
7473
TypeParameterElementImpl2,
7574
InterfaceType,
76-
InterfaceElement>;
75+
InterfaceElementImpl2>;
7776

7877
/// Instance of [shared.TypeConstraintOrigin] specific to the Analyzer.
7978
typedef TypeConstraintOrigin = shared.TypeConstraintOrigin<
8079
DartType,
8180
PromotableElementImpl2,
8281
TypeParameterElementImpl2,
8382
InterfaceType,
84-
InterfaceElement>;
83+
InterfaceElementImpl2>;
8584

8685
/// Instance of [shared.UnknownTypeConstraintOrigin] specific to the Analyzer.
8786
typedef UnknownTypeConstraintOrigin = shared.UnknownTypeConstraintOrigin<
8887
DartType,
8988
PromotableElementImpl2,
9089
TypeParameterElementImpl2,
9190
InterfaceType,
92-
InterfaceElement>;
91+
InterfaceElementImpl2>;
9392

9493
/// Creates sets of [GeneratedTypeConstraint]s for type parameters, based on an
9594
/// attempt to make one type schema a subtype of another.
@@ -99,7 +98,7 @@ class TypeConstraintGatherer extends shared.TypeConstraintGenerator<
9998
PromotableElementImpl2,
10099
TypeParameterElementImpl2,
101100
InterfaceType,
102-
InterfaceElement,
101+
InterfaceElementImpl2,
103102
AstNode>
104103
with
105104
shared.TypeConstraintGeneratorMixin<
@@ -108,7 +107,7 @@ class TypeConstraintGatherer extends shared.TypeConstraintGenerator<
108107
PromotableElementImpl2,
109108
TypeParameterElementImpl2,
110109
InterfaceType,
111-
InterfaceElement,
110+
InterfaceElementImpl2,
112111
AstNode> {
113112
@override
114113
final Set<TypeParameterElementImpl2> typeParametersToConstrain =
@@ -213,9 +212,9 @@ class TypeConstraintGatherer extends shared.TypeConstraintGenerator<
213212

214213
@override
215214
List<DartType>? getTypeArgumentsAsInstanceOf(
216-
InterfaceType type, InterfaceElement typeDeclaration) {
215+
InterfaceType type, InterfaceElementImpl2 typeDeclaration) {
217216
for (var interface in type.element.allSupertypes) {
218-
if (interface.element == typeDeclaration) {
217+
if (interface.element3 == typeDeclaration) {
219218
var substitution = Substitution.fromInterfaceType(type);
220219
var substitutedInterface =
221220
substitution.substituteType(interface) as InterfaceType;

pkg/analyzer/lib/src/dart/resolver/flow_analysis_visitor.dart

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,10 @@ class FlowAnalysisHelper {
424424
class TypeSystemOperations
425425
with
426426
TypeAnalyzerOperationsMixin<DartType, PromotableElementImpl2,
427-
TypeParameterElementImpl2, InterfaceType, InterfaceElement>
427+
TypeParameterElementImpl2, InterfaceType, InterfaceElementImpl2>
428428
implements
429429
TypeAnalyzerOperations<DartType, PromotableElementImpl2,
430-
TypeParameterElementImpl2, InterfaceType, InterfaceElement> {
430+
TypeParameterElementImpl2, InterfaceType, InterfaceElementImpl2> {
431431
final bool strictCasts;
432432
final TypeSystemImpl typeSystem;
433433

@@ -529,10 +529,8 @@ class TypeSystemOperations
529529

530530
@override
531531
Variance getTypeParameterVariance(
532-
InterfaceElement typeDeclaration, int parameterIndex) {
533-
return (typeDeclaration.typeParameters[parameterIndex]
534-
as TypeParameterElementImpl)
535-
.variance;
532+
InterfaceElementImpl2 typeDeclaration, int parameterIndex) {
533+
return typeDeclaration.typeParameters2[parameterIndex].variance;
536534
}
537535

538536
@override
@@ -740,21 +738,21 @@ class TypeSystemOperations
740738
}
741739

742740
@override
743-
TypeDeclarationMatchResult<InterfaceType, InterfaceElement, DartType>?
741+
TypeDeclarationMatchResult<InterfaceType, InterfaceElementImpl2, DartType>?
744742
matchTypeDeclarationTypeInternal(DartType type) {
745743
if (isInterfaceTypeInternal(type)) {
746-
InterfaceType interfaceType = type as InterfaceType;
744+
InterfaceTypeImpl interfaceType = type as InterfaceTypeImpl;
747745
return TypeDeclarationMatchResult(
748746
typeDeclarationKind: TypeDeclarationKind.interfaceDeclaration,
749747
typeDeclarationType: interfaceType,
750-
typeDeclaration: interfaceType.element,
748+
typeDeclaration: interfaceType.element3,
751749
typeArguments: interfaceType.typeArguments);
752750
} else if (isExtensionTypeInternal(type)) {
753-
InterfaceType interfaceType = type as InterfaceType;
751+
InterfaceTypeImpl interfaceType = type as InterfaceTypeImpl;
754752
return TypeDeclarationMatchResult(
755753
typeDeclarationKind: TypeDeclarationKind.extensionTypeDeclaration,
756754
typeDeclarationType: interfaceType,
757-
typeDeclaration: interfaceType.element,
755+
typeDeclaration: interfaceType.element3,
758756
typeArguments: interfaceType.typeArguments);
759757
} else {
760758
return null;

pkg/analyzer/lib/src/generated/resolver.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
130130
void,
131131
TypeParameterElementImpl2,
132132
InterfaceType,
133-
InterfaceElement>,
133+
InterfaceElementImpl2>,
134134
// TODO(paulberry): not yet used.
135135
NullShortingMixin<Null, Expression, SharedTypeView<DartType>> {
136136
/// Debug-only: if `true`, manipulations of [_rewriteStack] performed by
@@ -457,7 +457,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
457457
PromotableElementImpl2,
458458
TypeParameterElementImpl2,
459459
InterfaceType,
460-
InterfaceElement> get operations => flowAnalysis.typeOperations;
460+
InterfaceElementImpl2> get operations => flowAnalysis.typeOperations;
461461

462462
/// Gets the current depth of the [_rewriteStack]. This may be used in
463463
/// assertions to verify that pushes and pops are properly balanced.

0 commit comments

Comments
 (0)