Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Unified Diff: pkg/compiler/lib/src/cps_ir/type_propagation.dart

Issue 1080003004: Optimize identical based on types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase and update. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/compiler/dart2js/js_backend_cps_ir_control_flow_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « no previous file | tests/compiler/dart2js/js_backend_cps_ir_control_flow_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698