Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit cb3a9b0

Browse files
johnniwinthercommit-bot@chromium.org
authored andcommitted
[cfe] Remove old method invocation encoding nodes
TEST=existing Change-Id: I05ee649ecfa7945e2e0f5e5d09441d8916a9c46e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/208185 Commit-Queue: Johnni Winther <[email protected]> Reviewed-by: Dmitry Stefantsov <[email protected]>
1 parent 9cbc497 commit cb3a9b0

File tree

58 files changed

+801
-2836
lines changed

Some content is hidden

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

58 files changed

+801
-2836
lines changed

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

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,32 +1049,6 @@ class KernelTypeGraphBuilder extends ir.Visitor<TypeInformation>
10491049
node, node.receiver, receiverType, selector, arguments, null);
10501050
}
10511051

1052-
@override
1053-
TypeInformation visitMethodInvocation(ir.MethodInvocation node) {
1054-
Selector selector = _elementMap.getSelector(node);
1055-
ir.Expression receiver = node.receiver;
1056-
if (receiver is ir.VariableGet &&
1057-
receiver.variable.parent is ir.FunctionDeclaration) {
1058-
// TODO(johnniwinther). This triggers the computation of the mask for the
1059-
// receiver of the call to `call`. Remove this when the ssa builder
1060-
// recognizes local function invocation directly.
1061-
_typeOfReceiver(node, node.receiver);
1062-
// This is an invocation of a named local function.
1063-
return _handleLocalFunctionInvocation(
1064-
node, receiver.variable.parent, node.arguments, selector);
1065-
}
1066-
1067-
TypeInformation receiverType = visit(receiver);
1068-
ArgumentsTypes arguments = analyzeArguments(node.arguments);
1069-
if (selector.name == '==') {
1070-
return _handleEqualsCall(node, node.receiver, receiverType,
1071-
node.arguments.positional.first, arguments.positional[0]);
1072-
}
1073-
1074-
return _handleMethodInvocation(node, node.receiver, receiverType, selector,
1075-
arguments, node.interfaceTarget);
1076-
}
1077-
10781052
ir.VariableDeclaration _getVariableDeclaration(ir.Expression node) {
10791053
return node is ir.VariableGet ? node.variable : null;
10801054
}
@@ -1671,12 +1645,6 @@ class KernelTypeGraphBuilder extends ir.Visitor<TypeInformation>
16711645
return _handlePropertyGet(node, node.receiver);
16721646
}
16731647

1674-
@override
1675-
TypeInformation visitPropertyGet(ir.PropertyGet node) {
1676-
return _handlePropertyGet(node, node.receiver,
1677-
interfaceTarget: node.interfaceTarget);
1678-
}
1679-
16801648
TypeInformation _handlePropertySet(
16811649
ir.Expression node, ir.Expression receiver, ir.Expression value,
16821650
{ir.Member interfaceTarget}) {
@@ -1715,12 +1683,6 @@ class KernelTypeGraphBuilder extends ir.Visitor<TypeInformation>
17151683
return rhsType;
17161684
}
17171685

1718-
@override
1719-
TypeInformation visitPropertySet(ir.PropertySet node) {
1720-
return _handlePropertySet(node, node.receiver, node.value,
1721-
interfaceTarget: node.interfaceTarget);
1722-
}
1723-
17241686
@override
17251687
TypeInformation visitInstanceSet(ir.InstanceSet node) {
17261688
return _handlePropertySet(node, node.receiver, node.value,

pkg/compiler/lib/src/inferrer/inferrer_engine.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -650,20 +650,17 @@ class InferrerEngine {
650650
// TODO(johnniwinther): Implement the ad-hoc check in ast inferrer? This
651651
// mimicks that ast inferrer which return `true` for [ast.Send] and
652652
// non-const [ast.NewExpression].
653-
if (initializer is ir.MethodInvocation ||
654-
initializer is ir.InstanceInvocation ||
653+
if (initializer is ir.InstanceInvocation ||
655654
initializer is ir.InstanceGetterInvocation ||
656655
initializer is ir.DynamicInvocation ||
657656
initializer is ir.FunctionInvocation ||
658657
initializer is ir.LocalFunctionInvocation ||
659658
initializer is ir.EqualsNull ||
660659
initializer is ir.EqualsCall ||
661-
initializer is ir.PropertyGet ||
662660
initializer is ir.InstanceGet ||
663661
initializer is ir.DynamicGet ||
664662
initializer is ir.InstanceTearOff ||
665663
initializer is ir.FunctionTearOff ||
666-
initializer is ir.PropertySet ||
667664
initializer is ir.InstanceSet ||
668665
initializer is ir.DynamicSet ||
669666
initializer is ir.StaticInvocation ||

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,10 @@ class CachedStaticType extends StaticTypeBase implements StaticTypeProvider {
4545
@override
4646
ir.DartType visitVariableGet(ir.VariableGet node) => _getStaticType(node);
4747

48-
@override
49-
ir.DartType visitPropertyGet(ir.PropertyGet node) => _getStaticType(node);
50-
5148
@override
5249
ir.DartType visitSuperPropertyGet(ir.SuperPropertyGet node) =>
5350
_getStaticType(node);
5451

55-
@override
56-
ir.DartType visitMethodInvocation(ir.MethodInvocation node) =>
57-
_getStaticType(node);
58-
5952
@override
6053
ir.DartType visitStaticInvocation(ir.StaticInvocation node) =>
6154
_getStaticType(node);

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,14 @@ RuntimeTypeUseData computeRuntimeTypeUse(
9090

9191
/// Returns `true` if [node] is of the form `e.runtimeType`.
9292
bool isGetRuntimeType(ir.TreeNode node) {
93-
return node is ir.PropertyGet &&
93+
return node is ir.InstanceGet &&
9494
node.name.text == Identifiers.runtimeType_ ||
95-
node is ir.InstanceGet && node.name.text == Identifiers.runtimeType_ ||
9695
node is ir.DynamicGet && node.name.text == Identifiers.runtimeType_;
9796
}
9897

9998
/// Returns `true` if [node] is of the form `e.toString()`.
10099
bool isInvokeToString(ir.TreeNode node) {
101-
return node is ir.MethodInvocation && node.name.text == 'toString' ||
102-
node is ir.InstanceInvocation && node.name.text == 'toString';
100+
return node is ir.InstanceInvocation && node.name.text == 'toString';
103101
}
104102

105103
assert(isGetRuntimeType(node));
@@ -427,17 +425,13 @@ RuntimeTypeUseData computeRuntimeTypeUse(
427425

428426
/// Returns `true` if [node] is a potential invocation of an Object method.
429427
bool _isObjectMethodInvocation(ir.TreeNode node) {
430-
return node is ir.MethodInvocation ||
431-
node is ir.InstanceInvocation ||
432-
node is ir.EqualsCall;
428+
return node is ir.InstanceInvocation || node is ir.EqualsCall;
433429
}
434430

435431
/// Returns the [_RuntimeTypeAccess] corresponding to [node] if it is an access
436432
/// of `.runtimeType`, and `null` otherwise.
437433
_RuntimeTypeAccess _getRuntimeTypeAccess(ir.TreeNode node) {
438-
if (node is ir.PropertyGet && node.name.text == 'runtimeType') {
439-
return _RuntimeTypeAccess(node, node.receiver);
440-
} else if (node is ir.InstanceGet && node.name.text == 'runtimeType') {
434+
if (node is ir.InstanceGet && node.name.text == 'runtimeType') {
441435
return _RuntimeTypeAccess(node, node.receiver);
442436
} else if (node is ir.DynamicGet && node.name.text == 'runtimeType') {
443437
return _RuntimeTypeAccess(node, node.receiver);
@@ -455,10 +449,7 @@ class _RuntimeTypeAccess {
455449
/// Returns the [_EqualsInvocation] corresponding to [node] if it is a call to
456450
/// of `==`, and `null` otherwise.
457451
_EqualsInvocation _getEqualsInvocation(ir.TreeNode node) {
458-
if (node is ir.MethodInvocation && node.name.text == '==') {
459-
return _EqualsInvocation(
460-
node, node.receiver, node.arguments.positional.single);
461-
} else if (node is ir.EqualsCall) {
452+
if (node is ir.EqualsCall) {
462453
return _EqualsInvocation(node, node.left, node.right);
463454
}
464455
return null;

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

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,35 +1025,6 @@ class ScopeModelBuilder extends ir.Visitor<EvaluationComplexity>
10251025
return complexity;
10261026
}
10271027

1028-
@override
1029-
EvaluationComplexity visitMethodInvocation(ir.MethodInvocation node) {
1030-
node.receiver = _handleExpression(node.receiver);
1031-
EvaluationComplexity receiverComplexity = _lastExpressionComplexity;
1032-
ir.TreeNode receiver = node.receiver;
1033-
if (node.arguments.types.isNotEmpty) {
1034-
VariableUse usage;
1035-
if (receiver is ir.VariableGet &&
1036-
(receiver.variable.parent is ir.LocalFunction)) {
1037-
usage =
1038-
new VariableUse.localTypeArgument(receiver.variable.parent, node);
1039-
} else {
1040-
usage = new VariableUse.instanceTypeArgument(node);
1041-
}
1042-
visitNodesInContext(node.arguments.types, usage);
1043-
}
1044-
EvaluationComplexity complexity = visitArguments(node.arguments);
1045-
ir.Member interfaceTarget = node.interfaceTarget;
1046-
if (receiverComplexity.combine(complexity).isConstant &&
1047-
interfaceTarget is ir.Procedure &&
1048-
interfaceTarget.kind == ir.ProcedureKind.Operator) {
1049-
// Only operator invocations can be part of constant expressions so we
1050-
// only try to compute an implicit constant when the receiver and all
1051-
// arguments are constant - and are used in an operator call.
1052-
return _evaluateImplicitConstant(node);
1053-
}
1054-
return const EvaluationComplexity.lazy();
1055-
}
1056-
10571028
@override
10581029
EvaluationComplexity visitInstanceInvocation(ir.InstanceInvocation node) {
10591030
node.receiver = _handleExpression(node.receiver);
@@ -1168,16 +1139,6 @@ class ScopeModelBuilder extends ir.Visitor<EvaluationComplexity>
11681139
return const EvaluationComplexity.lazy();
11691140
}
11701141

1171-
@override
1172-
EvaluationComplexity visitPropertyGet(ir.PropertyGet node) {
1173-
node.receiver = _handleExpression(node.receiver);
1174-
EvaluationComplexity complexity = _lastExpressionComplexity;
1175-
if (complexity.isConstant && node.name.text == 'length') {
1176-
return _evaluateImplicitConstant(node);
1177-
}
1178-
return const EvaluationComplexity.lazy();
1179-
}
1180-
11811142
@override
11821143
EvaluationComplexity visitInstanceGet(ir.InstanceGet node) {
11831144
node.receiver = _handleExpression(node.receiver);
@@ -1210,13 +1171,6 @@ class ScopeModelBuilder extends ir.Visitor<EvaluationComplexity>
12101171
return const EvaluationComplexity.lazy();
12111172
}
12121173

1213-
@override
1214-
EvaluationComplexity visitPropertySet(ir.PropertySet node) {
1215-
node.receiver = _handleExpression(node.receiver);
1216-
node.value = _handleExpression(node.value);
1217-
return const EvaluationComplexity.lazy();
1218-
}
1219-
12201174
@override
12211175
EvaluationComplexity visitInstanceSet(ir.InstanceSet node) {
12221176
node.receiver = _handleExpression(node.receiver);

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

Lines changed: 0 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import 'runtime_type_analysis.dart';
1414
import 'scope.dart';
1515
import 'static_type_base.dart';
1616
import 'static_type_cache.dart';
17-
import 'util.dart';
1817

1918
/// Enum values for how the target of a static type should be interpreted.
2019
enum ClassRelation {
@@ -268,28 +267,6 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
268267
.substituteType(interfaceTarget.getterType);
269268
}
270269

271-
/// Computes the result type of the property access [node] on a receiver of
272-
/// type [receiverType].
273-
///
274-
/// If the `node.interfaceTarget` is `null` but matches an `Object` member
275-
/// it is updated to target this member.
276-
ir.DartType _computePropertyGetType(
277-
ir.PropertyGet node, ir.DartType receiverType) {
278-
node.interfaceTarget ??= _resolveDynamicTarget(receiverType, node.name);
279-
ir.Member interfaceTarget = node.interfaceTarget;
280-
if (interfaceTarget != null) {
281-
return _computeInstanceGetType(receiverType, interfaceTarget);
282-
}
283-
// Treat the properties of Object specially.
284-
String nameString = node.name.text;
285-
if (nameString == 'hashCode') {
286-
return typeEnvironment.coreTypes.intNonNullableRawType;
287-
} else if (nameString == 'runtimeType') {
288-
return typeEnvironment.coreTypes.typeNonNullableRawType;
289-
}
290-
return const ir.DynamicType();
291-
}
292-
293270
/// Replaces [original] with [replacement] in the AST and removes cached
294271
/// expression type information for [original].
295272
void _replaceExpression(ir.Expression original, ir.Expression replacement) {
@@ -308,23 +285,6 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
308285
void handleRuntimeTypeUse(ir.Expression node, RuntimeTypeUseKind kind,
309286
ir.DartType receiverType, ir.DartType argumentType) {}
310287

311-
@override
312-
ir.DartType visitPropertyGet(ir.PropertyGet node) {
313-
ir.DartType receiverType = visitNode(node.receiver);
314-
ir.DartType resultType = _staticTypeCache._expressionTypes[node] =
315-
_computePropertyGetType(node, receiverType);
316-
receiverType = _narrowInstanceReceiver(node.interfaceTarget, receiverType);
317-
if (node.interfaceTarget != null) {
318-
handleInstanceGet(node, receiverType, node.interfaceTarget, resultType);
319-
} else {
320-
handleDynamicGet(node, receiverType, node.name, resultType);
321-
}
322-
if (node.name.text == Identifiers.runtimeType_) {
323-
handleRuntimeTypeGet(receiverType, node);
324-
}
325-
return resultType;
326-
}
327-
328288
void handleRuntimeTypeGet(ir.DartType receiverType, ir.Expression node) {
329289
RuntimeTypeUseData data =
330290
computeRuntimeTypeUse(_pendingRuntimeTypeUseData, node);
@@ -460,37 +420,6 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
460420
return null;
461421
}
462422

463-
@override
464-
ir.DartType visitPropertySet(ir.PropertySet node) {
465-
ir.DartType receiverType = visitNode(node.receiver);
466-
ir.DartType valueType = super.visitPropertySet(node);
467-
ir.Member interfaceTarget = node.interfaceTarget;
468-
if (interfaceTarget == null) {
469-
interfaceTarget = _resolveDynamicSet(receiverType, node.name);
470-
if (interfaceTarget != null) {
471-
ir.DartType setterType =
472-
_computeInstanceSetType(receiverType, interfaceTarget);
473-
ir.AsExpression implicitCast =
474-
_createImplicitAsIfNeeded(node.value, valueType, setterType);
475-
if (implicitCast != null) {
476-
node.value = implicitCast..parent = node;
477-
// Visit the newly created as expression; the original value has
478-
// already been visited.
479-
handleAsExpression(implicitCast, valueType);
480-
valueType = setterType;
481-
}
482-
node.interfaceTarget = interfaceTarget;
483-
}
484-
}
485-
receiverType = _narrowInstanceReceiver(interfaceTarget, receiverType);
486-
if (interfaceTarget != null) {
487-
handleInstanceSet(node, receiverType, node.interfaceTarget, valueType);
488-
} else {
489-
handleDynamicSet(node, receiverType, node.name, valueType);
490-
}
491-
return valueType;
492-
}
493-
494423
@override
495424
ir.DartType visitDynamicSet(ir.DynamicSet node) {
496425
ir.DartType receiverType = visitNode(node.receiver);
@@ -910,69 +839,6 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
910839
}
911840
}
912841

913-
@override
914-
ir.DartType visitMethodInvocation(ir.MethodInvocation node) {
915-
ArgumentTypes argumentTypes = _visitArguments(node.arguments);
916-
ir.DartType receiverType = visitNode(node.receiver);
917-
ir.Member interfaceTarget = node.interfaceTarget ??
918-
_resolveDynamicInvocationTarget(
919-
receiverType, node.name, node.arguments);
920-
ir.DartType returnType;
921-
if (interfaceTarget != null) {
922-
ir.DartType functionType = _computeInstanceInvocationType(
923-
receiverType, interfaceTarget, node.arguments, argumentTypes);
924-
if (node.interfaceTarget == null) {
925-
// We change [node] from being a dynamic invocation to an instance
926-
// invocation, so we need to add static type checks to the arguments to
927-
// match instance invocations created by the CFE.
928-
// TODO(johnniwinther): Handle incremental target improvement.
929-
_updateMethodInvocationTarget(node, argumentTypes, functionType);
930-
node.interfaceTarget = interfaceTarget;
931-
}
932-
returnType = _getFunctionReturnType(functionType);
933-
} else {
934-
returnType = _computeDynamicInvocationReturnType(node, receiverType);
935-
}
936-
receiverType = _narrowInstanceReceiver(node.interfaceTarget, receiverType);
937-
if (node.name.text == '==') {
938-
TypeMap afterInvocation = typeMap;
939-
ir.Expression left = node.receiver;
940-
ir.Expression right = node.arguments.positional[0];
941-
if (isNullLiteral(right)) {
942-
_registerEqualsNull(afterInvocation, left);
943-
}
944-
if (isNullLiteral(left)) {
945-
_registerEqualsNull(afterInvocation, right);
946-
}
947-
assert(node.interfaceTarget != null);
948-
handleEqualsCall(left, receiverType, right, argumentTypes.positional[0],
949-
node.interfaceTarget);
950-
} else if (node.interfaceTarget != null) {
951-
handleInstanceInvocation(
952-
node, receiverType, interfaceTarget, argumentTypes);
953-
} else {
954-
ir.Expression receiver = node.receiver;
955-
if (receiver is ir.VariableGet &&
956-
receiver.variable.isFinal &&
957-
receiver.variable.parent is ir.FunctionDeclaration) {
958-
handleLocalFunctionInvocation(
959-
node, receiver.variable.parent, argumentTypes, returnType);
960-
} else {
961-
handleDynamicInvocation(node, receiverType, argumentTypes, returnType);
962-
// TODO(johnniwinther): Avoid treating a known function call as a
963-
// dynamic call when CFE provides a way to distinguish the two.
964-
if (operatorFromString(node.name.text) == null &&
965-
receiverType is ir.DynamicType) {
966-
// We might implicitly call a getter that returns a function.
967-
handleFunctionInvocation(
968-
node, const ir.DynamicType(), argumentTypes, returnType);
969-
}
970-
}
971-
}
972-
_staticTypeCache._expressionTypes[node] = returnType;
973-
return returnType;
974-
}
975-
976842
@override
977843
ir.DartType visitInstanceInvocation(ir.InstanceInvocation node) {
978844
ArgumentTypes argumentTypes = _visitArguments(node.arguments);
@@ -1060,9 +926,6 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
1060926
receiverType = _narrowInstanceReceiver(interfaceTarget, receiverType);
1061927
handleInstanceInvocation(
1062928
replacement, receiverType, interfaceTarget, argumentTypes);
1063-
if (replacement is ir.MethodInvocation) {
1064-
_staticTypeCache._expressionTypes[replacement] = resultType;
1065-
}
1066929
return resultType;
1067930
} else if (node.name == ir.Name.callName &&
1068931
(receiverType is ir.FunctionType ||

0 commit comments

Comments
 (0)