Use copyInto instead of copyRangeTo in generated code
This commit is contained in:
committed by
SvyatoslavScherbina
parent
09d082c678
commit
a52359fcec
+7
-4
@@ -308,12 +308,15 @@ internal class KonanSymbols(context: Context, val symbolTable: SymbolTable, val
|
|||||||
} ?: error(descriptor.toString())
|
} ?: error(descriptor.toString())
|
||||||
return symbolTable.referenceSimpleFunction(functionDescriptor)
|
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 packageViewDescriptor = builtIns.builtInsModule.getPackage(KotlinBuiltIns.COLLECTIONS_PACKAGE_FQ_NAME)
|
||||||
val functionDescriptor = packageViewDescriptor.memberScope
|
val functionDescriptor = packageViewDescriptor.memberScope
|
||||||
.getContributedFunctions(Name.identifier("copyRangeTo"), NoLookupLocation.FROM_BACKEND)
|
.getContributedFunctions(Name.identifier("copyInto"), NoLookupLocation.FROM_BACKEND)
|
||||||
.first {
|
.single {
|
||||||
it.extensionReceiverParameter?.type?.constructor?.declarationDescriptor == symbol.descriptor
|
!it.isExpect &&
|
||||||
|
it.extensionReceiverParameter?.type?.constructor?.declarationDescriptor == symbol.descriptor
|
||||||
}
|
}
|
||||||
symbol.descriptor to symbolTable.referenceSimpleFunction(functionDescriptor)
|
symbol.descriptor to symbolTable.referenceSimpleFunction(functionDescriptor)
|
||||||
}.toMap()
|
}.toMap()
|
||||||
|
|||||||
+7
-7
@@ -16,12 +16,12 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.backend.konan.lower
|
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.DeclarationContainerLoweringPass
|
||||||
import org.jetbrains.kotlin.backend.common.descriptors.synthesizedString
|
import org.jetbrains.kotlin.backend.common.descriptors.synthesizedString
|
||||||
import org.jetbrains.kotlin.backend.common.ir.ir2string
|
import org.jetbrains.kotlin.backend.common.ir.ir2string
|
||||||
import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
|
import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
|
||||||
import org.jetbrains.kotlin.backend.common.lower.irBlock
|
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.PrimitiveType
|
||||||
import org.jetbrains.kotlin.builtins.UnsignedType
|
import org.jetbrains.kotlin.builtins.UnsignedType
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
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.ir.visitors.transformChildrenVoid
|
||||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
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) {
|
override fun lower(irDeclarationContainer: IrDeclarationContainer) {
|
||||||
irDeclarationContainer.declarations.forEach{
|
irDeclarationContainer.declarations.forEach{
|
||||||
when (it) {
|
when (it) {
|
||||||
@@ -134,12 +134,12 @@ class VarargInjectionLowering constructor(val context: CommonBackendContext): De
|
|||||||
+incrementVariable(indexTmpVariable, kIntOne)
|
+incrementVariable(indexTmpVariable, kIntOne)
|
||||||
} else {
|
} else {
|
||||||
val arraySizeVariable = irTemporary(irArraySize(arrayHandle, irGet(dst)), "length".synthesizedString)
|
val arraySizeVariable = irTemporary(irArraySize(arrayHandle, irGet(dst)), "length".synthesizedString)
|
||||||
+irCall(arrayHandle.copyRangeToSymbol.owner).apply {
|
+irCall(arrayHandle.copyIntoSymbol.owner).apply {
|
||||||
extensionReceiver = irGet(dst)
|
extensionReceiver = irGet(dst)
|
||||||
putValueArgument(0, irGet(arrayTmpVariable)) /* destination */
|
putValueArgument(0, irGet(arrayTmpVariable)) /* destination */
|
||||||
putValueArgument(1, kIntZero) /* fromIndex */
|
putValueArgument(1, irGet(indexTmpVariable)) /* destinationOffset */
|
||||||
putValueArgument(2, irGet(arraySizeVariable)) /* toIndex */
|
putValueArgument(2, kIntZero) /* startIndex */
|
||||||
putValueArgument(3, irGet(indexTmpVariable)) /* destinationIndex */
|
putValueArgument(3, irGet(arraySizeVariable)) /* endIndex */
|
||||||
}
|
}
|
||||||
+incrementVariable(indexTmpVariable, irGet(arraySizeVariable))
|
+incrementVariable(indexTmpVariable, irGet(arraySizeVariable))
|
||||||
log { "element:$i:spread element> ${ir2string(element.expression)}" }
|
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) {
|
abstract inner class ArrayHandle(val arraySymbol: IrClassSymbol) {
|
||||||
val setMethodSymbol = arraySymbol.functions.single { it.descriptor.name == OperatorNameConventions.SET }
|
val setMethodSymbol = arraySymbol.functions.single { it.descriptor.name == OperatorNameConventions.SET }
|
||||||
val sizeGetterSymbol = arraySymbol.getPropertyGetter("size")!!
|
val sizeGetterSymbol = arraySymbol.getPropertyGetter("size")!!
|
||||||
val copyRangeToSymbol = symbols.copyRangeTo[arraySymbol.descriptor]!!
|
val copyIntoSymbol = symbols.copyInto[arraySymbol.descriptor]!!
|
||||||
protected val singleParameterConstructor =
|
protected val singleParameterConstructor =
|
||||||
arraySymbol.owner.constructors.find { it.valueParameters.size == 1 }!!
|
arraySymbol.owner.constructors.find { it.valueParameters.size == 1 }!!
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user