Skip to content

Commit 74be667

Browse files
johnniwinthercommit-bot@chromium.org
authored andcommitted
[kernel] Remove CoreTypes from legacyErasure
Change-Id: I9692c01ed3bf9982834144dd9eb477a97db5536f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175041 Reviewed-by: Dmitry Stefantsov <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent f7ae22a commit 74be667

13 files changed

+46
-64
lines changed

pkg/front_end/lib/src/fasta/builder/field_builder.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,7 @@ class SourceFieldBuilder extends MemberBuilderImpl implements FieldBuilder {
429429
// `fieldType` may have changed if a circularity was detected when
430430
// [inferredType] was computed.
431431
if (!library.isNonNullableByDefault) {
432-
inferredType = legacyErasure(
433-
library.loader.typeInferenceEngine.coreTypes, inferredType);
432+
inferredType = legacyErasure(inferredType);
434433
}
435434
fieldType = implicitFieldType.checkInferred(inferredType);
436435

pkg/front_end/lib/src/fasta/kernel/class_hierarchy_builder.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ class ClassHierarchyNodeBuilder {
12651265
norm(hierarchy.coreTypes, inheritedType));
12661266
}
12671267
} else {
1268-
inheritedType = legacyErasure(hierarchy.coreTypes, inheritedType);
1268+
inheritedType = legacyErasure(inheritedType);
12691269
if (inferredType == null) {
12701270
return inheritedType;
12711271
} else {
@@ -1703,8 +1703,7 @@ class ClassHierarchyNodeBuilder {
17031703
if (!classBuilder.library.isNonNullableByDefault &&
17041704
supernode.classBuilder.library.isNonNullableByDefault) {
17051705
for (int i = 0; i < superclasses.length; i++) {
1706-
superclasses[i] =
1707-
legacyErasureSupertype(hierarchy.coreTypes, superclasses[i]);
1706+
superclasses[i] = legacyErasureSupertype(superclasses[i]);
17081707
}
17091708
}
17101709

@@ -2377,7 +2376,7 @@ class ClassHierarchyNodeBuilder {
23772376
Supertype type) {
23782377
if (type == null) return null;
23792378
if (!classBuilder.library.isNonNullableByDefault) {
2380-
type = legacyErasureSupertype(hierarchy.coreTypes, type);
2379+
type = legacyErasureSupertype(type);
23812380
}
23822381
ClassHierarchyNode node = hierarchy.getNodeFromClass(type.classNode);
23832382
if (node == null) return null;

pkg/front_end/lib/src/fasta/kernel/combined_member_signature.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ abstract class CombinedMemberSignatureBase<T> {
301301
"No member computed for index ${index} in ${members}");
302302
candidateType = _computeMemberType(thisType, target);
303303
if (!classBuilder.library.isNonNullableByDefault) {
304-
DartType legacyErasure = rawLegacyErasure(_coreTypes, candidateType);
304+
DartType legacyErasure = rawLegacyErasure(candidateType);
305305
if (legacyErasure != null) {
306306
_neededLegacyErasureIndices ??= {};
307307
_neededLegacyErasureIndices.add(index);

pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,6 @@ class ConstantWeakener extends ComputeOnceConstantVisitor<Constant> {
174174

175175
ConstantWeakener(this._evaluator);
176176

177-
CoreTypes get _coreTypes => _evaluator.coreTypes;
178-
179177
Constant processValue(Constant node, Constant value) {
180178
if (value != null) {
181179
value = _evaluator.canonicalize(value);
@@ -207,8 +205,8 @@ class ConstantWeakener extends ComputeOnceConstantVisitor<Constant> {
207205

208206
@override
209207
Constant visitMapConstant(MapConstant node) {
210-
DartType keyType = rawLegacyErasure(_coreTypes, node.keyType);
211-
DartType valueType = rawLegacyErasure(_coreTypes, node.valueType);
208+
DartType keyType = rawLegacyErasure(node.keyType);
209+
DartType valueType = rawLegacyErasure(node.valueType);
212210
List<ConstantMapEntry> entries;
213211
for (int index = 0; index < node.entries.length; index++) {
214212
ConstantMapEntry entry = node.entries[index];
@@ -229,7 +227,7 @@ class ConstantWeakener extends ComputeOnceConstantVisitor<Constant> {
229227

230228
@override
231229
Constant visitListConstant(ListConstant node) {
232-
DartType typeArgument = rawLegacyErasure(_coreTypes, node.typeArgument);
230+
DartType typeArgument = rawLegacyErasure(node.typeArgument);
233231
List<Constant> entries;
234232
for (int index = 0; index < node.entries.length; index++) {
235233
Constant entry = visitConstant(node.entries[index]);
@@ -247,7 +245,7 @@ class ConstantWeakener extends ComputeOnceConstantVisitor<Constant> {
247245

248246
@override
249247
Constant visitSetConstant(SetConstant node) {
250-
DartType typeArgument = rawLegacyErasure(_coreTypes, node.typeArgument);
248+
DartType typeArgument = rawLegacyErasure(node.typeArgument);
251249
List<Constant> entries;
252250
for (int index = 0; index < node.entries.length; index++) {
253251
Constant entry = visitConstant(node.entries[index]);
@@ -267,8 +265,7 @@ class ConstantWeakener extends ComputeOnceConstantVisitor<Constant> {
267265
Constant visitInstanceConstant(InstanceConstant node) {
268266
List<DartType> typeArguments;
269267
for (int index = 0; index < node.typeArguments.length; index++) {
270-
DartType typeArgument =
271-
rawLegacyErasure(_coreTypes, node.typeArguments[index]);
268+
DartType typeArgument = rawLegacyErasure(node.typeArguments[index]);
272269
if (typeArgument != null) {
273270
typeArguments ??= node.typeArguments.toList(growable: false);
274271
typeArguments[index] = typeArgument;
@@ -294,7 +291,7 @@ class ConstantWeakener extends ComputeOnceConstantVisitor<Constant> {
294291
PartialInstantiationConstant node) {
295292
List<DartType> types;
296293
for (int index = 0; index < node.types.length; index++) {
297-
DartType type = rawLegacyErasure(_coreTypes, node.types[index]);
294+
DartType type = rawLegacyErasure(node.types[index]);
298295
if (type != null) {
299296
types ??= node.types.toList(growable: false);
300297
types[index] = type;
@@ -311,7 +308,7 @@ class ConstantWeakener extends ComputeOnceConstantVisitor<Constant> {
311308

312309
@override
313310
Constant visitTypeLiteralConstant(TypeLiteralConstant node) {
314-
DartType type = rawLegacyErasure(_coreTypes, node.type);
311+
DartType type = rawLegacyErasure(node.type);
315312
if (type != null) {
316313
return new TypeLiteralConstant(type);
317314
}
@@ -840,7 +837,7 @@ class ConstantEvaluator extends RecursiveVisitor<Constant> {
840837
case EvaluationMode.agnostic:
841838
return type;
842839
case EvaluationMode.weak:
843-
return legacyErasure(coreTypes, type);
840+
return legacyErasure(type);
844841
}
845842
throw new UnsupportedError(
846843
"Unexpected evaluation mode: ${evaluationMode}.");
@@ -852,9 +849,7 @@ class ConstantEvaluator extends RecursiveVisitor<Constant> {
852849
case EvaluationMode.agnostic:
853850
return types;
854851
case EvaluationMode.weak:
855-
return types
856-
.map((DartType type) => legacyErasure(coreTypes, type))
857-
.toList();
852+
return types.map((DartType type) => legacyErasure(type)).toList();
858853
}
859854
throw new UnsupportedError(
860855
"Unexpected evaluation mode: ${evaluationMode}.");
@@ -2608,7 +2603,7 @@ class ConstantEvaluator extends RecursiveVisitor<Constant> {
26082603
bool isSubtype(Constant constant, DartType type, SubtypeCheckMode mode) {
26092604
DartType constantType = constant.getType(_staticTypeContext);
26102605
if (mode == SubtypeCheckMode.ignoringNullabilities) {
2611-
constantType = rawLegacyErasure(coreTypes, constantType) ?? constantType;
2606+
constantType = rawLegacyErasure(constantType) ?? constantType;
26122607
}
26132608
bool result = typeEnvironment.isSubtypeOf(constantType, type, mode);
26142609
if (targetingJavaScript && !result) {

pkg/front_end/lib/src/fasta/kernel/implicit_field_type.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ class _ImplicitFieldTypeRoot extends ImplicitFieldType {
112112
for (ImplicitFieldType overridden in _overriddenFields) {
113113
DartType overriddenType = overridden.inferType();
114114
if (!fieldBuilder.library.isNonNullableByDefault) {
115-
overriddenType = legacyErasure(
116-
fieldBuilder.library.loader.coreTypes, overriddenType);
115+
overriddenType = legacyErasure(overriddenType);
117116
}
118117
if (inferredType == null) {
119118
inferredType = overriddenType;
@@ -166,8 +165,7 @@ class _ImplicitFieldTypeRoot extends ImplicitFieldType {
166165
for (ImplicitFieldType overridden in _overriddenFields) {
167166
DartType overriddenType = overridden.inferType();
168167
if (!fieldBuilder.library.isNonNullableByDefault) {
169-
overriddenType = legacyErasure(
170-
fieldBuilder.library.loader.coreTypes, overriddenType);
168+
overriddenType = legacyErasure(overriddenType);
171169
}
172170
if (type != overriddenType) {
173171
String name = fieldBuilder.fullNameForErrors;

pkg/front_end/lib/src/fasta/kernel/inference_visitor.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3837,7 +3837,7 @@ class InferenceVisitor
38373837
}
38383838

38393839
if (!inferrer.isNonNullableByDefault) {
3840-
binaryType = legacyErasure(inferrer.coreTypes, binaryType);
3840+
binaryType = legacyErasure(binaryType);
38413841
}
38423842

38433843
if (!inferrer.isTopLevel && binaryTarget.isNullable) {
@@ -3934,7 +3934,7 @@ class InferenceVisitor
39343934
}
39353935

39363936
if (!inferrer.isNonNullableByDefault) {
3937-
unaryType = legacyErasure(inferrer.coreTypes, unaryType);
3937+
unaryType = legacyErasure(unaryType);
39383938
}
39393939

39403940
if (!inferrer.isTopLevel && unaryTarget.isNullable) {
@@ -4022,7 +4022,7 @@ class InferenceVisitor
40224022
}
40234023

40244024
if (!inferrer.isNonNullableByDefault) {
4025-
readType = legacyErasure(inferrer.coreTypes, readType);
4025+
readType = legacyErasure(readType);
40264026
}
40274027

40284028
if (!inferrer.isTopLevel && readTarget.isNullable) {
@@ -4220,7 +4220,7 @@ class InferenceVisitor
42204220
}
42214221

42224222
if (!inferrer.isNonNullableByDefault) {
4223-
readType = legacyErasure(inferrer.coreTypes, readType);
4223+
readType = legacyErasure(readType);
42244224
}
42254225

42264226
readResult ??= new ExpressionInferenceResult(readType, read);
@@ -5275,7 +5275,7 @@ class InferenceVisitor
52755275
DartType type = target.getterType;
52765276

52775277
if (!inferrer.isNonNullableByDefault) {
5278-
type = legacyErasure(inferrer.coreTypes, type);
5278+
type = legacyErasure(type);
52795279
}
52805280

52815281
if (target is Procedure && target.kind == ProcedureKind.Method) {

pkg/front_end/lib/src/fasta/source/source_class_builder.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,8 +1234,7 @@ class SourceClassBuilder extends ClassBuilderImpl
12341234
}
12351235
DartType computedBound = substitution.substituteType(interfaceBound);
12361236
if (!library.isNonNullableByDefault) {
1237-
computedBound =
1238-
legacyErasure(types.hierarchy.coreTypes, computedBound);
1237+
computedBound = legacyErasure(computedBound);
12391238
}
12401239
if (!types
12411240
.performNullabilityAwareMutualSubtypesCheck(
@@ -1305,7 +1304,7 @@ class SourceClassBuilder extends ClassBuilderImpl
13051304

13061305
if (!declaredMember.isNonNullableByDefault &&
13071306
interfaceMember.isNonNullableByDefault) {
1308-
interfaceType = legacyErasure(types.hierarchy.coreTypes, interfaceType);
1307+
interfaceType = legacyErasure(interfaceType);
13091308
}
13101309

13111310
bool inParameter = declaredParameter != null || asIfDeclaredParameter;

pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,7 +1985,7 @@ class TypeInferrerImpl implements TypeInferrer {
19851985
typeSchemaEnvironment.inferGenericFunctionOrType(
19861986
isNonNullableByDefault
19871987
? calleeType.returnType
1988-
: legacyErasure(coreTypes, calleeType.returnType),
1988+
: legacyErasure(calleeType.returnType),
19891989
calleeTypeParameters,
19901990
null,
19911991
null,
@@ -2034,14 +2034,14 @@ class TypeInferrerImpl implements TypeInferrer {
20342034
arguments.positional[position],
20352035
isNonNullableByDefault
20362036
? inferredFormalType
2037-
: legacyErasure(coreTypes, inferredFormalType),
2037+
: legacyErasure(inferredFormalType),
20382038
inferenceNeeded ||
20392039
isSpecialCasedBinaryOperator ||
20402040
isSpecialCasedTernaryOperator ||
20412041
typeChecksNeeded);
20422042
inferredType = result.inferredType == null || isNonNullableByDefault
20432043
? result.inferredType
2044-
: legacyErasure(coreTypes, result.inferredType);
2044+
: legacyErasure(result.inferredType);
20452045
Expression expression =
20462046
_hoist(result.expression, inferredType, hoistedExpressions);
20472047
arguments.positional[position] = expression..parent = arguments;
@@ -2073,12 +2073,12 @@ class TypeInferrerImpl implements TypeInferrer {
20732073
namedArgument.value,
20742074
isNonNullableByDefault
20752075
? inferredFormalType
2076-
: legacyErasure(coreTypes, inferredFormalType),
2076+
: legacyErasure(inferredFormalType),
20772077
inferenceNeeded || isSpecialCasedBinaryOperator || typeChecksNeeded);
20782078
DartType inferredType =
20792079
result.inferredType == null || isNonNullableByDefault
20802080
? result.inferredType
2081-
: legacyErasure(coreTypes, result.inferredType);
2081+
: legacyErasure(result.inferredType);
20822082
Expression expression =
20832083
_hoist(result.expression, inferredType, hoistedExpressions);
20842084
namedArgument.value = expression..parent = namedArgument;
@@ -2216,7 +2216,7 @@ class TypeInferrerImpl implements TypeInferrer {
22162216
"Inferred function type: $calleeType.");
22172217

22182218
if (!isNonNullableByDefault) {
2219-
inferredType = legacyErasure(coreTypes, inferredType);
2219+
inferredType = legacyErasure(inferredType);
22202220
}
22212221

22222222
return new SuccessfulInferenceResult(inferredType);

pkg/kernel/lib/class_hierarchy.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -694,8 +694,8 @@ class ClosedWorldClassHierarchy implements ClassHierarchy {
694694
: Substitution.fromInterfaceType(type2).substituteType(
695695
info2.genericSuperType[next.classNode].asInterfaceType);
696696
if (!clientLibrary.isNonNullableByDefault) {
697-
superType1 = legacyErasure(coreTypes, superType1);
698-
superType2 = legacyErasure(coreTypes, superType2);
697+
superType1 = legacyErasure(superType1);
698+
superType2 = legacyErasure(superType2);
699699
}
700700
if (superType1 == superType2) {
701701
candidate = superType1.withDeclaredNullability(
@@ -1657,7 +1657,7 @@ class _ClassInfo {
16571657
Supertype canonical = genericSuperType[cls];
16581658
if (canonical == null) {
16591659
if (!classNode.enclosingLibrary.isNonNullableByDefault) {
1660-
canonical = legacyErasureSupertype(coreTypes, type);
1660+
canonical = legacyErasureSupertype(type);
16611661
} else {
16621662
canonical = type;
16631663
}
@@ -1679,7 +1679,7 @@ class _ClassInfo {
16791679
genericSuperType[cls] = result;
16801680
}
16811681
} else {
1682-
type = legacyErasureSupertype(coreTypes, type);
1682+
type = legacyErasureSupertype(type);
16831683
if (type != canonical) {
16841684
onAmbiguousSupertypes(classNode, canonical, type);
16851685
}

pkg/kernel/lib/src/bounds_checks.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ List<TypeArgumentIssue> findTypeArgumentIssues(
345345
} else if (variables[i].bound is! InvalidType) {
346346
DartType bound = substitute(variables[i].bound, substitutionMap);
347347
if (!library.isNonNullableByDefault) {
348-
bound = legacyErasure(typeEnvironment.coreTypes, bound);
348+
bound = legacyErasure(bound);
349349
}
350350
if (!typeEnvironment.isSubtypeOf(argument, bound, subtypeCheckMode)) {
351351
// If the bound is InvalidType it's not checked, because an error was
@@ -454,7 +454,7 @@ List<TypeArgumentIssue> findTypeArgumentIssuesForInvocation(
454454
} else if (parameters[i].bound is! InvalidType) {
455455
DartType bound = substitute(parameters[i].bound, substitutionMap);
456456
if (!library.isNonNullableByDefault) {
457-
bound = legacyErasure(typeEnvironment.coreTypes, bound);
457+
bound = legacyErasure(bound);
458458
}
459459
if (!typeEnvironment.isSubtypeOf(argument, bound, subtypeCheckMode)) {
460460
result ??= <TypeArgumentIssue>[];

pkg/kernel/lib/src/legacy_erasure.dart

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,36 @@
33
// BSD-style license that can be found in the LICENSE.md file.
44

55
import '../ast.dart' hide MapEntry;
6-
import '../core_types.dart';
76

87
import 'replacement_visitor.dart';
98

109
/// Returns legacy erasure of [type], that is, the type in which all nnbd
1110
/// nullabilities have been replaced with legacy nullability, and all required
1211
/// named parameters are not required.
13-
DartType legacyErasure(CoreTypes coreTypes, DartType type) {
14-
return rawLegacyErasure(coreTypes, type) ?? type;
12+
DartType legacyErasure(DartType type) {
13+
return rawLegacyErasure(type) ?? type;
1514
}
1615

1716
/// Returns legacy erasure of [type], that is, the type in which all nnbd
1817
/// nullabilities have been replaced with legacy nullability, and all required
1918
/// named parameters are not required.
2019
///
2120
/// Returns `null` if the type wasn't changed.
22-
DartType rawLegacyErasure(CoreTypes coreTypes, DartType type) {
23-
return type.accept(new _LegacyErasure(coreTypes));
21+
DartType rawLegacyErasure(DartType type) {
22+
return type.accept(const _LegacyErasure());
2423
}
2524

2625
/// Returns legacy erasure of [supertype], that is, the type in which all nnbd
2726
/// nullabilities have been replaced with legacy nullability, and all required
2827
/// named parameters are not required.
29-
Supertype legacyErasureSupertype(CoreTypes coreTypes, Supertype supertype) {
28+
Supertype legacyErasureSupertype(Supertype supertype) {
3029
if (supertype.typeArguments.isEmpty) {
3130
return supertype;
3231
}
3332
List<DartType> newTypeArguments;
3433
for (int i = 0; i < supertype.typeArguments.length; i++) {
3534
DartType typeArgument = supertype.typeArguments[i];
36-
DartType newTypeArgument =
37-
typeArgument.accept(new _LegacyErasure(coreTypes));
35+
DartType newTypeArgument = typeArgument.accept(const _LegacyErasure());
3836
if (newTypeArgument != null) {
3937
newTypeArguments ??= supertype.typeArguments.toList(growable: false);
4038
newTypeArguments[i] = newTypeArgument;
@@ -51,9 +49,7 @@ Supertype legacyErasureSupertype(CoreTypes coreTypes, Supertype supertype) {
5149
///
5250
/// The visitor returns `null` if the type wasn't changed.
5351
class _LegacyErasure extends ReplacementVisitor {
54-
final CoreTypes coreTypes;
55-
56-
_LegacyErasure(this.coreTypes);
52+
const _LegacyErasure();
5753

5854
Nullability visitNullability(DartType node) {
5955
if (node.declaredNullability != Nullability.legacy) {

0 commit comments

Comments
 (0)