[cfe] Migrate front_end libraries from wave 5 Change-Id: Id603bf1c94966131886ed24f65e0cd3b7b862852 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196490 Reviewed-by: Dmitry Stefantsov <dmitryas@google.com> Commit-Queue: Johnni Winther <johnniwinther@google.com>
diff --git a/pkg/front_end/lib/src/fasta/incremental_serializer.dart b/pkg/front_end/lib/src/fasta/incremental_serializer.dart index 208022e..c9d9a0b 100644 --- a/pkg/front_end/lib/src/fasta/incremental_serializer.dart +++ b/pkg/front_end/lib/src/fasta/incremental_serializer.dart
@@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart = 2.9 - library fasta.incremental_serializer; import 'dart:typed_data' show Uint8List; @@ -40,7 +38,7 @@ for (int i = 0; i < views.length; i++) { SubComponentView view = views[i]; bool good = true; - String packageName; + String? packageName; for (Library lib in view.libraries) { Uri uri = lib.importUri; // Uris need to be unique. @@ -89,7 +87,7 @@ /// Write packages to sink, cache new package data, trim input component. void writePackagesToSinkAndTrimComponent( - Component component, Sink<List<int>> sink) { + Component? component, Sink<List<int>> sink) { if (component == null) return; if (component.libraries.isEmpty) return; @@ -132,13 +130,12 @@ Set<SerializationGroup> cachedPackagesInOutput = new Set<SerializationGroup>.identity(); for (Library lib in packageLibraries) { - SerializationGroup group = uriToGroup[lib.fileUri]; + SerializationGroup? group = uriToGroup[lib.fileUri]; if (group != null) { addDataButNotDependentData(group, cachedPackagesInOutput, sink); } else { String package = lib.importUri.pathSegments.first; - newPackages[package] ??= <Library>[]; - newPackages[package].add(lib); + (newPackages[package] ??= <Library>[]).add(lib); } } @@ -147,7 +144,7 @@ for (SerializationGroup group in upFrontGroups) { if (group.dependencies != null) { // Now also add all dependencies. - for (SerializationGroup dep in group.dependencies) { + for (SerializationGroup dep in group.dependencies!) { addDataAndDependentData(dep, cachedPackagesInOutput, sink); } } @@ -157,7 +154,7 @@ Map<String, SerializationGroup> newPackageGroups = new Map<String, SerializationGroup>(); for (String package in newPackages.keys) { - List<Library> libraries = newPackages[package]; + List<Library> libraries = newPackages[package]!; List<int> data = serialize(component, libraries); sink.add(data); SerializationGroup newGroup = createGroupFor(libraries, data); @@ -166,8 +163,8 @@ // Setup dependency tracking for the new groups. for (String package in newPackages.keys) { - List<Library> libraries = newPackages[package]; - SerializationGroup packageGroup = newPackageGroups[package]; + List<Library> libraries = newPackages[package]!; + SerializationGroup packageGroup = newPackageGroups[package]!; setupDependencyTracking(libraries, packageGroup); } @@ -228,7 +225,7 @@ while (workList.isNotEmpty) { SerializationGroup group = workList.removeLast(); if (group.othersDependingOnMe == null) continue; - for (SerializationGroup dependsOnGroup in group.othersDependingOnMe) { + for (SerializationGroup dependsOnGroup in group.othersDependingOnMe!) { removeUriFromMap(dependsOnGroup.uris.first, removed, workList); } } @@ -247,7 +244,7 @@ if (dependencyLibrary.importUri.scheme != "package") continue; Uri dependencyLibraryUri = dep.importedLibraryReference.asLibrary.fileUri; - SerializationGroup depGroup = uriToGroup[dependencyLibraryUri]; + SerializationGroup? depGroup = uriToGroup[dependencyLibraryUri]; if (depGroup == null) { throw "Didn't contain group for $dependencyLibraryUri"; } @@ -274,7 +271,7 @@ sink.add(group.serializedData); if (group.dependencies != null) { // Now also add all dependencies. - for (SerializationGroup dep in group.dependencies) { + for (SerializationGroup dep in group.dependencies!) { addDataAndDependentData(dep, cachedPackagesInOutput, sink); } } @@ -318,13 +315,13 @@ /// the worklist. void removeUriFromMap(Uri uri, Set<SerializationGroup> removed, List<SerializationGroup> workList) { - SerializationGroup group = uriToGroup.remove(uri); + SerializationGroup? group = uriToGroup.remove(uri); if (group == null) return; bool added = removed.add(group); assert(added); workList.add(group); for (Uri groupUri in group.uris) { - SerializationGroup sameGroup = uriToGroup.remove(groupUri); + SerializationGroup? sameGroup = uriToGroup.remove(groupUri); assert((groupUri == uri && sameGroup == null) || (groupUri != uri && sameGroup != null)); } @@ -334,8 +331,8 @@ class SerializationGroup { final List<int> serializedData; final Set<Uri> uris; - Set<SerializationGroup> dependencies; - Set<SerializationGroup> othersDependingOnMe; + Set<SerializationGroup>? dependencies; + Set<SerializationGroup>? othersDependingOnMe; SerializationGroup(this.serializedData, this.uris); @@ -344,9 +341,9 @@ /// this, and this is added as a "others depend on me" for [other]. void registerDependency(SerializationGroup other) { dependencies ??= new Set<SerializationGroup>.identity(); - if (dependencies.add(other)) { + if (dependencies!.add(other)) { other.othersDependingOnMe ??= new Set<SerializationGroup>.identity(); - other.othersDependingOnMe.add(this); + other.othersDependingOnMe!.add(this); } } }
diff --git a/pkg/front_end/lib/src/fasta/type_inference/type_constraint_gatherer.dart b/pkg/front_end/lib/src/fasta/type_inference/type_constraint_gatherer.dart index 7e7f6cd..caf6767 100644 --- a/pkg/front_end/lib/src/fasta/type_inference/type_constraint_gatherer.dart +++ b/pkg/front_end/lib/src/fasta/type_inference/type_constraint_gatherer.dart
@@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE.md file. -// @dart = 2.9 - import 'package:kernel/ast.dart'; import 'package:kernel/core_types.dart'; @@ -47,12 +45,12 @@ void addLowerBound( TypeConstraint constraint, DartType lower, Library clientLibrary); - Member getInterfaceMember(Class class_, Name name, {bool setter: false}); + Member? getInterfaceMember(Class class_, Name name, {bool setter: false}); - InterfaceType getTypeAsInstanceOf(InterfaceType type, Class superclass, + InterfaceType? getTypeAsInstanceOf(InterfaceType type, Class superclass, Library clientLibrary, CoreTypes coreTypes); - List<DartType> getTypeArgumentsAsInstanceOf( + List<DartType>? getTypeArgumentsAsInstanceOf( InterfaceType type, Class superclass); InterfaceType futureType(DartType type, Nullability nullability); @@ -66,10 +64,10 @@ } for (_ProtoConstraint protoConstraint in _protoConstraints) { if (protoConstraint.isUpper) { - addUpperBound(result[protoConstraint.parameter], protoConstraint.bound, + addUpperBound(result[protoConstraint.parameter]!, protoConstraint.bound, clientLibrary); } else { - addLowerBound(result[protoConstraint.parameter], protoConstraint.bound, + addLowerBound(result[protoConstraint.parameter]!, protoConstraint.bound, clientLibrary); } } @@ -134,7 +132,8 @@ /// parameters isn't allowed to also contain [UnknownType], that is, to be a /// type schema. bool _tryNullabilityAwareSubtypeMatch(DartType subtype, DartType supertype, - {bool constrainSupertype}) { + {required bool constrainSupertype}) { + // ignore: unnecessary_null_comparison assert(constrainSupertype != null); int baseConstraintCount = _protoConstraints.length; bool isMatch = _isNullabilityAwareSubtypeMatch(subtype, supertype, @@ -258,7 +257,7 @@ // of supertypes of a given type more than once, the order of the checks // above is irrelevant; we just need to find the matched superclass, // substitute, and then iterate through type variables. - List<DartType> matchingSupertypeOfSubtypeArguments = + List<DartType>? matchingSupertypeOfSubtypeArguments = getTypeArgumentsAsInstanceOf(subtype, supertype.classNode); if (matchingSupertypeOfSubtypeArguments == null) return false; for (int i = 0; i < supertype.classNode.typeParameters.length; i++) { @@ -309,9 +308,12 @@ /// The type that contains the type parameters isn't allowed to also contain /// [UnknownType], that is, to be a type schema. bool _isNullabilityAwareSubtypeMatch(DartType p, DartType q, - {bool constrainSupertype}) { + {required bool constrainSupertype}) { + // ignore: unnecessary_null_comparison assert(p != null); + // ignore: unnecessary_null_comparison assert(q != null); + // ignore: unnecessary_null_comparison assert(constrainSupertype != null); // If the type parameters being constrained occur in the supertype (that is, @@ -639,7 +641,7 @@ // Bj> is a subtype match for C1<N0, ..., Nj> with respect to L under // constraints C. if (p is InterfaceType && q is InterfaceType) { - final List<DartType> sArguments = + final List<DartType>? sArguments = getTypeArgumentsAsInstanceOf(p, q.classNode); if (sArguments != null) { assert(sArguments.length == q.typeArguments.length); @@ -724,7 +726,7 @@ isMatch && pNamedTypes.containsKey(q.namedParameters[i].name); isMatch = isMatch && _isNullabilityAwareSubtypeMatch(q.namedParameters[i].type, - pNamedTypes[q.namedParameters[i].name], + pNamedTypes[q.namedParameters[i].name]!, constrainSupertype: !constrainSupertype); } if (isMatch) return true; @@ -972,9 +974,10 @@ // and `F` is a subtype match for a type `Q` with respect to `L` under // constraints `C`. if (subtype is InterfaceType) { - Member callMember = getInterfaceMember(subtype.classNode, callName); + Member? callMember = getInterfaceMember(subtype.classNode, callName); if (callMember is Procedure && !callMember.isGetter) { DartType callType = callMember.getterType; + // ignore: unnecessary_null_comparison if (callType != null) { callType = Substitution.fromInterfaceType(subtype).substituteType(callType); @@ -1053,20 +1056,20 @@ } @override - Member getInterfaceMember(Class class_, Name name, {bool setter: false}) { + Member? getInterfaceMember(Class class_, Name name, {bool setter: false}) { return environment.hierarchy .getInterfaceMember(class_, name, setter: setter); } @override - InterfaceType getTypeAsInstanceOf(InterfaceType type, Class superclass, + InterfaceType? getTypeAsInstanceOf(InterfaceType type, Class superclass, Library clientLibrary, CoreTypes coreTypes) { return environment.getTypeAsInstanceOf( type, superclass, clientLibrary, coreTypes); } @override - List<DartType> getTypeArgumentsAsInstanceOf( + List<DartType>? getTypeArgumentsAsInstanceOf( InterfaceType type, Class superclass) { return environment.getTypeArgumentsAsInstanceOf(type, superclass); }
diff --git a/pkg/front_end/lib/src/fasta/type_inference/type_schema_environment.dart b/pkg/front_end/lib/src/fasta/type_inference/type_schema_environment.dart index 5e8e77f..f7e463b 100644 --- a/pkg/front_end/lib/src/fasta/type_inference/type_schema_environment.dart +++ b/pkg/front_end/lib/src/fasta/type_inference/type_schema_environment.dart
@@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE.md file. -// @dart = 2.9 - import 'package:kernel/ast.dart'; import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; @@ -49,7 +47,7 @@ requiredParameterCount: type.requiredParameterCount, typedefType: type.typedefType == null ? null - : substitution.substituteType(type.typedefType)); + : substitution.substituteType(type.typedefType!) as TypedefType); } /// Given a [FunctionType], gets the type of the named parameter with the given @@ -247,8 +245,8 @@ void inferGenericFunctionOrType( DartType declaredReturnType, List<TypeParameter> typeParametersToInfer, - List<DartType> formalTypes, - List<DartType> actualTypes, + List<DartType>? formalTypes, + List<DartType>? actualTypes, DartType returnContextType, List<DartType> inferredTypes, Library clientLibrary, @@ -283,7 +281,7 @@ for (int i = 0; i < formalTypes.length; i++) { // Try to pass each argument to each parameter, recording any type // parameter bounds that were implied by this assignment. - gatherer.tryConstrainLower(formalTypes[i], actualTypes[i]); + gatherer.tryConstrainLower(formalTypes[i], actualTypes![i]); } } @@ -332,27 +330,27 @@ List<DartType> inferredTypes, Library clientLibrary, {bool downwardsInferPhase: false}) { - List<DartType> typesFromDownwardsInference = + List<DartType>? typesFromDownwardsInference = downwardsInferPhase ? null : inferredTypes.toList(growable: false); for (int i = 0; i < typeParametersToInfer.length; i++) { TypeParameter typeParam = typeParametersToInfer[i]; DartType typeParamBound = typeParam.bound; - DartType extendsConstraint; + DartType? extendsConstraint; if (!hasOmittedBound(typeParam)) { extendsConstraint = Substitution.fromPairs(typeParametersToInfer, inferredTypes) .substituteType(typeParamBound); } - TypeConstraint constraint = constraints[typeParam]; + TypeConstraint constraint = constraints[typeParam]!; if (downwardsInferPhase) { inferredTypes[i] = _inferTypeParameterFromContext( constraint, extendsConstraint, clientLibrary); } else { inferredTypes[i] = _inferTypeParameterFromAll( - typesFromDownwardsInference[i], + typesFromDownwardsInference![i], constraint, extendsConstraint, clientLibrary, @@ -405,7 +403,7 @@ DartType unwrappedSupertype = supertype; while (unwrappedSupertype is FutureOrType) { - unwrappedSupertype = (unwrappedSupertype as FutureOrType).typeArgument; + unwrappedSupertype = unwrappedSupertype.typeArgument; } if (unwrappedSupertype is UnknownType) { return const IsSubtypeOf.always(); @@ -413,7 +411,8 @@ return super.performNullabilityAwareSubtypeCheck(subtype, supertype); } - bool isEmptyContext(DartType context) { + // TODO(johnniwinther): Should [context] be non-nullable? + bool isEmptyContext(DartType? context) { if (context is DynamicType) { // Analyzer treats a type context of `dynamic` as equivalent to an empty // context. TODO(paulberry): this is not spec'ed anywhere; do we still @@ -433,7 +432,8 @@ /// by giving special treatment to certain arithmetic operators. bool isSpecialCasesBinaryForReceiverType( Procedure member, DartType receiverType, - {bool isNonNullableByDefault}) { + {required bool isNonNullableByDefault}) { + // ignore: unnecessary_null_comparison assert(isNonNullableByDefault != null); if (!isNonNullableByDefault) { // TODO(paulberry): this matches what is defined in the spec. It would be @@ -523,7 +523,7 @@ DartType _inferTypeParameterFromAll( DartType typeFromContextInference, TypeConstraint constraint, - DartType extendsConstraint, + DartType? extendsConstraint, Library clientLibrary, {bool isContravariant: false, bool preferUpwardsInference: false}) { @@ -552,7 +552,7 @@ } DartType _inferTypeParameterFromContext(TypeConstraint constraint, - DartType extendsConstraint, Library clientLibrary) { + DartType? extendsConstraint, Library clientLibrary) { DartType t = solveTypeConstraint( constraint, clientLibrary.isNonNullableByDefault