From 30a2058f74f136cec2fcdfa9e8ec488eddce8a62 Mon Sep 17 00:00:00 2001 From: Georgy Bronnikov Date: Thu, 23 Aug 2018 18:54:35 +0300 Subject: [PATCH] Fix JVM_IR backend crashes when compiling for Android ^KT-23963 Fixed ^KT-23968 FIxed ^KT-23972 Fixed --- .../jetbrains/kotlin/backend/common/ir/Ir.kt | 42 ++++++------------- .../backend/jvm/lower/EnumClassLowering.kt | 2 +- 2 files changed, 13 insertions(+), 31 deletions(-) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/Ir.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/Ir.kt index 27d2bcc44fe..2b434e4a057 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/Ir.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/Ir.kt @@ -16,6 +16,7 @@ import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable import org.jetbrains.kotlin.ir.util.referenceFunction import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.resolve.calls.components.isVararg import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.util.OperatorNameConventions @@ -109,7 +110,10 @@ abstract class Symbols(val context: T, private val val arrayOf = symbolTable.referenceSimpleFunction( builtInsPackage("kotlin").getContributedFunctions( Name.identifier("arrayOf"), NoLookupLocation.FROM_BACKEND - ).single() + ).first { + it.extensionReceiverParameter == null && it.dispatchReceiverParameter == null && it.valueParameters.size == 1 && + it.valueParameters[0].isVararg + } ) val array = symbolTable.referenceClass(builtIns.array) @@ -142,7 +146,7 @@ abstract class Symbols(val context: T, private val protected fun arrayExtensionFun(type: KotlinType, name: String): IrSimpleFunctionSymbol { val descriptor = builtInsPackage("kotlin") .getContributedFunctions(Name.identifier(name), NoLookupLocation.FROM_BACKEND) - .singleOrNull { + .firstOrNull { it.valueParameters.isEmpty() && (it.extensionReceiverParameter?.type?.constructor?.declarationDescriptor as? ClassDescriptor)?.defaultType == type } @@ -152,20 +156,6 @@ abstract class Symbols(val context: T, private val abstract val copyRangeTo: Map - val intAnd = symbolTable.referenceSimpleFunction( - builtIns.intType.memberScope - .getContributedFunctions(OperatorNameConventions.AND, NoLookupLocation.FROM_BACKEND) - .single() - ) - - val intPlusInt = symbolTable.referenceSimpleFunction( - builtIns.intType.memberScope - .getContributedFunctions(OperatorNameConventions.PLUS, NoLookupLocation.FROM_BACKEND) - .single { - it.valueParameters.single().type == builtIns.intType - } - ) - // val valuesForEnum = symbolTable.referenceSimpleFunction( // context.getInternalFunctions("valuesForEnum").single()) // @@ -179,22 +169,11 @@ abstract class Symbols(val context: T, private val abstract val coroutineSuspendedGetter: IrSimpleFunctionSymbol - val kFunctionImpl = calc { symbolTable.referenceClass(context.reflectionTypes.kFunctionImpl) } - val functionReference = calc { symbolTable.referenceClass(context.getInternalClass("FunctionReference")) } - val kProperty0Impl = calc { symbolTable.referenceClass(context.reflectionTypes.kProperty0Impl) } - val kProperty1Impl = calc { symbolTable.referenceClass(context.reflectionTypes.kProperty1Impl) } - val kProperty2Impl = calc { symbolTable.referenceClass(context.reflectionTypes.kProperty2Impl) } - val kMutableProperty0Impl = calc { symbolTable.referenceClass(context.reflectionTypes.kMutableProperty0Impl) } - val kMutableProperty1Impl = calc { symbolTable.referenceClass(context.reflectionTypes.kMutableProperty1Impl) } - val kMutableProperty2Impl = calc { symbolTable.referenceClass(context.reflectionTypes.kMutableProperty2Impl) } -// val kLocalDelegatedPropertyImpl = symbolTable.referenceClass(context.reflectionTypes.kLocalDelegatedPropertyImpl) -// val kLocalDelegatedMutablePropertyImpl = symbolTable.referenceClass(context.reflectionTypes.kLocalDelegatedMutablePropertyImpl) - fun getFunction(name: Name, receiverType: KotlinType, vararg argTypes: KotlinType) = symbolTable.referenceFunction(receiverType.memberScope.getContributedFunctions(name, NoLookupLocation.FROM_BACKEND) - .single { + .first { var i = 0 it.valueParameters.size == argTypes.size && it.valueParameters.all { type -> type == argTypes[i++] } } @@ -206,7 +185,7 @@ abstract class Symbols(val context: T, private val var result = binaryOperatorCache[key] if (result == null) { result = symbolTable.referenceFunction(lhsType.memberScope.getContributedFunctions(name, NoLookupLocation.FROM_BACKEND) - .single { it.valueParameters.size == 1 && it.valueParameters[0].type == rhsType } + .first { it.valueParameters.size == 1 && it.valueParameters[0].type == rhsType } ) binaryOperatorCache[key] = result } @@ -219,10 +198,13 @@ abstract class Symbols(val context: T, private val var result = unaryOperatorCache[key] if (result == null) { result = symbolTable.referenceFunction(receiverType.memberScope.getContributedFunctions(name, NoLookupLocation.FROM_BACKEND) - .single { it.valueParameters.isEmpty() } + .first { it.valueParameters.isEmpty() } ) unaryOperatorCache[key] = result } return result } + + val intAnd = getBinaryOperator(OperatorNameConventions.AND, builtIns.intType, builtIns.intType) + val intPlusInt = getBinaryOperator(OperatorNameConventions.PLUS, builtIns.intType, builtIns.intType) } \ No newline at end of file diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt index 3035828e7df..c0c0fcc620e 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt @@ -45,7 +45,7 @@ class EnumClassLowering(val context: JvmBackendContext) : ClassLoweringPass { fun transform(delegatingConstructorCall: IrDelegatingConstructorCall): IrExpression } - private val unsubstitutedArrayOfFun = context.builtIns.findSingleFunction(Name.identifier("arrayOf")) + private val unsubstitutedArrayOfFun = context.ir.symbols.arrayOf.descriptor private fun createArrayOfExpression(arrayElementType: KotlinType, arrayElements: List): IrExpression { val typeParameter0 = unsubstitutedArrayOfFun.typeParameters[0]