[dart2js] Fix folding of x is Object when x may be null.

Change-Id: Ie45dae49c936e6a163963773747a17006f9554c1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/156481
Commit-Queue: Mayank Patke <fishythefish@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
This commit is contained in:
Mayank Patke
2020-07-31 00:45:54 +00:00
committed by commit-bot@chromium.org
parent 2b51d59e69
commit 9b5f0f32ee
3 changed files with 21 additions and 22 deletions
+1 -2
View File
@@ -6308,7 +6308,7 @@ class TryCatchFinallyBuilder {
AbstractValue unwrappedType = kernelBuilder._typeInferenceMap
.getReturnTypeOf(kernelBuilder._commonElements.exceptionUnwrapper);
if (!kernelBuilder.options.useLegacySubtyping) {
if (kernelBuilder.options.useNullSafety) {
// Global type analysis does not currently understand that strong mode
// `Object` is not nullable, so is imprecise in the return type of the
// unwrapper, which leads to unnecessary checks for 'on Object'.
@@ -6326,7 +6326,6 @@ class TryCatchFinallyBuilder {
int catchesIndex = 0;
void pushCondition(ir.Catch catchBlock) {
// `guard` is often `dynamic`, which generates `true`.
kernelBuilder._pushIsTest(catchBlock.guard, unwrappedException,
kernelBuilder._sourceInformationBuilder.buildCatch(catchBlock));
}
+20 -16
View File
@@ -4130,26 +4130,30 @@ AbstractBool _isTestResult(
AbstractValueDomain abstractValueDomain = closedWorld.abstractValueDomain;
AbstractValue subsetType = expression.instructionType;
AbstractValue supersetType = checkedAbstractValue.abstractValue;
AbstractBool expressionIsNull = expression.isNull(abstractValueDomain);
if (useNullSafety &&
expression.isNull(abstractValueDomain).isDefinitelyTrue) {
if (dartType.isObject) return AbstractBool.False;
if (closedWorld.dartTypes.isTopType(dartType) ||
dartType is NullableType ||
dartType.isNull) {
return AbstractBool.True;
}
if (dartType is TypeVariableType || dartType is FunctionTypeVariable) {
return AbstractBool.Maybe;
}
if (dartType is LegacyType) {
DartType baseType = dartType.baseType;
if (baseType is NeverType) return AbstractBool.True;
if (baseType is TypeVariableType || baseType is FunctionTypeVariable) {
if (useNullSafety) {
if (expressionIsNull.isDefinitelyTrue) {
if (dartType.isObject) return AbstractBool.False;
if (closedWorld.dartTypes.isTopType(dartType) ||
dartType is NullableType ||
dartType.isNull) {
return AbstractBool.True;
}
if (dartType is TypeVariableType || dartType is FunctionTypeVariable) {
return AbstractBool.Maybe;
}
if (dartType is LegacyType) {
DartType baseType = dartType.baseType;
if (baseType is NeverType) return AbstractBool.True;
if (baseType is TypeVariableType || baseType is FunctionTypeVariable) {
return AbstractBool.Maybe;
}
}
return AbstractBool.False;
} else if (expressionIsNull.isPotentiallyTrue) {
if (dartType.isObject) return AbstractBool.Maybe;
}
return AbstractBool.False;
}
if (checkedAbstractValue.isPrecise &&
-4
View File
@@ -1887,10 +1887,6 @@ class SsaInstructionSimplifier extends HBaseVisitor
if (typeInput is HLoadType) {
TypeExpressionRecipe recipe = typeInput.typeExpression;
DartType dartType = recipe.type;
if (_closedWorld.dartTypes.isTopType(dartType)) {
return _graph.addConstantBool(true, _closedWorld);
}
IsTestSpecialization specialization =
SpecializedChecks.findIsTestSpecialization(
dartType, _graph, _closedWorld);