Skip to content

Commit 929d5e4

Browse files
Dmitry Stefantsovcommit-bot@chromium.org
authored andcommitted
[cfe,ddc,dart2js,vm] Add FutureOrType
This CL is the sum of the following 5 CLs: * https://dart-review.googlesource.com/c/sdk/+/149297/ * https://dart-review.googlesource.com/c/sdk/+/149299/ * https://dart-review.googlesource.com/c/sdk/+/149320/ * https://dart-review.googlesource.com/c/sdk/+/149321/ * https://dart-review.googlesource.com/c/sdk/+/149323/ The reason for landing the 5 CLs as one CL is to prevent potential troubles with bisecting over the branch because the change is fully functional only with all 5 CLs. Closes #40123. Bug: #40123 Change-Id: Ice52250a98acfe455b1d7fa5bb0624c115ca5dac Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150934 Commit-Queue: Dmitry Stefantsov <[email protected]> Reviewed-by: Alexander Markov <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent 8d4d3a3 commit 929d5e4

File tree

300 files changed

+2635
-2387
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

300 files changed

+2635
-2387
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,11 @@ abstract class ImpactBuilderBase extends StaticTypeVisitor
298298

299299
case ir.AsyncMarker.Async:
300300
ir.DartType elementType = const ir.DynamicType();
301-
if (returnType is ir.InterfaceType) {
302-
if (returnType.classNode == typeEnvironment.coreTypes.futureOrClass) {
303-
elementType = returnType.typeArguments.first;
304-
} else if (returnType.classNode ==
305-
typeEnvironment.coreTypes.futureClass) {
306-
elementType = returnType.typeArguments.first;
307-
}
301+
if (returnType is ir.InterfaceType &&
302+
returnType.classNode == typeEnvironment.coreTypes.futureClass) {
303+
elementType = returnType.typeArguments.first;
304+
} else if (returnType is ir.FutureOrType) {
305+
elementType = returnType.typeArgument;
308306
}
309307
registerAsync(elementType);
310308
break;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,11 @@ class ScopeModelBuilder extends ir.Visitor<InitializerComplexity>
634634
return visitNodes(node.typeArguments);
635635
}
636636

637+
@override
638+
InitializerComplexity visitFutureOrType(ir.FutureOrType node) {
639+
return visitNode(node.typeArgument);
640+
}
641+
637642
@override
638643
InitializerComplexity visitFunctionType(ir.FunctionType node) {
639644
InitializerComplexity complexity = visitNode(node.returnType);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,7 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
742742
assert(
743743
node.promotedType == null ||
744744
promotedType == typeEnvironment.nullType ||
745-
promotedType is ir.InterfaceType &&
746-
promotedType.classNode == typeEnvironment.futureOrClass ||
745+
promotedType is ir.FutureOrType ||
747746
typeEnvironment.isSubtypeOf(promotedType, node.promotedType,
748747
ir.SubtypeCheckMode.ignoringNullabilities),
749748
"Unexpected promotion of ${node.variable} in ${node.parent}. "

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ class _FreeVariableVisitor implements ir.DartTypeVisitor<bool> {
204204
return visitList(node.typeArguments);
205205
}
206206

207+
@override
208+
bool visitFutureOrType(ir.FutureOrType node) {
209+
return visit(node.typeArgument);
210+
}
211+
207212
@override
208213
bool visitBottomType(ir.BottomType node) => false;
209214

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,18 @@ class DartTypeConverter extends ir.DartTypeVisitor<DartType> {
148148
@override
149149
DartType visitInterfaceType(ir.InterfaceType node) {
150150
ClassEntity cls = elementMap.getClass(node.classNode);
151-
if (cls.name == 'FutureOr' &&
152-
cls.library == elementMap.commonElements.asyncLibrary) {
153-
return _convertNullability(
154-
_dartTypes.futureOrType(visitTypes(node.typeArguments).single),
155-
node.nullability);
156-
}
157151
return _convertNullability(
158152
_dartTypes.interfaceType(cls, visitTypes(node.typeArguments)),
159153
node.nullability);
160154
}
161155

156+
@override
157+
DartType visitFutureOrType(ir.FutureOrType node) {
158+
return _convertNullability(
159+
_dartTypes.futureOrType(visitType(node.typeArgument)),
160+
node.declaredNullability);
161+
}
162+
162163
@override
163164
DartType visitVoidType(ir.VoidType node) {
164165
return _dartTypes.voidType();

pkg/compiler/lib/src/kernel/kernel_impact.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,6 @@ abstract class KernelImpactRegistryMixin implements ImpactRegistry {
137137
Object _computeReceiverConstraint(
138138
ir.DartType receiverType, ClassRelation relation) {
139139
if (receiverType is ir.InterfaceType) {
140-
if (receiverType.classNode == typeEnvironment.futureOrClass) {
141-
// CFE encodes FutureOr as an interface type!
142-
return null;
143-
}
144140
return new StrongModeConstraint(commonElements, _nativeBasicData,
145141
elementMap.getClass(receiverType.classNode), relation);
146142
}

pkg/compiler/lib/src/serialization/abstract_source.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ abstract class AbstractDataSource extends DataSourceMixin
272272
return new ir.TypedefType(typedef, nullability, typeArguments);
273273
case DartTypeNodeKind.dynamicType:
274274
return const ir.DynamicType();
275+
case DartTypeNodeKind.futureOrType:
276+
ir.Nullability nullability = readEnum(ir.Nullability.values);
277+
ir.DartType typeArgument = _readDartTypeNode(functionTypeVariables);
278+
return new ir.FutureOrType(typeArgument, nullability);
275279
}
276280
throw new UnsupportedError("Unexpected DartTypeKind $kind");
277281
}

pkg/compiler/lib/src/serialization/helpers.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ enum DartTypeNodeKind {
119119
exactInterfaceType,
120120
doesNotComplete,
121121
neverType,
122+
futureOrType,
122123
}
123124

124125
const String functionTypeNodeTag = 'function-type-node';
@@ -194,6 +195,14 @@ class DartTypeNodeWriter
194195
visitTypes(node.typeArguments, functionTypeVariables);
195196
}
196197

198+
@override
199+
void visitFutureOrType(
200+
ir.FutureOrType node, List<ir.TypeParameter> functionTypeVariables) {
201+
_sink.writeEnum(DartTypeNodeKind.futureOrType);
202+
_sink.writeEnum(node.declaredNullability);
203+
_sink._writeDartTypeNode(node.typeArgument, functionTypeVariables);
204+
}
205+
197206
@override
198207
void visitFunctionType(
199208
ir.FunctionType node, List<ir.TypeParameter> functionTypeVariables) {

pkg/compiler/lib/src/ssa/builder_kernel.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3257,7 +3257,8 @@ class KernelSsaGraphBuilder extends ir.Visitor {
32573257
if (type is ir.InterfaceType ||
32583258
type is ir.DynamicType ||
32593259
type is ir.TypedefType ||
3260-
type is ir.FunctionType) {
3260+
type is ir.FunctionType ||
3261+
type is ir.FutureOrType) {
32613262
ConstantValue constant =
32623263
_elementMap.getConstantValue(_memberContextNode, node);
32633264
stack.add(graph.addConstant(constant, closedWorld,

pkg/compiler/test/analyses/analysis_helper.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,7 @@ class DynamicVisitor extends StaticTypeVisitorBase {
310310
assert(
311311
node is! ir.Expression ||
312312
staticType == typeEnvironment.nullType ||
313-
staticType is ir.InterfaceType &&
314-
staticType.classNode == typeEnvironment.futureOrClass ||
313+
staticType is ir.FutureOrType ||
315314
typeEnvironment.isSubtypeOf(
316315
staticType,
317316
_getStaticTypeFromExpression(node),

0 commit comments

Comments
 (0)