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 87f9abeb58e426b238675eff6af539112b913ace..60fdd45eb1a30c8917b5a7821e5339f20a764451 100644 |
--- a/pkg/compiler/lib/src/cps_ir/type_propagation.dart |
+++ b/pkg/compiler/lib/src/cps_ir/type_propagation.dart |
@@ -33,10 +33,12 @@ abstract class TypeSystem<T> { |
T getSelectorReturnType(Selector selector); |
T getParameterType(ParameterElement element); |
T join(T a, T b); |
- T typeOf(ConstantValue constant); |
+ T getTypeOf(ConstantValue constant); |
/// True if all values satisfying [type] are booleans (null is not a boolean). |
bool isDefinitelyBool(T type); |
+ |
+ bool areDisjoint(T left, T right); |
} |
class UnitTypeSystem implements TypeSystem<String> { |
@@ -55,9 +57,12 @@ class UnitTypeSystem implements TypeSystem<String> { |
getReturnType(_) => UNIT; |
getSelectorReturnType(_) => UNIT; |
join(a, b) => UNIT; |
- typeOf(_) => UNIT; |
+ getTypeOf(_) => UNIT; |
bool isDefinitelyBool(_) => false; |
+ |
+ @override |
+ bool areDisjoint(a, b) => false; |
} |
class TypeMaskSystem implements TypeSystem<TypeMask> { |
@@ -96,13 +101,18 @@ class TypeMaskSystem implements TypeSystem<TypeMask> { |
} |
@override |
- TypeMask typeOf(ConstantValue constant) { |
+ TypeMask getTypeOf(ConstantValue constant) { |
return computeTypeMask(inferrer.compiler, constant); |
} |
bool isDefinitelyBool(TypeMask t) { |
return t.containsOnlyBool(classWorld) && !t.isNullable; |
} |
+ |
+ bool areDisjoint(TypeMask left, TypeMask right) { |
+ TypeMask intersection = left.intersection(right, classWorld); |
+ return intersection.isEmpty && !intersection.isNullable; |
+ } |
} |
/** |
@@ -575,7 +585,7 @@ class _TypePropagationVisitor<T> implements Visitor { |
if (result == null) { |
setValues(nonConstant()); |
} else { |
- T type = typeSystem.typeOf(result); |
+ T type = typeSystem.getTypeOf(result); |
setValues(constantValue(result, type)); |
} |
} |
@@ -735,7 +745,7 @@ class _TypePropagationVisitor<T> implements Visitor { |
void visitConstant(Constant node) { |
ConstantValue value = node.value; |
- setValue(node, constantValue(value, typeSystem.typeOf(value))); |
+ setValue(node, constantValue(value, typeSystem.getTypeOf(value))); |
} |
void visitCreateFunction(CreateFunction node) { |
@@ -826,7 +836,12 @@ class _TypePropagationVisitor<T> implements Visitor { |
} else if (!leftConst.isConstant || !rightConst.isConstant) { |
T leftType = leftConst.type; |
T rightType = rightConst.type; |
- setValue(node, nonConstant(typeSystem.boolType)); |
+ if (typeSystem.areDisjoint(leftType, rightType)) { |
+ setValue(node, |
+ constantValue(new FalseConstantValue(), typeSystem.boolType)); |
+ } else { |
+ setValue(node, nonConstant(typeSystem.boolType)); |
+ } |
} else if (leftValue.isPrimitive && rightValue.isPrimitive) { |
assert(leftConst.isConstant && rightConst.isConstant); |
PrimitiveConstantValue left = leftValue; |