Rename "lowerBound/upperBound" to "first/last" and move loopVariable to
ForLoopHeader base class. These terms are less loaded and less confusing, especially with "downTo" progressions, and once we start handling "reversed()".
This commit is contained in:
committed by
max-kammerer
parent
8e1be5424f
commit
93deff5e57
+4
-6
@@ -8,17 +8,17 @@ package org.jetbrains.kotlin.backend.common.lower.loops
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext
|
||||
import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder
|
||||
import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
|
||||
import org.jetbrains.kotlin.backend.common.lower.irIfThen
|
||||
import org.jetbrains.kotlin.backend.common.phaser.makeIrFilePhase
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.builders.irCallOp
|
||||
import org.jetbrains.kotlin.ir.builders.irGet
|
||||
import org.jetbrains.kotlin.ir.builders.irSetVar
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrVariable
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrCompositeImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.IrVariableSymbol
|
||||
import org.jetbrains.kotlin.ir.types.toKotlinType
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
@@ -178,9 +178,7 @@ private class RangeLoopTransformer(
|
||||
forLoopInfo.inductionVariable.type.toKotlinType(),
|
||||
forLoopInfo.step.type.toKotlinType()
|
||||
)
|
||||
if (forLoopInfo is ProgressionLoopHeader) {
|
||||
forLoopInfo.loopVariable = variable
|
||||
}
|
||||
forLoopInfo.loopVariable = variable
|
||||
return with(context.createIrBuilder(getScopeOwnerSymbol(), initializer.startOffset, initializer.endOffset)) {
|
||||
variable.initializer = forLoopInfo.initializeLoopVariable(symbols, this)
|
||||
val increment = irSetVar(
|
||||
|
||||
+9
-9
@@ -58,8 +58,8 @@ internal enum class ProgressionDirection { DECREASING, INCREASING, UNKNOWN }
|
||||
// Information about loop that is required by HeaderProcessor to build ForLoopHeader
|
||||
internal sealed class HeaderInfo(
|
||||
val progressionType: ProgressionType,
|
||||
val lowerBound: IrExpression,
|
||||
val upperBound: IrExpression,
|
||||
val first: IrExpression,
|
||||
val last: IrExpression,
|
||||
val step: IrExpression,
|
||||
val closed: Boolean
|
||||
) {
|
||||
@@ -78,22 +78,22 @@ internal sealed class HeaderInfo(
|
||||
|
||||
internal class ProgressionHeaderInfo(
|
||||
progressionType: ProgressionType,
|
||||
lowerBound: IrExpression,
|
||||
upperBound: IrExpression,
|
||||
first: IrExpression,
|
||||
last: IrExpression,
|
||||
step: IrExpression,
|
||||
closed: Boolean = true,
|
||||
val additionalNotEmptyCondition: IrExpression? = null
|
||||
) : HeaderInfo(progressionType, lowerBound, upperBound, step, closed)
|
||||
) : HeaderInfo(progressionType, first, last, step, closed)
|
||||
|
||||
internal class ArrayHeaderInfo(
|
||||
lowerBound: IrExpression,
|
||||
upperBound: IrExpression,
|
||||
first: IrExpression,
|
||||
last: IrExpression,
|
||||
step: IrExpression,
|
||||
val arrayVariable: IrVariable
|
||||
) : HeaderInfo(
|
||||
ProgressionType.INT_PROGRESSION,
|
||||
lowerBound,
|
||||
upperBound,
|
||||
first,
|
||||
last,
|
||||
step,
|
||||
closed = false
|
||||
)
|
||||
|
||||
+5
-5
@@ -32,7 +32,8 @@ internal sealed class ForLoopHeader(
|
||||
val last: IrVariable,
|
||||
val step: IrVariable,
|
||||
val progressionType: ProgressionType,
|
||||
val needsEmptinessCheck: Boolean
|
||||
val needsEmptinessCheck: Boolean,
|
||||
var loopVariable: IrVariable? = null
|
||||
) {
|
||||
abstract fun initializeLoopVariable(symbols: Symbols<CommonBackendContext>, builder: DeclarationIrBuilder): IrExpression
|
||||
|
||||
@@ -48,8 +49,7 @@ internal class ProgressionLoopHeader(
|
||||
inductionVariable: IrVariable,
|
||||
bound: IrVariable,
|
||||
last: IrVariable,
|
||||
step: IrVariable,
|
||||
var loopVariable: IrVariable? = null
|
||||
step: IrVariable
|
||||
) : ForLoopHeader(inductionVariable, bound, last, step, headerInfo.progressionType, needsEmptinessCheck = true) {
|
||||
|
||||
override fun initializeLoopVariable(symbols: Symbols<CommonBackendContext>, builder: DeclarationIrBuilder) = with(builder) {
|
||||
@@ -200,14 +200,14 @@ internal class HeaderProcessor(
|
||||
// Due to features of PSI2IR we can obtain nullable arguments here while actually
|
||||
// they are non-nullable (the frontend takes care about this). So we need to cast them to non-nullable.
|
||||
val inductionVariable = scope.createTemporaryVariable(
|
||||
lowerBound.castIfNecessary(progressionType),
|
||||
first.castIfNecessary(progressionType),
|
||||
nameHint = "inductionVariable",
|
||||
isMutable = true,
|
||||
origin = IrDeclarationOrigin.FOR_LOOP_IMPLICIT_VARIABLE
|
||||
)
|
||||
|
||||
val upperBoundTmpVariable = scope.createTemporaryVariable(
|
||||
ensureNotNullable(upperBound.castIfNecessary(progressionType)),
|
||||
ensureNotNullable(last.castIfNecessary(progressionType)),
|
||||
nameHint = "upperBound",
|
||||
origin = IrDeclarationOrigin.FOR_LOOP_IMPLICIT_VARIABLE
|
||||
)
|
||||
|
||||
+8
-8
@@ -38,8 +38,8 @@ internal class RangeToHandler(private val context: CommonBackendContext, private
|
||||
with(context.createIrBuilder(call.symbol, call.startOffset, call.endOffset)) {
|
||||
ProgressionHeaderInfo(
|
||||
data,
|
||||
lowerBound = call.dispatchReceiver!!,
|
||||
upperBound = call.getValueArgument(0)!!,
|
||||
first = call.dispatchReceiver!!,
|
||||
last = call.getValueArgument(0)!!,
|
||||
step = irInt(1)
|
||||
)
|
||||
}
|
||||
@@ -57,8 +57,8 @@ internal class DownToHandler(private val context: CommonBackendContext, private
|
||||
with(context.createIrBuilder(call.symbol, call.startOffset, call.endOffset)) {
|
||||
ProgressionHeaderInfo(
|
||||
data,
|
||||
lowerBound = call.extensionReceiver!!,
|
||||
upperBound = call.getValueArgument(0)!!,
|
||||
first = call.extensionReceiver!!,
|
||||
last = call.getValueArgument(0)!!,
|
||||
step = irInt(-1)
|
||||
)
|
||||
}
|
||||
@@ -98,8 +98,8 @@ internal class UntilHandler(private val context: CommonBackendContext, private v
|
||||
// TODO: Do not add additionalEmptinessCondition if "bound" is const and > MIN_VALUE
|
||||
ProgressionHeaderInfo(
|
||||
data,
|
||||
lowerBound = call.extensionReceiver!!,
|
||||
upperBound = call.getValueArgument(0)!!,
|
||||
first = call.extensionReceiver!!,
|
||||
last = call.getValueArgument(0)!!,
|
||||
step = irInt(1),
|
||||
closed = false,
|
||||
additionalNotEmptyCondition = buildMinValueConditionIfNecessary(data, call.getValueArgument(0)!!)
|
||||
@@ -194,8 +194,8 @@ internal class ArrayIterationHandler(val context: CommonBackendContext) : Header
|
||||
dispatchReceiver = irGet(arrayReference)
|
||||
}
|
||||
ArrayHeaderInfo(
|
||||
lowerBound = irInt(0),
|
||||
upperBound = upperBound,
|
||||
first = irInt(0),
|
||||
last = upperBound,
|
||||
step = irInt(1),
|
||||
arrayVariable = arrayReference
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user