| Index: pkg/compiler/lib/src/cps_ir/type_propagation.dart
|
| diff --git a/pkg/compiler/lib/src/cps_ir/type_propagation.dart b/pkg/compiler/lib/src/cps_ir/type_propagation.dart
|
| index 25e9e102e378f385a8a32eb28a6d4ac7f5f7673b..0d37e7622ef0d02807df58cf74a4a04eb9cb252d 100644
|
| --- a/pkg/compiler/lib/src/cps_ir/type_propagation.dart
|
| +++ b/pkg/compiler/lib/src/cps_ir/type_propagation.dart
|
| @@ -452,6 +452,10 @@ class ConstantPropagationLattice {
|
| return folded ?? closedOnUint(left, right) ?? closedOnInt(left, right);
|
| }
|
|
|
| + AbstractValue codeUnitAtSpecial(AbstractValue left, AbstractValue right) {
|
| + return foldBinary(constantSystem.codeUnitAt, left, right);
|
| + }
|
| +
|
| AbstractValue equalSpecial(AbstractValue left, AbstractValue right) {
|
| AbstractValue folded = foldBinary(constantSystem.equal, left, right);
|
| if (folded != null) return folded;
|
| @@ -1121,6 +1125,21 @@ class TransformingVisitor extends DeepRecursiveVisitor {
|
| replaceWithBinary(BuiltinOperator.NumRemainder, receiver, arg);
|
| }
|
| }
|
| + } else if (name == 'codeUnitAt') {
|
| + if (node.arguments.length == 2) {
|
| + Primitive index = node.dartArgument(0);
|
| + if (lattice.isDefinitelyString(receiverValue) &&
|
| + lattice.isDefinitelyInt(getValue(index))) {
|
| + SourceInformation sourceInfo = node.sourceInformation;
|
| + CpsFragment cps = makeBoundsCheck(receiver, index, sourceInfo);
|
| + ApplyBuiltinOperator get =
|
| + cps.applyBuiltin(BuiltinOperator.CharCodeAt,
|
| + <Primitive>[receiver, index]);
|
| + node.replaceUsesWith(get);
|
| + get.hint = node.hint; // TODO(asgerf): Make replaceUsesWith set the hint?
|
| + return cps;
|
| + }
|
| + }
|
| }
|
| }
|
| return null;
|
| @@ -2498,16 +2517,35 @@ class TypePropagationVisitor implements Visitor {
|
| return; // And come back later.
|
| }
|
|
|
| - // Constant fold known length of containers.
|
| - if (node.selector == Selectors.length) {
|
| - AbstractValue object = getValue(node.dartReceiver);
|
| - if (typeSystem.isDefinitelyIndexable(object.type, allowNull: true)) {
|
| - int length = typeSystem.getContainerLength(object.type.nonNullable());
|
| - if (length != null) {
|
| - setResult(node, constantValue(new IntConstantValue(length)),
|
| - canReplace: !object.isNullable);
|
| + if (node.selector.isGetter) {
|
| + // Constant fold known length of containers.
|
| + if (node.selector == Selectors.length) {
|
| + AbstractValue object = getValue(node.dartReceiver);
|
| + if (typeSystem.isDefinitelyIndexable(object.type, allowNull: true)) {
|
| + int length = typeSystem.getContainerLength(object.type.nonNullable());
|
| + if (length != null) {
|
| + setResult(node, constantValue(new IntConstantValue(length)),
|
| + canReplace: !object.isNullable);
|
| + }
|
| }
|
| }
|
| + setResult(node, lattice.getInvokeReturnType(node.selector, node.mask));
|
| + return;
|
| + }
|
| +
|
| + if (node.selector.isCall) {
|
| + AbstractValue result;
|
| + if (node.selector == Selectors.codeUnitAt) {
|
| + AbstractValue object = getValue(node.dartReceiver);
|
| + AbstractValue right = getValue(node.dartArgument(0));
|
| + result = lattice.codeUnitAtSpecial(object, right);
|
| + }
|
| + if (result == null) {
|
| + setResult(node, lattice.getInvokeReturnType(node.selector, node.mask));
|
| + } else {
|
| + setResult(node, result, canReplace: true);
|
| + }
|
| + return;
|
| }
|
|
|
| if (!node.selector.isOperator) {
|
| @@ -2601,6 +2639,10 @@ class TypePropagationVisitor implements Visitor {
|
| }
|
| break;
|
|
|
| + case BuiltinOperator.CharCodeAt:
|
| + binaryOp(lattice.codeUnitAtSpecial, typeSystem.uint31Type);
|
| + break;
|
| +
|
| case BuiltinOperator.Identical:
|
| case BuiltinOperator.StrictEq:
|
| case BuiltinOperator.LooseEq:
|
|
|