| 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 c90f777e0fcefd4f0001729dd8c7ab6a9b08b9e8..dc36d80432fe901283e506f7e2d18ec7dd41374b 100644
|
| --- a/pkg/compiler/lib/src/cps_ir/type_propagation.dart
|
| +++ b/pkg/compiler/lib/src/cps_ir/type_propagation.dart
|
| @@ -53,6 +53,7 @@ class TypeMaskSystem implements TypeSystem<TypeMask> {
|
| TypeMask get listType => inferrer.listType;
|
| TypeMask get mapType => inferrer.mapType;
|
|
|
| + // TODO(karlklose): remove compiler here.
|
| TypeMaskSystem(dart2js.Compiler compiler)
|
| : inferrer = compiler.typesTask,
|
| classWorld = compiler.world;
|
| @@ -92,8 +93,6 @@ class TypeMaskSystem implements TypeSystem<TypeMask> {
|
| * by Wegman, Zadeck.
|
| */
|
| class TypePropagator<T> extends PassMixin {
|
| - // TODO(karlklose): remove reference to _compiler. It is currently used to
|
| - // compute [TypeMask]s.
|
| final types.DartTypes _dartTypes;
|
|
|
| // The constant system is used for evaluation of expressions with constant
|
| @@ -103,7 +102,6 @@ class TypePropagator<T> extends PassMixin {
|
| final dart2js.InternalErrorFunction _internalError;
|
| final Map<Node, _AbstractValue> _types;
|
|
|
| -
|
| TypePropagator(this._dartTypes,
|
| this._constantSystem,
|
| this._typeSystem,
|
| @@ -307,42 +305,43 @@ class _TypePropagationVisitor<T> extends Visitor {
|
| final Set<Definition> defWorkset = new Set<Definition>();
|
|
|
| final dart2js.ConstantSystem constantSystem;
|
| - final TypeSystem typeSystem;
|
| + final TypeSystem<T> typeSystem;
|
| final dart2js.InternalErrorFunction internalError;
|
| final types.DartTypes _dartTypes;
|
|
|
| - _AbstractValue unknownDynamic;
|
| + _AbstractValue<T> unknownDynamic;
|
|
|
| - _AbstractValue unknown([T t]) {
|
| + _AbstractValue<T> unknown([T t]) {
|
| if (t == null) {
|
| return unknownDynamic;
|
| } else {
|
| - return new _AbstractValue.unknown(t);
|
| + return new _AbstractValue<T>.unknown(t);
|
| }
|
| }
|
|
|
| - _AbstractValue nonConst([T type]) {
|
| + _AbstractValue<T> nonConst([T type]) {
|
| if (type == null) {
|
| type = typeSystem.dynamicType;
|
| }
|
| - return new _AbstractValue.nonConst(type);
|
| + return new _AbstractValue<T>.nonConst(type);
|
| }
|
|
|
| - _AbstractValue constantValue(ConstantValue constant, T type) {
|
| - return new _AbstractValue(constant, type);
|
| + _AbstractValue<T> constantValue(ConstantValue constant, T type) {
|
| + return new _AbstractValue<T>(constant, type);
|
| }
|
|
|
| // Stores the current lattice value for nodes. Note that it contains not only
|
| // definitions as keys, but also expressions such as method invokes.
|
| // Access through [getValue] and [setValue].
|
| - final Map<Node, _AbstractValue> values;
|
| + final Map<Node, _AbstractValue<T>> values;
|
|
|
| _TypePropagationVisitor(this.constantSystem,
|
| TypeSystem typeSystem,
|
| this.values,
|
| this.internalError,
|
| this._dartTypes)
|
| - : this.unknownDynamic = new _AbstractValue.unknown(typeSystem.dynamicType),
|
| + : this.unknownDynamic =
|
| + new _AbstractValue<T>.unknown(typeSystem.dynamicType),
|
| this.typeSystem = typeSystem;
|
|
|
| void analyze(ExecutableDefinition root) {
|
| @@ -387,17 +386,17 @@ class _TypePropagationVisitor<T> extends Visitor {
|
| /// Returns the lattice value corresponding to [node], defaulting to unknown.
|
| ///
|
| /// Never returns null.
|
| - _AbstractValue getValue(Node node) {
|
| - _AbstractValue value = values[node];
|
| + _AbstractValue<T> getValue(Node node) {
|
| + _AbstractValue<T> value = values[node];
|
| return (value == null) ? unknown() : value;
|
| }
|
|
|
| /// Joins the passed lattice [updateValue] to the current value of [node],
|
| /// and adds it to the definition work set if it has changed and [node] is
|
| /// a definition.
|
| - void setValue(Node node, _AbstractValue updateValue) {
|
| - _AbstractValue oldValue = getValue(node);
|
| - _AbstractValue newValue = updateValue.join(oldValue, typeSystem);
|
| + void setValue(Node node, _AbstractValue<T> updateValue) {
|
| + _AbstractValue<T> oldValue = getValue(node);
|
| + _AbstractValue<T> newValue = updateValue.join(oldValue, typeSystem);
|
| if (oldValue == newValue) {
|
| return;
|
| }
|
| @@ -472,7 +471,7 @@ class _TypePropagationVisitor<T> extends Visitor {
|
| // continuation. Note that this is effectively a phi node in SSA terms.
|
| for (int i = 0; i < node.arguments.length; i++) {
|
| Definition def = node.arguments[i].definition;
|
| - _AbstractValue cell = getValue(def);
|
| + _AbstractValue<T> cell = getValue(def);
|
| setValue(cont.parameters[i], cell);
|
| }
|
| }
|
| @@ -483,13 +482,13 @@ class _TypePropagationVisitor<T> extends Visitor {
|
|
|
| /// Sets the value of both the current node and the target continuation
|
| /// parameter.
|
| - void setValues(_AbstractValue updateValue) {
|
| + void setValues(_AbstractValue<T> updateValue) {
|
| setValue(node, updateValue);
|
| Parameter returnValue = cont.parameters[0];
|
| setValue(returnValue, updateValue);
|
| }
|
|
|
| - _AbstractValue lhs = getValue(node.receiver.definition);
|
| + _AbstractValue<T> lhs = getValue(node.receiver.definition);
|
| if (lhs.isUnknown) {
|
| // This may seem like a missed opportunity for evaluating short-circuiting
|
| // boolean operations; we are currently skipping these intentionally since
|
| @@ -523,7 +522,7 @@ class _TypePropagationVisitor<T> extends Visitor {
|
| } else if (node.selector.argumentCount == 1) {
|
| // Binary operator.
|
|
|
| - _AbstractValue rhs = getValue(node.arguments[0].definition);
|
| + _AbstractValue<T> rhs = getValue(node.arguments[0].definition);
|
| if (!rhs.isConstant) {
|
| setValues(rhs);
|
| return;
|
| @@ -541,7 +540,7 @@ class _TypePropagationVisitor<T> extends Visitor {
|
| setValues(nonConst());
|
| } else {
|
| T type = typeSystem.typeOf(result);
|
| - setValues(new _AbstractValue(result, type));
|
| + setValues(new _AbstractValue<T>(result, type));
|
| }
|
| }
|
|
|
| @@ -568,7 +567,7 @@ class _TypePropagationVisitor<T> extends Visitor {
|
| Continuation cont = node.continuation.definition;
|
| setReachable(cont);
|
|
|
| - void setValues(_AbstractValue updateValue) {
|
| + void setValues(_AbstractValue<T> updateValue) {
|
| setValue(node, updateValue);
|
| Parameter returnValue = cont.parameters[0];
|
| setValue(returnValue, updateValue);
|
| @@ -595,7 +594,7 @@ class _TypePropagationVisitor<T> extends Visitor {
|
| });
|
| LiteralDartString dartString = new LiteralDartString(allStrings.join());
|
| ConstantValue constant = new StringConstantValue(dartString);
|
| - setValues(new _AbstractValue(constant, type));
|
| + setValues(new _AbstractValue<T>(constant, type));
|
| } else {
|
| setValues(nonConst(type));
|
| }
|
| @@ -603,7 +602,7 @@ class _TypePropagationVisitor<T> extends Visitor {
|
|
|
| void visitBranch(Branch node) {
|
| IsTrue isTrue = node.condition;
|
| - _AbstractValue conditionCell = getValue(isTrue.value.definition);
|
| + _AbstractValue<T> conditionCell = getValue(isTrue.value.definition);
|
|
|
| if (conditionCell.isUnknown) {
|
| return; // And come back later.
|
| @@ -630,7 +629,7 @@ class _TypePropagationVisitor<T> extends Visitor {
|
| Continuation cont = node.continuation.definition;
|
| setReachable(cont);
|
|
|
| - void setValues(_AbstractValue updateValue) {
|
| + void setValues(_AbstractValue<T> updateValue) {
|
| setValue(node, updateValue);
|
| Parameter returnValue = cont.parameters[0];
|
| setValue(returnValue, updateValue);
|
| @@ -641,7 +640,7 @@ class _TypePropagationVisitor<T> extends Visitor {
|
| setValues(nonConst());
|
| }
|
|
|
| - _AbstractValue cell = getValue(node.receiver.definition);
|
| + _AbstractValue<T> cell = getValue(node.receiver.definition);
|
| if (cell.isUnknown) {
|
| return; // And come back later.
|
| } else if (cell.isNonConst) {
|
| @@ -655,7 +654,7 @@ class _TypePropagationVisitor<T> extends Visitor {
|
| types.DartType constantType = constant.getType(_dartTypes.coreTypes);
|
|
|
| T type = typeSystem.boolType;
|
| - _AbstractValue result;
|
| + _AbstractValue<T> result;
|
| if (constant.isNull &&
|
| checkedType != _dartTypes.coreTypes.nullType &&
|
| checkedType != _dartTypes.coreTypes.objectType) {
|
| @@ -775,8 +774,8 @@ class _TypePropagationVisitor<T> extends Visitor {
|
| // JavaScript specific nodes.
|
|
|
| void visitIdentical(Identical node) {
|
| - _AbstractValue leftConst = getValue(node.left.definition);
|
| - _AbstractValue rightConst = getValue(node.right.definition);
|
| + _AbstractValue<T> leftConst = getValue(node.left.definition);
|
| + _AbstractValue<T> rightConst = getValue(node.right.definition);
|
| ConstantValue leftValue = leftConst.constant;
|
| ConstantValue rightValue = rightConst.constant;
|
| if (leftConst.isUnknown || rightConst.isUnknown) {
|
| @@ -797,7 +796,7 @@ class _TypePropagationVisitor<T> extends Visitor {
|
| PrimitiveConstantValue right = rightValue;
|
| ConstantValue result =
|
| new BoolConstantValue(left.primitiveValue == right.primitiveValue);
|
| - setValue(node, new _AbstractValue(result, typeSystem.boolType));
|
| + setValue(node, new _AbstractValue<T>(result, typeSystem.boolType));
|
| }
|
| }
|
|
|
|
|