[cfe] Remove pre-NNBD options from type parameter eliminators
This is a similar change to
https://dart-review.googlesource.com/c/sdk/+/395963, but for
eliminating type parameters in types. Fixing both the top and the
bottom types to their expected NNBD values is possible in this case,
since only those type options were used at the call sites.
Change-Id: Iff857a2f767b519b5cb80aeb225c25677e3a8183
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/396601
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
diff --git a/pkg/front_end/lib/src/kernel/body_builder.dart b/pkg/front_end/lib/src/kernel/body_builder.dart
index dd97dd4..7c5a195 100644
--- a/pkg/front_end/lib/src/kernel/body_builder.dart
+++ b/pkg/front_end/lib/src/kernel/body_builder.dart
@@ -737,8 +737,8 @@
for (Statement statement in declaration.users) {
statement.parent!.replaceChild(
statement,
- wrapInProblemStatement(statement,
- cfe.templateLabelNotFound.withArguments(name)));
+ wrapInProblemStatement(
+ statement, cfe.templateLabelNotFound.withArguments(name)));
}
} else {
outerSwitchScope.forwardDeclareLabel(name, declaration);
@@ -2790,10 +2790,8 @@
Name name = new Name(operator);
if (!isBinaryOperator(operator) && !isMinusOperator(operator)) {
if (isUserDefinableOperator(operator)) {
- push(buildProblem(
- cfe.templateNotBinaryOperator.withArguments(token),
- token.charOffset,
- token.length));
+ push(buildProblem(cfe.templateNotBinaryOperator.withArguments(token),
+ token.charOffset, token.length));
} else {
push(buildProblem(cfe.templateInvalidOperator.withArguments(token),
token.charOffset, token.length));
@@ -3129,8 +3127,8 @@
constantContext != ConstantContext.none &&
!context.allowedInConstantExpression) {
// Coverage-ignore-block(suite): Not run.
- addProblem(cfe.messageNotAConstantExpression, token.charOffset,
- token.length);
+ addProblem(
+ cfe.messageNotAConstantExpression, token.charOffset, token.length);
}
if (token.isSynthetic) {
push(new ParserRecovery(offsetForToken(token)));
@@ -3398,8 +3396,8 @@
if (!(readTarget is Field && readTarget.isConst ||
// Static tear-offs are also compile time constants.
readTarget is Procedure)) {
- addProblem(cfe.messageNotAConstantExpression, nameOffset,
- nameToken.length);
+ addProblem(
+ cfe.messageNotAConstantExpression, nameOffset, nameToken.length);
}
}
return generator;
@@ -4713,8 +4711,8 @@
]));
if (constantContext == ConstantContext.required && constKeyword == null) {
- addProblem(cfe.messageMissingExplicitConst, offsetForToken(leftBrace),
- noLength);
+ addProblem(
+ cfe.messageMissingExplicitConst, offsetForToken(leftBrace), noLength);
}
List<dynamic> setOrMapEntries =
@@ -6405,16 +6403,16 @@
ConstantContext savedConstantContext = pop() as ConstantContext;
if (arguments is! Arguments) {
- push(new ParserErrorGenerator(
- this, nameToken, cfe.messageSyntheticToken));
+ push(
+ new ParserErrorGenerator(this, nameToken, cfe.messageSyntheticToken));
arguments = forest.createArguments(offset, []);
} else if (type is Generator) {
push(type.invokeConstructor(
typeArguments, name, arguments, nameToken, nameLastToken, constness,
inImplicitCreationContext: inImplicitCreationContext));
} else if (type is ParserRecovery) {
- push(new ParserErrorGenerator(
- this, nameToken, cfe.messageSyntheticToken));
+ push(
+ new ParserErrorGenerator(this, nameToken, cfe.messageSyntheticToken));
} else if (type is InvalidExpression) {
push(type);
} else if (type is Expression) {
@@ -6511,13 +6509,13 @@
required UnresolvedKind unresolvedKind}) {
if (arguments == null) {
// Coverage-ignore-block(suite): Not run.
- return buildProblem(cfe.messageMissingArgumentList,
- nameToken.charOffset, nameToken.length);
+ return buildProblem(cfe.messageMissingArgumentList, nameToken.charOffset,
+ nameToken.length);
}
if (name.isNotEmpty && arguments.types.isNotEmpty) {
// TODO(ahe): Point to the type arguments instead.
- addProblem(cfe.messageConstructorWithTypeArguments,
- nameToken.charOffset, nameToken.length);
+ addProblem(cfe.messageConstructorWithTypeArguments, nameToken.charOffset,
+ nameToken.length);
}
String? errorName;
@@ -7101,8 +7099,8 @@
// Coverage-ignore(suite): Not run.
offsetForToken(ifToken);
node = new MapLiteralEntry(
- buildProblem(cfe.templateExpectedAfterButGot.withArguments(':'),
- offset, 1),
+ buildProblem(
+ cfe.templateExpectedAfterButGot.withArguments(':'), offset, 1),
new NullLiteral())
..fileOffset = offsetForToken(ifToken);
}
@@ -7138,8 +7136,8 @@
// Coverage-ignore(suite): Not run.
offsetForToken(ifToken);
node = new MapLiteralEntry(
- buildProblem(cfe.templateExpectedAfterButGot.withArguments(':'),
- offset, 1),
+ buildProblem(
+ cfe.templateExpectedAfterButGot.withArguments(':'), offset, 1),
new NullLiteral())
..fileOffset = offsetForToken(ifToken);
}
@@ -9355,10 +9353,8 @@
typeParameter.declaration is ExtensionTypeDeclaration) {
if (constantContext != ConstantContext.none &&
(!inConstructorInitializer || !allowPotentiallyConstantType)) {
- LocatedMessage message =
- cfe.messageTypeVariableInConstantContext.withLocation(
- builder.fileUri!,
- builder.charOffset!,
+ LocatedMessage message = cfe.messageTypeVariableInConstantContext
+ .withLocation(builder.fileUri!, builder.charOffset!,
typeParameter.name!.length);
builder.bind(
libraryBuilder,
@@ -9450,8 +9446,7 @@
!isConstantExpression &&
!libraryFeatures.constFunctions.isEnabled) {
return buildProblem(
- cfe.templateNotConstantExpression
- .withArguments('Method invocation'),
+ cfe.templateNotConstantExpression.withArguments('Method invocation'),
offset,
name.text.length);
}
@@ -9480,8 +9475,7 @@
!isConstantExpression &&
!libraryFeatures.constFunctions.isEnabled) {
return buildProblem(
- cfe.templateNotConstantExpression
- .withArguments('Method invocation'),
+ cfe.templateNotConstantExpression.withArguments('Method invocation'),
offset,
name.text.length);
}
@@ -9904,8 +9898,7 @@
if (colon != null) {
Object? identifier = pop();
if (identifier is ParserRecovery) {
- push(
- new ParserErrorGenerator(this, colon, cfe.messageSyntheticToken));
+ push(new ParserErrorGenerator(this, colon, cfe.messageSyntheticToken));
} else {
String? name;
if (identifier is Identifier) {
diff --git a/pkg/front_end/lib/src/kernel/utils.dart b/pkg/front_end/lib/src/kernel/utils.dart
index 89c5e04..123808f 100644
--- a/pkg/front_end/lib/src/kernel/utils.dart
+++ b/pkg/front_end/lib/src/kernel/utils.dart
@@ -226,8 +226,7 @@
return a.fileOffset.compareTo(b.fileOffset);
}
-List<Combinator>? toCombinators(
- List<CombinatorBuilder>? combinatorBuilders) {
+List<Combinator>? toCombinators(List<CombinatorBuilder>? combinatorBuilders) {
if (combinatorBuilders == null) {
// Note: it's safe to return null here as Kernel's LibraryDependency will
// convert null to an empty list.
diff --git a/pkg/front_end/lib/src/source/source_compilation_unit.dart b/pkg/front_end/lib/src/source/source_compilation_unit.dart
index 2b14af6..a7a3e1a 100644
--- a/pkg/front_end/lib/src/source/source_compilation_unit.dart
+++ b/pkg/front_end/lib/src/source/source_compilation_unit.dart
@@ -528,8 +528,7 @@
LibraryBuilder imported = import.importedLibraryBuilder!.origin;
Library targetLibrary = imported.library;
libraryDependency = new LibraryDependency.import(targetLibrary,
- name: import.prefix,
- combinators: toCombinators(import.combinators))
+ name: import.prefix, combinators: toCombinators(import.combinators))
..fileOffset = import.importOffset;
}
library.addDependency(libraryDependency);
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 e19618c..24038ac 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
@@ -974,10 +974,7 @@
DartType greatestClosureOfTypeInternal(DartType type,
List<SharedTypeParameterStructure<DartType>> typeParametersToEliminate) {
return new NullabilityAwareFreeTypeParameterEliminator(
- bottomType: const NeverType.nonNullable(),
- topType: typeEnvironment.coreTypes.objectNullableRawType,
- topFunctionType: typeEnvironment.coreTypes
- .functionRawType(Nullability.nonNullable))
+ coreTypes: typeEnvironment.coreTypes)
.eliminateToGreatest(type);
}
@@ -985,10 +982,7 @@
DartType leastClosureOfTypeInternal(DartType type,
List<SharedTypeParameterStructure<DartType>> typeParametersToEliminate) {
return new NullabilityAwareFreeTypeParameterEliminator(
- bottomType: const NeverType.nonNullable(),
- topType: typeEnvironment.coreTypes.objectNullableRawType,
- topFunctionType: typeEnvironment.coreTypes
- .functionRawType(Nullability.nonNullable))
+ coreTypes: typeEnvironment.coreTypes)
.eliminateToLeast(type);
}
diff --git a/pkg/front_end/lib/src/type_inference/type_schema_environment.dart b/pkg/front_end/lib/src/type_inference/type_schema_environment.dart
index 28b3ca9..474e7ce 100644
--- a/pkg/front_end/lib/src/type_inference/type_schema_environment.dart
+++ b/pkg/front_end/lib/src/type_inference/type_schema_environment.dart
@@ -64,6 +64,7 @@
TypeSchemaEnvironment(CoreTypes coreTypes, this.hierarchy)
: super(coreTypes, hierarchy);
+ // Coverage-ignore(suite): Not run.
InterfaceType functionRawType(Nullability nullability) {
return coreTypes.functionRawType(nullability);
}
@@ -370,9 +371,7 @@
if (!isEmptyContext(returnContextType)) {
if (isConst) {
returnContextType = new NullabilityAwareFreeTypeParameterEliminator(
- bottomType: const NeverType.nonNullable(),
- topType: objectNullableRawType,
- topFunctionType: functionRawType(Nullability.nonNullable))
+ coreTypes: coreTypes)
.eliminateToLeast(returnContextType!);
}
gatherer.tryConstrainUpper(declaredReturnType!, returnContextType!,
diff --git a/pkg/front_end/test/coverage_suite_expected.dart b/pkg/front_end/test/coverage_suite_expected.dart
index fc30fcc..6154662 100644
--- a/pkg/front_end/test/coverage_suite_expected.dart
+++ b/pkg/front_end/test/coverage_suite_expected.dart
@@ -560,7 +560,7 @@
),
// 100.0%.
"package:front_end/src/kernel/body_builder.dart": (
- hitCount: 7173,
+ hitCount: 7185,
missCount: 0,
),
// 100.0%.
@@ -765,7 +765,7 @@
),
// 100.0%.
"package:front_end/src/kernel/member_covariance.dart": (
- hitCount: 257,
+ hitCount: 258,
missCount: 0,
),
// 100.0%.
@@ -926,12 +926,12 @@
),
// 100.0%.
"package:front_end/src/source/source_field_builder.dart": (
- hitCount: 1246,
+ hitCount: 1250,
missCount: 0,
),
// 100.0%.
"package:front_end/src/source/source_function_builder.dart": (
- hitCount: 316,
+ hitCount: 345,
missCount: 0,
),
// 100.0%.
@@ -1006,7 +1006,7 @@
),
// 100.0%.
"package:front_end/src/type_inference/inference_visitor_base.dart": (
- hitCount: 2460,
+ hitCount: 2458,
missCount: 0,
),
// 100.0%.
@@ -1046,7 +1046,7 @@
),
// 100.0%.
"package:front_end/src/type_inference/type_inference_engine.dart": (
- hitCount: 547,
+ hitCount: 530,
missCount: 0,
),
// 100.0%.
@@ -1061,12 +1061,12 @@
),
// 100.0%.
"package:front_end/src/type_inference/type_schema_elimination.dart": (
- hitCount: 32,
+ hitCount: 29,
missCount: 0,
),
// 100.0%.
"package:front_end/src/type_inference/type_schema_environment.dart": (
- hitCount: 267,
+ hitCount: 261,
missCount: 0,
),
// 100.0%.
diff --git a/pkg/kernel/lib/src/standard_bounds.dart b/pkg/kernel/lib/src/standard_bounds.dart
index 0e4b53e..9f9bab7 100644
--- a/pkg/kernel/lib/src/standard_bounds.dart
+++ b/pkg/kernel/lib/src/standard_bounds.dart
@@ -1693,9 +1693,7 @@
nominalEliminationTargets: {
if (nominalEliminationTarget != null) nominalEliminationTarget
},
- bottomType: const NeverType.nonNullable(),
- topType: coreTypes.objectNullableRawType,
- topFunctionType: coreTypes.functionNonNullableRawType,
+ coreTypes: coreTypes,
unhandledTypeHandler: (type, recursor) => false);
DartType result = _getNullabilityAwareStandardUpperBound(
eliminator.eliminateToGreatest(bound1), type2);
@@ -1730,9 +1728,7 @@
new NullabilityAwareTypeParameterEliminator(
structuralEliminationTargets: {},
nominalEliminationTargets: {type1.left.parameter},
- bottomType: const NeverType.nonNullable(),
- topType: coreTypes.objectNullableRawType,
- topFunctionType: coreTypes.functionNonNullableRawType,
+ coreTypes: coreTypes,
unhandledTypeHandler: (type, recursor) => false);
Nullability resultingNullability =
uniteNullabilities(type1.right.declaredNullability, type2.nullability);
diff --git a/pkg/kernel/lib/type_algebra.dart b/pkg/kernel/lib/type_algebra.dart
index 28f4440..4faa805 100644
--- a/pkg/kernel/lib/type_algebra.dart
+++ b/pkg/kernel/lib/type_algebra.dart
@@ -5,6 +5,7 @@
library kernel.type_algebra;
import 'ast.dart';
+import 'core_types.dart';
import 'src/find_type_visitor.dart';
import 'src/replacement_visitor.dart';
@@ -1933,15 +1934,10 @@
abstract class NullabilityAwareTypeVariableEliminatorBase
extends ReplacementVisitor {
- final DartType bottomType;
- final DartType topType;
- final DartType topFunctionType;
+ final CoreTypes coreTypes;
late bool _isLeastClosure;
- NullabilityAwareTypeVariableEliminatorBase(
- {required this.bottomType,
- required this.topType,
- required this.topFunctionType});
+ NullabilityAwareTypeVariableEliminatorBase({required this.coreTypes});
bool containsTypeVariablesToEliminate(DartType type);
@@ -1964,15 +1960,15 @@
DartType getTypeParameterReplacement(Variance variance) {
bool isCovariant = variance == Variance.covariant;
return _isLeastClosure && isCovariant || (!_isLeastClosure && !isCovariant)
- ? bottomType
- : topType;
+ ? const NeverType.nonNullable()
+ : coreTypes.objectNullableRawType;
}
DartType getFunctionReplacement(Variance variance) {
bool isCovariant = variance == Variance.covariant;
return _isLeastClosure && isCovariant || (!_isLeastClosure && !isCovariant)
- ? bottomType
- : topFunctionType;
+ ? const NeverType.nonNullable()
+ : coreTypes.functionNonNullableRawType;
}
@override
@@ -2038,14 +2034,9 @@
NullabilityAwareTypeParameterEliminator(
{required this.structuralEliminationTargets,
required this.nominalEliminationTargets,
- required DartType bottomType,
- required DartType topType,
- required DartType topFunctionType,
+ required CoreTypes coreTypes,
this.unhandledTypeHandler})
- : super(
- bottomType: bottomType,
- topType: topType,
- topFunctionType: topFunctionType);
+ : super(coreTypes: coreTypes);
@override
bool containsTypeVariablesToEliminate(DartType type) {
@@ -2080,14 +2071,8 @@
extends NullabilityAwareTypeVariableEliminatorBase {
Set<StructuralParameter> _boundVariables = <StructuralParameter>{};
- NullabilityAwareFreeTypeParameterEliminator(
- {required DartType bottomType,
- required DartType topType,
- required DartType topFunctionType})
- : super(
- bottomType: bottomType,
- topType: topType,
- topFunctionType: topFunctionType);
+ NullabilityAwareFreeTypeParameterEliminator({required CoreTypes coreTypes})
+ : super(coreTypes: coreTypes);
@override
DartType? visitFunctionType(FunctionType node, Variance variance) {