diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/ForLoopsLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/ForLoopsLowering.kt index 0a3f961688c..65d9b893bf6 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/ForLoopsLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/ForLoopsLowering.kt @@ -118,7 +118,7 @@ private class RangeLoopTransformer( ) : IrElementTransformerVoidWithContext() { private val symbols = context.ir.symbols - private val headerInfoBuilder = HeaderInfoBuilder(context, this::getScopeOwnerSymbol) + private val headerInfoBuilder = DefaultHeaderInfoBuilder(context, this::getScopeOwnerSymbol) private val headerProcessor = HeaderProcessor(context, headerInfoBuilder, this::getScopeOwnerSymbol) fun getScopeOwnerSymbol() = currentScope!!.scope.scopeOwnerSymbol diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/HeaderInfo.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/HeaderInfo.kt index d3642f61733..99c02af27c1 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/HeaderInfo.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/HeaderInfo.kt @@ -212,6 +212,13 @@ internal class WithIndexHeaderInfo(val nestedInfo: HeaderInfo) : HeaderInfo() { override fun asReversed(): HeaderInfo? = null } +/** + * Information about a for-loop over an Iterable or Sequence. + */ +internal class IterableHeaderInfo(val iteratorVariable: IrVariable) : HeaderInfo() { + override fun asReversed(): HeaderInfo? = null +} + /** Matches an iterable expression and builds a [HeaderInfo] from the expression. */ internal interface HeaderInfoHandler { /** Returns true if the handler can build a [HeaderInfo] from the iterable expression. */ @@ -249,7 +256,7 @@ internal interface HeaderInfoFromCallHandler : HeaderInfoHandler { internal typealias ProgressionHandler = HeaderInfoFromCallHandler -internal class HeaderInfoBuilder(context: CommonBackendContext, private val scopeOwnerSymbol: () -> IrSymbol) : +internal abstract class HeaderInfoBuilder(context: CommonBackendContext, private val scopeOwnerSymbol: () -> IrSymbol) : IrElementVisitor { private val symbols = context.ir.symbols @@ -272,19 +279,8 @@ internal class HeaderInfoBuilder(context: CommonBackendContext, private val scop StepHandler(context, this) ) - private val callHandlers = listOf( - ReversedHandler(context, this), - WithIndexHandler(context, this) - ) - - // NOTE: StringIterationHandler MUST come before CharSequenceIterationHandler. - // String is subtype of CharSequence and therefore its handler is more specialized. - private val expressionHandlers = listOf( - ArrayIterationHandler(context), - DefaultProgressionHandler(context), - StringIterationHandler(context), - CharSequenceIterationHandler(context) - ) + protected abstract val callHandlers: List> + protected abstract val expressionHandlers: List override fun visitElement(element: IrElement, data: IrCall?): HeaderInfo? = null @@ -309,4 +305,45 @@ internal class HeaderInfoBuilder(context: CommonBackendContext, private val scop return expressionHandlers.firstNotNullResult { it.handle(iterable, iteratorCall, null, scopeOwnerSymbol()) } ?: super.visitExpression(iterable, iteratorCall) } +} + +internal class DefaultHeaderInfoBuilder(context: CommonBackendContext, scopeOwnerSymbol: () -> IrSymbol) : + HeaderInfoBuilder(context, scopeOwnerSymbol) { + override val callHandlers = listOf( + ReversedHandler(context, this), + WithIndexHandler(context, NestedHeaderInfoBuilderForWithIndex(context, scopeOwnerSymbol)) + ) + + // NOTE: StringIterationHandler MUST come before CharSequenceIterationHandler. + // String is subtype of CharSequence and therefore its handler is more specialized. + override val expressionHandlers = listOf( + ArrayIterationHandler(context), + DefaultProgressionHandler(context), + StringIterationHandler(context), + CharSequenceIterationHandler(context) + ) +} + +// WithIndexHandler attempts to retrieve the HeaderInfo from the underlying index, using NestedHeaderInfoBuilderForWithIndex instead of +// DefaultHeaderInfoBuilder. The differences between the two are that NestedHeaderInfoBuilderForWithIndex: +// +// - Has NO WithIndexHandler. We do not attempt to optimize `*.withIndex().withIndex()`. +// - Has DefaultIterableHandler. This allows us to optimize `Iterable<*>.withIndex()` and `Sequence<*>.withIndex()`. +internal class NestedHeaderInfoBuilderForWithIndex(context: CommonBackendContext, scopeOwnerSymbol: () -> IrSymbol) : + HeaderInfoBuilder(context, scopeOwnerSymbol) { + // NOTE: No WithIndexHandler; we cannot lower `iterable.withIndex().withIndex()`. + override val callHandlers = listOf( + ReversedHandler(context, this) + ) + + // NOTE: StringIterationHandler MUST come before CharSequenceIterationHandler. + // String is subtype of CharSequence and therefore its handler is more specialized. + // DefaultIterableHandler must come last as it is handles iterables not handled by more specialized handlers. + override val expressionHandlers = listOf( + ArrayIterationHandler(context), + DefaultProgressionHandler(context), + StringIterationHandler(context), + CharSequenceIterationHandler(context), + DefaultIterableHandler(context) + ) } \ No newline at end of file diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/HeaderProcessor.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/HeaderProcessor.kt index e3a4d59334d..1d22053a8d1 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/HeaderProcessor.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/HeaderProcessor.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrDoWhileLoopImpl import org.jetbrains.kotlin.ir.expressions.impl.IrWhileLoopImpl import org.jetbrains.kotlin.ir.symbols.IrSymbol import org.jetbrains.kotlin.ir.types.* +import org.jetbrains.kotlin.ir.util.coerceToUnitIfNeeded import org.jetbrains.kotlin.ir.util.deepCopyWithSymbols import org.jetbrains.kotlin.ir.util.functions import org.jetbrains.kotlin.util.OperatorNameConventions @@ -348,7 +349,7 @@ internal class IndexedGetLoopHeader( } internal class WithIndexLoopHeader( - private val headerInfo: WithIndexHeaderInfo, + headerInfo: WithIndexHeaderInfo, builder: DeclarationIrBuilder ) : ForLoopHeader { @@ -361,8 +362,9 @@ internal class WithIndexLoopHeader( // To build the optimized/lowered `for` loop over a `withIndex()` call, we first need the header for the underlying iterable so // so that we know how to build the loop for that iterable. More info in comments in initializeIteration(). nestedLoopHeader = when (val nestedInfo = headerInfo.nestedInfo) { - is IndexedGetHeaderInfo -> IndexedGetLoopHeader(nestedInfo, builder) - is ProgressionHeaderInfo -> ProgressionLoopHeader(nestedInfo, builder) + is IndexedGetHeaderInfo -> IndexedGetLoopHeader(nestedInfo, this@with) + is ProgressionHeaderInfo -> ProgressionLoopHeader(nestedInfo, this@with) + is IterableHeaderInfo -> IterableLoopHeader(nestedInfo) is WithIndexHeaderInfo -> throw IllegalStateException("Nested WithIndexHeaderInfo not allowed for WithIndexLoopHeader") } @@ -424,9 +426,9 @@ internal class WithIndexLoopHeader( // val step = 2 // if (inductionVar <= last) { // do { - // val v = inductionVar - // inductionVar += step - // // Loop body + // val v = inductionVar + // inductionVar += step + // // Loop body // } while (inductionVar <= last) // } // @@ -438,14 +440,30 @@ internal class WithIndexLoopHeader( // var index = 0 // ADDED // if (inductionVar <= last) { // do { - // val i = index // ADDED - // val v = inductionVar - // inductionVar += step - // // Loop body - // checkIndexOverflow(index++) // ADDED + // val i = index // ADDED + // val v = inductionVar + // inductionVar += step + // // Loop body + // checkIndexOverflow(index++) // ADDED // } while (inductionVar <= last) // } // + // As another example, in a for-loop over a call to `Iterable<*>.withIndex()` or `Sequence<*>.withIndex()`, e.g.: + // + // for ((i, v) in listOf(2, 3, 5, 7, 11).withIndex()) { /* Loop body */ } + // + // For-loops over an Iterable are normally not optimized, but when getting the underlying iterable for `withIndex()` (and ONLY + // in this case), we use DefaultIterableHandler to match it and IterableLoopHeader to build the underlying loop. The optimized + // loop with `withIndex()` looks something like this: + // + // val iterator = listOf(2, 3, 5, 7, 11).iterator() + // var index = 0 + // while (it.hasNext()) + // val i = index + // val v = it.next() + // checkIndexOverflow(index++) + // } + // // We "wire" the 1st destructured component to index, and the 2nd to the loop variable value from the underlying iterable. loopVariableComponents[1]?.initializer = irGet(indexVariable) listOfNotNull(loopVariableComponents[1]) + nestedLoopHeader.initializeIteration( @@ -482,6 +500,53 @@ internal class WithIndexLoopHeader( } } +internal class IterableLoopHeader( + private val headerInfo: IterableHeaderInfo +) : ForLoopHeader { + override val loopInitStatements = listOf(headerInfo.iteratorVariable) + + override val consumesLoopVariableComponents = false + + override fun initializeIteration( + loopVariable: IrVariable?, + loopVariableComponents: Map, + symbols: Symbols, + builder: DeclarationIrBuilder + ) = + with(builder) { + // loopVariable = iteratorVar.next() + val iteratorClass = headerInfo.iteratorVariable.type.getClass()!! + val next = + irCall(iteratorClass.functions.first { it.name == OperatorNameConventions.NEXT && it.valueParameters.isEmpty() }).apply { + dispatchReceiver = irGet(headerInfo.iteratorVariable) + } + loopVariable?.initializer = next + // Even if there is no loop variable, we always want to call `next()` for iterables and sequences. + listOf(loopVariable ?: next.coerceToUnitIfNeeded(next.type, context.irBuiltIns)) + } + + override fun buildLoop(builder: DeclarationIrBuilder, oldLoop: IrLoop, newBody: IrExpression?): LoopReplacement = with(builder) { + // Loop is lowered into something like: + // + // var iteratorVar = someIterable.iterator() + // while (iteratorVar.hasNext()) { + // val loopVar = iteratorVar.next() + // // Loop body + // } + val iteratorClass = headerInfo.iteratorVariable.type.getClass()!! + val hasNext = + irCall(iteratorClass.functions.first { it.name == OperatorNameConventions.HAS_NEXT && it.valueParameters.isEmpty() }).apply { + dispatchReceiver = irGet(headerInfo.iteratorVariable) + } + val newLoop = IrWhileLoopImpl(oldLoop.startOffset, oldLoop.endOffset, oldLoop.type, oldLoop.origin).apply { + label = oldLoop.label + condition = hasNext + body = newBody + } + LoopReplacement(newLoop, newLoop) + } +} + /** * Given the for-loop iterator variable, extract information about the iterable subject * and create a [ForLoopHeader] from it. @@ -529,6 +594,7 @@ internal class HeaderProcessor( is IndexedGetHeaderInfo -> IndexedGetLoopHeader(headerInfo, builder) is ProgressionHeaderInfo -> ProgressionLoopHeader(headerInfo, builder) is WithIndexHeaderInfo -> WithIndexLoopHeader(headerInfo, builder) + is IterableHeaderInfo -> IterableLoopHeader(headerInfo) } } } diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/ProgressionHandlers.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/ProgressionHandlers.kt index 917e7462315..5b58759e794 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/ProgressionHandlers.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/ProgressionHandlers.kt @@ -697,14 +697,14 @@ internal class StringIterationHandler(context: CommonBackendContext) : CharSeque } /** Builds a [HeaderInfo] for calls to `withIndex()`. */ -internal class WithIndexHandler(context: CommonBackendContext, private val visitor: HeaderInfoBuilder) : +internal class WithIndexHandler(context: CommonBackendContext, private val visitor: NestedHeaderInfoBuilderForWithIndex) : HeaderInfoFromCallHandler { // Use Quantifier.ANY so we can handle all `withIndex()` calls in the same manner. override val matcher = createIrCallMatcher(Quantifier.ANY) { callee { fqName { it == FqName("kotlin.collections.withIndex") } - extensionReceiver { it != null && it.type.run { isArray() || isPrimitiveArray() } } + extensionReceiver { it != null && it.type.run { isArray() || isPrimitiveArray() || isIterable() } } parameterCount { it == 0 } } callee { @@ -712,8 +712,11 @@ internal class WithIndexHandler(context: CommonBackendContext, private val visit extensionReceiver { it != null && it.type.isSubtypeOfClass(context.ir.symbols.charSequence) } parameterCount { it == 0 } } - - // TODO: Handle Iterable.withIndex(), Sequence.withIndex() + callee { + fqName { it == FqName("kotlin.sequences.withIndex") } + extensionReceiver { it != null && it.type.run { isSequence() } } + parameterCount { it == 0 } + } } override fun build(expression: IrCall, data: Nothing?, scopeOwner: IrSymbol): HeaderInfo? { @@ -721,8 +724,30 @@ internal class WithIndexHandler(context: CommonBackendContext, private val visit val nestedInfo = expression.extensionReceiver!!.accept(visitor, null) ?: return null // We cannot lower `iterable.withIndex().withIndex()`. - if (nestedInfo is WithIndexHeaderInfo) return null + // NestedHeaderInfoBuilderForWithIndex should not be yielding a WithIndexHeaderInfo, hence the assert. + assert(nestedInfo !is WithIndexHeaderInfo) return WithIndexHeaderInfo(nestedInfo) } } + +/** Builds a [HeaderInfo] for iterables not handled by more specialized handlers. */ +internal class DefaultIterableHandler(private val context: CommonBackendContext) : ExpressionHandler { + + override fun matchIterable(expression: IrExpression) = true + + override fun build(expression: IrExpression, scopeOwner: IrSymbol): HeaderInfo? = + with(context.createIrBuilder(scopeOwner, expression.startOffset, expression.endOffset)) { + val iterableClass = expression.type.getClass()!! + val iterator = + irCall(iterableClass.functions.single { + it.name == OperatorNameConventions.ITERATOR && + it.valueParameters.isEmpty() + }).apply { + dispatchReceiver = expression + } + IterableHeaderInfo( + scope.createTemporaryVariable(iterator, nameHint = "iterator") + ) + } +} diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/irTypePredicates.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/irTypePredicates.kt index 230342b7483..00570a69576 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/irTypePredicates.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/irTypePredicates.kt @@ -73,6 +73,8 @@ fun IrType.isNumber(): Boolean = isNotNullClassType(KotlinBuiltIns.FQ_NAMES.numb fun IrType.isComparable(): Boolean = isNotNullClassType(KotlinBuiltIns.FQ_NAMES.comparable.toUnsafe()) fun IrType.isCharSequence(): Boolean = isNotNullClassType(KotlinBuiltIns.FQ_NAMES.charSequence) +fun IrType.isIterable(): Boolean = isNotNullClassType(KotlinBuiltIns.FQ_NAMES.iterable.toUnsafe()) +fun IrType.isSequence(): Boolean = isNotNullClassType(FqNameUnsafe("kotlin.sequences.Sequence")) fun IrType.isBooleanArray(): Boolean = isNotNullClassType(FqNameUnsafe("kotlin.BooleanArray")) fun IrType.isCharArray(): Boolean = isNotNullClassType(FqNameUnsafe("kotlin.CharArray")) diff --git a/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInDownToWithIndex.kt b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInDownToWithIndex.kt new file mode 100644 index 00000000000..34502bbccf3 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInDownToWithIndex.kt @@ -0,0 +1,18 @@ +// IGNORE_BACKEND_FIR: JVM_IR +// KJS_WITH_FULL_RUNTIME +// WITH_RUNTIME + +import kotlin.test.assertEquals + +fun box(): String { + val indexList = mutableListOf() + val valueList = mutableListOf() + for ((i, v) in (7 downTo 4).withIndex()) { + indexList += i + valueList += v + } + assertEquals(listOf(0, 1, 2, 3), indexList) + assertEquals(listOf(7, 6, 5, 4), valueList) + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInIndicesWithIndex.kt b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInIndicesWithIndex.kt new file mode 100644 index 00000000000..4dc3b140e83 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInIndicesWithIndex.kt @@ -0,0 +1,18 @@ +// IGNORE_BACKEND_FIR: JVM_IR +// KJS_WITH_FULL_RUNTIME +// WITH_RUNTIME + +import kotlin.test.assertEquals + +fun box(): String { + val indexList = mutableListOf() + val valueList = mutableListOf() + for ((i, v) in listOf(4, 5, 6, 7).indices.withIndex()) { + indexList += i + valueList += v + } + assertEquals(listOf(0, 1, 2, 3), indexList) + assertEquals(listOf(0, 1, 2, 3), valueList) + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInRangeToWithIndex.kt b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInRangeToWithIndex.kt new file mode 100644 index 00000000000..c5d38f4a980 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInRangeToWithIndex.kt @@ -0,0 +1,18 @@ +// IGNORE_BACKEND_FIR: JVM_IR +// KJS_WITH_FULL_RUNTIME +// WITH_RUNTIME + +import kotlin.test.assertEquals + +fun box(): String { + val indexList = mutableListOf() + val valueList = mutableListOf() + for ((i, v) in (4..7).withIndex()) { + indexList += i + valueList += v + } + assertEquals(listOf(0, 1, 2, 3), indexList) + assertEquals(listOf(4, 5, 6, 7), valueList) + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInReversedStepWithIndex.kt b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInReversedStepWithIndex.kt new file mode 100644 index 00000000000..34813c553f2 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInReversedStepWithIndex.kt @@ -0,0 +1,18 @@ +// IGNORE_BACKEND_FIR: JVM_IR +// KJS_WITH_FULL_RUNTIME +// WITH_RUNTIME + +import kotlin.test.assertEquals + +fun box(): String { + val indexList = mutableListOf() + val valueList = mutableListOf() + for ((i, v) in ((4..11).reversed() step 2).withIndex()) { + indexList += i + valueList += v + } + assertEquals(listOf(0, 1, 2, 3), indexList) + assertEquals(listOf(11, 9, 7, 5), valueList) + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInReversedWithIndex.kt b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInReversedWithIndex.kt new file mode 100644 index 00000000000..a2957d5c8b7 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInReversedWithIndex.kt @@ -0,0 +1,18 @@ +// IGNORE_BACKEND_FIR: JVM_IR +// KJS_WITH_FULL_RUNTIME +// WITH_RUNTIME + +import kotlin.test.assertEquals + +fun box(): String { + val indexList = mutableListOf() + val valueList = mutableListOf() + for ((i, v) in (4..7).reversed().withIndex()) { + indexList += i + valueList += v + } + assertEquals(listOf(0, 1, 2, 3), indexList) + assertEquals(listOf(7, 6, 5, 4), valueList) + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInStepReversedWithIndex.kt b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInStepReversedWithIndex.kt new file mode 100644 index 00000000000..182d7c68ca5 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInStepReversedWithIndex.kt @@ -0,0 +1,18 @@ +// IGNORE_BACKEND_FIR: JVM_IR +// KJS_WITH_FULL_RUNTIME +// WITH_RUNTIME + +import kotlin.test.assertEquals + +fun box(): String { + val indexList = mutableListOf() + val valueList = mutableListOf() + for ((i, v) in (4..11 step 2).reversed().withIndex()) { + indexList += i + valueList += v + } + assertEquals(listOf(0, 1, 2, 3), indexList) + assertEquals(listOf(10, 8, 6, 4), valueList) + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInStepWithIndex.kt b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInStepWithIndex.kt new file mode 100644 index 00000000000..dc94f1c617d --- /dev/null +++ b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInStepWithIndex.kt @@ -0,0 +1,18 @@ +// IGNORE_BACKEND_FIR: JVM_IR +// KJS_WITH_FULL_RUNTIME +// WITH_RUNTIME + +import kotlin.test.assertEquals + +fun box(): String { + val indexList = mutableListOf() + val valueList = mutableListOf() + for ((i, v) in (4..11 step 2).withIndex()) { + indexList += i + valueList += v + } + assertEquals(listOf(0, 1, 2, 3), indexList) + assertEquals(listOf(4, 6, 8, 10), valueList) + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInUntilWithIndex.kt b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInUntilWithIndex.kt new file mode 100644 index 00000000000..15872a92fa2 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInUntilWithIndex.kt @@ -0,0 +1,18 @@ +// IGNORE_BACKEND_FIR: JVM_IR +// KJS_WITH_FULL_RUNTIME +// WITH_RUNTIME + +import kotlin.test.assertEquals + +fun box(): String { + val indexList = mutableListOf() + val valueList = mutableListOf() + for ((i, v) in (4 until 8).withIndex()) { + indexList += i + valueList += v + } + assertEquals(listOf(0, 1, 2, 3), indexList) + assertEquals(listOf(4, 5, 6, 7), valueList) + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexNoIndexOrElementVar.kt b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexNoIndexOrElementVar.kt new file mode 100644 index 00000000000..807059ba260 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexNoIndexOrElementVar.kt @@ -0,0 +1,15 @@ +// IGNORE_BACKEND_FIR: JVM_IR +// KJS_WITH_FULL_RUNTIME +// WITH_RUNTIME + +import kotlin.test.assertEquals + +fun box(): String { + var count = 0 + for ((_, _) in (4..7).withIndex()) { + count++ + } + assertEquals(4, count) + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexNotDestructured.kt b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexNotDestructured.kt new file mode 100644 index 00000000000..33f4568227d --- /dev/null +++ b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexNotDestructured.kt @@ -0,0 +1,19 @@ +// IGNORE_BACKEND_FIR: JVM_IR +// KJS_WITH_FULL_RUNTIME +// WITH_RUNTIME + +import kotlin.test.assertEquals + +fun box(): String { + val indexList = mutableListOf() + val valueList = mutableListOf() + for (iv in (4..7).withIndex()) { + val (i, v) = iv + indexList += i + valueList += v + } + assertEquals(listOf(0, 1, 2, 3), indexList) + assertEquals(listOf(4, 5, 6, 7), valueList) + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexReversed.kt b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexReversed.kt new file mode 100644 index 00000000000..225825666b3 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexReversed.kt @@ -0,0 +1,18 @@ +// IGNORE_BACKEND_FIR: JVM_IR +// KJS_WITH_FULL_RUNTIME +// WITH_RUNTIME + +import kotlin.test.assertEquals + +fun box(): String { + val indexList = mutableListOf() + val valueList = mutableListOf() + for ((i, v) in (4..7).withIndex().reversed()) { + indexList += i + valueList += v + } + assertEquals(listOf(3, 2, 1, 0), indexList) + assertEquals(listOf(7, 6, 5, 4), valueList) + + return "OK" +} diff --git a/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithDestructuringInLoop.kt b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithDestructuringInLoop.kt new file mode 100644 index 00000000000..e4f3d6687a5 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithDestructuringInLoop.kt @@ -0,0 +1,23 @@ +// IGNORE_BACKEND_FIR: JVM_IR +// KJS_WITH_FULL_RUNTIME +// WITH_RUNTIME + +import kotlin.test.assertEquals + +fun box(): String { + val indexList = mutableListOf() + val valueList = mutableListOf() + val valueAndIndexList = mutableListOf() + for ((i, v) in (4..7).withIndex()) { + val (v2, i2) = Pair(v, i) + indexList += i + valueList += v + valueAndIndexList += v2 + valueAndIndexList += i2 + } + assertEquals(listOf(0, 1, 2, 3), indexList) + assertEquals(listOf(4, 5, 6, 7), valueList) + assertEquals(listOf(4, 0, 5, 1, 6, 2, 7, 3), valueAndIndexList) + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithIndex.kt b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithIndex.kt new file mode 100644 index 00000000000..f9795a081a7 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithIndex.kt @@ -0,0 +1,22 @@ +// IGNORE_BACKEND_FIR: JVM_IR +// KJS_WITH_FULL_RUNTIME +// WITH_RUNTIME + +import kotlin.test.assertEquals + +fun box(): String { + val outerIndexList = mutableListOf() + val innerIndexList = mutableListOf() + val valueList = mutableListOf() + for ((outer, iv) in (4..7).withIndex().withIndex()) { + outerIndexList += outer + val (inner, v) = iv + innerIndexList += inner + valueList += v + } + assertEquals(listOf(0, 1, 2, 3), outerIndexList) + assertEquals(listOf(0, 1, 2, 3), innerIndexList) + assertEquals(listOf(4, 5, 6, 7), valueList) + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInEmptyListWithIndex.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInEmptyListWithIndex.kt index f9603af5287..11e1e90e934 100644 --- a/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInEmptyListWithIndex.kt +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInEmptyListWithIndex.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR val xs = listOf() fun box(): String { @@ -15,3 +14,6 @@ fun box(): String { // 1 next // 0 component1 // 0 component2 + +// The 1st ICONST_0 is for initializing the list. 2nd is for initializing the index in the lowered for-loop. +// 2 ICONST_0 diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndex.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndex.kt index 03a6c9d13cb..ca24aea5f50 100644 --- a/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndex.kt +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndex.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR val xs = listOf("a", "b", "c", "d") fun box(): String { @@ -18,3 +17,6 @@ fun box(): String { // 1 next // 0 component1 // 0 component2 + +// The 1st ICONST_0 is for initializing the list. 2nd is for initializing the index in the lowered for-loop. +// 2 ICONST_0 diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndexNoElementVar.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndexNoElementVar.kt index 804d1b6f85b..bf45c85dd48 100644 --- a/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndexNoElementVar.kt +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndexNoElementVar.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR val xs = listOf("a", "b", "c", "d") fun box(): String { @@ -18,3 +17,6 @@ fun box(): String { // 1 next // 0 component1 // 0 component2 + +// The 1st ICONST_0 is for initializing the list. 2nd is for initializing the index in the lowered for-loop. +// 2 ICONST_0 diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndexNoIndexVar.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndexNoIndexVar.kt index 1bd1b8b3479..65973a4eb44 100644 --- a/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndexNoIndexVar.kt +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndexNoIndexVar.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR val xs = listOf("a", "b", "c", "d") fun box(): String { @@ -18,3 +17,6 @@ fun box(): String { // 1 next // 0 component1 // 0 component2 + +// The 1st ICONST_0 is for initializing the list. 2nd is for initializing the index in the lowered for-loop. +// 2 ICONST_0 diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndexWithExplicitlyTypedIndexVariable.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndexWithExplicitlyTypedIndexVariable.kt index 9c573baebf1..bf105d25ccd 100644 --- a/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndexWithExplicitlyTypedIndexVariable.kt +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndexWithExplicitlyTypedIndexVariable.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR val xs = listOf("a", "b", "c", "d") fun useAny(x: Any) {} @@ -21,3 +20,6 @@ fun box(): String { // 1 next // 0 component1 // 0 component2 + +// The 1st ICONST_0 is for initializing the list. 2nd is for initializing the index in the lowered for-loop. +// 2 ICONST_0 diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInDownToWithIndex.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInDownToWithIndex.kt new file mode 100644 index 00000000000..f6f3f0117bf --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInDownToWithIndex.kt @@ -0,0 +1,28 @@ +fun box(): String { + for ((i, v) in (7 downTo 4).withIndex()) { + } + + return "OK" +} + +// 0 withIndex +// 0 component1 +// 0 component2 + +// The ICONST_0 is for initializing the index in the lowered for-loop. +// 1 ICONST_0 + +// JVM_TEMPLATES +// 1 iterator +// 1 hasNext +// 1 next + +// JVM_IR_TEMPLATES +// 0 iterator +// 0 hasNext +// 0 next +// 0 getStart +// 0 getEnd +// 0 getFirst +// 0 getLast +// 0 getStep diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInIndicesWithIndex.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInIndicesWithIndex.kt new file mode 100644 index 00000000000..a1317973b8c --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInIndicesWithIndex.kt @@ -0,0 +1,29 @@ +fun box(): String { + for ((i, v) in listOf(4, 5, 6, 7).indices.withIndex()) { + } + + return "OK" +} + +// 0 withIndex +// 0 component1 +// 0 component2 + +// The 1st ICONST_0 is for initializing the list. 2nd is for initializing the index in the lowered for-loop. +// 2 ICONST_0 + +// JVM_TEMPLATES +// 1 iterator +// 1 hasNext +// 1 next + +// JVM_IR_TEMPLATES +// 0 iterator +// 0 hasNext +// 0 next +// 0 getStart +// 0 getEnd +// 0 getFirst +// 0 getLast +// 0 getStep +// 0 getIndices diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInRangeToWithIndex.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInRangeToWithIndex.kt new file mode 100644 index 00000000000..1ecf9393c31 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInRangeToWithIndex.kt @@ -0,0 +1,28 @@ +fun box(): String { + for ((i, v) in (4..7).withIndex()) { + } + + return "OK" +} + +// 0 withIndex +// 0 component1 +// 0 component2 + +// The ICONST_0 is for initializing the index in the lowered for-loop. +// 1 ICONST_0 + +// JVM_TEMPLATES +// 1 iterator +// 1 hasNext +// 1 next + +// JVM_IR_TEMPLATES +// 0 iterator +// 0 hasNext +// 0 next +// 0 getStart +// 0 getEnd +// 0 getFirst +// 0 getLast +// 0 getStep diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInReversedStepWithIndex.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInReversedStepWithIndex.kt new file mode 100644 index 00000000000..fe9d6410905 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInReversedStepWithIndex.kt @@ -0,0 +1,30 @@ +fun box(): String { + for ((i, v) in ((4..11).reversed() step 2).withIndex()) { + } + + return "OK" +} + +// 0 withIndex +// 0 component1 +// 0 component2 + +// The ICONST_0 is for initializing the index in the lowered for-loop. +// 1 ICONST_0 + +// JVM_TEMPLATES +// 1 iterator +// 1 hasNext +// 1 next + +// JVM_IR_TEMPLATES +// 0 iterator +// 0 hasNext +// 0 next +// 0 getStart +// 0 getEnd +// 0 getFirst +// 0 getLast +// 0 getStep +// 0 reversed +// 0 step diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInReversedWithIndex.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInReversedWithIndex.kt new file mode 100644 index 00000000000..bb91ad6b49a --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInReversedWithIndex.kt @@ -0,0 +1,29 @@ +fun box(): String { + for ((i, v) in (4..7).reversed().withIndex()) { + } + + return "OK" +} + +// 0 withIndex +// 0 component1 +// 0 component2 + +// The ICONST_0 is for initializing the index in the lowered for-loop. +// 1 ICONST_0 + +// JVM_TEMPLATES +// 1 iterator +// 1 hasNext +// 1 next + +// JVM_IR_TEMPLATES +// 0 iterator +// 0 hasNext +// 0 next +// 0 getStart +// 0 getEnd +// 0 getFirst +// 0 getLast +// 0 getStep +// 0 reversed diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInStepReversedWithIndex.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInStepReversedWithIndex.kt new file mode 100644 index 00000000000..d4de60ca43c --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInStepReversedWithIndex.kt @@ -0,0 +1,30 @@ +fun box(): String { + for ((i, v) in (4..11 step 2).reversed().withIndex()) { + } + + return "OK" +} + +// 0 withIndex +// 0 component1 +// 0 component2 + +// The ICONST_0 is for initializing the index in the lowered for-loop. +// 1 ICONST_0 + +// JVM_TEMPLATES +// 1 iterator +// 1 hasNext +// 1 next + +// JVM_IR_TEMPLATES +// 0 iterator +// 0 hasNext +// 0 next +// 0 getStart +// 0 getEnd +// 0 getFirst +// 0 getLast +// 0 getStep +// 0 reversed +// 0 step diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInStepWithIndex.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInStepWithIndex.kt new file mode 100644 index 00000000000..64675641f7c --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInStepWithIndex.kt @@ -0,0 +1,29 @@ +fun box(): String { + for ((i, v) in (4..11 step 2).withIndex()) { + } + + return "OK" +} + +// 0 withIndex +// 0 component1 +// 0 component2 + +// The ICONST_0 is for initializing the index in the lowered for-loop. +// 1 ICONST_0 + +// JVM_TEMPLATES +// 1 iterator +// 1 hasNext +// 1 next + +// JVM_IR_TEMPLATES +// 0 iterator +// 0 hasNext +// 0 next +// 0 getStart +// 0 getEnd +// 0 getFirst +// 0 getLast +// 0 getStep +// 0 step diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInUntilWithIndex.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInUntilWithIndex.kt new file mode 100644 index 00000000000..95424d6035f --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInUntilWithIndex.kt @@ -0,0 +1,28 @@ +fun box(): String { + for ((i, v) in (4 until 8).withIndex()) { + } + + return "OK" +} + +// 0 withIndex +// 0 component1 +// 0 component2 + +// The ICONST_0 is for initializing the index in the lowered for-loop. +// 1 ICONST_0 + +// JVM_TEMPLATES +// 1 iterator +// 1 hasNext +// 1 next + +// JVM_IR_TEMPLATES +// 0 iterator +// 0 hasNext +// 0 next +// 0 getStart +// 0 getEnd +// 0 getFirst +// 0 getLast +// 0 getStep diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInWithIndexNoIndexOrElementVar.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInWithIndexNoIndexOrElementVar.kt new file mode 100644 index 00000000000..7b02976222b --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInWithIndexNoIndexOrElementVar.kt @@ -0,0 +1,28 @@ +fun box(): String { + for ((_, _) in (4..7).withIndex()) { + } + + return "OK" +} + +// 0 withIndex +// 0 component1 +// 0 component2 + +// The ICONST_0 is for initializing the index in the lowered for-loop. +// 1 ICONST_0 + +// JVM_TEMPLATES +// 1 iterator +// 1 hasNext +// 1 next + +// JVM_IR_TEMPLATES +// 0 iterator +// 0 hasNext +// 0 next +// 0 getStart +// 0 getEnd +// 0 getFirst +// 0 getLast +// 0 getStep diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInWithIndexNotDestructured.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInWithIndexNotDestructured.kt new file mode 100644 index 00000000000..155aa7c1c76 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInWithIndexNotDestructured.kt @@ -0,0 +1,15 @@ +fun box(): String { + for (iv in (4..7).withIndex()) { + } + + return "OK" +} + +// We do not optimize `withIndex()` if the loop variable is not destructured + +// 1 withIndex +// 1 iterator +// 1 hasNext +// 1 next +// 0 component1 +// 0 component2 diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInWithIndexReversed.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInWithIndexReversed.kt new file mode 100644 index 00000000000..745022b3872 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInWithIndexReversed.kt @@ -0,0 +1,16 @@ +fun box(): String { + for ((i, v) in (4..7).withIndex().reversed()) { + } + + return "OK" +} + +// We do not optimize `withIndex().reversed()` + +// 1 withIndex +// 1 iterator +// 1 hasNext +// 1 next +// 1 component1 +// 1 component2 +// 1 reversed diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInWithIndexWithIndex.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInWithIndexWithIndex.kt new file mode 100644 index 00000000000..5ea2c2ff2f9 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInWithIndexWithIndex.kt @@ -0,0 +1,18 @@ +fun box(): String { + for ((outer, iv) in (4..7).withIndex().withIndex()) { + } + + return "OK" +} + +// We optimize the outer `withIndex()` and treat the inner one as an Iterable + +// 1 withIndex +// 1 iterator +// 1 hasNext +// 1 next +// 0 component1 +// 0 component2 + +// The ICONST_0 is for initializing the index in the lowered for-loop. +// 1 ICONST_0 diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInEmptySequenceWithIndex.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInEmptySequenceWithIndex.kt index 1014031aabf..85dfef60a20 100644 --- a/compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInEmptySequenceWithIndex.kt +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInEmptySequenceWithIndex.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR val xs = listOf().asSequence() fun box(): String { @@ -15,3 +14,6 @@ fun box(): String { // 1 next // 0 component1 // 0 component2 + +// The 1st ICONST_0 is for initializing the list. 2nd is for initializing the index in the lowered for-loop. +// 2 ICONST_0 diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndex.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndex.kt index 032b511752f..8265acf47dd 100644 --- a/compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndex.kt +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndex.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR val xs = listOf("a", "b", "c", "d").asSequence() fun box(): String { @@ -18,3 +17,6 @@ fun box(): String { // 1 next // 0 component1 // 0 component2 + +// The 1st ICONST_0 is for initializing the list. 2nd is for initializing the index in the lowered for-loop. +// 2 ICONST_0 diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndexNoElementVar.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndexNoElementVar.kt index f0bcabefd49..1b4816399d1 100644 --- a/compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndexNoElementVar.kt +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndexNoElementVar.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR val xs = listOf("a", "b", "c", "d").asSequence() fun box(): String { @@ -18,3 +17,6 @@ fun box(): String { // 1 next // 0 component1 // 0 component2 + +// The 1st ICONST_0 is for initializing the list. 2nd is for initializing the index in the lowered for-loop. +// 2 ICONST_0 diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndexNoIndexVar.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndexNoIndexVar.kt index 2afae594a5e..6a36dcd46d6 100644 --- a/compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndexNoIndexVar.kt +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndexNoIndexVar.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR val xs = listOf("a", "b", "c", "d").asSequence() fun box(): String { @@ -18,3 +17,6 @@ fun box(): String { // 1 next // 0 component1 // 0 component2 + +// The 1st ICONST_0 is for initializing the list. 2nd is for initializing the index in the lowered for-loop. +// 2 ICONST_0 diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndexThrowsCME.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndexThrowsCME.kt index 7acb6c7c52d..85e19c93ceb 100644 --- a/compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndexThrowsCME.kt +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndexThrowsCME.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // FULL_JDK val xsl = arrayListOf("a", "b", "c", "d") @@ -29,3 +28,6 @@ fun box(): String { // 1 next // 0 component1 // 0 component2 + +// The 1st ICONST_0 is for initializing the list. 2nd is for cmeThrown. 3rd is for initializing the index in the lowered for-loop. +// 3 ICONST_0 diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndexWithExplicitlyTypedIndexVariable.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndexWithExplicitlyTypedIndexVariable.kt index c3e5662f693..bcaf1e3b5af 100644 --- a/compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndexWithExplicitlyTypedIndexVariable.kt +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndexWithExplicitlyTypedIndexVariable.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR val xs = listOf("a", "b", "c", "d").asSequence() fun useAny(x: Any) {} @@ -21,3 +20,6 @@ fun box(): String { // 1 next // 0 component1 // 0 component2 + +// The 1st ICONST_0 is for initializing the list. 2nd is for initializing the index in the lowered for-loop. +// 2 ICONST_0 diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 04246915cce..9af860a2c72 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -20265,6 +20265,84 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { } } + @TestMetadata("compiler/testData/codegen/box/ranges/forInProgressionWithIndex") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ForInProgressionWithIndex extends AbstractBlackBoxCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + public void testAllFilesPresentInForInProgressionWithIndex() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/ranges/forInProgressionWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("forInDownToWithIndex.kt") + public void testForInDownToWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInDownToWithIndex.kt"); + } + + @TestMetadata("forInIndicesWithIndex.kt") + public void testForInIndicesWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInIndicesWithIndex.kt"); + } + + @TestMetadata("forInRangeToWithIndex.kt") + public void testForInRangeToWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInRangeToWithIndex.kt"); + } + + @TestMetadata("forInReversedStepWithIndex.kt") + public void testForInReversedStepWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInReversedStepWithIndex.kt"); + } + + @TestMetadata("forInReversedWithIndex.kt") + public void testForInReversedWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInReversedWithIndex.kt"); + } + + @TestMetadata("forInStepReversedWithIndex.kt") + public void testForInStepReversedWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInStepReversedWithIndex.kt"); + } + + @TestMetadata("forInStepWithIndex.kt") + public void testForInStepWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInStepWithIndex.kt"); + } + + @TestMetadata("forInUntilWithIndex.kt") + public void testForInUntilWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInUntilWithIndex.kt"); + } + + @TestMetadata("forInWithIndexNoIndexOrElementVar.kt") + public void testForInWithIndexNoIndexOrElementVar() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexNoIndexOrElementVar.kt"); + } + + @TestMetadata("forInWithIndexNotDestructured.kt") + public void testForInWithIndexNotDestructured() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexNotDestructured.kt"); + } + + @TestMetadata("forInWithIndexReversed.kt") + public void testForInWithIndexReversed() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexReversed.kt"); + } + + @TestMetadata("forInWithIndexWithDestructuringInLoop.kt") + public void testForInWithIndexWithDestructuringInLoop() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithDestructuringInLoop.kt"); + } + + @TestMetadata("forInWithIndexWithIndex.kt") + public void testForInWithIndexWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithIndex.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/ranges/forInReversed") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index d616b69fcd3..16b31b9e893 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -2007,6 +2007,79 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { } } + @TestMetadata("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ForInProgressionWithIndex extends AbstractBytecodeTextTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + public void testAllFilesPresentInForInProgressionWithIndex() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("forInDownToWithIndex.kt") + public void testForInDownToWithIndex() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInDownToWithIndex.kt"); + } + + @TestMetadata("forInIndicesWithIndex.kt") + public void testForInIndicesWithIndex() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInIndicesWithIndex.kt"); + } + + @TestMetadata("forInRangeToWithIndex.kt") + public void testForInRangeToWithIndex() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInRangeToWithIndex.kt"); + } + + @TestMetadata("forInReversedStepWithIndex.kt") + public void testForInReversedStepWithIndex() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInReversedStepWithIndex.kt"); + } + + @TestMetadata("forInReversedWithIndex.kt") + public void testForInReversedWithIndex() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInReversedWithIndex.kt"); + } + + @TestMetadata("forInStepReversedWithIndex.kt") + public void testForInStepReversedWithIndex() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInStepReversedWithIndex.kt"); + } + + @TestMetadata("forInStepWithIndex.kt") + public void testForInStepWithIndex() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInStepWithIndex.kt"); + } + + @TestMetadata("forInUntilWithIndex.kt") + public void testForInUntilWithIndex() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInUntilWithIndex.kt"); + } + + @TestMetadata("forInWithIndexNoIndexOrElementVar.kt") + public void testForInWithIndexNoIndexOrElementVar() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInWithIndexNoIndexOrElementVar.kt"); + } + + @TestMetadata("forInWithIndexNotDestructured.kt") + public void testForInWithIndexNotDestructured() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInWithIndexNotDestructured.kt"); + } + + @TestMetadata("forInWithIndexReversed.kt") + public void testForInWithIndexReversed() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInWithIndexReversed.kt"); + } + + @TestMetadata("forInWithIndexWithIndex.kt") + public void testForInWithIndexWithIndex() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInWithIndexWithIndex.kt"); + } + } + @TestMetadata("compiler/testData/codegen/bytecodeText/forLoop/forInReversed") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 57a4219df36..653042a30b3 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -20265,6 +20265,84 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes } } + @TestMetadata("compiler/testData/codegen/box/ranges/forInProgressionWithIndex") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ForInProgressionWithIndex extends AbstractLightAnalysisModeTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + public void testAllFilesPresentInForInProgressionWithIndex() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/ranges/forInProgressionWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("forInDownToWithIndex.kt") + public void testForInDownToWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInDownToWithIndex.kt"); + } + + @TestMetadata("forInIndicesWithIndex.kt") + public void testForInIndicesWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInIndicesWithIndex.kt"); + } + + @TestMetadata("forInRangeToWithIndex.kt") + public void testForInRangeToWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInRangeToWithIndex.kt"); + } + + @TestMetadata("forInReversedStepWithIndex.kt") + public void testForInReversedStepWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInReversedStepWithIndex.kt"); + } + + @TestMetadata("forInReversedWithIndex.kt") + public void testForInReversedWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInReversedWithIndex.kt"); + } + + @TestMetadata("forInStepReversedWithIndex.kt") + public void testForInStepReversedWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInStepReversedWithIndex.kt"); + } + + @TestMetadata("forInStepWithIndex.kt") + public void testForInStepWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInStepWithIndex.kt"); + } + + @TestMetadata("forInUntilWithIndex.kt") + public void testForInUntilWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInUntilWithIndex.kt"); + } + + @TestMetadata("forInWithIndexNoIndexOrElementVar.kt") + public void testForInWithIndexNoIndexOrElementVar() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexNoIndexOrElementVar.kt"); + } + + @TestMetadata("forInWithIndexNotDestructured.kt") + public void testForInWithIndexNotDestructured() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexNotDestructured.kt"); + } + + @TestMetadata("forInWithIndexReversed.kt") + public void testForInWithIndexReversed() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexReversed.kt"); + } + + @TestMetadata("forInWithIndexWithDestructuringInLoop.kt") + public void testForInWithIndexWithDestructuringInLoop() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithDestructuringInLoop.kt"); + } + + @TestMetadata("forInWithIndexWithIndex.kt") + public void testForInWithIndexWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithIndex.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/ranges/forInReversed") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index 9daa941f491..dc48af0497e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -18800,6 +18800,84 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT } } + @TestMetadata("compiler/testData/codegen/box/ranges/forInProgressionWithIndex") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ForInProgressionWithIndex extends AbstractFirBlackBoxCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTestWithCustomIgnoreDirective(this::doTest, TargetBackend.JVM_IR, testDataFilePath, "// IGNORE_BACKEND_FIR: "); + } + + public void testAllFilesPresentInForInProgressionWithIndex() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/ranges/forInProgressionWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true); + } + + @TestMetadata("forInDownToWithIndex.kt") + public void testForInDownToWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInDownToWithIndex.kt"); + } + + @TestMetadata("forInIndicesWithIndex.kt") + public void testForInIndicesWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInIndicesWithIndex.kt"); + } + + @TestMetadata("forInRangeToWithIndex.kt") + public void testForInRangeToWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInRangeToWithIndex.kt"); + } + + @TestMetadata("forInReversedStepWithIndex.kt") + public void testForInReversedStepWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInReversedStepWithIndex.kt"); + } + + @TestMetadata("forInReversedWithIndex.kt") + public void testForInReversedWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInReversedWithIndex.kt"); + } + + @TestMetadata("forInStepReversedWithIndex.kt") + public void testForInStepReversedWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInStepReversedWithIndex.kt"); + } + + @TestMetadata("forInStepWithIndex.kt") + public void testForInStepWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInStepWithIndex.kt"); + } + + @TestMetadata("forInUntilWithIndex.kt") + public void testForInUntilWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInUntilWithIndex.kt"); + } + + @TestMetadata("forInWithIndexNoIndexOrElementVar.kt") + public void testForInWithIndexNoIndexOrElementVar() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexNoIndexOrElementVar.kt"); + } + + @TestMetadata("forInWithIndexNotDestructured.kt") + public void testForInWithIndexNotDestructured() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexNotDestructured.kt"); + } + + @TestMetadata("forInWithIndexReversed.kt") + public void testForInWithIndexReversed() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexReversed.kt"); + } + + @TestMetadata("forInWithIndexWithDestructuringInLoop.kt") + public void testForInWithIndexWithDestructuringInLoop() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithDestructuringInLoop.kt"); + } + + @TestMetadata("forInWithIndexWithIndex.kt") + public void testForInWithIndexWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithIndex.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/ranges/forInReversed") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index cf8f8923075..cf725fe7c47 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -18800,6 +18800,84 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes } } + @TestMetadata("compiler/testData/codegen/box/ranges/forInProgressionWithIndex") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ForInProgressionWithIndex extends AbstractIrBlackBoxCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath); + } + + public void testAllFilesPresentInForInProgressionWithIndex() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/ranges/forInProgressionWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true); + } + + @TestMetadata("forInDownToWithIndex.kt") + public void testForInDownToWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInDownToWithIndex.kt"); + } + + @TestMetadata("forInIndicesWithIndex.kt") + public void testForInIndicesWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInIndicesWithIndex.kt"); + } + + @TestMetadata("forInRangeToWithIndex.kt") + public void testForInRangeToWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInRangeToWithIndex.kt"); + } + + @TestMetadata("forInReversedStepWithIndex.kt") + public void testForInReversedStepWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInReversedStepWithIndex.kt"); + } + + @TestMetadata("forInReversedWithIndex.kt") + public void testForInReversedWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInReversedWithIndex.kt"); + } + + @TestMetadata("forInStepReversedWithIndex.kt") + public void testForInStepReversedWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInStepReversedWithIndex.kt"); + } + + @TestMetadata("forInStepWithIndex.kt") + public void testForInStepWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInStepWithIndex.kt"); + } + + @TestMetadata("forInUntilWithIndex.kt") + public void testForInUntilWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInUntilWithIndex.kt"); + } + + @TestMetadata("forInWithIndexNoIndexOrElementVar.kt") + public void testForInWithIndexNoIndexOrElementVar() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexNoIndexOrElementVar.kt"); + } + + @TestMetadata("forInWithIndexNotDestructured.kt") + public void testForInWithIndexNotDestructured() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexNotDestructured.kt"); + } + + @TestMetadata("forInWithIndexReversed.kt") + public void testForInWithIndexReversed() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexReversed.kt"); + } + + @TestMetadata("forInWithIndexWithDestructuringInLoop.kt") + public void testForInWithIndexWithDestructuringInLoop() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithDestructuringInLoop.kt"); + } + + @TestMetadata("forInWithIndexWithIndex.kt") + public void testForInWithIndexWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithIndex.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/ranges/forInReversed") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java index a5cc00ea86c..bc3e5e0e8ea 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java @@ -1962,6 +1962,79 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest { } } + @TestMetadata("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ForInProgressionWithIndex extends AbstractIrBytecodeTextTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath); + } + + public void testAllFilesPresentInForInProgressionWithIndex() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true); + } + + @TestMetadata("forInDownToWithIndex.kt") + public void testForInDownToWithIndex() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInDownToWithIndex.kt"); + } + + @TestMetadata("forInIndicesWithIndex.kt") + public void testForInIndicesWithIndex() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInIndicesWithIndex.kt"); + } + + @TestMetadata("forInRangeToWithIndex.kt") + public void testForInRangeToWithIndex() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInRangeToWithIndex.kt"); + } + + @TestMetadata("forInReversedStepWithIndex.kt") + public void testForInReversedStepWithIndex() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInReversedStepWithIndex.kt"); + } + + @TestMetadata("forInReversedWithIndex.kt") + public void testForInReversedWithIndex() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInReversedWithIndex.kt"); + } + + @TestMetadata("forInStepReversedWithIndex.kt") + public void testForInStepReversedWithIndex() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInStepReversedWithIndex.kt"); + } + + @TestMetadata("forInStepWithIndex.kt") + public void testForInStepWithIndex() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInStepWithIndex.kt"); + } + + @TestMetadata("forInUntilWithIndex.kt") + public void testForInUntilWithIndex() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInUntilWithIndex.kt"); + } + + @TestMetadata("forInWithIndexNoIndexOrElementVar.kt") + public void testForInWithIndexNoIndexOrElementVar() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInWithIndexNoIndexOrElementVar.kt"); + } + + @TestMetadata("forInWithIndexNotDestructured.kt") + public void testForInWithIndexNotDestructured() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInWithIndexNotDestructured.kt"); + } + + @TestMetadata("forInWithIndexReversed.kt") + public void testForInWithIndexReversed() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInWithIndexReversed.kt"); + } + + @TestMetadata("forInWithIndexWithIndex.kt") + public void testForInWithIndexWithIndex() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInProgressionWithIndex/forInWithIndexWithIndex.kt"); + } + } + @TestMetadata("compiler/testData/codegen/bytecodeText/forLoop/forInReversed") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 72aaa57d417..00cd0d0db6e 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -15950,6 +15950,84 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { } } + @TestMetadata("compiler/testData/codegen/box/ranges/forInProgressionWithIndex") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ForInProgressionWithIndex extends AbstractIrJsCodegenBoxTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath); + } + + public void testAllFilesPresentInForInProgressionWithIndex() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/ranges/forInProgressionWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS_IR, true); + } + + @TestMetadata("forInDownToWithIndex.kt") + public void testForInDownToWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInDownToWithIndex.kt"); + } + + @TestMetadata("forInIndicesWithIndex.kt") + public void testForInIndicesWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInIndicesWithIndex.kt"); + } + + @TestMetadata("forInRangeToWithIndex.kt") + public void testForInRangeToWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInRangeToWithIndex.kt"); + } + + @TestMetadata("forInReversedStepWithIndex.kt") + public void testForInReversedStepWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInReversedStepWithIndex.kt"); + } + + @TestMetadata("forInReversedWithIndex.kt") + public void testForInReversedWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInReversedWithIndex.kt"); + } + + @TestMetadata("forInStepReversedWithIndex.kt") + public void testForInStepReversedWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInStepReversedWithIndex.kt"); + } + + @TestMetadata("forInStepWithIndex.kt") + public void testForInStepWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInStepWithIndex.kt"); + } + + @TestMetadata("forInUntilWithIndex.kt") + public void testForInUntilWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInUntilWithIndex.kt"); + } + + @TestMetadata("forInWithIndexNoIndexOrElementVar.kt") + public void testForInWithIndexNoIndexOrElementVar() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexNoIndexOrElementVar.kt"); + } + + @TestMetadata("forInWithIndexNotDestructured.kt") + public void testForInWithIndexNotDestructured() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexNotDestructured.kt"); + } + + @TestMetadata("forInWithIndexReversed.kt") + public void testForInWithIndexReversed() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexReversed.kt"); + } + + @TestMetadata("forInWithIndexWithDestructuringInLoop.kt") + public void testForInWithIndexWithDestructuringInLoop() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithDestructuringInLoop.kt"); + } + + @TestMetadata("forInWithIndexWithIndex.kt") + public void testForInWithIndexWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithIndex.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/ranges/forInReversed") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 47245c9a160..13a9463a26b 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -17125,6 +17125,84 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { } } + @TestMetadata("compiler/testData/codegen/box/ranges/forInProgressionWithIndex") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ForInProgressionWithIndex extends AbstractJsCodegenBoxTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath); + } + + public void testAllFilesPresentInForInProgressionWithIndex() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/ranges/forInProgressionWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); + } + + @TestMetadata("forInDownToWithIndex.kt") + public void testForInDownToWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInDownToWithIndex.kt"); + } + + @TestMetadata("forInIndicesWithIndex.kt") + public void testForInIndicesWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInIndicesWithIndex.kt"); + } + + @TestMetadata("forInRangeToWithIndex.kt") + public void testForInRangeToWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInRangeToWithIndex.kt"); + } + + @TestMetadata("forInReversedStepWithIndex.kt") + public void testForInReversedStepWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInReversedStepWithIndex.kt"); + } + + @TestMetadata("forInReversedWithIndex.kt") + public void testForInReversedWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInReversedWithIndex.kt"); + } + + @TestMetadata("forInStepReversedWithIndex.kt") + public void testForInStepReversedWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInStepReversedWithIndex.kt"); + } + + @TestMetadata("forInStepWithIndex.kt") + public void testForInStepWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInStepWithIndex.kt"); + } + + @TestMetadata("forInUntilWithIndex.kt") + public void testForInUntilWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInUntilWithIndex.kt"); + } + + @TestMetadata("forInWithIndexNoIndexOrElementVar.kt") + public void testForInWithIndexNoIndexOrElementVar() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexNoIndexOrElementVar.kt"); + } + + @TestMetadata("forInWithIndexNotDestructured.kt") + public void testForInWithIndexNotDestructured() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexNotDestructured.kt"); + } + + @TestMetadata("forInWithIndexReversed.kt") + public void testForInWithIndexReversed() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexReversed.kt"); + } + + @TestMetadata("forInWithIndexWithDestructuringInLoop.kt") + public void testForInWithIndexWithDestructuringInLoop() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithDestructuringInLoop.kt"); + } + + @TestMetadata("forInWithIndexWithIndex.kt") + public void testForInWithIndexWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithIndex.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/ranges/forInReversed") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)