IR: build primitive array only when required
This commit is contained in:
committed by
vvlevchenko
parent
e3c2f78b63
commit
f0a99963a7
+20
-12
@@ -5,6 +5,8 @@ import org.jetbrains.kotlin.backend.konan.Context
|
|||||||
import org.jetbrains.kotlin.backend.konan.KonanPlatform
|
import org.jetbrains.kotlin.backend.konan.KonanPlatform
|
||||||
import org.jetbrains.kotlin.backend.konan.ir.ir2string
|
import org.jetbrains.kotlin.backend.konan.ir.ir2string
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns.FQ_NAMES
|
||||||
|
import org.jetbrains.kotlin.builtins.PrimitiveType
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
@@ -21,6 +23,7 @@ import org.jetbrains.kotlin.name.FqName
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
import org.jetbrains.kotlin.types.TypeUtils
|
||||||
|
|
||||||
|
|
||||||
class VarargInjectionLowering internal constructor(val context: Context): FunctionLoweringPass {
|
class VarargInjectionLowering internal constructor(val context: Context): FunctionLoweringPass {
|
||||||
@@ -72,7 +75,8 @@ class VarargInjectionLowering internal constructor(val context: Context): Functi
|
|||||||
log("skipped vararg expression because it's string array literal")
|
log("skipped vararg expression because it's string array literal")
|
||||||
return@forEach
|
return@forEach
|
||||||
}
|
}
|
||||||
val arrayHandle = arrayType(type)
|
log ("$it: array type:$type, is array of primitives ${KotlinBuiltIns.isArray(it.type)}")
|
||||||
|
val arrayHandle = arrayType(it.type)
|
||||||
val arrayConstructor = arrayHandle.arrayDescriptor.constructors.find { it.valueParameters.size == 1 }!!
|
val arrayConstructor = arrayHandle.arrayDescriptor.constructors.find { it.valueParameters.size == 1 }!!
|
||||||
val block = irBlock(arrayHandle.arrayDescriptor.defaultType)
|
val block = irBlock(arrayHandle.arrayDescriptor.defaultType)
|
||||||
val arrayConstructorCall = irCall(
|
val arrayConstructorCall = irCall(
|
||||||
@@ -146,18 +150,22 @@ class VarargInjectionLowering internal constructor(val context: Context): Functi
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun arrayType(type: KotlinType): ArrayHandle {
|
private fun arrayType(type: KotlinType): ArrayHandle = when {
|
||||||
return when {
|
KotlinBuiltIns.isPrimitiveArray(type) -> {
|
||||||
KotlinBuiltIns.isByte(type) -> kByteArrayHandler
|
val primitiveType = KotlinBuiltIns.getPrimitiveTypeByArrayClassFqName(DescriptorUtils.getFqName(type.constructor.declarationDescriptor!!))
|
||||||
KotlinBuiltIns.isShort(type) -> kShortArrayHandler
|
when (primitiveType) {
|
||||||
KotlinBuiltIns.isChar(type) -> kCharArrayHandler
|
PrimitiveType.BYTE -> kByteArrayHandler
|
||||||
KotlinBuiltIns.isInt(type) -> kIntArrayHandler
|
PrimitiveType.SHORT -> kShortArrayHandler
|
||||||
KotlinBuiltIns.isLong(type) -> kLongArrayHandler
|
PrimitiveType.CHAR -> kCharArrayHandler
|
||||||
KotlinBuiltIns.isFloat(type) -> kFloatArrayHandler
|
PrimitiveType.INT -> kIntArrayHandler
|
||||||
KotlinBuiltIns.isDouble(type) -> kDoubleArrayHandler
|
PrimitiveType.LONG -> kLongArrayHandler
|
||||||
KotlinBuiltIns.isBoolean(type) -> kBooleanArrayHandler
|
PrimitiveType.FLOAT -> kFloatArrayHandler
|
||||||
else -> kArrayHandler
|
PrimitiveType.DOUBLE -> kDoubleArrayHandler
|
||||||
|
PrimitiveType.BOOLEAN -> kBooleanArrayHandler
|
||||||
|
else -> TODO("unsupported type: $primitiveType")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else -> kArrayHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Offset.intPlus() = irCall(kIntPlusDescriptor, null)
|
private fun Offset.intPlus() = irCall(kIntPlusDescriptor, null)
|
||||||
|
|||||||
Reference in New Issue
Block a user