From 5e5a1bd68635c5d53bc56222b79779a1007bfef3 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Mon, 26 Jun 2017 13:06:06 +0300 Subject: [PATCH] Use java.lang.Object as a fall-back reference type If for some reason during preliminary analysis in redundant null check elimination we failed to determine a local variable type statically, treat it as java.lang.Object. This will disable some further optimizations using precise type information (such as INSTANCEOF check elimination), but will not fail with an exception anyway. --- .../nullCheck/RedundantNullCheckMethodTransformer.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/nullCheck/RedundantNullCheckMethodTransformer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/nullCheck/RedundantNullCheckMethodTransformer.kt index 13111ce8bc5..f8cec744e50 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/nullCheck/RedundantNullCheckMethodTransformer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/nullCheck/RedundantNullCheckMethodTransformer.kt @@ -27,6 +27,7 @@ import org.jetbrains.kotlin.codegen.optimization.common.isInsn import org.jetbrains.kotlin.codegen.optimization.fixStack.peek import org.jetbrains.kotlin.codegen.optimization.fixStack.top import org.jetbrains.kotlin.codegen.optimization.transformer.MethodTransformer +import org.jetbrains.kotlin.resolve.jvm.AsmTypes import org.jetbrains.kotlin.utils.SmartList import org.jetbrains.org.objectweb.asm.Label import org.jetbrains.org.objectweb.asm.Opcodes @@ -42,9 +43,6 @@ class RedundantNullCheckMethodTransformer : MethodTransformer() { private class TransformerPass(val internalClassName: String, val methodNode: MethodNode) { private var changes = false - private fun AbstractInsnNode.getIndex() = - methodNode.instructions.indexOf(this) - fun run(): Boolean { val checkedReferenceTypes = analyzeTypesAndRemoveDeadCode() eliminateRedundantChecks(checkedReferenceTypes) @@ -236,7 +234,7 @@ class RedundantNullCheckMethodTransformer : MethodTransformer() { for ((varIndex, dependentChecks) in checksDependingOnVariable) { for (checkInsn in dependentChecks) { val varType = checkedReferenceTypes[checkInsn] - ?: throw AssertionError("No var type @${checkInsn.getIndex()}") + ?: AsmTypes.OBJECT_TYPE nullabilityAssumptions.injectAssumptionsForCheck(varIndex, checkInsn, varType) } }