[IR] Refactor ir infrastructure

- Remove range-based uniq id indexes using to link built ins
 - Limit KotlinType usages, replace them with corresponding IrType
This commit is contained in:
Roman Artemev
2019-10-28 10:50:15 +03:00
committed by romanart
parent 90d07eee53
commit a343a57207
22 changed files with 409 additions and 232 deletions
@@ -18,8 +18,8 @@ import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.copyTypeArgumentsFrom
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
import org.jetbrains.kotlin.ir.types.classifierOrFail
import org.jetbrains.kotlin.ir.types.getClass
import org.jetbrains.kotlin.ir.types.toKotlinType
import org.jetbrains.kotlin.ir.util.constructedClass
import org.jetbrains.kotlin.ir.util.constructors
import org.jetbrains.kotlin.ir.util.functions
@@ -78,7 +78,7 @@ class ArrayConstructorLowering(val context: CommonBackendContext) : IrElementTra
val invoke = invokable.type.getClass()!!.functions.single { it.name == OperatorNameConventions.INVOKE }
val invokableVar = if (lambda == null) irTemporary(invokable) else null
+irWhile().apply {
condition = irCall(context.irBuiltIns.lessFunByOperandType[index.type.toKotlinType()]!!).apply {
condition = irCall(context.irBuiltIns.lessFunByOperandType[index.type.classifierOrFail]!!).apply {
putValueArgument(0, irGet(index))
putValueArgument(1, irGet(sizeVar))
}
@@ -78,10 +78,10 @@ internal sealed class ForLoopHeader(
with(builder) {
val builtIns = context.irBuiltIns
val progressionType = headerInfo.progressionType
val progressionKotlinType = progressionType.elementType(builtIns).toKotlinType()
val progressionElementType = progressionType.elementType(builtIns)
val compFun =
if (isLastInclusive) builtIns.lessOrEqualFunByOperandType[progressionKotlinType]!!
else builtIns.lessFunByOperandType[progressionKotlinType]!!
if (isLastInclusive) builtIns.lessOrEqualFunByOperandType[progressionElementType.classifierOrFail]!!
else builtIns.lessFunByOperandType[progressionElementType.classifierOrFail]!!
// The default condition depends on the direction.
when (headerInfo.direction) {
@@ -101,11 +101,11 @@ internal sealed class ForLoopHeader(
// If the direction is unknown, we check depending on the "step" value:
// // (use `<` if last is exclusive)
// (step > 0 && inductionVar <= last) || (step < 0 || last <= inductionVar)
val stepKotlinType = progressionType.stepType(builtIns).toKotlinType()
val stepType = progressionType.stepType(builtIns)
val isLong = progressionType == ProgressionType.LONG_PROGRESSION
context.oror(
context.andand(
irCall(builtIns.greaterFunByOperandType[stepKotlinType]!!).apply {
irCall(builtIns.greaterFunByOperandType[stepType.classifierOrFail]!!).apply {
putValueArgument(0, irGet(step))
putValueArgument(1, if (isLong) irLong(0) else irInt(0))
},
@@ -114,7 +114,7 @@ internal sealed class ForLoopHeader(
putValueArgument(1, lastExpression)
}),
context.andand(
irCall(builtIns.lessFunByOperandType[stepKotlinType]!!).apply {
irCall(builtIns.lessFunByOperandType[stepType.classifierOrFail]!!).apply {
putValueArgument(0, irGet(step))
putValueArgument(1, if (isLong) irLong(0) else irInt(0))
},
@@ -257,7 +257,7 @@ internal class StepHandler(
//
// We insert this check in the lowered form only if necessary.
val stepType = data.stepType(context.irBuiltIns)
val stepGreaterFun = context.irBuiltIns.greaterFunByOperandType[stepType.toKotlinType()]!!
val stepGreaterFun = context.irBuiltIns.greaterFunByOperandType[stepType.classifierOrFail]!!
val zeroStep = if (data == ProgressionType.LONG_PROGRESSION) irLong(0) else irInt(0)
val throwIllegalStepExceptionCall = {
irCall(context.irBuiltIns.illegalArgumentExceptionSymbol).apply {