mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 04:27:17 +00:00
dart2js cps: Change type tests to null tests when applicable.
When null is the only value that might fail a type test we can rewrite it to just compare against null. R=kmillikin@google.com, sra@google.com Review URL: https://codereview.chromium.org//1306773005 .
This commit is contained in:
parent
2bbf0c61ae
commit
29dedfa97e
|
@ -43,12 +43,15 @@ class ConstantPropagationLattice {
|
|||
final ConstantSystem constantSystem;
|
||||
final types.DartTypes dartTypes;
|
||||
final AbstractValue anything;
|
||||
final AbstractValue nullValue;
|
||||
|
||||
ConstantPropagationLattice(TypeMaskSystem typeSystem,
|
||||
this.constantSystem,
|
||||
this.dartTypes)
|
||||
: this.typeSystem = typeSystem,
|
||||
anything = new AbstractValue.nonConstant(typeSystem.dynamicType);
|
||||
anything = new AbstractValue.nonConstant(typeSystem.dynamicType),
|
||||
nullValue = new AbstractValue.constantValue(
|
||||
new NullConstantValue(), new TypeMask.empty());
|
||||
|
||||
final AbstractValue nothing = new AbstractValue.nothing();
|
||||
|
||||
|
@ -1830,6 +1833,23 @@ class TransformingVisitor extends LeafVisitor {
|
|||
<Primitive>[prim],
|
||||
node.sourceInformation);
|
||||
}
|
||||
AbstractBool isNullableSubtype =
|
||||
lattice.isSubtypeOf(value, node.dartType, allowNull: true);
|
||||
AbstractBool isNullPassingTest =
|
||||
lattice.isSubtypeOf(lattice.nullValue, node.dartType);
|
||||
if (isNullableSubtype == AbstractBool.True &&
|
||||
isNullPassingTest == AbstractBool.False) {
|
||||
// Null is the only value not satisfying the type test.
|
||||
// Replace the type test with a null-check.
|
||||
// This has lower priority than the 'typeof'-based tests because
|
||||
// 'typeof' expressions might give the VM some more useful information.
|
||||
Primitive nullConst = makeConstantPrimitive(new NullConstantValue());
|
||||
insertLetPrim(node.parent, nullConst);
|
||||
return new ApplyBuiltinOperator(
|
||||
BuiltinOperator.LooseNeq,
|
||||
<Primitive>[prim, nullConst],
|
||||
node.sourceInformation);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue