Skip to content

Commit 9a47293

Browse files
stereotype441Commit Queue
authored andcommitted
[_fe_analyzer_shared] Renames to prepare for analyzer refactoring.
The following shared getters are renamed so that their names are distinct from the corresponding getters in the analyzer: - `SharedFunctionTypeStructure.positionalParameterTypes` is renamed to `positionalParameterTypesShared` to be distinct from the analyzer's public getter `FunctionType.positionalParameterTypes`.* - `SharedFunctionTypeStructure.returnType` is renamed to `returnTypeShared` to be distinct from the analyzer's public getter `FunctionType.returnType`. - `SharedNamedFunctionParameterStructure.type` is renamed to `typeShared` to be distinct from the analyzer's public getter `FormalParameterElement.type`. - `SharedNamedTypeStructure.type` is renamed to `typeShared` to be distinct from the analyzer's public getter `RecordTypeNamedField.type`. - `SharedRecordTypeStructure.positionalTypes` is renamed to `positionalTypesShared` to be distinct from the analyzer's public getter `RecordType.positionalTypes`.* - `SharedRecordTypeStructure.sortedNamedTypes` is renamed to `sortedNamedTypesShared` to be distinct from the analyzer's public getter `RecordType.sortedNamedTypes`. - `SharedTypeParameterStructure.bound` is renamed to `boundShared` to be distinct from the analyzer's public getter `TypeParameterElement2.bound`. *Note that `FunctionType.positionalParameterTypes`, `RecordType.positionalTypes`, and `RecordType.sortedNamedTypes` were unintentionally exposed as part of the analyzer's public API. In a previous CL I marked them as deprecated. These renames pave the way for changing the analyzer's `DartType` class so that it implements `SharedTypeStructure<TypeImpl>` rather than `SharedTypeStructure<DartType>` (without the renames, the public getters mentioned above would all have to be changed to have type `TypeImpl`, and that in turn would expose `TypeImpl` through the analyzer public API, which we don't want to do). Once `DartType` implements `SharedTypeStructure<TypeImpl>`, that will allow all the other uses of `SharedTypeStructure<DartType>` in the analyzer to be gradually migrated to `SharedTypeStructure<TypeImpl>`. Once that is done, `DartType` can be changed so that it no longer implements `SharedTypeStructure<TypeImpl>` at all (`TypeImpl` will implement `SharedTypeStructure<TypeImpl> instead). This will free us up to make future changes to the `SharedTypeStructure` base class without inadvertently exposing those changes through the analyzer public API. 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: I0686fdeae304f8948484516f0249841b79e7da6c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403625 Reviewed-by: Chloe Stefantsova <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent 11d24d6 commit 9a47293

File tree

7 files changed

+108
-56
lines changed

7 files changed

+108
-56
lines changed

pkg/_fe_analyzer_shared/lib/src/type_inference/type_analyzer_operations.dart

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ mixin TypeAnalyzerOperationsMixin<
967967
// constraints (i.e. `X <: B` in this example), then they are added to
968968
// the set of constraints just before choosing the final type.
969969

970-
TypeStructure typeParameterToInferBound = typeParameterToInfer.bound!;
970+
TypeStructure typeParameterToInferBound = typeParameterToInfer.boundShared!;
971971

972972
// TODO(cstefantsova): Pass [dataForTesting] when
973973
// [InferenceDataForTesting] is merged with [TypeInferenceResultForTesting].
@@ -1231,16 +1231,16 @@ abstract class TypeConstraintGenerator<
12311231
// with respect to `L` under constraints `C0 + ... + Cm`
12321232
// If for `i` in `0...m`, `Mi` is a subtype match for `Ni` with respect
12331233
// to `L` under constraints `Ci`.
1234-
if (p.positionalTypes.length != q.positionalTypes.length ||
1235-
p.sortedNamedTypes.length != q.sortedNamedTypes.length) {
1234+
if (p.positionalTypesShared.length != q.positionalTypesShared.length ||
1235+
p.sortedNamedTypesShared.length != q.sortedNamedTypesShared.length) {
12361236
return false;
12371237
}
12381238

12391239
final TypeConstraintGeneratorState state = currentState;
12401240

1241-
for (int i = 0; i < p.positionalTypes.length; ++i) {
1241+
for (int i = 0; i < p.positionalTypesShared.length; ++i) {
12421242
if (!performSubtypeConstraintGenerationInternal(
1243-
p.positionalTypes[i], q.positionalTypes[i],
1243+
p.positionalTypesShared[i], q.positionalTypesShared[i],
12441244
leftSchema: leftSchema, astNodeForTesting: astNodeForTesting)) {
12451245
restoreState(state);
12461246
return false;
@@ -1251,12 +1251,14 @@ abstract class TypeConstraintGenerator<
12511251
// parameters, and the named parameters are sorted, it's sufficient to
12521252
// check that the named parameters at the same index have the same name
12531253
// and matching types.
1254-
for (int i = 0; i < p.sortedNamedTypes.length; ++i) {
1255-
if (p.sortedNamedTypes[i].nameShared !=
1256-
q.sortedNamedTypes[i].nameShared ||
1254+
for (int i = 0; i < p.sortedNamedTypesShared.length; ++i) {
1255+
if (p.sortedNamedTypesShared[i].nameShared !=
1256+
q.sortedNamedTypesShared[i].nameShared ||
12571257
!performSubtypeConstraintGenerationInternal(
1258-
p.sortedNamedTypes[i].type, q.sortedNamedTypes[i].type,
1259-
leftSchema: leftSchema, astNodeForTesting: astNodeForTesting)) {
1258+
p.sortedNamedTypesShared[i].typeShared,
1259+
q.sortedNamedTypesShared[i].typeShared,
1260+
leftSchema: leftSchema,
1261+
astNodeForTesting: astNodeForTesting)) {
12601262
restoreState(state);
12611263
return false;
12621264
}
@@ -1506,11 +1508,11 @@ abstract class TypeConstraintGenerator<
15061508
when qNullability == NullabilitySuffix.none &&
15071509
typeParametersToConstrain.contains(qParameter) &&
15081510
(!inferenceUsingBoundsIsEnabled ||
1509-
(qParameter.bound == null ||
1511+
(qParameter.boundShared == null ||
15101512
typeAnalyzerOperations.isSubtypeOfInternal(
15111513
p,
15121514
typeAnalyzerOperations.greatestClosureOfTypeInternal(
1513-
qParameter.bound!,
1515+
qParameter.boundShared!,
15141516
[...typeParametersToConstrain]))))) {
15151517
addLowerConstraintForParameter(qParameter, p,
15161518
astNodeForTesting: astNodeForTesting);
@@ -1704,16 +1706,16 @@ abstract class TypeConstraintGenerator<
17041706
for (int i = 0; isMatch && i < p.typeParametersShared.length; ++i) {
17051707
isMatch = isMatch &&
17061708
performSubtypeConstraintGenerationInternal(
1707-
p.typeParametersShared[i].bound ??
1709+
p.typeParametersShared[i].boundShared ??
17081710
typeAnalyzerOperations.objectQuestionType.unwrapTypeView(),
1709-
q.typeParametersShared[i].bound ??
1711+
q.typeParametersShared[i].boundShared ??
17101712
typeAnalyzerOperations.objectQuestionType.unwrapTypeView(),
17111713
leftSchema: leftSchema,
17121714
astNodeForTesting: astNodeForTesting) &&
17131715
performSubtypeConstraintGenerationInternal(
1714-
q.typeParametersShared[i].bound ??
1716+
q.typeParametersShared[i].boundShared ??
17151717
typeAnalyzerOperations.objectQuestionType.unwrapTypeView(),
1716-
p.typeParametersShared[i].bound ??
1718+
p.typeParametersShared[i].boundShared ??
17171719
typeAnalyzerOperations.objectQuestionType.unwrapTypeView(),
17181720
leftSchema: !leftSchema,
17191721
astNodeForTesting: astNodeForTesting);
@@ -1767,27 +1769,29 @@ abstract class TypeConstraintGenerator<
17671769
q.sortedNamedParametersShared.isEmpty &&
17681770
p.requiredPositionalParameterCount <=
17691771
q.requiredPositionalParameterCount &&
1770-
p.positionalParameterTypes.length >=
1771-
q.positionalParameterTypes.length) {
1772+
p.positionalParameterTypesShared.length >=
1773+
q.positionalParameterTypesShared.length) {
17721774
final TypeConstraintGeneratorState state = currentState;
17731775

17741776
if (!performSubtypeConstraintGenerationInternal(
1775-
p.returnType, q.returnType,
1777+
p.returnTypeShared, q.returnTypeShared,
17761778
leftSchema: leftSchema, astNodeForTesting: astNodeForTesting)) {
17771779
return false;
17781780
}
1779-
for (int i = 0; i < q.positionalParameterTypes.length; ++i) {
1781+
for (int i = 0; i < q.positionalParameterTypesShared.length; ++i) {
17801782
if (!performSubtypeConstraintGenerationInternal(
1781-
q.positionalParameterTypes[i], p.positionalParameterTypes[i],
1782-
leftSchema: !leftSchema, astNodeForTesting: astNodeForTesting)) {
1783+
q.positionalParameterTypesShared[i],
1784+
p.positionalParameterTypesShared[i],
1785+
leftSchema: !leftSchema,
1786+
astNodeForTesting: astNodeForTesting)) {
17831787
restoreState(state);
17841788
return false;
17851789
}
17861790
}
17871791
return true;
1788-
} else if (p.positionalParameterTypes.length ==
1792+
} else if (p.positionalParameterTypesShared.length ==
17891793
p.requiredPositionalParameterCount &&
1790-
q.positionalParameterTypes.length ==
1794+
q.positionalParameterTypesShared.length ==
17911795
q.requiredPositionalParameterCount &&
17921796
p.requiredPositionalParameterCount ==
17931797
q.requiredPositionalParameterCount &&
@@ -1800,14 +1804,16 @@ abstract class TypeConstraintGenerator<
18001804
final TypeConstraintGeneratorState state = currentState;
18011805

18021806
if (!performSubtypeConstraintGenerationInternal(
1803-
p.returnType, q.returnType,
1807+
p.returnTypeShared, q.returnTypeShared,
18041808
leftSchema: leftSchema, astNodeForTesting: astNodeForTesting)) {
18051809
return false;
18061810
}
1807-
for (int i = 0; i < p.positionalParameterTypes.length; ++i) {
1811+
for (int i = 0; i < p.positionalParameterTypesShared.length; ++i) {
18081812
if (!performSubtypeConstraintGenerationInternal(
1809-
q.positionalParameterTypes[i], p.positionalParameterTypes[i],
1810-
leftSchema: !leftSchema, astNodeForTesting: astNodeForTesting)) {
1813+
q.positionalParameterTypesShared[i],
1814+
p.positionalParameterTypesShared[i],
1815+
leftSchema: !leftSchema,
1816+
astNodeForTesting: astNodeForTesting)) {
18111817
restoreState(state);
18121818
return false;
18131819
}
@@ -1859,8 +1865,8 @@ abstract class TypeConstraintGenerator<
18591865
} else {
18601866
// The next parameter in p and q matches, so match their types.
18611867
if (!performSubtypeConstraintGenerationInternal(
1862-
q.sortedNamedParametersShared[j].type,
1863-
p.sortedNamedParametersShared[i].type,
1868+
q.sortedNamedParametersShared[j].typeShared,
1869+
p.sortedNamedParametersShared[i].typeShared,
18641870
leftSchema: !leftSchema,
18651871
astNodeForTesting: astNodeForTesting)) {
18661872
restoreState(state);

pkg/_fe_analyzer_shared/lib/src/types/shared_type.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ abstract interface class SharedFunctionTypeStructure<
1919
TypeStructure>> implements SharedTypeStructure<TypeStructure> {
2020
/// All the positional parameter types, starting with the required ones, and
2121
/// followed by the optional ones.
22-
List<TypeStructure> get positionalParameterTypes;
22+
List<TypeStructure> get positionalParameterTypesShared;
2323

24-
/// The number of elements of [positionalParameterTypes] that are required
25-
/// parameters.
24+
/// The number of elements of [positionalParameterTypesShared] that are
25+
/// required parameters.
2626
int get requiredPositionalParameterCount;
2727

2828
/// The return type.
29-
TypeStructure get returnType;
29+
TypeStructure get returnTypeShared;
3030

3131
/// All the named parameters, sorted by name.
3232
List<FunctionParameterStructure> get sortedNamedParametersShared;
@@ -55,15 +55,15 @@ abstract interface class SharedNamedFunctionParameterStructure<
5555
String get nameShared;
5656

5757
/// The type of the parameter.
58-
TypeStructure get type;
58+
TypeStructure get typeShared;
5959
}
6060

6161
/// Common interface for data structures used by the implementations to
6262
/// represent a name/type pair.
6363
abstract interface class SharedNamedTypeStructure<
6464
TypeStructure extends SharedTypeStructure<TypeStructure>> {
6565
String get nameShared;
66-
TypeStructure get type;
66+
TypeStructure get typeShared;
6767
}
6868

6969
/// Common interface for data structures used by implementations to represent
@@ -77,18 +77,18 @@ abstract interface class SharedNullTypeStructure<
7777
abstract interface class SharedRecordTypeStructure<
7878
TypeStructure extends SharedTypeStructure<TypeStructure>>
7979
implements SharedTypeStructure<TypeStructure> {
80-
List<TypeStructure> get positionalTypes;
80+
List<TypeStructure> get positionalTypesShared;
8181

8282
/// All the named fields, sorted by name.
83-
List<SharedNamedTypeStructure<TypeStructure>> get sortedNamedTypes;
83+
List<SharedNamedTypeStructure<TypeStructure>> get sortedNamedTypesShared;
8484
}
8585

8686
/// Common interface for data structures used by the implementations to
8787
/// represent a generic type parameter.
8888
abstract interface class SharedTypeParameterStructure<
8989
TypeStructure extends SharedTypeStructure<TypeStructure>> {
9090
/// The bound of the type parameter.
91-
TypeStructure? get bound;
91+
TypeStructure? get boundShared;
9292

9393
/// The name of the type parameter, for display to the user.
9494
String get displayName;
@@ -159,20 +159,20 @@ extension type SharedNamedTypeView<
159159
String get name => _namedTypeStructure.nameShared;
160160

161161
SharedTypeView<TypeStructure> get type =>
162-
new SharedTypeView(_namedTypeStructure.type);
162+
new SharedTypeView(_namedTypeStructure.typeShared);
163163
}
164164

165165
extension type SharedRecordTypeSchemaView<
166166
TypeStructure extends SharedTypeStructure<TypeStructure>>(
167167
SharedRecordTypeStructure<TypeStructure> _typeStructure)
168168
implements SharedTypeSchemaView<TypeStructure> {
169169
List<SharedNamedTypeSchemaView<TypeStructure>> get namedTypes {
170-
return _typeStructure.sortedNamedTypes
170+
return _typeStructure.sortedNamedTypesShared
171171
as List<SharedNamedTypeSchemaView<TypeStructure>>;
172172
}
173173

174174
List<SharedTypeSchemaView<TypeStructure>> get positionalTypes {
175-
return _typeStructure.positionalTypes
175+
return _typeStructure.positionalTypesShared
176176
as List<SharedTypeSchemaView<TypeStructure>>;
177177
}
178178
}
@@ -182,12 +182,12 @@ extension type SharedRecordTypeView<
182182
SharedRecordTypeStructure<TypeStructure> _typeStructure)
183183
implements SharedTypeView<TypeStructure> {
184184
List<SharedNamedTypeView<TypeStructure>> get namedTypes {
185-
return _typeStructure.sortedNamedTypes
185+
return _typeStructure.sortedNamedTypesShared
186186
as List<SharedNamedTypeView<TypeStructure>>;
187187
}
188188

189189
List<SharedTypeView<TypeStructure>> get positionalTypes {
190-
return _typeStructure.positionalTypes
190+
return _typeStructure.positionalTypesShared
191191
as List<SharedTypeView<TypeStructure>>;
192192
}
193193
}

pkg/_fe_analyzer_shared/test/mini_types.dart

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ class FunctionType extends Type
6262
implements
6363
SharedFunctionTypeStructure<Type, TypeParameter,
6464
NamedFunctionParameter> {
65-
@override
6665
final Type returnType;
6766

6867
@override
@@ -147,9 +146,14 @@ class FunctionType extends Type
147146
}
148147
}
149148

150-
@override
151149
List<Type> get positionalParameterTypes => positionalParameters;
152150

151+
@override
152+
List<Type> get positionalParameterTypesShared => positionalParameterTypes;
153+
154+
@override
155+
Type get returnTypeShared => returnType;
156+
153157
@override
154158
List<NamedFunctionParameter> get sortedNamedParametersShared =>
155159
namedParameters;
@@ -412,7 +416,6 @@ class NamedFunctionParameter
412416
_Substitutable<NamedFunctionParameter> {
413417
final String name;
414418

415-
@override
416419
final Type type;
417420

418421
@override
@@ -427,6 +430,9 @@ class NamedFunctionParameter
427430
@override
428431
String get nameShared => name;
429432

433+
@override
434+
Type get typeShared => type;
435+
430436
@override
431437
bool operator ==(Object other) =>
432438
other is NamedFunctionParameter &&
@@ -450,7 +456,6 @@ class NamedType
450456
implements SharedNamedTypeStructure<Type>, _Substitutable<NamedType> {
451457
final String name;
452458

453-
@override
454459
final Type type;
455460

456461
NamedType({required this.name, required this.type});
@@ -461,6 +466,9 @@ class NamedType
461466
@override
462467
String get nameShared => name;
463468

469+
@override
470+
Type get typeShared => type;
471+
464472
@override
465473
bool operator ==(Object other) =>
466474
other is NamedType && name == other.name && type == other.type;
@@ -600,7 +608,6 @@ class PrimaryType extends Type {
600608
}
601609

602610
class RecordType extends Type implements SharedRecordTypeStructure<Type> {
603-
@override
604611
final List<Type> positionalTypes;
605612

606613
final List<NamedType> namedTypes;
@@ -624,8 +631,14 @@ class RecordType extends Type implements SharedRecordTypeStructure<Type> {
624631
nullabilitySuffix);
625632

626633
@override
634+
List<Type> get positionalTypesShared => positionalTypes;
635+
627636
List<NamedType> get sortedNamedTypes => namedTypes;
628637

638+
@override
639+
List<SharedNamedTypeStructure<Type>> get sortedNamedTypesShared =>
640+
sortedNamedTypes;
641+
629642
@override
630643
bool operator ==(Object other) =>
631644
other is RecordType &&
@@ -888,9 +901,11 @@ class TypeParameter extends TypeNameInfo
888901

889902
TypeParameter._(super.name) : super(expectedRuntimeType: TypeParameterType);
890903

891-
@override
892904
Type get bound => explicitBound ?? Type('Object?');
893905

906+
@override
907+
Type? get boundShared => bound;
908+
894909
@override
895910
String get displayName => name;
896911

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4493,6 +4493,9 @@ class FormalParameterElementImpl extends PromotableElementImpl2
44934493
// TODO(augmentations): Implement the merge of formal parameters.
44944494
List<TypeParameterElement2> get typeParameters2 => const [];
44954495

4496+
@override
4497+
DartType get typeShared => type;
4498+
44964499
@override
44974500
Element? get _enclosingFunction => wrappedElement._enclosingElement3;
44984501

@@ -10991,6 +10994,9 @@ class TypeParameterElementImpl2 extends TypeDefiningElementImpl2
1099110994
@override
1099210995
TypeParameterElement2 get baseElement => this;
1099310996

10997+
@override
10998+
DartType? get boundShared => bound;
10999+
1099411000
bool get isLegacyCovariant => firstFragment.isLegacyCovariant;
1099511001

1099611002
@override

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,9 @@ class ParameterMember extends VariableMember
11941194
@override
11951195
List<TypeParameterElement2> get typeParameters2 => _element2.typeParameters2;
11961196

1197+
@override
1198+
DartType get typeShared => type;
1199+
11971200
@override
11981201
FormalParameterElement get _element2 => declaration.asElement2;
11991202

0 commit comments

Comments
 (0)