From 063ccf07f3c4f705784d7a4a18f98f18b39f7e72 Mon Sep 17 00:00:00 2001 From: Vasily Levchenko Date: Tue, 3 Apr 2018 17:00:42 +0300 Subject: [PATCH] [kotlin compiler] 1.2.50-dev-321 - Fix code after type argument refactoring in Kotlin (cherry picked from commit e6b9131910d5440272e6613856365a8277b1f58d) --- .../kotlin/backend/konan/KonanLower.kt | 1 + .../kotlin/backend/konan/ir/KonanIr.kt | 11 +++++-- .../lower/DeepCopyIrTreeWithDescriptors.kt | 29 +++++++++---------- .../backend/konan/lower/FunctionInlining.kt | 11 ++++--- .../konan/optimizations/Devirtualization.kt | 7 +++-- gradle.properties | 4 +-- 6 files changed, 37 insertions(+), 26 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLower.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLower.kt index 8e4b38fdacb..cea3755a4dd 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLower.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLower.kt @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.backend.konan.irasdescriptors.referenceAllTypeExtern import org.jetbrains.kotlin.backend.konan.lower.* import org.jetbrains.kotlin.backend.konan.lower.DefaultArgumentStubGenerator import org.jetbrains.kotlin.backend.konan.lower.DefaultParameterInjector +import org.jetbrains.kotlin.backend.konan.lower.InitializersLowering import org.jetbrains.kotlin.backend.konan.lower.LateinitLowering import org.jetbrains.kotlin.backend.konan.lower.LocalDeclarationsLowering import org.jetbrains.kotlin.ir.declarations.IrFile diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/KonanIr.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/KonanIr.kt index 6554d045580..706156dadaf 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/KonanIr.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/KonanIr.kt @@ -196,12 +196,17 @@ internal class IrPrivateFunctionCallImpl(startOffset: Int, type: KotlinType, override val symbol: IrFunctionSymbol, override val descriptor: FunctionDescriptor, - typeArguments: Map?, + typeArgumentsCount: Int, override val moduleDescriptor: ModuleDescriptor, override val totalFunctions: Int, override val functionIndex: Int -) : IrPrivateFunctionCall, - IrCallWithIndexedArgumentsBase(startOffset, endOffset, type, symbol.descriptor.valueParameters.size, typeArguments) { +) : IrPrivateFunctionCall, IrCallWithIndexedArgumentsBase( + startOffset, + endOffset, + type, + typeArgumentsCount = typeArgumentsCount, + valueArgumentsCount = symbol.descriptor.valueParameters.size +) { override val superQualifierSymbol: IrClassSymbol? get() = null diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/DeepCopyIrTreeWithDescriptors.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/DeepCopyIrTreeWithDescriptors.kt index 08e10ac244d..32eaf579f58 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/DeepCopyIrTreeWithDescriptors.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/DeepCopyIrTreeWithDescriptors.kt @@ -487,11 +487,14 @@ internal class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescr startOffset = expression.startOffset, endOffset = expression.endOffset, type = newDescriptor.returnType!!, - calleeDescriptor = newDescriptor, - typeArguments = substituteTypeArguments(expression.transformTypeArguments(newDescriptor)), + descriptor = newDescriptor, + typeArgumentsCount = expression.typeArgumentsCount, origin = expression.origin, superQualifierDescriptor = mapSuperQualifier(expression.superQualifier) - ).transformValueArguments(expression) + ).apply { + transformValueArguments(expression) + substituteTypeArguments(expression) + } } //---------------------------------------------------------------------// @@ -622,18 +625,12 @@ internal class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescr //-------------------------------------------------------------------------// - private fun substituteTypeArguments(oldTypeArguments: Map ?): Map ? { - - if (oldTypeArguments == null) return null - if (typeSubstitutor == null) return oldTypeArguments - - val newTypeArguments = oldTypeArguments.entries.associate { - val typeParameterDescriptor = it.key - val oldTypeArgument = it.value - val newTypeArgument = substituteType(oldTypeArgument)!! - typeParameterDescriptor to newTypeArgument + private fun IrMemberAccessExpression.substituteTypeArguments(original: IrMemberAccessExpression) { + for (index in 0 until original.typeArgumentsCount) { + val originalTypeArgument = original.getTypeArgument(index) + val newTypeArgument = substituteType(originalTypeArgument)!! + this.putTypeArgument(index, newTypeArgument) } - return newTypeArguments } //-------------------------------------------------------------------------// @@ -745,10 +742,12 @@ class DescriptorSubstitutorForExternalScope(val globalSubstituteMap: MutableMap< type = newDescriptor.returnType!!, symbol = createFunctionSymbol(newDescriptor), descriptor = newDescriptor, - typeArguments = oldExpression.typeArguments, + typeArgumentsCount = oldExpression.typeArgumentsCount, origin = oldExpression.origin, superQualifierSymbol = createClassSymbolOrNull(oldExpression.superQualifier) ).apply { + copyTypeArgumentsFrom(oldExpression) + oldExpression.descriptor.valueParameters.forEach { val valueArgument = oldExpression.getValueArgument(it) putValueArgument(it.index, valueArgument) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt index 60aabc9410c..a3e5b4f8657 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt @@ -47,6 +47,8 @@ import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.resolve.calls.components.hasDefaultValue import org.jetbrains.kotlin.resolve.inline.InlineUtil +import org.jetbrains.kotlin.types.TypeConstructor +import org.jetbrains.kotlin.types.TypeProjection import org.jetbrains.kotlin.types.TypeProjectionImpl import org.jetbrains.kotlin.types.TypeSubstitutor @@ -241,12 +243,13 @@ private class Inliner(val globalSubstituteMap: MutableMap - typeParameters[typeParameter.index].typeConstructor to TypeProjectionImpl(typeArgument) + val substitutionContext = mutableMapOf() + for (index in 0 until irCall.typeArgumentsCount) { + val typeArgument = irCall.getTypeArgument(index) ?: continue + substitutionContext[typeParameters[index].typeConstructor] = TypeProjectionImpl(typeArgument) } return TypeSubstitutor.create(substitutionContext) } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/Devirtualization.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/Devirtualization.kt index 5a31af09afc..f2b7ec917b1 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/Devirtualization.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/Devirtualization.kt @@ -34,6 +34,7 @@ import org.jetbrains.kotlin.ir.builders.* import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.expressions.IrCall import org.jetbrains.kotlin.ir.expressions.IrExpression +import org.jetbrains.kotlin.ir.expressions.copyTypeArgumentsFrom import org.jetbrains.kotlin.ir.expressions.getValueArgument import org.jetbrains.kotlin.ir.expressions.impl.IrBranchImpl import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl @@ -1025,11 +1026,13 @@ internal object Devirtualization { type = actualType, symbol = callee.symbol, descriptor = callee.descriptor, - typeArguments = (callee as? IrCallImpl)?.typeArguments, + typeArgumentsCount = callee.typeArgumentsCount, moduleDescriptor = devirtualizedCallee.module.descriptor, totalFunctions = devirtualizedCallee.module.numberOfFunctions, functionIndex = devirtualizedCallee.symbolTableIndex - ) + ).apply { + copyTypeArgumentsFrom(callee) + } }) } diff --git a/gradle.properties b/gradle.properties index 78f37fe8f0e..5e6bb12a63e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,8 +20,8 @@ remoteRoot=konan_tests #kotlinCompilerModule=org.jetbrains.kotlin:kotlin-compiler:1.1-SNAPSHOT # Download artifacts of https://teamcity.jetbrains.com/viewType.html?buildTypeId=Kotlin_120_Compiler testDataVersion=1226829:id -kotlinCompilerRepo=https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_dev_CompilerAllPlugins),number:1.2.50-dev-139,tag:kotlin-native,pinned:true/artifacts/content/maven -kotlinVersion=1.2.50-dev-139 +kotlinCompilerRepo=https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_dev_CompilerAllPlugins),number:1.2.50-dev-321,tag:kotlin-native,pinned:true/artifacts/content/maven +kotlinVersion=1.2.50-dev-321 konanVersion=0.6.2 org.gradle.jvmargs='-Dfile.encoding=UTF-8'