From e643b423ca968e875b29e9d17a20f989aec77088 Mon Sep 17 00:00:00 2001 From: Stephen Adams Date: Fri, 10 Jan 2020 05:08:07 +0000 Subject: [PATCH] [dart2js] Fix over-eager NullCheck removal Change-Id: I6a6a7ca3bb4621eac35305b96dec6039bc630d9e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/130966 Reviewed-by: Sigmund Cherem Commit-Queue: Stephen Adams --- pkg/compiler/lib/src/ssa/codegen_helpers.dart | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/compiler/lib/src/ssa/codegen_helpers.dart b/pkg/compiler/lib/src/ssa/codegen_helpers.dart index 1d96fc4ef61..5283f94ffa7 100644 --- a/pkg/compiler/lib/src/ssa/codegen_helpers.dart +++ b/pkg/compiler/lib/src/ssa/codegen_helpers.dart @@ -112,13 +112,31 @@ class SsaInstructionSelection extends HBaseVisitor with CodegenPhase { if (current is HGetLength) return current; if (current is HIndex) return current; if (current is HIndexAssign) return current; - if (current is HInvokeDynamic) return current; + if (current is HInvokeDynamic) { + HInstruction receiver = current.receiver; + // Either no interceptor or self-interceptor: + if (receiver == nullCheck) return current; + return null; + } } if (current is HForeignCode) { if (current.isNullGuardFor(nullCheck)) return current; } + // TODO(sra): Recognize other usable faulting patterns: + // + // - HInstanceEnvironment when the generated code is `receiver.$ti`. + // + // - super-calls using aliases. + // + // - one-shot interceptor receiver for selector not defined on + // null. The fault will appear to happen in the one-shot + // interceptor. + // + // - a constant interceptor can be replaced with a conditional + // HInterceptor (e.g. (a && JSArray_methods).get$first(a)). + if (current.canThrow(_abstractValueDomain) || current.sideEffects.hasSideEffects()) { return null;