Skip to content

Commit 3393bef

Browse files
chloestefantsovaCommit Queue
authored andcommitted
[cfe] Remove constructors for alpha renaming
In this CL methods StructuralParameterType.forAlphaRenaming, StructuralParameterType.forAlphaRenamingFromTypeParameter, TypeParameterType.forAlphaRenaming, and TypeParameterType.forAlphaRenamingFromStructuralParameter are removed, and their call sites are replaced with invocations of other constructors of StructuralParameterType and TypeParameterType. The reason for this change is call sites having more information for correct computing of type nullabilities. In addition to the primary update, the following related changes are made in this CL. * Method StructuralParameterType.computeDefaultNullabilityForLibrary is renamed into StructuralParameterType.computeDefaultNullability, and TypeParameterType.computeDefaultNullabilityForLibrary is renamed into TypeParameterType.computeDefaultNullability. The parameter `library` is removed from both methods, since it's no longer needed. * The static methods named `computeNullabilityFromBound` are removed from `StructuralParameterType` and `TypeParameterType` and re-introduced as instance members in classes `StructuralParameter` and `TestParameter` respectively TEST=existing Change-Id: I26cccf17ccc9bda1e8b750196f427325b544a7ac Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402820 Reviewed-by: Johnni Winther <[email protected]> Reviewed-by: Mayank Patke <[email protected]> Reviewed-by: Alexander Markov <[email protected]>
1 parent d3818ff commit 3393bef

39 files changed

+405
-450
lines changed

pkg/compiler/lib/src/ir/scope_visitor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ class ScopeModelBuilder extends ir.VisitorDefault<EvaluationComplexity>
377377
EvaluationComplexity visitTypeParameter(ir.TypeParameter node) {
378378
TypeVariableTypeWithContext typeVariable(ir.Library library) =>
379379
TypeVariableTypeWithContext(
380-
ir.TypeParameterType.withDefaultNullabilityForLibrary(node, library),
380+
ir.TypeParameterType.withDefaultNullability(node),
381381
// If this typeParameter is part of a function type then its
382382
// declaration is null because it has no context. Just pass in null
383383
// for the context in that case.

pkg/dart2bytecode/lib/generics.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ List<DartType> getTypeParameterTypes(List<TypeParameter> typeParameters) {
2424
}
2525
final types = List<DartType>.generate(typeParameters.length, (int i) {
2626
final tp = typeParameters[i];
27-
return TypeParameterType(
28-
tp, TypeParameterType.computeNullabilityFromBound(tp));
27+
return TypeParameterType.withDefaultNullability(tp);
2928
});
3029
return types;
3130
}
@@ -37,8 +36,7 @@ bool _canReuseSuperclassTypeArguments(List<DartType> superTypeArgs,
3736
final typeParam = typeParameters[i];
3837
if (!(superTypeArg is TypeParameterType &&
3938
superTypeArg.parameter == typeParameters[i] &&
40-
superTypeArg.nullability ==
41-
TypeParameterType.computeNullabilityFromBound(typeParam))) {
39+
superTypeArg.nullability == typeParam.computeNullabilityFromBound())) {
4240
return false;
4341
}
4442
}

pkg/front_end/lib/src/builder/type_parameter_builder.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,7 @@ class NominalParameterBuilder extends TypeParameterBuilder {
248248
kind: TypeParameterKind.fromKernel,
249249
bound: loader?.computeTypeBuilder(parameter.bound),
250250
defaultType: loader?.computeTypeBuilder(parameter.defaultType)) {
251-
_nullabilityFromParameterBound =
252-
TypeParameterType.computeNullabilityFromBound(parameter);
251+
_nullabilityFromParameterBound = parameter.computeNullabilityFromBound();
253252
}
254253

255254
@override
@@ -585,8 +584,7 @@ class StructuralParameterBuilder extends TypeParameterBuilder {
585584
// parameters from kernel?
586585
super(parameter.name ?? "", parameter.fileOffset, null,
587586
kind: TypeParameterKind.fromKernel) {
588-
_nullabilityFromParameterBound =
589-
StructuralParameterType.computeNullabilityFromBound(parameter);
587+
_nullabilityFromParameterBound = parameter.computeNullabilityFromBound();
590588
}
591589

592590
@override

pkg/front_end/lib/src/fragment/method.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -704,9 +704,8 @@ mixin _ExtensionInstanceMethodEncodingMixin implements _MethodEncoding {
704704
for (TypeParameter typeParameter in procedure.function.typeParameters) {
705705
TypeParameter newTypeParameter = new TypeParameter(typeParameter.name);
706706
typeParameters.add(newTypeParameter);
707-
typeArguments.add(substitutionMap[typeParameter] =
708-
new TypeParameterType.forAlphaRenaming(
709-
typeParameter, newTypeParameter));
707+
typeArguments.add(substitutionMap[typeParameter] = new TypeParameterType(
708+
newTypeParameter, typeParameter.computeNullabilityFromBound()));
710709
}
711710

712711
List<TypeParameter> tearOffTypeParameters = <TypeParameter>[];

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,8 +1421,8 @@ class BodyBuilder extends StackListenerImpl
14211421
RedirectionTarget _getRedirectionTarget(Procedure factory) {
14221422
List<DartType> typeArguments = new List<DartType>.generate(
14231423
factory.function.typeParameters.length, (int i) {
1424-
return new TypeParameterType.withDefaultNullabilityForLibrary(
1425-
factory.function.typeParameters[i], factory.enclosingLibrary);
1424+
return new TypeParameterType.withDefaultNullability(
1425+
factory.function.typeParameters[i]);
14261426
}, growable: true);
14271427

14281428
// Cyclic factories are detected earlier, so we're guaranteed to

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -345,13 +345,10 @@ abstract class CombinedMemberSignatureBase {
345345
if (typeParameterCount == 0) {
346346
return type;
347347
}
348-
List<DartType> types =
349-
new List<DartType>.filled(typeParameterCount, dummyDartType);
350-
for (int i = 0; i < typeParameterCount; i++) {
351-
types[i] =
352-
new TypeParameterType.forAlphaRenamingFromStructuralParameters(
353-
signatureTypeParameters[i], typeParameters[i]);
354-
}
348+
List<DartType> types = [
349+
for (TypeParameter parameter in typeParameters)
350+
new TypeParameterType.withDefaultNullability(parameter)
351+
];
355352
FunctionTypeInstantiator instantiator =
356353
new FunctionTypeInstantiator.fromIterables(
357354
signatureTypeParameters, types);

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,15 @@ bool isProperRenameForTypeDeclaration(
215215
}
216216
for (int i = 0; i < fromParameters.length; ++i) {
217217
if (typeArguments[i] !=
218-
new TypeParameterType.withDefaultNullabilityForLibrary(
219-
fromParameters[i], typedefLibrary)) {
218+
new TypeParameterType.withDefaultNullability(fromParameters[i])) {
220219
return false;
221220
}
222221
}
223222

224223
Map<TypeParameter, DartType> substitutionMap = {};
225224
for (int i = 0; i < fromParameters.length; ++i) {
226-
substitutionMap[fromParameters[i]] = new TypeParameterType.forAlphaRenaming(
227-
fromParameters[i], toParameters[i]);
225+
substitutionMap[fromParameters[i]] =
226+
new TypeParameterType.withDefaultNullability(toParameters[i]);
228227
}
229228
Substitution substitution = Substitution.fromMap(substitutionMap);
230229
for (int i = 0; i < fromParameters.length; ++i) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,8 @@ class Forest {
671671

672672
TypeParameterType createTypeParameterTypeWithDefaultNullabilityForLibrary(
673673
TypeParameter typeParameter, Library library) {
674-
return new TypeParameterType.withDefaultNullabilityForLibrary(
675-
typeParameter, library);
674+
return new TypeParameterType.withDefaultNullability(
675+
typeParameter);
676676
}
677677

678678
Expression createExpressionInvocation(

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,7 @@ class ForwardingNode {
312312
type,
313313
function.typeParameters
314314
.map((TypeParameter parameter) =>
315-
new TypeParameterType.withDefaultNullabilityForLibrary(
316-
parameter, procedure.enclosingLibrary))
315+
new TypeParameterType.withDefaultNullability(parameter))
317316
.toList());
318317
}
319318
List<Expression> positionalArguments = new List.generate(
@@ -367,8 +366,7 @@ class ForwardingNode {
367366
}, growable: true);
368367
List<DartType> typeArguments = function.typeParameters
369368
.map<DartType>((typeParameter) =>
370-
new TypeParameterType.withDefaultNullabilityForLibrary(
371-
typeParameter, libraryBuilder.library))
369+
new TypeParameterType.withDefaultNullability(typeParameter))
372370
.toList();
373371
Arguments arguments = new Arguments(positionalArguments,
374372
types: typeArguments, named: namedArguments);

pkg/front_end/lib/src/kernel/hierarchy/mixin_inferrer.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,11 @@ class BuilderMixinInferrer {
157157
}
158158
// Bounds might mention the mixin class's type parameters so we have to
159159
// substitute them before calling instantiate to bounds.
160-
Substitution substitution = Substitution.fromPairs(
161-
mixinClass.typeParameters,
162-
new List<DartType>.generate(
163-
parameters.length,
164-
(i) => new TypeParameterType.forAlphaRenaming(
165-
mixinClass.typeParameters[i], parameters[i])));
160+
Substitution substitution =
161+
Substitution.fromPairs(mixinClass.typeParameters, [
162+
for (TypeParameter parameter in parameters)
163+
new TypeParameterType.withDefaultNullability(parameter)
164+
]);
166165
for (TypeParameter p in parameters) {
167166
p.bound = substitution.substituteType(p.bound);
168167
}

0 commit comments

Comments
 (0)