Skip to content

Commit 17b9bf2

Browse files
chloestefantsovaCommit Queue
authored andcommitted
[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 <[email protected]> Commit-Queue: Chloe Stefantsova <[email protected]>
1 parent 5bb9e92 commit 17b9bf2

File tree

8 files changed

+54
-89
lines changed

8 files changed

+54
-89
lines changed

pkg/front_end/lib/src/kernel/body_builder.dart

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -737,8 +737,8 @@ class BodyBuilder extends StackListenerImpl
737737
for (Statement statement in declaration.users) {
738738
statement.parent!.replaceChild(
739739
statement,
740-
wrapInProblemStatement(statement,
741-
cfe.templateLabelNotFound.withArguments(name)));
740+
wrapInProblemStatement(
741+
statement, cfe.templateLabelNotFound.withArguments(name)));
742742
}
743743
} else {
744744
outerSwitchScope.forwardDeclareLabel(name, declaration);
@@ -2790,10 +2790,8 @@ class BodyBuilder extends StackListenerImpl
27902790
Name name = new Name(operator);
27912791
if (!isBinaryOperator(operator) && !isMinusOperator(operator)) {
27922792
if (isUserDefinableOperator(operator)) {
2793-
push(buildProblem(
2794-
cfe.templateNotBinaryOperator.withArguments(token),
2795-
token.charOffset,
2796-
token.length));
2793+
push(buildProblem(cfe.templateNotBinaryOperator.withArguments(token),
2794+
token.charOffset, token.length));
27972795
} else {
27982796
push(buildProblem(cfe.templateInvalidOperator.withArguments(token),
27992797
token.charOffset, token.length));
@@ -3129,8 +3127,8 @@ class BodyBuilder extends StackListenerImpl
31293127
constantContext != ConstantContext.none &&
31303128
!context.allowedInConstantExpression) {
31313129
// Coverage-ignore-block(suite): Not run.
3132-
addProblem(cfe.messageNotAConstantExpression, token.charOffset,
3133-
token.length);
3130+
addProblem(
3131+
cfe.messageNotAConstantExpression, token.charOffset, token.length);
31343132
}
31353133
if (token.isSynthetic) {
31363134
push(new ParserRecovery(offsetForToken(token)));
@@ -3398,8 +3396,8 @@ class BodyBuilder extends StackListenerImpl
33983396
if (!(readTarget is Field && readTarget.isConst ||
33993397
// Static tear-offs are also compile time constants.
34003398
readTarget is Procedure)) {
3401-
addProblem(cfe.messageNotAConstantExpression, nameOffset,
3402-
nameToken.length);
3399+
addProblem(
3400+
cfe.messageNotAConstantExpression, nameOffset, nameToken.length);
34033401
}
34043402
}
34053403
return generator;
@@ -4713,8 +4711,8 @@ class BodyBuilder extends StackListenerImpl
47134711
]));
47144712

47154713
if (constantContext == ConstantContext.required && constKeyword == null) {
4716-
addProblem(cfe.messageMissingExplicitConst, offsetForToken(leftBrace),
4717-
noLength);
4714+
addProblem(
4715+
cfe.messageMissingExplicitConst, offsetForToken(leftBrace), noLength);
47184716
}
47194717

47204718
List<dynamic> setOrMapEntries =
@@ -6405,16 +6403,16 @@ class BodyBuilder extends StackListenerImpl
64056403
ConstantContext savedConstantContext = pop() as ConstantContext;
64066404

64076405
if (arguments is! Arguments) {
6408-
push(new ParserErrorGenerator(
6409-
this, nameToken, cfe.messageSyntheticToken));
6406+
push(
6407+
new ParserErrorGenerator(this, nameToken, cfe.messageSyntheticToken));
64106408
arguments = forest.createArguments(offset, []);
64116409
} else if (type is Generator) {
64126410
push(type.invokeConstructor(
64136411
typeArguments, name, arguments, nameToken, nameLastToken, constness,
64146412
inImplicitCreationContext: inImplicitCreationContext));
64156413
} else if (type is ParserRecovery) {
6416-
push(new ParserErrorGenerator(
6417-
this, nameToken, cfe.messageSyntheticToken));
6414+
push(
6415+
new ParserErrorGenerator(this, nameToken, cfe.messageSyntheticToken));
64186416
} else if (type is InvalidExpression) {
64196417
push(type);
64206418
} else if (type is Expression) {
@@ -6511,13 +6509,13 @@ class BodyBuilder extends StackListenerImpl
65116509
required UnresolvedKind unresolvedKind}) {
65126510
if (arguments == null) {
65136511
// Coverage-ignore-block(suite): Not run.
6514-
return buildProblem(cfe.messageMissingArgumentList,
6515-
nameToken.charOffset, nameToken.length);
6512+
return buildProblem(cfe.messageMissingArgumentList, nameToken.charOffset,
6513+
nameToken.length);
65166514
}
65176515
if (name.isNotEmpty && arguments.types.isNotEmpty) {
65186516
// TODO(ahe): Point to the type arguments instead.
6519-
addProblem(cfe.messageConstructorWithTypeArguments,
6520-
nameToken.charOffset, nameToken.length);
6517+
addProblem(cfe.messageConstructorWithTypeArguments, nameToken.charOffset,
6518+
nameToken.length);
65216519
}
65226520

65236521
String? errorName;
@@ -7101,8 +7099,8 @@ class BodyBuilder extends StackListenerImpl
71017099
// Coverage-ignore(suite): Not run.
71027100
offsetForToken(ifToken);
71037101
node = new MapLiteralEntry(
7104-
buildProblem(cfe.templateExpectedAfterButGot.withArguments(':'),
7105-
offset, 1),
7102+
buildProblem(
7103+
cfe.templateExpectedAfterButGot.withArguments(':'), offset, 1),
71067104
new NullLiteral())
71077105
..fileOffset = offsetForToken(ifToken);
71087106
}
@@ -7138,8 +7136,8 @@ class BodyBuilder extends StackListenerImpl
71387136
// Coverage-ignore(suite): Not run.
71397137
offsetForToken(ifToken);
71407138
node = new MapLiteralEntry(
7141-
buildProblem(cfe.templateExpectedAfterButGot.withArguments(':'),
7142-
offset, 1),
7139+
buildProblem(
7140+
cfe.templateExpectedAfterButGot.withArguments(':'), offset, 1),
71437141
new NullLiteral())
71447142
..fileOffset = offsetForToken(ifToken);
71457143
}
@@ -9355,10 +9353,8 @@ class BodyBuilder extends StackListenerImpl
93559353
typeParameter.declaration is ExtensionTypeDeclaration) {
93569354
if (constantContext != ConstantContext.none &&
93579355
(!inConstructorInitializer || !allowPotentiallyConstantType)) {
9358-
LocatedMessage message =
9359-
cfe.messageTypeVariableInConstantContext.withLocation(
9360-
builder.fileUri!,
9361-
builder.charOffset!,
9356+
LocatedMessage message = cfe.messageTypeVariableInConstantContext
9357+
.withLocation(builder.fileUri!, builder.charOffset!,
93629358
typeParameter.name!.length);
93639359
builder.bind(
93649360
libraryBuilder,
@@ -9450,8 +9446,7 @@ class BodyBuilder extends StackListenerImpl
94509446
!isConstantExpression &&
94519447
!libraryFeatures.constFunctions.isEnabled) {
94529448
return buildProblem(
9453-
cfe.templateNotConstantExpression
9454-
.withArguments('Method invocation'),
9449+
cfe.templateNotConstantExpression.withArguments('Method invocation'),
94559450
offset,
94569451
name.text.length);
94579452
}
@@ -9480,8 +9475,7 @@ class BodyBuilder extends StackListenerImpl
94809475
!isConstantExpression &&
94819476
!libraryFeatures.constFunctions.isEnabled) {
94829477
return buildProblem(
9483-
cfe.templateNotConstantExpression
9484-
.withArguments('Method invocation'),
9478+
cfe.templateNotConstantExpression.withArguments('Method invocation'),
94859479
offset,
94869480
name.text.length);
94879481
}
@@ -9904,8 +9898,7 @@ class BodyBuilder extends StackListenerImpl
99049898
if (colon != null) {
99059899
Object? identifier = pop();
99069900
if (identifier is ParserRecovery) {
9907-
push(
9908-
new ParserErrorGenerator(this, colon, cfe.messageSyntheticToken));
9901+
push(new ParserErrorGenerator(this, colon, cfe.messageSyntheticToken));
99099902
} else {
99109903
String? name;
99119904
if (identifier is Identifier) {

pkg/front_end/lib/src/kernel/utils.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ int compareProcedures(Procedure a, Procedure b) {
226226
return a.fileOffset.compareTo(b.fileOffset);
227227
}
228228

229-
List<Combinator>? toCombinators(
230-
List<CombinatorBuilder>? combinatorBuilders) {
229+
List<Combinator>? toCombinators(List<CombinatorBuilder>? combinatorBuilders) {
231230
if (combinatorBuilders == null) {
232231
// Note: it's safe to return null here as Kernel's LibraryDependency will
233232
// convert null to an empty list.

pkg/front_end/lib/src/source/source_compilation_unit.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,7 @@ class SourceCompilationUnitImpl implements SourceCompilationUnit {
528528
LibraryBuilder imported = import.importedLibraryBuilder!.origin;
529529
Library targetLibrary = imported.library;
530530
libraryDependency = new LibraryDependency.import(targetLibrary,
531-
name: import.prefix,
532-
combinators: toCombinators(import.combinators))
531+
name: import.prefix, combinators: toCombinators(import.combinators))
533532
..fileOffset = import.importOffset;
534533
}
535534
library.addDependency(libraryDependency);

pkg/front_end/lib/src/type_inference/type_inference_engine.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -974,21 +974,15 @@ class OperationsCfe
974974
DartType greatestClosureOfTypeInternal(DartType type,
975975
List<SharedTypeParameterStructure<DartType>> typeParametersToEliminate) {
976976
return new NullabilityAwareFreeTypeParameterEliminator(
977-
bottomType: const NeverType.nonNullable(),
978-
topType: typeEnvironment.coreTypes.objectNullableRawType,
979-
topFunctionType: typeEnvironment.coreTypes
980-
.functionRawType(Nullability.nonNullable))
977+
coreTypes: typeEnvironment.coreTypes)
981978
.eliminateToGreatest(type);
982979
}
983980

984981
@override
985982
DartType leastClosureOfTypeInternal(DartType type,
986983
List<SharedTypeParameterStructure<DartType>> typeParametersToEliminate) {
987984
return new NullabilityAwareFreeTypeParameterEliminator(
988-
bottomType: const NeverType.nonNullable(),
989-
topType: typeEnvironment.coreTypes.objectNullableRawType,
990-
topFunctionType: typeEnvironment.coreTypes
991-
.functionRawType(Nullability.nonNullable))
985+
coreTypes: typeEnvironment.coreTypes)
992986
.eliminateToLeast(type);
993987
}
994988

pkg/front_end/lib/src/type_inference/type_schema_environment.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class TypeSchemaEnvironment extends HierarchyBasedTypeEnvironment
6464
TypeSchemaEnvironment(CoreTypes coreTypes, this.hierarchy)
6565
: super(coreTypes, hierarchy);
6666

67+
// Coverage-ignore(suite): Not run.
6768
InterfaceType functionRawType(Nullability nullability) {
6869
return coreTypes.functionRawType(nullability);
6970
}
@@ -370,9 +371,7 @@ class TypeSchemaEnvironment extends HierarchyBasedTypeEnvironment
370371
if (!isEmptyContext(returnContextType)) {
371372
if (isConst) {
372373
returnContextType = new NullabilityAwareFreeTypeParameterEliminator(
373-
bottomType: const NeverType.nonNullable(),
374-
topType: objectNullableRawType,
375-
topFunctionType: functionRawType(Nullability.nonNullable))
374+
coreTypes: coreTypes)
376375
.eliminateToLeast(returnContextType!);
377376
}
378377
gatherer.tryConstrainUpper(declaredReturnType!, returnContextType!,

pkg/front_end/test/coverage_suite_expected.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ const Map<String, ({int hitCount, int missCount})> _expect = {
560560
),
561561
// 100.0%.
562562
"package:front_end/src/kernel/body_builder.dart": (
563-
hitCount: 7173,
563+
hitCount: 7185,
564564
missCount: 0,
565565
),
566566
// 100.0%.
@@ -765,7 +765,7 @@ const Map<String, ({int hitCount, int missCount})> _expect = {
765765
),
766766
// 100.0%.
767767
"package:front_end/src/kernel/member_covariance.dart": (
768-
hitCount: 257,
768+
hitCount: 258,
769769
missCount: 0,
770770
),
771771
// 100.0%.
@@ -926,12 +926,12 @@ const Map<String, ({int hitCount, int missCount})> _expect = {
926926
),
927927
// 100.0%.
928928
"package:front_end/src/source/source_field_builder.dart": (
929-
hitCount: 1246,
929+
hitCount: 1250,
930930
missCount: 0,
931931
),
932932
// 100.0%.
933933
"package:front_end/src/source/source_function_builder.dart": (
934-
hitCount: 316,
934+
hitCount: 345,
935935
missCount: 0,
936936
),
937937
// 100.0%.
@@ -1006,7 +1006,7 @@ const Map<String, ({int hitCount, int missCount})> _expect = {
10061006
),
10071007
// 100.0%.
10081008
"package:front_end/src/type_inference/inference_visitor_base.dart": (
1009-
hitCount: 2460,
1009+
hitCount: 2458,
10101010
missCount: 0,
10111011
),
10121012
// 100.0%.
@@ -1046,7 +1046,7 @@ const Map<String, ({int hitCount, int missCount})> _expect = {
10461046
),
10471047
// 100.0%.
10481048
"package:front_end/src/type_inference/type_inference_engine.dart": (
1049-
hitCount: 547,
1049+
hitCount: 530,
10501050
missCount: 0,
10511051
),
10521052
// 100.0%.
@@ -1061,12 +1061,12 @@ const Map<String, ({int hitCount, int missCount})> _expect = {
10611061
),
10621062
// 100.0%.
10631063
"package:front_end/src/type_inference/type_schema_elimination.dart": (
1064-
hitCount: 32,
1064+
hitCount: 29,
10651065
missCount: 0,
10661066
),
10671067
// 100.0%.
10681068
"package:front_end/src/type_inference/type_schema_environment.dart": (
1069-
hitCount: 267,
1069+
hitCount: 261,
10701070
missCount: 0,
10711071
),
10721072
// 100.0%.

pkg/kernel/lib/src/standard_bounds.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,9 +1693,7 @@ mixin StandardBounds {
16931693
nominalEliminationTargets: {
16941694
if (nominalEliminationTarget != null) nominalEliminationTarget
16951695
},
1696-
bottomType: const NeverType.nonNullable(),
1697-
topType: coreTypes.objectNullableRawType,
1698-
topFunctionType: coreTypes.functionNonNullableRawType,
1696+
coreTypes: coreTypes,
16991697
unhandledTypeHandler: (type, recursor) => false);
17001698
DartType result = _getNullabilityAwareStandardUpperBound(
17011699
eliminator.eliminateToGreatest(bound1), type2);
@@ -1730,9 +1728,7 @@ mixin StandardBounds {
17301728
new NullabilityAwareTypeParameterEliminator(
17311729
structuralEliminationTargets: {},
17321730
nominalEliminationTargets: {type1.left.parameter},
1733-
bottomType: const NeverType.nonNullable(),
1734-
topType: coreTypes.objectNullableRawType,
1735-
topFunctionType: coreTypes.functionNonNullableRawType,
1731+
coreTypes: coreTypes,
17361732
unhandledTypeHandler: (type, recursor) => false);
17371733
Nullability resultingNullability =
17381734
uniteNullabilities(type1.right.declaredNullability, type2.nullability);

pkg/kernel/lib/type_algebra.dart

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
library kernel.type_algebra;
66

77
import 'ast.dart';
8+
import 'core_types.dart';
89
import 'src/find_type_visitor.dart';
910
import 'src/replacement_visitor.dart';
1011

@@ -1933,15 +1934,10 @@ class _NullabilityConstructorUnwrapper implements DartTypeVisitor<DartType> {
19331934

19341935
abstract class NullabilityAwareTypeVariableEliminatorBase
19351936
extends ReplacementVisitor {
1936-
final DartType bottomType;
1937-
final DartType topType;
1938-
final DartType topFunctionType;
1937+
final CoreTypes coreTypes;
19391938
late bool _isLeastClosure;
19401939

1941-
NullabilityAwareTypeVariableEliminatorBase(
1942-
{required this.bottomType,
1943-
required this.topType,
1944-
required this.topFunctionType});
1940+
NullabilityAwareTypeVariableEliminatorBase({required this.coreTypes});
19451941

19461942
bool containsTypeVariablesToEliminate(DartType type);
19471943

@@ -1964,15 +1960,15 @@ abstract class NullabilityAwareTypeVariableEliminatorBase
19641960
DartType getTypeParameterReplacement(Variance variance) {
19651961
bool isCovariant = variance == Variance.covariant;
19661962
return _isLeastClosure && isCovariant || (!_isLeastClosure && !isCovariant)
1967-
? bottomType
1968-
: topType;
1963+
? const NeverType.nonNullable()
1964+
: coreTypes.objectNullableRawType;
19691965
}
19701966

19711967
DartType getFunctionReplacement(Variance variance) {
19721968
bool isCovariant = variance == Variance.covariant;
19731969
return _isLeastClosure && isCovariant || (!_isLeastClosure && !isCovariant)
1974-
? bottomType
1975-
: topFunctionType;
1970+
? const NeverType.nonNullable()
1971+
: coreTypes.functionNonNullableRawType;
19761972
}
19771973

19781974
@override
@@ -2038,14 +2034,9 @@ class NullabilityAwareTypeParameterEliminator
20382034
NullabilityAwareTypeParameterEliminator(
20392035
{required this.structuralEliminationTargets,
20402036
required this.nominalEliminationTargets,
2041-
required DartType bottomType,
2042-
required DartType topType,
2043-
required DartType topFunctionType,
2037+
required CoreTypes coreTypes,
20442038
this.unhandledTypeHandler})
2045-
: super(
2046-
bottomType: bottomType,
2047-
topType: topType,
2048-
topFunctionType: topFunctionType);
2039+
: super(coreTypes: coreTypes);
20492040

20502041
@override
20512042
bool containsTypeVariablesToEliminate(DartType type) {
@@ -2080,14 +2071,8 @@ class NullabilityAwareFreeTypeParameterEliminator
20802071
extends NullabilityAwareTypeVariableEliminatorBase {
20812072
Set<StructuralParameter> _boundVariables = <StructuralParameter>{};
20822073

2083-
NullabilityAwareFreeTypeParameterEliminator(
2084-
{required DartType bottomType,
2085-
required DartType topType,
2086-
required DartType topFunctionType})
2087-
: super(
2088-
bottomType: bottomType,
2089-
topType: topType,
2090-
topFunctionType: topFunctionType);
2074+
NullabilityAwareFreeTypeParameterEliminator({required CoreTypes coreTypes})
2075+
: super(coreTypes: coreTypes);
20912076

20922077
@override
20932078
DartType? visitFunctionType(FunctionType node, Variance variance) {

0 commit comments

Comments
 (0)