From a52359fcec5dd489492c5e32e8e461e9f5d53cb2 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Tue, 15 Jan 2019 18:21:08 +0300 Subject: [PATCH] Use copyInto instead of copyRangeTo in generated code --- .../org/jetbrains/kotlin/backend/konan/ir/Ir.kt | 11 +++++++---- .../kotlin/backend/konan/lower/VarargLowering.kt | 14 +++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt index 9fed6c70417..147b1beb24c 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt @@ -308,12 +308,15 @@ internal class KonanSymbols(context: Context, val symbolTable: SymbolTable, val } ?: error(descriptor.toString()) return symbolTable.referenceSimpleFunction(functionDescriptor) } - override val copyRangeTo = arrays.map { symbol -> + override val copyRangeTo get() = TODO() + + val copyInto = arrays.map { symbol -> val packageViewDescriptor = builtIns.builtInsModule.getPackage(KotlinBuiltIns.COLLECTIONS_PACKAGE_FQ_NAME) val functionDescriptor = packageViewDescriptor.memberScope - .getContributedFunctions(Name.identifier("copyRangeTo"), NoLookupLocation.FROM_BACKEND) - .first { - it.extensionReceiverParameter?.type?.constructor?.declarationDescriptor == symbol.descriptor + .getContributedFunctions(Name.identifier("copyInto"), NoLookupLocation.FROM_BACKEND) + .single { + !it.isExpect && + it.extensionReceiverParameter?.type?.constructor?.declarationDescriptor == symbol.descriptor } symbol.descriptor to symbolTable.referenceSimpleFunction(functionDescriptor) }.toMap() diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/VarargLowering.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/VarargLowering.kt index 278eec500d0..0fb5fdef5db 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/VarargLowering.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/VarargLowering.kt @@ -16,12 +16,12 @@ package org.jetbrains.kotlin.backend.konan.lower -import org.jetbrains.kotlin.backend.common.CommonBackendContext import org.jetbrains.kotlin.backend.common.DeclarationContainerLoweringPass import org.jetbrains.kotlin.backend.common.descriptors.synthesizedString import org.jetbrains.kotlin.backend.common.ir.ir2string import org.jetbrains.kotlin.backend.common.lower.createIrBuilder import org.jetbrains.kotlin.backend.common.lower.irBlock +import org.jetbrains.kotlin.backend.konan.KonanBackendContext import org.jetbrains.kotlin.builtins.PrimitiveType import org.jetbrains.kotlin.builtins.UnsignedType import org.jetbrains.kotlin.ir.IrElement @@ -39,7 +39,7 @@ import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid import org.jetbrains.kotlin.util.OperatorNameConventions -class VarargInjectionLowering constructor(val context: CommonBackendContext): DeclarationContainerLoweringPass { +internal class VarargInjectionLowering constructor(val context: KonanBackendContext): DeclarationContainerLoweringPass { override fun lower(irDeclarationContainer: IrDeclarationContainer) { irDeclarationContainer.declarations.forEach{ when (it) { @@ -134,12 +134,12 @@ class VarargInjectionLowering constructor(val context: CommonBackendContext): De +incrementVariable(indexTmpVariable, kIntOne) } else { val arraySizeVariable = irTemporary(irArraySize(arrayHandle, irGet(dst)), "length".synthesizedString) - +irCall(arrayHandle.copyRangeToSymbol.owner).apply { + +irCall(arrayHandle.copyIntoSymbol.owner).apply { extensionReceiver = irGet(dst) putValueArgument(0, irGet(arrayTmpVariable)) /* destination */ - putValueArgument(1, kIntZero) /* fromIndex */ - putValueArgument(2, irGet(arraySizeVariable)) /* toIndex */ - putValueArgument(3, irGet(indexTmpVariable)) /* destinationIndex */ + putValueArgument(1, irGet(indexTmpVariable)) /* destinationOffset */ + putValueArgument(2, kIntZero) /* startIndex */ + putValueArgument(3, irGet(arraySizeVariable)) /* endIndex */ } +incrementVariable(indexTmpVariable, irGet(arraySizeVariable)) log { "element:$i:spread element> ${ir2string(element.expression)}" } @@ -203,7 +203,7 @@ class VarargInjectionLowering constructor(val context: CommonBackendContext): De abstract inner class ArrayHandle(val arraySymbol: IrClassSymbol) { val setMethodSymbol = arraySymbol.functions.single { it.descriptor.name == OperatorNameConventions.SET } val sizeGetterSymbol = arraySymbol.getPropertyGetter("size")!! - val copyRangeToSymbol = symbols.copyRangeTo[arraySymbol.descriptor]!! + val copyIntoSymbol = symbols.copyInto[arraySymbol.descriptor]!! protected val singleParameterConstructor = arraySymbol.owner.constructors.find { it.valueParameters.size == 1 }!!