Chromium Code Reviews| 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 383b39fb68ce20471bb7b6a76aadfcea68172dd6..79fb5d3218d036bc33ac477d8478ad499aa506b2 100644 |
| --- a/pkg/compiler/lib/src/cps_ir/type_propagation.dart |
| +++ b/pkg/compiler/lib/src/cps_ir/type_propagation.dart |
| @@ -156,6 +156,12 @@ class ConstantPropagationLattice { |
| typeSystem.isDefinitelyIndexable(value.type, allowNull: allowNull); |
| } |
| + bool isDefinitelyNotIntercepted(AbstractValue value, |
| + {bool allowNull: false}) { |
| + return value.isNothing || |
| + typeSystem.isDefinitelyNotIntercepted(value.type, allowNull: allowNull); |
| + } |
| + |
| /// Returns whether the given [value] is an instance of [type]. |
| /// |
| /// Since [value] and [type] are not always known, [AbstractBool.Maybe] is |
| @@ -1805,7 +1811,16 @@ class TransformingVisitor extends LeafVisitor { |
| } |
| Primitive visitTypeTest(TypeTest node) { |
| + return null; |
| + } |
| + |
| + Primitive visitTypeTestRaw(TypeTestRaw node) { |
| Primitive prim = node.value.definition; |
| + |
| + Primitive unaryBuiltinOperator(BuiltinOperator operator) => |
| + new ApplyBuiltinOperator( |
| + operator, <Primitive>[prim], node.sourceInformation); |
| + |
| AbstractValue value = getValue(prim); |
| if (node.dartType == dartTypes.coreTypes.intType) { |
| // Compile as typeof x === 'number' && Math.floor(x) === x |
| @@ -1819,10 +1834,7 @@ class TransformingVisitor extends LeafVisitor { |
| if (lattice.isDefinitelyNotNonIntegerDouble(value)) { |
| // If the value cannot be a non-integer double, but might not be a |
| // number at all, we can skip the Math.floor test. |
| - return new ApplyBuiltinOperator( |
| - BuiltinOperator.IsNumber, |
| - <Primitive>[prim], |
| - node.sourceInformation); |
| + return unaryBuiltinOperator(BuiltinOperator.IsNumber); |
| } |
| return new ApplyBuiltinOperator( |
| BuiltinOperator.IsNumberAndFloor, |
| @@ -1831,11 +1843,58 @@ class TransformingVisitor extends LeafVisitor { |
| } |
| if (node.dartType == dartTypes.coreTypes.numType || |
| node.dartType == dartTypes.coreTypes.doubleType) { |
| - return new ApplyBuiltinOperator( |
| - BuiltinOperator.IsNumber, |
| - <Primitive>[prim], |
| - node.sourceInformation); |
| + return unaryBuiltinOperator(BuiltinOperator.IsNumber); |
| + } |
| + |
| + if (node.dartType.element == functionCompiler.glue.jsFixedArrayClass) { |
| + // TODO(sra): Check input is restricted to JSArray. |
| + return unaryBuiltinOperator(BuiltinOperator.IsFixedLengthJSArray); |
| + } |
| + |
| + if (node.dartType.element == functionCompiler.glue.jsExtendableArrayClass) { |
| + // TODO(sra): Check input is restricted to JSArray. |
| + return unaryBuiltinOperator(BuiltinOperator.IsExtendableJSArray); |
| + } |
| + |
| + if (node.dartType.element == functionCompiler.glue.jsMutableArrayClass) { |
| + // TODO(sra): Check input is restricted to JSArray. |
| + return unaryBuiltinOperator(BuiltinOperator.IsModifiableJSArray); |
| + } |
| + |
| + if (node.dartType.element == |
| + functionCompiler.glue.jsUnmodifiableArrayClass) { |
| + // TODO(sra): Check input is restricted to JSArray. |
| + return unaryBuiltinOperator(BuiltinOperator.IsUnmodifiableJSArray); |
| } |
| + |
| + void unlinkInterceptor() { |
|
sra1
2015/10/06 06:47:58
If instead of removing the interceptor, we add one
|
| + if (node.interceptor != null) { |
| + node.interceptor.unlink(); |
| + node.interceptor = null; |
| + } |
| + } |
| + |
| + if (node.dartType == dartTypes.coreTypes.stringType || |
| + node.dartType == dartTypes.coreTypes.boolType) { |
| + // These types are recognized in tree_ir TypeOperator codegen. |
| + unlinkInterceptor(); |
| + return null; |
| + } |
| + |
| + // 'x is C' where x can be directly property-tested. |
| + if (lattice.isDefinitelyNotIntercepted(value, allowNull: false)) { |
| + unlinkInterceptor(); |
| + node.usePropertyTest = true; |
| + return null; |
| + } |
| + |
| + // Do a property test on the interceptor, by moving it to the value. |
| + assert(node.interceptor != null); |
| + node.usePropertyTest = true; |
| + node.value.unlink(); |
| + node.value = node.interceptor; |
| + node.interceptor = null; |
| + |
|
sra1
2015/10/06 06:47:58
I think what I would like to do is replace the cur
sra1
2015/10/07 03:55:34
I did this in the new CL https://codereview.chromi
|
| return null; |
| } |
| @@ -2316,9 +2375,17 @@ class TypePropagationVisitor implements Visitor { |
| } |
| void visitTypeTest(TypeTest node) { |
| - AbstractValue input = getValue(node.value.definition); |
| + handleTypeTest(node, getValue(node.value.definition), node.dartType); |
| + } |
| + |
| + void visitTypeTestRaw(TypeTestRaw node) { |
| + handleTypeTest(node, getValue(node.value.definition), node.dartType); |
| + } |
| + |
| + void handleTypeTest( |
| + Primitive node, AbstractValue input, types.DartType dartType) { |
| TypeMask boolType = typeSystem.boolType; |
| - switch(lattice.isSubtypeOf(input, node.dartType, allowNull: false)) { |
| + switch(lattice.isSubtypeOf(input, dartType, allowNull: false)) { |
| case AbstractBool.Nothing: |
| break; // And come back later. |